vesa_stage.S 16 KB

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