From 6c4ee8ed0201fa95052ba24e882562879042df22 Mon Sep 17 00:00:00 2001 From: Greg Bowne Date: Fri, 15 Mar 2024 15:21:51 -0700 Subject: [PATCH] fixed 2nd stage bootloader --- .vscode/browse.vc.db | Bin 33939456 -> 33939456 bytes .vscode/browse.vc.db-shm | Bin 32768 -> 32768 bytes src/boot/boot2.asm | 30 +++++++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.vscode/browse.vc.db b/.vscode/browse.vc.db index 2adcb51e3ee336c473060bdcecad40036e973fa4..5e5b21f8474ed14f192b3990a5ab4abaa152d058 100644 GIT binary patch delta 3577 zcmajfdsGx<1IKY@c6Mjj<+88~3k&SByWT)WM9jP-R9ae@X^JT+A{Rvk7Qr+t8BND) zUh*=PmYSw1mZHX(TB3$#YGr9!nxbY|UedC%vV4C(?YyV=uXoP*es<36JkQLY^X#M6 z>vk1w3}m@7O-*Ae^NWk}s><`qgGFUkW5yP_W@Ierl;sxMZSJ4dDY^NkC{t7M-}gvc z9HtbppuDgsucWG|v@)->yinTwd|lqOx;z1idR?CBF>7&`kdTnGk@5C!hJC2%j|fL} z2U7(u-8r&S@!3_k*T_yid!=l#2S?{u6_<}GO&gK8HzY&|*H^^*y6EY}o+y1`xoM`5 zqI-j;=3+>eKB-7amb>Tl#GUP@l?P2oLS|$!%7gNvHp*(DD#SZjs4}d}<(`6EB#aNs zv|ZL~(_L|TaHE`RA68yo)rMrG?XPg9EUUbjp3 zntZ12dhH6?r4K1JDSE|9*{$0>0a;9J;LF4qZFb9_y;_YQv{RTL;yvPB>z(Ay^=5h% z&neGl&vZ||=Pr*msWGW8X--mpQpY5F;`fQ$6Bi_oNX$-*OSqD-FJVbSMZyCK$?hBO z1Mb(|r8bDj?W!y9TOZ6J3P_XqZ^`^Mwdn38yy#Q zDeC>GMNz|}I!1-tzqN0(&$ExPceY1Fo{QWXIV&xaJg>MO; z65cPoS=i06Pr{amRfcs7i?v;_ZMV&^4X~xy6zf@Q^-im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>hN5BUJv1DZqB5kQ5ojbDg+`+> zNJZsnEEn5j%+_Q6!o;h?B&SSmGjaB%ZiQ0`U+p zNhCg!MEoR~q>um!k`Spvs*gp-AH%RgS<|%$r~hx^dz~Y7wJvAN5JMCRcceY`k!diIH*hMW??^%uEbi8xNjm+WaK_AJfJQKe#tP W%2MLp+)`P?w()`r_vRD9HEaMZ4?N`n diff --git a/src/boot/boot2.asm b/src/boot/boot2.asm index 9a610e3..098226c 100644 --- a/src/boot/boot2.asm +++ b/src/boot/boot2.asm @@ -15,7 +15,7 @@ start: switch_to_protected_mode: CLI ; Disable interrupts - LGDT [gdt_descriptor] ; Load the global descriptor table + lgdt [gdt_descriptor] ; Load the global descriptor table MOV EAX, CR0 OR EAX, 0x1 ; Set the PE (Protection Enable) bit MOV CR0, EAX @@ -23,7 +23,10 @@ start: JMP CODE_SEG:init_pm ; CODE_SEG is the segment selector for code segment in GDT init_pm: ; Update segment registers here - ; ... + ; Set code segment register (CS) to point to code segment descriptor (selector 1) + mov ax, 0x0001 + mov ds, ax ; Set data segment register (DS) to point to data segment descriptor (selector 2) + mov es, ax ; Set other segment registers (ES, SS, etc.) as needed RET @@ -62,7 +65,28 @@ start: ; Code to set up flat memory model for protected mode ; This involves setting up the segment registers with selectors ; that point to descriptors in the GDT that define a flat memory model - ; ... + + ; Define GDT structure + gdt_struct: + ; Null descriptor (ignored) + dq 0x0000000000000000h + dq 0x0000000000000000h + + ; Code segment descriptor (flat memory model) + ; Base address 0, limit 0xffffffff (full 4GB) + ; Present, Readable, Accessed, Code segment, 4KB granularity + ; Flags: 0x9A (Bits explained below) + dq 0x0000000000000000h + dq 0x00CFFFFFFFh + db 0x9A + db 0xCF + + ; Data segment descriptor (flat memory model) + ; Similar structure to code segment descriptor with Data segment flag set + dq 0x0000000000000000h + dq 0x00CFFFFFFFh + db 0x92 + db 0xCF ; Jump to the kernel entry point JMP 0x1000:0x0000 ; Assuming the kernel is loaded at 0x1000:0x0000