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