vesa_stage.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * VESA real-mode stage: runs at 0x7E00 before protected mode.
  3. *
  4. * Called by the boot sector in real mode (CS=0, IP=0x7E00).
  5. * Probes the E820 map, loads the compressed command-pack rootfs in 16 KB
  6. * chunks through the 0x3000 staging buffer and copies each chunk straight
  7. * above the 8 MB VGA-shadow reserve (PACK_HIGH_ADDR) with a temporary
  8. * flat protected-mode rep movsb. The X201 BIOS silently turns the
  9. * equivalent INT 15h AH=87h block move into zeros for this range, which
  10. * left the kernel with an empty pack. The stage then walks the VBE mode
  11. * list and picks the best mode (highest resolution,
  12. * >= 16 bpp, LFB, fits in VRAM), writes the mode info to 0x600 and the boot
  13. * info to 0x500, then enables A20, enters protected mode and jumps to
  14. * kernel_entry. Because the pack never occupies the low gap behind the
  15. * kernel, the pack size is bounded by RAM, not by 0x60000..0x9FBFF, and the
  16. * kernel BSS/boot stack may extend far past 0x60000.
  17. *
  18. * If no VESA mode works, boots in text mode (valid=0 at 0x600).
  19. */
  20. .code16
  21. .section .text.stage2, "ax", @progbits
  22. .globl _vesa_stage
  23. /* E820 map constants (must match mm.h). */
  24. .equ E820_MAGIC, 0xE820E820
  25. .equ E820_BUF_END, 0x1008 + 32*24 /* 32 entries * 24 bytes */
  26. /* Rootfs/boot-info constants (must match rootfs.h / bootinfo.h). */
  27. .equ ROOTFS_VERSION, 1
  28. .equ PACK_MAX, 0x200000 /* 2 MB compressed rootfs cap */
  29. .equ PACK_HIGH_ADDR, 0x900000 /* above the 8 MB VGA-shadow reserve */
  30. .equ BOOT_INFO_MAGIC, 0x4E425349
  31. .equ BOOT_INFO_VERSION, 2
  32. .equ BOOT_INFO_WORDS, 12
  33. _vesa_stage:
  34. xorw %ax, %ax
  35. movw %ax, %ds
  36. movw %ax, %es
  37. cld
  38. movb %dl, stage_drive
  39. /* Ask the BIOS whether this drive supports EDD LBA reads. USB sticks
  40. * are sometimes presented as floppies (DL=0); the CHS geometry used
  41. * below cannot reach a rootfs image there. */
  42. movb stage_drive, %dl
  43. movb $0x41, %ah
  44. movw $0x55AA, %bx
  45. int $0x13
  46. jc 1f
  47. cmpw $0xAA55, %bx
  48. jne 1f
  49. testb $0x01, %cl
  50. jz 1f
  51. movb $1, use_lba
  52. 1: xorw %ax, %ax
  53. movw %ax, %ds
  54. movw %ax, %es
  55. /* No UEFI boot-info block on the BIOS path (see bootinfo.h). The boot
  56. * sector used 0x500 as its disk-address packet, so clear the magic;
  57. * write_bootinfo fills in the real block before the PM jump. */
  58. movl $0, 0x500
  59. /* ---- Probe INT 15h E820 memory map into 0:0x1000 ----
  60. * Layout (see mm.h): [magic u32][count u32][24-byte entries...].
  61. * Stored below the kernel (0x7E00) so it survives kexec reloads,
  62. * which re-run kernel_main but not this real-mode stage. */
  63. movl $E820_MAGIC, 0x1000 /* magic */
  64. movl $0, 0x1004 /* count = 0 */
  65. xorl %ebx, %ebx /* continuation value */
  66. movl $0x1008, %edi /* ES:DI -> first entry */
  67. e820_loop:
  68. xorw %ax, %ax
  69. movw %ax, %es /* (re)set ES for the BIOS buffer */
  70. movl $0xE820, %eax
  71. movl $0x534D4150, %edx /* "SMAP" */
  72. movl $24, %ecx
  73. int $0x15
  74. jc e820_done /* CF set -> unsupported / done */
  75. cmpl $0x534D4150, %eax
  76. jne e820_done /* not "SMAP" -> done */
  77. cmpb $20, %cl
  78. jb e820_done /* too short -> stop */
  79. movl $0, 20(%edi) /* zero ACPI attrs (BIOS may write 20 B) */
  80. incl 0x1004 /* count++ */
  81. addl $24, %edi
  82. testl %ebx, %ebx
  83. jz e820_done /* continuation == 0 -> done */
  84. cmpl $E820_BUF_END, %edi
  85. jae e820_done /* buffer full -> stop */
  86. jmp e820_loop
  87. e820_done:
  88. /* ---- Rootfs: load the command pack directly to high memory ----
  89. * The pack is a gzip blob behind a one-sector NBROOT1 header (rootfs.h).
  90. * Each 16 KB chunk is read into 0x3000 and copied to PACK_HIGH_ADDR with
  91. * INT 15h AH=87h, so the size is no longer limited by the
  92. * 0x60000..0x9FBFF low gap. A20 must be on before the first high write;
  93. * the old path enabled it only at stage_finish. The kernel sanitizes
  94. * CR4/EFER after this BIOS call (the X201 leaves translation state
  95. * behind). */
  96. call enable_a20
  97. xorw %ax, %ax
  98. movw %ax, %ds
  99. movw %ax, %es
  100. movl 0x7C42, %eax /* boot-sector pack_lba field */
  101. movl %eax, pack_lba
  102. movl $0, pack_addr
  103. movl $0, pack_bytes
  104. movw $msg_pack, %si
  105. call print_str
  106. movzbl stage_drive, %eax
  107. call print_hex32
  108. movw $msg_lba, %si
  109. call print_str
  110. movl pack_lba, %eax
  111. call print_hex32
  112. movw $msg_e, %si
  113. call print_str
  114. movzbl use_lba, %eax
  115. addl $'0', %eax
  116. movb $0x0E, %ah
  117. movb $0x00, %bh
  118. int $0x10
  119. movw $msg_m, %si
  120. call print_str
  121. cmpb $0x80, stage_drive
  122. jb 1f
  123. movb $'L', %al
  124. jmp 2f
  125. 1: movb $'C', %al
  126. 2: movb $0x0E, %ah
  127. movb $0x00, %bh
  128. int $0x10
  129. movw $msg_end, %si
  130. call print_str
  131. xorw %ax, %ax
  132. movw %ax, %ds
  133. movw %ax, %es
  134. /* Read and validate the header, then copy the payload in 16 KB
  135. * chunks (32 sectors) through the 0x3000 staging buffer. */
  136. cmpl $0, pack_lba
  137. je pack_fail
  138. movl pack_lba, %eax
  139. movw $1, %cx
  140. call read_sectors
  141. jc pack_fail
  142. /* Validate the header at 0x3000: "NBROOT1\0", version 1. */
  143. movl $0x3000, %esi
  144. movl 0(%esi), %eax
  145. cmpl $0x4F52424E, %eax /* "NBRO" */
  146. jne pack_fail
  147. movl 4(%esi), %eax
  148. cmpl $0x0031544F, %eax /* "OT1\0" */
  149. jne pack_fail
  150. cmpl $ROOTFS_VERSION, 8(%esi)
  151. jne pack_fail
  152. movl 12(%esi), %eax /* pack_bytes */
  153. testl %eax, %eax
  154. jz pack_fail
  155. cmpl $PACK_MAX, %eax
  156. ja pack_fail
  157. movl %eax, pack_bytes
  158. movw $msg_dot, %si
  159. call print_str
  160. movl $0, pack_off
  161. load_loop:
  162. movl pack_off, %eax
  163. cmpl pack_bytes, %eax
  164. jae load_ok
  165. movl pack_bytes, %ecx
  166. subl %eax, %ecx
  167. addl $511, %ecx
  168. shrl $9, %ecx
  169. cmpl $32, %ecx
  170. jbe 1f
  171. movl $32, %ecx
  172. 1: movl %ecx, chunk_sectors
  173. movl pack_off, %eax
  174. shrl $9, %eax
  175. addl pack_lba, %eax
  176. incl %eax /* pack data starts after the header */
  177. call read_sectors
  178. jc pack_fail
  179. movl chunk_sectors, %eax
  180. shll $9, %eax
  181. movl %eax, copy_len
  182. movl $PACK_HIGH_ADDR, %eax
  183. addl pack_off, %eax
  184. movl %eax, copy_dst
  185. call pm_copy
  186. movl chunk_sectors, %eax
  187. shll $9, %eax
  188. addl %eax, pack_off
  189. movw $msg_dot, %si
  190. call print_str
  191. jmp load_loop
  192. load_ok:
  193. movl $PACK_HIGH_ADDR, pack_addr
  194. movw $msg_ok, %si
  195. call print_str
  196. jmp pack_done
  197. pack_fail:
  198. movw $msg_fail, %si
  199. call print_str
  200. pack_clear:
  201. movl $0, pack_addr
  202. movl $0, pack_bytes
  203. pack_done:
  204. /* read_sectors leaves ES at the staging segment; the VBE calls below
  205. * expect a normal zero segment. */
  206. xorw %ax, %ax
  207. movw %ax, %ds
  208. movw %ax, %es
  209. /* ---- VBE Controller Info into 0:0x2000 ---- */
  210. movw $0x2000, %di
  211. movw $0x4256, (%di) /* "VB" */
  212. movw $0x3245, 2(%di) /* "E2" */
  213. movw $0x4F00, %ax
  214. int $0x10
  215. cmpw $0x004F, %ax
  216. jnz vesa_no_vbe
  217. /* Save VRAM size (offset 0x12: TotalMemory in 64KB blocks). */
  218. movw 0x12(%di), %ax
  219. testw %ax, %ax
  220. jnz 1f
  221. movw $0xFFFF, %ax
  222. 1: movw %ax, vram_64k
  223. /* Get mode list pointer (offset 0x0E: far pointer seg:off). */
  224. movw 0x200E, %si /* offset (buffer at 0x2000) */
  225. movw 0x2010, %ax /* segment */
  226. movw %ax, %fs /* FS:SI = mode list */
  227. /* ---- Walk mode list, pick best mode ---- */
  228. movw $0, best_mode
  229. movl $0, best_score
  230. walk_modes:
  231. movw %fs:(%si), %cx
  232. cmpw $0xFFFF, %cx
  233. jz walk_done
  234. addw $2, %si
  235. /* Query mode info: VBE 4F01h into 0:0x2200. */
  236. pushw %si
  237. pushw %cx
  238. xorw %ax, %ax
  239. movw %ax, %es
  240. movw $0x2200, %di
  241. movw $0x4F01, %ax
  242. int $0x10
  243. popw %cx
  244. popw %si
  245. cmpw $0x004F, %ax
  246. jnz walk_modes
  247. /* Check: supported (bit 0) + graphics (bit 4) + LFB (bit 7). */
  248. movw 0x2200, %ax
  249. andw $0x0091, %ax
  250. cmpw $0x0091, %ax
  251. jnz walk_modes
  252. /* Check: BitsPerPixel >= 16. */
  253. cmpb $16, 0x2219
  254. jb walk_modes
  255. /* 1920x1080x32 fits the 8 MB shadow reserve and the 4 MB window
  256. * canvas slot; wider modes would need a larger shadow. */
  257. cmpw $1920, 0x2212
  258. ja walk_modes
  259. /* Check: fits in VRAM. */
  260. movw 0x2210, %ax
  261. mulw 0x2214
  262. testw %ax, %ax
  263. jz 2f
  264. incw %dx
  265. 2: cmpw vram_64k, %dx
  266. ja walk_modes
  267. /* Keep the 32bpp shadow inside the 8 MB reserve at 0x100000:
  268. * pitch * height must not exceed 8 MB. This rejects 1920x1200
  269. * (9.2 MB) while allowing 1920x1080 (8.29 MB). */
  270. movzwl 0x2210, %eax /* bytes per scanline */
  271. movzwl 0x2214, %edx /* height */
  272. imull %edx, %eax
  273. cmpl $0x800000, %eax
  274. ja walk_modes
  275. /* The WM maps every window's RGB565 canvas in a 4 MB slot. A
  276. * 1920x1200 canvas needs 4.6 MB, so cap the mode at 2 M pixels
  277. * (1920x1080 = 2.07 M fits). */
  278. movzwl 0x2212, %eax /* width */
  279. movzwl 0x2214, %edx /* height */
  280. imull %edx, %eax
  281. cmpl $0x200000, %eax
  282. ja walk_modes
  283. /* Score = width * height + bpp. */
  284. movzwl 0x2212, %eax
  285. movzwl 0x2214, %edx
  286. imull %edx, %eax
  287. movzbl 0x2219, %edx
  288. addl %edx, %eax
  289. cmpl best_score, %eax
  290. jbe walk_modes
  291. movl %eax, best_score
  292. movw %cx, best_mode
  293. /* Save mode info block to 0:0x2400. */
  294. pushw %si
  295. pushw %cx
  296. movw $0x2200, %si
  297. movw $0x2400, %di
  298. movw $128, %cx
  299. cld
  300. rep movsw
  301. popw %cx
  302. popw %si
  303. jmp walk_modes
  304. walk_done:
  305. /* Did we find a mode? */
  306. movw best_mode, %cx
  307. testw %cx, %cx
  308. jz vesa_no_vbe
  309. /* ---- Set the mode ---- */
  310. movw %cx, %bx
  311. orw $0x4000, %bx /* LFB */
  312. movw $0x4F02, %ax
  313. int $0x10
  314. cmpw $0x004F, %ax
  315. jnz vesa_no_vbe
  316. /* ---- Fill 0x600 boot FB info from saved block at 0x2400 ---- */
  317. movw $0x600, %bx
  318. movb $1, (%bx)
  319. movw 0x2412, %ax
  320. movw %ax, 1(%bx) /* width */
  321. movw 0x2414, %ax
  322. movw %ax, 3(%bx) /* height */
  323. movw 0x2410, %ax
  324. movw %ax, 5(%bx) /* pitch */
  325. movb 0x2419, %al
  326. movb %al, 7(%bx) /* bpp */
  327. movw 0x2428, %ax
  328. movw %ax, 8(%bx) /* lfb_base lo */
  329. movw 0x242A, %ax
  330. movw %ax, 10(%bx) /* lfb_base hi */
  331. movw vram_64k, %ax
  332. movw %ax, 12(%bx) /* vram_64k */
  333. jmp stage_finish
  334. vesa_no_vbe:
  335. /* No VESA: stay in text mode, mark fb info invalid. */
  336. movw $0x600, %bx
  337. movb $0, (%bx)
  338. stage_finish:
  339. /* The pack is loaded (A20 is already on); finish boot info and enter
  340. * protected mode. */
  341. call write_bootinfo
  342. jmp enter_pm
  343. /* ---- A20 ---------------------------------------------------------------- */
  344. enable_a20:
  345. movw $0x2401, %ax
  346. int $0x15
  347. call a20_wait
  348. movb $0xD1, %al
  349. outb %al, $0x64
  350. call a20_wait
  351. movb $0xDF, %al
  352. outb %al, $0x60
  353. call a20_wait
  354. inb $0x92, %al
  355. testb $0x02, %al
  356. jnz 1f
  357. orb $0x02, %al
  358. andb $0xFE, %al
  359. outb %al, $0x92
  360. 1: ret
  361. a20_wait:
  362. inb $0x64, %al
  363. testb $0x02, %al
  364. jnz a20_wait
  365. ret
  366. /* ---- Read sectors via INT 13h ------------------------------------------
  367. * in: eax = LBA, cx = sector count
  368. * out: data at 0x3000, CF set on failure
  369. * Clobbers all general registers. */
  370. read_sectors:
  371. /* One INT 13h per run of sectors, not per sector: EDD transfers the
  372. * whole chunk (<= 32 sectors into the 16 KB 0x3000 buffer), CHS
  373. * transfers up to the end of the current track (the buffer never
  374. * crosses a 64 KB ISA DMA boundary). The old per-sector loop made
  375. * ~3600 BIOS calls for a 1.8 MB rootfs. A BIOS that refuses a
  376. * multi-sector request falls back to one sector per call for the
  377. * rest of this read, so the old behaviour is the failure path. */
  378. movl %eax, rd_lba
  379. movw %cx, rd_left
  380. movw $0, rd_off
  381. movw $0, rd_tries
  382. movb $0, rd_single
  383. read_retry:
  384. xorw %ax, %ax
  385. movw %ax, %ds
  386. movw rd_left, %ax
  387. cmpb $0, rd_single
  388. je 1f
  389. movw $1, %ax
  390. 1: movw %ax, rd_count
  391. movw $0x0300, %ax
  392. movw %ax, %es
  393. movb stage_drive, %dl
  394. cmpb $0x80, %dl
  395. jb read_chs
  396. read_lba:
  397. /* EDD LBA read */
  398. movw $0x10, 0x500
  399. movw rd_count, %ax
  400. movw %ax, 0x502
  401. movw rd_off, %bx
  402. movw %bx, 0x504
  403. movw $0x0300, 0x506
  404. movl rd_lba, %eax
  405. movl %eax, 0x508
  406. movl $0, 0x50C
  407. movw $0x500, %si
  408. movb $0x42, %ah
  409. jmp read_int
  410. read_chs:
  411. movw rd_lba, %ax
  412. xorw %dx, %dx
  413. movw $18, %di
  414. divw %di /* ax = track index, dx = sector - 1 */
  415. movw $18, %bx
  416. subw %dx, %bx /* sectors left on this track */
  417. cmpw rd_count, %bx
  418. jae 2f
  419. movw %bx, rd_count
  420. 2: movb %dl, %cl
  421. incb %cl
  422. xorw %dx, %dx
  423. movw $2, %di
  424. divw %di
  425. movb %dl, %dh
  426. movb %al, %ch
  427. movb stage_drive, %dl
  428. movb $0x02, %ah
  429. movb rd_count, %al
  430. movw rd_off, %bx
  431. read_int:
  432. int $0x13
  433. jnc read_ok
  434. /* Reset the drive. A refused multi-sector request switches to the
  435. * single-sector path; a single sector gets a few retries. */
  436. pushw %cx
  437. movb stage_drive, %dl
  438. xorw %ax, %ax
  439. int $0x13
  440. popw %cx
  441. cmpw $1, rd_count
  442. je 3f
  443. movb $1, rd_single
  444. jmp read_retry
  445. 3: incw rd_tries
  446. cmpw $3, rd_tries
  447. jb read_retry
  448. stc
  449. ret
  450. read_ok:
  451. movzwl rd_count, %eax
  452. addl %eax, rd_lba
  453. shlw $9, %ax
  454. addw %ax, rd_off
  455. movw rd_count, %ax
  456. subw %ax, rd_left
  457. jnz read_retry
  458. clc
  459. ret
  460. /* ---- Print a NUL-terminated string with the BIOS teletype ------------- */
  461. print_str:
  462. pushw %ax
  463. pushw %bx
  464. movb $0x0E, %ah
  465. xorw %bx, %bx
  466. 1: lodsb
  467. testb %al, %al
  468. jz 2f
  469. int $0x10
  470. jmp 1b
  471. 2: popw %bx
  472. popw %ax
  473. ret
  474. /* ---- Flat protected-mode copy -----------------------------------------
  475. * The X201 BIOS silently turns INT 15h AH=87h into zeros for this range.
  476. * Enter temporary protected mode, copy with a flat rep movsb, then return
  477. * to real mode. SS/ESP are left untouched; only DS/ES are widened. */
  478. pm_copy:
  479. cli
  480. lgdt stage2_gdtr
  481. movl %cr0, %eax
  482. orl $1, %eax
  483. movl %eax, %cr0
  484. .byte 0x66, 0xea
  485. .long pm_copy32
  486. .word 0x08
  487. .code32
  488. pm_copy32:
  489. movw $0x10, %ax
  490. movw %ax, %ds
  491. movw %ax, %es
  492. cld
  493. movl $0x3000, %esi
  494. movl copy_dst, %edi
  495. movl copy_len, %ecx
  496. rep movsb
  497. /* Leave through a 16-bit protected-mode code segment before
  498. * clearing PE, then return to real mode. */
  499. .byte 0xea
  500. .long pm_copy16pm
  501. .word 0x18
  502. .code16
  503. pm_copy16pm:
  504. movl %cr0, %eax
  505. andl $0xfffffffe, %eax
  506. movl %eax, %cr0
  507. .byte 0xea
  508. .word pm_copy16
  509. .word 0x0000
  510. pm_copy16:
  511. xorw %ax, %ax
  512. movw %ax, %ds
  513. movw %ax, %es
  514. movw %ax, %fs
  515. movw %ax, %gs
  516. ret
  517. /* ---- Hex print (EAX, 8 digits) ----------------------------------------- */
  518. print_hex32:
  519. movl $8, %ecx
  520. jmp print_hex
  521. print_hex:
  522. pushal
  523. movl %eax, %ebx
  524. 1: roll $4, %ebx
  525. movl %ebx, %eax
  526. andl $0x0F, %eax
  527. cmpl $10, %eax
  528. jb 2f
  529. addl $55, %eax
  530. jmp 3f
  531. 2: addl $48, %eax
  532. 3: pushl %ebx
  533. pushl %ecx
  534. movb $0x0E, %ah
  535. xorw %bx, %bx
  536. int $0x10
  537. popl %ecx
  538. popl %ebx
  539. loop 1b
  540. popal
  541. ret
  542. /* ---- Boot-info block at 0x500 (bootinfo.h) ----------------------------
  543. * twelve dwords: magic, version, checksum, rsdp, flags, pack_addr,
  544. * pack_size, reserved[5]; the checksum makes the sum zero. */
  545. write_bootinfo:
  546. xorw %ax, %ax
  547. movw %ax, %ds
  548. movl $BOOT_INFO_MAGIC, 0x500
  549. movl $BOOT_INFO_VERSION, 0x504
  550. movl $0, 0x508
  551. movl $0, 0x50C
  552. movl $0, 0x510
  553. movl pack_addr, %eax
  554. movl %eax, 0x514
  555. movl pack_bytes, %eax
  556. movl %eax, 0x518
  557. movl $0, 0x51C
  558. movl $0, 0x520
  559. movl $0, 0x524
  560. movl $0, 0x528
  561. movl $0, 0x52C
  562. xorl %eax, %eax
  563. movl $0x500, %esi
  564. movl $BOOT_INFO_WORDS, %ecx
  565. 1: addl (%esi), %eax
  566. addl $4, %esi
  567. loop 1b
  568. negl %eax
  569. movl %eax, 0x508
  570. ret
  571. /* ---- Protected-mode entry ---------------------------------------------- */
  572. enter_pm:
  573. cli
  574. lgdt stage2_gdtr
  575. movl %cr0, %eax
  576. orl $1, %eax
  577. movl %eax, %cr0
  578. .byte 0x66, 0xea
  579. .long stage2_pm
  580. .word 0x08
  581. .code32
  582. stage2_pm:
  583. movw $0x10, %ax
  584. movw %ax, %ds
  585. movw %ax, %es
  586. movw %ax, %fs
  587. movw %ax, %gs
  588. movw %ax, %ss
  589. movl $__boot_stack_top, %esp
  590. jmp kernel_entry
  591. .align 4
  592. stage2_gdt:
  593. .quad 0
  594. .word 0xffff, 0x0000
  595. .byte 0x00, 0x9a, 0xcf, 0x00
  596. .word 0xffff, 0x0000
  597. .byte 0x00, 0x92, 0xcf, 0x00
  598. /* 16-bit code: base 0, 4 GB limit, D=0 */
  599. .word 0xffff, 0x0000
  600. .byte 0x00, 0x9a, 0x8f, 0x00
  601. stage2_gdt_end:
  602. stage2_gdtr:
  603. .word stage2_gdt_end - stage2_gdt - 1
  604. .long stage2_gdt
  605. /* ---- Stage variables --------------------------------------------------- */
  606. .align 4
  607. stage_drive: .byte 0
  608. use_lba: .byte 0
  609. pack_lba: .long 0
  610. pack_bytes: .long 0
  611. pack_addr: .long 0
  612. pack_off: .long 0
  613. chunk_sectors: .long 0
  614. copy_dst: .long 0
  615. copy_len: .long 0
  616. rd_lba: .long 0
  617. rd_off: .word 0
  618. rd_left: .word 0
  619. rd_count: .word 0
  620. rd_single: .byte 0
  621. rd_tries: .word 0
  622. msg_pack: .asciz "Loading rootfs [d="
  623. msg_lba: .asciz " lba="
  624. msg_e: .asciz " e="
  625. msg_m: .asciz " m="
  626. msg_end: .asciz "]... "
  627. msg_dot: .asciz "."
  628. msg_ok: .asciz " ok\r\n"
  629. msg_fail: .asciz " failed\r\n"
  630. .align 2
  631. vram_64k:
  632. .word 0
  633. best_mode:
  634. .word 0
  635. best_score:
  636. .long 0