head_32.S 4.5 KB

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