Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

lkrnprefix.S 4.3KB

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