commit c0038ab9cb149b99b147760338d3d06af2ea0688
parent 61a3f7deb2c2daa11fd43d539396b391c6802845
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 22 Jul 2022 16:06:20 -0400
pc: initialize all segments
... and set the table for the journey to bare metal.
Diffstat:
4 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/buildpc.fs b/buildpc.fs
@@ -2,5 +2,5 @@
f<< /asm/i386.fs
f<< /xcomp/pc/mbr.fs
ORG $200 spit
-f<< /xcomp/pc/boot.fs
-ORG $200 spit bye
+f<< /xcomp/i386.fs
+ORG here ORG - spit bye
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -0,0 +1,10 @@
+\ This is (well, will be) the i386 Dusk kernel. It is called when the bootloader
+\ has finished loading this binary as well as the Forth boot code following it
+\ in memory. We're in protected mode and all segments have been initialized.
+\ ESP and EBP are uninitialized.
+
+$8000 const BINSTART \ This code lives at $8000.
+create ORG
+ax $07690748 i) mov,
+$b8000 m) ax mov,
+0 jmp, \ infinite loop
diff --git a/fs/xcomp/pc/boot.fs b/fs/xcomp/pc/boot.fs
@@ -1,8 +0,0 @@
-\ This part is called when the bootloader has finished loading the kernel as
-\ well as the Forth boot code following it in memory. We're freshly out of real
-\ mode. SS is uninitialized. This code lives at $8000
-create ORG
-ax 16 i) mov, ds ax mov,
-ax $07690748 i) mov,
-$b8000 m) ax mov,
-0 jmp, \ infinite loop
diff --git a/fs/xcomp/pc/mbr.fs b/fs/xcomp/pc/mbr.fs
@@ -12,8 +12,16 @@ ax $0003 i) mov, $10 int, \ video mode 80x25
\ read sector 2 from boot floppy in memory at address $8000
ax $0201 i) mov, bx $8000 i) mov, cx $0002 i) mov, dx $0000 i) mov, $13 int,
ax cr0 mov, ax 1 i) or, cr0 ax mov,
-$08 $8000 jmpfar, 0 to realmode
-
+$08 0 jmpfar, here ORG - BINSTART + here 4 - w! 0 to realmode
+\ initialize all segments
+ax 16 i) mov,
+ds ax mov,
+ss ax mov,
+es ax mov,
+gs ax mov,
+fs ax mov,
+\ Jump to payload
+$08 $8000 jmpfar,
\ Inspired by GNU grub at grub-core/kern/i386/realmode.S
ORG $1e0 + to here \ GDT
\ First entry (the null entry) is a reference to itself