head_32.S 4.6 KB

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