head_32.S 4.8 KB

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