|
|
@@ -1,4 +1,5 @@
|
|
|
-/* Boot sector: load contiguous kernel sectors 1..N to 0x7E00, then PM. No FAT. */
|
|
|
+/* Boot sector: load contiguous kernel sectors 1..N to 0x7E00,
|
|
|
+ then jump to 0x7E00 in real mode (VESA stage handles the rest). */
|
|
|
|
|
|
.code16
|
|
|
.section .text
|
|
|
@@ -23,78 +24,7 @@ loader_start:
|
|
|
movw $0x0003, %ax
|
|
|
int $0x10
|
|
|
|
|
|
- /* VESA: query VRAM size, then try mode list. Buffer at ES:DI = 0:0x6000. */
|
|
|
- xorw %ax, %ax
|
|
|
- movw %ax, %es
|
|
|
- movw $0x6000, %di
|
|
|
- /* Get VBE controller info (TotalMemory at offset 0x12, in 64KB blocks) */
|
|
|
- movw $0xFFFF, %si /* default: assume unlimited VRAM */
|
|
|
- movw $0x4256, (%di) /* "VB" */
|
|
|
- movw $0x3245, 2(%di) /* "E2" */
|
|
|
- movw $0x4F00, %ax
|
|
|
- int $0x10
|
|
|
- cmpw $0x004F, %ax
|
|
|
- jnz 4f
|
|
|
- movw 0x12(%di), %ax
|
|
|
- testw %ax, %ax
|
|
|
- jz 4f
|
|
|
- movw %ax, %si /* SI = VRAM in 64KB blocks */
|
|
|
-4:
|
|
|
- /* Try modes: 0x11C..0x110 (descending res, >= 16bpp, must fit in VRAM). */
|
|
|
- movw $0x11C, %cx
|
|
|
-1: movw $0x4F01, %ax
|
|
|
- int $0x10
|
|
|
- cmpw $0x004F, %ax
|
|
|
- jnz 2f
|
|
|
- cmpb $16, 0x19(%di) /* BitsPerPixel >= 16 */
|
|
|
- jb 2f
|
|
|
- testw $0x80, (%di) /* ModeAttributes bit 7 = LFB */
|
|
|
- jz 2f
|
|
|
- /* Check if pitch * height fits in VRAM */
|
|
|
- movw 0x10(%di), %ax /* BytesPerScanLine */
|
|
|
- mulw 0x14(%di) /* DX:AX = pitch * height */
|
|
|
- testw %ax, %ax
|
|
|
- jz 3f
|
|
|
- incw %dx /* round up partial 64KB block */
|
|
|
-3: cmpw %si, %dx /* needed_64k > total_64k? */
|
|
|
- ja 2f /* skip: doesn't fit */
|
|
|
- movw %cx, %bx
|
|
|
- orw $0x4000, %bx /* Set mode with LFB */
|
|
|
- movw $0x4F02, %ax
|
|
|
- int $0x10
|
|
|
- cmpw $0x004F, %ax
|
|
|
- jz vesa_ok
|
|
|
-2: cmpw $0x110, %cx
|
|
|
- jz vesa_fail
|
|
|
- subw $1, %cx /* 0x11C -> 0x11B -> 0x118 -> 0x114 */
|
|
|
- jmp 1b
|
|
|
-vesa_fail:
|
|
|
- jmp halt
|
|
|
-vesa_ok:
|
|
|
- /* Re-query mode info (CX still has mode number). ES:DI = 0:0x6000. */
|
|
|
- xorw %ax, %ax
|
|
|
- movw %ax, %es
|
|
|
- movw $0x6000, %di
|
|
|
- movw $0x4F01, %ax
|
|
|
- int $0x10
|
|
|
- movw $0x600, %bx
|
|
|
- movb $1, (%bx) /* valid = 1 */
|
|
|
- movw 0x12(%di), %ax
|
|
|
- movw %ax, 1(%bx) /* width */
|
|
|
- movw 0x14(%di), %ax
|
|
|
- movw %ax, 3(%bx) /* height */
|
|
|
- movw 0x10(%di), %ax
|
|
|
- movw %ax, 5(%bx) /* pitch */
|
|
|
- movb 0x19(%di), %al
|
|
|
- movb %al, 7(%bx) /* bpp */
|
|
|
- movw 0x28(%di), %ax
|
|
|
- movw %ax, 8(%bx) /* lfb_base lo */
|
|
|
- movw 0x2a(%di), %ax
|
|
|
- movw %ax, 10(%bx) /* lfb_base hi */
|
|
|
- movw %si, 12(%bx) /* vram_64k */
|
|
|
-
|
|
|
load_kernel:
|
|
|
- /* Load kernel: sectors 1..kernel_sectors to 0x7E00. */
|
|
|
movw kernel_sectors, %cx
|
|
|
movw $1, %si
|
|
|
movw $0x07e0, %ax
|
|
|
@@ -109,7 +39,6 @@ load_loop:
|
|
|
movb boot_drive, %dl
|
|
|
cmpb $0x80, %dl
|
|
|
jb read_chs
|
|
|
- /* LBA read via INT 13h AH=42h. DAP at 0:0x500. */
|
|
|
xorw %ax, %ax
|
|
|
movw %ax, 0x50a
|
|
|
movw %ax, 0x50c
|
|
|
@@ -154,70 +83,16 @@ do_int13:
|
|
|
jnz load_loop
|
|
|
|
|
|
load_done:
|
|
|
- movb boot_drive, %al
|
|
|
- movb %al, 0x600
|
|
|
-
|
|
|
- /* Enable A20 gate (address bit 20). Try three methods. */
|
|
|
- movw $0x2401, %ax /* Method 1: BIOS */
|
|
|
- int $0x15
|
|
|
- call a20_8042_wait /* Method 2: keyboard controller (8042) */
|
|
|
- movb $0xD1, %al
|
|
|
- outb %al, $0x64
|
|
|
- call a20_8042_wait
|
|
|
- movb $0xDF, %al
|
|
|
- outb %al, $0x60
|
|
|
- call a20_8042_wait
|
|
|
- inb $0x92, %al /* Method 3: fast A20 gate */
|
|
|
- testb $0x02, %al
|
|
|
- jnz 5f
|
|
|
- orb $0x02, %al
|
|
|
- andb $0xFE, %al
|
|
|
- outb %al, $0x92
|
|
|
-5:
|
|
|
- cli
|
|
|
- lgdt gdtr
|
|
|
- movl %cr0, %eax
|
|
|
- orl $1, %eax
|
|
|
- movl %eax, %cr0
|
|
|
- .byte 0x66, 0xea
|
|
|
- .long pm_start
|
|
|
- .word 0x08
|
|
|
+ /* Jump to VESA stage at 0x7E00 (real mode). */
|
|
|
+ ljmp $0x0000, $0x7E00
|
|
|
|
|
|
boot_drive:
|
|
|
.byte 0
|
|
|
- .align 2
|
|
|
-gdt:
|
|
|
- .quad 0
|
|
|
- .word 0xffff, 0x0000
|
|
|
- .byte 0x00, 0x9a, 0xcf, 0x00
|
|
|
- .word 0xffff, 0x0000
|
|
|
- .byte 0x00, 0x92, 0xcf, 0x00
|
|
|
-gdt_end:
|
|
|
-gdtr:
|
|
|
- .word gdt_end - gdt - 1
|
|
|
- .long gdt
|
|
|
-
|
|
|
-a20_8042_wait:
|
|
|
- inb $0x64, %al
|
|
|
- testb $0x02, %al
|
|
|
- jnz a20_8042_wait
|
|
|
- ret
|
|
|
|
|
|
halt:
|
|
|
cli
|
|
|
1: hlt
|
|
|
jmp 1b
|
|
|
|
|
|
-.code32
|
|
|
-pm_start:
|
|
|
- movw $0x10, %ax
|
|
|
- movw %ax, %ds
|
|
|
- movw %ax, %es
|
|
|
- movw %ax, %fs
|
|
|
- movw %ax, %gs
|
|
|
- movw %ax, %ss
|
|
|
- movl $0x20800, %esp
|
|
|
- ljmp $0x08, $0x7e00
|
|
|
-
|
|
|
.section .bootsig
|
|
|
.byte 0x55, 0xaa
|