head_32.S 3.9 KB

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