head_32.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_types.h>
  26. #include <asm/boot.h>
  27. #include <asm/asm-offsets.h>
  28. .section ".text.head","ax",@progbits
  29. ENTRY(startup_32)
  30. cld
  31. /*
  32. * Test KEEP_SEGMENTS flag to see if the bootloader is asking
  33. * us to not reload segments
  34. */
  35. testb $(1<<6), BP_loadflags(%esi)
  36. jnz 1f
  37. cli
  38. movl $__BOOT_DS, %eax
  39. movl %eax, %ds
  40. movl %eax, %es
  41. movl %eax, %fs
  42. movl %eax, %gs
  43. movl %eax, %ss
  44. 1:
  45. /*
  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 (BP_scratch+4)(%esi), %esp
  54. call 1f
  55. 1: popl %ebp
  56. subl $1b, %ebp
  57. /*
  58. * %ebp contains the address we are loaded at by the boot loader and %ebx
  59. * contains the address where we should move the kernel image temporarily
  60. * for safe in-place decompression.
  61. */
  62. #ifdef CONFIG_RELOCATABLE
  63. movl %ebp, %ebx
  64. movl BP_kernel_alignment(%esi), %eax
  65. decl %eax
  66. addl %eax, %ebx
  67. notl %eax
  68. andl %eax, %ebx
  69. #else
  70. movl $LOAD_PHYSICAL_ADDR, %ebx
  71. #endif
  72. /* Target address to relocate to for decompression */
  73. addl $z_extract_offset, %ebx
  74. /* Set up the stack */
  75. leal boot_stack_end(%ebx), %esp
  76. /* Zero EFLAGS */
  77. pushl $0
  78. popfl
  79. /*
  80. * Copy the compressed kernel to the end of our buffer
  81. * where decompression in place becomes safe.
  82. */
  83. pushl %esi
  84. leal (_bss-4)(%ebp), %esi
  85. leal (_bss-4)(%ebx), %edi
  86. movl $(_bss - startup_32), %ecx
  87. shrl $2, %ecx
  88. std
  89. rep movsl
  90. cld
  91. popl %esi
  92. /*
  93. * Jump to the relocated address.
  94. */
  95. leal relocated(%ebx), %eax
  96. jmp *%eax
  97. ENDPROC(startup_32)
  98. .text
  99. relocated:
  100. /*
  101. * Clear BSS (stack is currently empty)
  102. */
  103. xorl %eax, %eax
  104. leal _bss(%ebx), %edi
  105. leal _ebss(%ebx), %ecx
  106. subl %edi, %ecx
  107. shrl $2, %ecx
  108. rep stosl
  109. /*
  110. * Do the decompression, and jump to the new kernel..
  111. */
  112. leal z_extract_offset_negative(%ebx), %ebp
  113. /* push arguments for decompress_kernel: */
  114. pushl %ebp /* output address */
  115. pushl $z_input_len /* input_len */
  116. leal input_data(%ebx), %eax
  117. pushl %eax /* input_data */
  118. leal boot_heap(%ebx), %eax
  119. pushl %eax /* heap area */
  120. pushl %esi /* real mode pointer */
  121. call decompress_kernel
  122. addl $20, %esp
  123. #if CONFIG_RELOCATABLE
  124. /*
  125. * Find the address of the relocations.
  126. */
  127. leal z_output_len(%ebp), %edi
  128. /*
  129. * Calculate the delta between where vmlinux was compiled to run
  130. * and where it was actually loaded.
  131. */
  132. movl %ebp, %ebx
  133. subl $LOAD_PHYSICAL_ADDR, %ebx
  134. jz 2f /* Nothing to be done if loaded at compiled addr. */
  135. /*
  136. * Process relocations.
  137. */
  138. 1: subl $4, %edi
  139. movl (%edi), %ecx
  140. testl %ecx, %ecx
  141. jz 2f
  142. addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
  143. jmp 1b
  144. 2:
  145. #endif
  146. /*
  147. * Jump to the decompressed kernel.
  148. */
  149. xorl %ebx, %ebx
  150. jmp *%ebp
  151. /*
  152. * Stack and heap for uncompression
  153. */
  154. .bss
  155. .balign 4
  156. boot_heap:
  157. .fill BOOT_HEAP_SIZE, 1, 0
  158. boot_stack:
  159. .fill BOOT_STACK_SIZE, 1, 0
  160. boot_stack_end: