head_32.S 3.8 KB

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