Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
  2. #include <librm.h>
  3. #define BZI_LOAD_HIGH_ADDR 0x100000
  4. .text
  5. .arch i386
  6. .code16
  7. .section ".prefix", "ax", @progbits
  8. .globl _lkrn_start
  9. _lkrn_start:
  10. /*****************************************************************************
  11. *
  12. * Kernel header
  13. *
  14. * We place our prefix (i.e. our .prefix and .text16.early sections)
  15. * within the bzImage real-mode portion which gets loaded at
  16. * 1000:0000, and our payload (i.e. everything else) within the
  17. * bzImage protected-mode portion which gets loaded at 0x100000
  18. * upwards.
  19. *
  20. */
  21. .org 0x1f1
  22. setup_sects:
  23. .byte -1 /* Allow for initial "boot sector" */
  24. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  25. .ascii "ADHL"
  26. .long setup_sects
  27. .long 512
  28. .long 0
  29. .previous
  30. root_flags:
  31. .word 0
  32. syssize:
  33. .long 0
  34. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  35. .ascii "ADPL"
  36. .long syssize
  37. .long 16
  38. .long 0
  39. .previous
  40. ram_size:
  41. .word 0
  42. vid_mode:
  43. .word 0
  44. root_dev:
  45. .word 0
  46. boot_flag:
  47. .word 0xaa55
  48. jump:
  49. /* Manually specify a two-byte jmp instruction here rather
  50. * than leaving it up to the assembler.
  51. */
  52. .byte 0xeb, ( setup - header )
  53. header:
  54. .byte 'H', 'd', 'r', 'S'
  55. version:
  56. .word 0x0207 /* 2.07 */
  57. realmode_swtch:
  58. .long 0
  59. start_sys:
  60. .word 0
  61. kernel_version:
  62. .word version_string - 0x200
  63. type_of_loader:
  64. .byte 0
  65. loadflags:
  66. .byte 0x01 /* LOADED_HIGH */
  67. setup_move_size:
  68. .word 0
  69. code32_start:
  70. .long 0
  71. ramdisk_image:
  72. .long 0
  73. ramdisk_size:
  74. .long 0
  75. bootsect_kludge:
  76. .long 0
  77. heap_end_ptr:
  78. .word 0
  79. ext_loader_ver:
  80. .byte 0
  81. ext_loader_type:
  82. .byte 0
  83. cmd_line_ptr:
  84. .long 0
  85. initrd_addr_max:
  86. .long 0xffffffff
  87. kernel_alignment:
  88. .long 0
  89. relocatable_kernel:
  90. .byte 0
  91. min_alignment:
  92. .byte 0
  93. xloadflags:
  94. .word 0
  95. cmdline_size:
  96. .long 0x7ff
  97. hardware_subarch:
  98. .long 0
  99. hardware_subarch_data:
  100. .byte 0, 0, 0, 0, 0, 0, 0, 0
  101. version_string:
  102. .asciz VERSION
  103. /*****************************************************************************
  104. *
  105. * Setup code
  106. *
  107. */
  108. setup:
  109. /* Fix up code segment */
  110. pushw %ds
  111. pushw $1f
  112. lret
  113. 1:
  114. /* Set up stack just below 0x7c00 and clear direction flag */
  115. xorw %ax, %ax
  116. movw %ax, %ss
  117. movw $0x7c00, %sp
  118. cld
  119. /* Retrieve command-line pointer */
  120. movl cmd_line_ptr, %edx
  121. testl %edx, %edx
  122. jz no_cmd_line
  123. /* Set up %es:%di to point to command line */
  124. movl %edx, %edi
  125. andl $0xf, %edi
  126. rorl $4, %edx
  127. movw %dx, %es
  128. /* Find length of command line */
  129. pushw %di
  130. movw $0xffff, %cx
  131. repnz scasb
  132. notw %cx
  133. popw %si
  134. /* Make space for command line on stack */
  135. movw %sp, %di
  136. subw %cx, %di
  137. andw $~0xf, %di
  138. movw %di, %sp
  139. /* Copy command line to stack */
  140. pushw %ds
  141. pushw %es
  142. popw %ds
  143. pushw %ss
  144. popw %es
  145. rep movsb
  146. popw %ds
  147. /* Store new command-line pointer */
  148. movzwl %sp, %edx
  149. no_cmd_line:
  150. /* Calculate maximum relocation address */
  151. movl ramdisk_image, %ebp
  152. testl %ebp, %ebp
  153. jnz 1f
  154. orl $0xffffffff, %ebp /* Allow arbitrary relocation if no initrd */
  155. 1:
  156. /* Install iPXE */
  157. call alloc_basemem
  158. xorl %esi, %esi
  159. xorl %edi, %edi
  160. call install_prealloc
  161. /* Set up real-mode stack */
  162. movw %bx, %ss
  163. movw $_estack16, %sp
  164. /* Jump to .text16 segment */
  165. pushw %ax
  166. pushw $1f
  167. lret
  168. .section ".text16", "awx", @progbits
  169. 1:
  170. /* Retrieve initrd pointer and size */
  171. movl ramdisk_image, %ebp
  172. movl ramdisk_size, %ecx
  173. /* Set up %ds for access to .data16 */
  174. movw %bx, %ds
  175. /* Store command-line pointer */
  176. movl %edx, cmdline_phys
  177. /* Store initrd pointer and size */
  178. movl %ebp, initrd_phys
  179. movl %ecx, initrd_len
  180. /* Run iPXE */
  181. virtcall main
  182. /* Uninstall iPXE */
  183. call uninstall
  184. /* Boot next device */
  185. int $0x18
  186. /*****************************************************************************
  187. *
  188. * Open payload (called by libprefix)
  189. *
  190. * Parameters:
  191. * %ds:0000 : Prefix
  192. * %esi : Buffer for copy of image source (or zero if no buffer available)
  193. * %ecx : Expected offset within buffer of first payload block
  194. * Returns:
  195. * %esi : Valid image source address (buffered or unbuffered)
  196. * %ecx : Actual offset within buffer of first payload block
  197. * CF set on error
  198. */
  199. .section ".text16.early", "awx", @progbits
  200. .globl open_payload
  201. open_payload:
  202. /* Our payload will always end up at BZI_LOAD_HIGH_ADDR */
  203. movl $BZI_LOAD_HIGH_ADDR, %esi
  204. xorl %ecx, %ecx
  205. lret
  206. /* Payload must be aligned to a whole number of setup sectors */
  207. .globl _payload_align
  208. .equ _payload_align, 512