head_32.S 4.4 KB

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