head_32.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/linkage.h>
  24. #include <asm/segment.h>
  25. #include <asm/page.h>
  26. #include <asm/boot.h>
  27. #include <asm/asm-offsets.h>
  28. .section ".text.head","ax",@progbits
  29. .globl startup_32
  30. startup_32:
  31. cld
  32. /* test KEEP_SEGMENTS flag to see if the bootloader is asking
  33. * us to not reload segments */
  34. testb $(1<<6), BP_loadflags(%esi)
  35. jnz 1f
  36. cli
  37. movl $(__BOOT_DS),%eax
  38. movl %eax,%ds
  39. movl %eax,%es
  40. movl %eax,%fs
  41. movl %eax,%gs
  42. movl %eax,%ss
  43. 1:
  44. /* Calculate the delta between where we were compiled to run
  45. * at and where we were actually loaded at. This can only be done
  46. * with a short local call on x86. Nothing else will tell us what
  47. * address we are running at. The reserved chunk of the real-mode
  48. * data at 0x1e4 (defined as a scratch field) are used as the stack
  49. * for this calculation. Only 4 bytes are needed.
  50. */
  51. leal (0x1e4+4)(%esi), %esp
  52. call 1f
  53. 1: popl %ebp
  54. subl $1b, %ebp
  55. /* %ebp contains the address we are loaded at by the boot loader and %ebx
  56. * contains the address where we should move the kernel image temporarily
  57. * for safe in-place decompression.
  58. */
  59. #ifdef CONFIG_RELOCATABLE
  60. movl %ebp, %ebx
  61. addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
  62. andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
  63. #else
  64. movl $LOAD_PHYSICAL_ADDR, %ebx
  65. #endif
  66. /* Replace the compressed data size with the uncompressed size */
  67. subl input_len(%ebp), %ebx
  68. movl output_len(%ebp), %eax
  69. addl %eax, %ebx
  70. /* Add 8 bytes for every 32K input block */
  71. shrl $12, %eax
  72. addl %eax, %ebx
  73. /* Add 32K + 18 bytes of extra slack */
  74. addl $(32768 + 18), %ebx
  75. /* Align on a 4K boundary */
  76. addl $4095, %ebx
  77. andl $~4095, %ebx
  78. /* Copy the compressed kernel to the end of our buffer
  79. * where decompression in place becomes safe.
  80. */
  81. pushl %esi
  82. leal _end(%ebp), %esi
  83. leal _end(%ebx), %edi
  84. movl $(_end - startup_32), %ecx
  85. std
  86. rep
  87. movsb
  88. cld
  89. popl %esi
  90. /* Compute the kernel start address.
  91. */
  92. #ifdef CONFIG_RELOCATABLE
  93. addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
  94. andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
  95. #else
  96. movl $LOAD_PHYSICAL_ADDR, %ebp
  97. #endif
  98. /*
  99. * Jump to the relocated address.
  100. */
  101. leal relocated(%ebx), %eax
  102. jmp *%eax
  103. .section ".text"
  104. relocated:
  105. /*
  106. * Clear BSS
  107. */
  108. xorl %eax,%eax
  109. leal _edata(%ebx),%edi
  110. leal _end(%ebx), %ecx
  111. subl %edi,%ecx
  112. cld
  113. rep
  114. stosb
  115. /*
  116. * Setup the stack for the decompressor
  117. */
  118. leal boot_stack_end(%ebx), %esp
  119. /*
  120. * Do the decompression, and jump to the new kernel..
  121. */
  122. movl output_len(%ebx), %eax
  123. pushl %eax
  124. # push arguments for decompress_kernel:
  125. pushl %ebp # output address
  126. movl input_len(%ebx), %eax
  127. pushl %eax # input_len
  128. leal input_data(%ebx), %eax
  129. pushl %eax # input_data
  130. leal boot_heap(%ebx), %eax
  131. pushl %eax # heap area
  132. pushl %esi # real mode pointer
  133. call decompress_kernel
  134. addl $20, %esp
  135. popl %ecx
  136. #if CONFIG_RELOCATABLE
  137. /* Find the address of the relocations.
  138. */
  139. movl %ebp, %edi
  140. addl %ecx, %edi
  141. /* Calculate the delta between where vmlinux was compiled to run
  142. * and where it was actually loaded.
  143. */
  144. movl %ebp, %ebx
  145. subl $LOAD_PHYSICAL_ADDR, %ebx
  146. jz 2f /* Nothing to be done if loaded at compiled addr. */
  147. /*
  148. * Process relocations.
  149. */
  150. 1: subl $4, %edi
  151. movl 0(%edi), %ecx
  152. testl %ecx, %ecx
  153. jz 2f
  154. addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
  155. jmp 1b
  156. 2:
  157. #endif
  158. /*
  159. * Jump to the decompressed kernel.
  160. */
  161. xorl %ebx,%ebx
  162. jmp *%ebp
  163. .bss
  164. /* Stack and heap for uncompression */
  165. .balign 4
  166. boot_heap:
  167. .fill BOOT_HEAP_SIZE, 1, 0
  168. boot_stack:
  169. .fill BOOT_STACK_SIZE, 1, 0
  170. boot_stack_end: