head.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. .section ".text.head"
  27. .globl startup_32
  28. startup_32:
  29. cld
  30. cli
  31. movl $(__BOOT_DS),%eax
  32. movl %eax,%ds
  33. movl %eax,%es
  34. movl %eax,%fs
  35. movl %eax,%gs
  36. movl %eax,%ss
  37. /* Calculate the delta between where we were compiled to run
  38. * at and where we were actually loaded at. This can only be done
  39. * with a short local call on x86. Nothing else will tell us what
  40. * address we are running at. The reserved chunk of the real-mode
  41. * data at 0x34-0x3f are used as the stack for this calculation.
  42. * Only 4 bytes are needed.
  43. */
  44. leal 0x40(%esi), %esp
  45. call 1f
  46. 1: popl %ebp
  47. subl $1b, %ebp
  48. /* Compute the delta between where we were compiled to run at
  49. * and where the code will actually run at.
  50. */
  51. /* Start with the delta to where the kernel will run at. If we are
  52. * a relocatable kernel this is the delta to our load address otherwise
  53. * this is the delta to CONFIG_PHYSICAL start.
  54. */
  55. #ifdef CONFIG_RELOCATABLE
  56. movl %ebp, %ebx
  57. #else
  58. movl $(CONFIG_PHYSICAL_START - startup_32), %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. leal startup_32(%ebp), %ebp
  88. #else
  89. movl $CONFIG_PHYSICAL_START, %ebp
  90. #endif
  91. /*
  92. * Jump to the relocated address.
  93. */
  94. leal relocated(%ebx), %eax
  95. jmp *%eax
  96. .section ".text"
  97. relocated:
  98. /*
  99. * Clear BSS
  100. */
  101. xorl %eax,%eax
  102. leal _edata(%ebx),%edi
  103. leal _end(%ebx), %ecx
  104. subl %edi,%ecx
  105. cld
  106. rep
  107. stosb
  108. /*
  109. * Setup the stack for the decompressor
  110. */
  111. leal stack_end(%ebx), %esp
  112. /*
  113. * Do the decompression, and jump to the new kernel..
  114. */
  115. movl output_len(%ebx), %eax
  116. pushl %eax
  117. pushl %ebp # output address
  118. movl input_len(%ebx), %eax
  119. pushl %eax # input_len
  120. leal input_data(%ebx), %eax
  121. pushl %eax # input_data
  122. leal _end(%ebx), %eax
  123. pushl %eax # end of the image as third argument
  124. pushl %esi # real mode pointer as second arg
  125. call decompress_kernel
  126. addl $20, %esp
  127. popl %ecx
  128. #if CONFIG_RELOCATABLE
  129. /* Find the address of the relocations.
  130. */
  131. movl %ebp, %edi
  132. addl %ecx, %edi
  133. /* Calculate the delta between where vmlinux was compiled to run
  134. * and where it was actually loaded.
  135. */
  136. movl %ebp, %ebx
  137. subl $CONFIG_PHYSICAL_START, %ebx
  138. /*
  139. * Process relocations.
  140. */
  141. 1: subl $4, %edi
  142. movl 0(%edi), %ecx
  143. testl %ecx, %ecx
  144. jz 2f
  145. addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
  146. jmp 1b
  147. 2:
  148. #endif
  149. /*
  150. * Jump to the decompressed kernel.
  151. */
  152. xorl %ebx,%ebx
  153. jmp *%ebp
  154. .bss
  155. .balign 4
  156. stack:
  157. .fill 4096, 1, 0
  158. stack_end: