head_32.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * linux/boot/head.S
  3. *
  4. * Copyright (C) 1991, 1992, 1993 Linus Torvalds
  5. */
  6. /*
  7. * head.S contains the 32-bit startup code.
  8. *
  9. * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
  10. * the page directory will exist. The startup code will be overwritten by
  11. * the page directory. [According to comments etc elsewhere on a compressed
  12. * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
  13. *
  14. * Page 0 is deliberately kept safe, since System Management Mode code in
  15. * laptops may need to access the BIOS data stored there. This is also
  16. * useful for future device drivers that either access the BIOS via VM86
  17. * mode.
  18. */
  19. /*
  20. * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  21. */
  22. .text
  23. #include <linux/init.h>
  24. #include <linux/linkage.h>
  25. #include <asm/segment.h>
  26. #include <asm/page_types.h>
  27. #include <asm/boot.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/bootparam.h>
  30. __HEAD
  31. ENTRY(startup_32)
  32. #ifdef CONFIG_EFI_STUB
  33. jmp preferred_addr
  34. /*
  35. * We don't need the return address, so set up the stack so
  36. * efi_main() can find its arguments.
  37. */
  38. ENTRY(efi_pe_entry)
  39. add $0x4, %esp
  40. call 1f
  41. 1: popl %esi
  42. subl $1b, %esi
  43. popl %ecx
  44. movl %ecx, efi32_config(%esi) /* Handle */
  45. popl %ecx
  46. movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
  47. /* Relocate efi_config->call() */
  48. leal efi32_config(%esi), %eax
  49. add %esi, 88(%eax)
  50. pushl %eax
  51. call make_boot_params
  52. cmpl $0, %eax
  53. je fail
  54. movl %esi, BP_code32_start(%eax)
  55. popl %ecx
  56. pushl %eax
  57. pushl %ecx
  58. jmp 2f /* Skip efi_config initialization */
  59. ENTRY(efi32_stub_entry)
  60. add $0x4, %esp
  61. popl %ecx
  62. popl %edx
  63. call 1f
  64. 1: popl %esi
  65. subl $1b, %esi
  66. movl %ecx, efi32_config(%esi) /* Handle */
  67. movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
  68. /* Relocate efi_config->call() */
  69. leal efi32_config(%esi), %eax
  70. add %esi, 88(%eax)
  71. pushl %eax
  72. 2:
  73. call efi_main
  74. cmpl $0, %eax
  75. movl %eax, %esi
  76. jne 2f
  77. fail:
  78. /* EFI init failed, so hang. */
  79. hlt
  80. jmp fail
  81. 2:
  82. movl BP_code32_start(%esi), %eax
  83. leal preferred_addr(%eax), %eax
  84. jmp *%eax
  85. preferred_addr:
  86. #endif
  87. cld
  88. /*
  89. * Test KEEP_SEGMENTS flag to see if the bootloader is asking
  90. * us to not reload segments
  91. */
  92. testb $KEEP_SEGMENTS, BP_loadflags(%esi)
  93. jnz 1f
  94. cli
  95. movl $__BOOT_DS, %eax
  96. movl %eax, %ds
  97. movl %eax, %es
  98. movl %eax, %fs
  99. movl %eax, %gs
  100. movl %eax, %ss
  101. 1:
  102. /*
  103. * Calculate the delta between where we were compiled to run
  104. * at and where we were actually loaded at. This can only be done
  105. * with a short local call on x86. Nothing else will tell us what
  106. * address we are running at. The reserved chunk of the real-mode
  107. * data at 0x1e4 (defined as a scratch field) are used as the stack
  108. * for this calculation. Only 4 bytes are needed.
  109. */
  110. leal (BP_scratch+4)(%esi), %esp
  111. call 1f
  112. 1: popl %ebp
  113. subl $1b, %ebp
  114. /*
  115. * %ebp contains the address we are loaded at by the boot loader and %ebx
  116. * contains the address where we should move the kernel image temporarily
  117. * for safe in-place decompression.
  118. */
  119. #ifdef CONFIG_RELOCATABLE
  120. movl %ebp, %ebx
  121. movl BP_kernel_alignment(%esi), %eax
  122. decl %eax
  123. addl %eax, %ebx
  124. notl %eax
  125. andl %eax, %ebx
  126. cmpl $LOAD_PHYSICAL_ADDR, %ebx
  127. jge 1f
  128. #endif
  129. movl $LOAD_PHYSICAL_ADDR, %ebx
  130. 1:
  131. /* Target address to relocate to for decompression */
  132. addl $z_extract_offset, %ebx
  133. /* Set up the stack */
  134. leal boot_stack_end(%ebx), %esp
  135. /* Zero EFLAGS */
  136. pushl $0
  137. popfl
  138. /*
  139. * Copy the compressed kernel to the end of our buffer
  140. * where decompression in place becomes safe.
  141. */
  142. pushl %esi
  143. leal (_bss-4)(%ebp), %esi
  144. leal (_bss-4)(%ebx), %edi
  145. movl $(_bss - startup_32), %ecx
  146. shrl $2, %ecx
  147. std
  148. rep movsl
  149. cld
  150. popl %esi
  151. /*
  152. * Jump to the relocated address.
  153. */
  154. leal relocated(%ebx), %eax
  155. jmp *%eax
  156. ENDPROC(startup_32)
  157. .text
  158. relocated:
  159. /*
  160. * Clear BSS (stack is currently empty)
  161. */
  162. xorl %eax, %eax
  163. leal _bss(%ebx), %edi
  164. leal _ebss(%ebx), %ecx
  165. subl %edi, %ecx
  166. shrl $2, %ecx
  167. rep stosl
  168. /*
  169. * Adjust our own GOT
  170. */
  171. leal _got(%ebx), %edx
  172. leal _egot(%ebx), %ecx
  173. 1:
  174. cmpl %ecx, %edx
  175. jae 2f
  176. addl %ebx, (%edx)
  177. addl $4, %edx
  178. jmp 1b
  179. 2:
  180. /*
  181. * Do the decompression, and jump to the new kernel..
  182. */
  183. /* push arguments for decompress_kernel: */
  184. pushl $z_run_size /* size of kernel with .bss and .brk */
  185. pushl $z_output_len /* decompressed length, end of relocs */
  186. leal z_extract_offset_negative(%ebx), %ebp
  187. pushl %ebp /* output address */
  188. pushl $z_input_len /* input_len */
  189. leal input_data(%ebx), %eax
  190. pushl %eax /* input_data */
  191. leal boot_heap(%ebx), %eax
  192. pushl %eax /* heap area */
  193. pushl %esi /* real mode pointer */
  194. call decompress_kernel /* returns kernel location in %eax */
  195. addl $28, %esp
  196. /*
  197. * Jump to the decompressed kernel.
  198. */
  199. xorl %ebx, %ebx
  200. jmp *%eax
  201. #ifdef CONFIG_EFI_STUB
  202. .data
  203. efi32_config:
  204. .fill 11,8,0
  205. .long efi_call_phys
  206. .long 0
  207. .byte 0
  208. #endif
  209. /*
  210. * Stack and heap for uncompression
  211. */
  212. .bss
  213. .balign 4
  214. boot_heap:
  215. .fill BOOT_HEAP_SIZE, 1, 0
  216. boot_stack:
  217. .fill BOOT_STACK_SIZE, 1, 0
  218. boot_stack_end: