head_32.S 4.3 KB

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