commit 0d2ac308a8325cd3ec62f81a590bb48d761acc94
parent d09530f6e8010fee5ae99b59c2603484556fd893
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 2 Aug 2022 14:42:30 -0400
pc: setup IDT
This makes Dusk boot on both my machines. All interrupt handlers for now are
noop.
Diffstat:
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -17,13 +17,17 @@
\ equivalent to r1 pspop, then r2 pspop,
: pspop2, ( r1 r2 -- ) r! bp CELLSZ d) mov, r! [ebp] mov, bp CELLSZ << i) add, ;
: wcall, xwordlbl abs>rel call, ;
+0 value lblintnoop
+: idtgen ( entrycount -- ) >r begin
+ lblintnoop $ffff and w, $08 w, 0 c, $8e c, lblintnoop 16 rshift w, next ;
\ Constants and labels
0 to realmode
: values ( n -- ) >r begin 0 value next ;
-22 values L1 L2 lblmainalias lbltoptr lbltoexec lblbootptr lblin< lblcurword
+23 values L1 L2 lblmainalias lbltoptr lbltoexec lblbootptr lblin< lblcurword
lblret lblcurrent lblemit lblparsec lblparseh lblparseud lblerrmsg
lblrtype lblhere lblmovewrite lblwrite lblcwrite lblcompiling lblareg
+ lblidt
$a000 const HERESTART \ TODO: find a better place
$80000 const HEREMAX
$8000 to binstart \ This code lives at $8000.
@@ -33,6 +37,14 @@ $7c00 const PSTOP
\ Let's go!
align4 here to org
forward16 jmp, to L1
+pc to lblintnoop iret,
+\ Interrupt Descriptor Table
+pc $100 idtgen
+pc to lblidt
+$100 8 * 1- w, ( pc ) ,
+L1 forward!
+lblidt m) lidt,
+forward16 jmp, to L1
xcode noop pc to lblret ret,
diff --git a/fs/xcomp/pc/kernel.fs b/fs/xcomp/pc/kernel.fs
@@ -4,18 +4,21 @@
pc to L1 \ back to protected mode!
ax $10 i) mov, ds ax mov, ss ax mov, es ax mov, gs ax mov, fs ax mov,
+ lblidt m) lidt, sti,
ret,
+pc $ffff w, 0 , \ real mode IVT
+
pc to L2 1 to realmode \ we're in realmode
- ax ax xor, es ax mov,
+ ax ax xor, es ax mov, ( pc ) m) lidt, sti,
ax $0201 i) mov, $13 int,
\ we've done what we came for, let's go back to 32bit
- ax cr0 mov, ax 1 i) or, cr0 ax mov,
+ cli, ax cr0 mov, ax 1 i) or, cr0 ax mov,
$08 L1 jmpfar,
pc to L1 \ segment with ffff limits
ax $20 i) mov, ds ax mov, ss ax mov, es ax mov, gs ax mov, fs ax mov,
- ax cr0 mov, ax $fffffffe i) and, cr0 ax mov,
+ cli, ax cr0 mov, ax $fffffffe i) and, cr0 ax mov,
0 L2 jmpfar,
0 to realmode
diff --git a/fs/xcomp/pc/mbr.fs b/fs/xcomp/pc/mbr.fs
@@ -31,15 +31,12 @@ pc to lblerror
pc to lblpayload 0 to realmode
\ initialize all segments
ax $10 i) mov, ds ax mov, ss ax mov, es ax mov, gs ax mov, fs ax mov,
- \ ah 7 i) mov, al $7c73 m) mov,
- \ $b8000 m) ax mov,
- \ ah 7 i) mov, al $107c73 m) mov,
- \ $b8002 m) ax mov, 0 jmp,
+ sti,
\ Jump to payload
$08 $8000 jmpfar,
1 to realmode
lblstart forward!
-cli, cld, ax ax xor, es ax mov, ds ax mov,
+cld, ax ax xor, es ax mov, ds ax mov,
lblgdt m) lgdt,
\ DL is set by BIOS to the proper drive number for int13h. The field
\ BS_DrvNum is often not set properly, so let's set it.
@@ -50,5 +47,5 @@ ah 2 i) mov, al $7c0e ( BPB_RsvdSecCnt ) m) mov, al dec,
bx $8000 i) mov, cx $0002 i) mov, dh 0 i) mov, $13 int,
lblerror abs>rel jc,
ax $0003 i) mov, $10 int, \ video mode 80x25
-ax cr0 mov, ax 1 i) or, cr0 ax mov,
+cli, ax cr0 mov, ax 1 i) or, cr0 ax mov,
$08 lblpayload jmpfar,