commit 15f69e9e5dc734f9f88d5b0fd2bc919500ebe095
parent 167f48bda984fd888d8d299d9144b4a2fe1962ca
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 16 Mar 2023 14:23:30 -0400
hal i386: implement "entry" and "code"
EAX=11c7
Diffstat:
2 files changed, 58 insertions(+), 25 deletions(-)
diff --git a/fs/xcomp/bootlo2.fs b/fs/xcomp/bootlo2.fs
@@ -1 +1,2 @@
-$1234 bye
+code foo exit,
+$1234 44 - 'A' - foo bye
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -3,6 +3,10 @@
\ We're in protected mode and all segments have been initialized.
\ ESP=RSP SI=PSP DI=A EAX=W. They begin uninitialized.
\ HAL operand structure is the same as asm/i386 opmod structure.
+\ Registers preserved/destroyed by words usually don't matter much: as an API,
+\ we must assume that all registers are destroyed. However, some words within
+\ the kernel refer to other words with register preservation assumptions. In
+\ these cases, the word itself mentions which registers are preserved.
?f<< /asm/i386.fs
?f<< /xcomp/tools.fs
@@ -46,9 +50,9 @@ $106 const MODRM_[SI]
$104 const MODRM_[SP]
: _ dx lblhere m) mov, dx 0 d) swap mov, ;
-: cwrite, ( opmod -- ) _ lblhere m) inc, ;
-: wwrite, ( opmod -- ) _ lblhere m) 2 i) add, ;
-: dwrite, ( opmod -- ) _ lblhere m) 4 i) add, ;
+: cwrite, ( opmod -- ) _ lblhere m) inc, ; \ Destroys dx
+: wwrite, ( opmod -- ) _ lblhere m) 2 i) add, ; \ Destroys dx
+: dwrite, ( opmod -- ) _ lblhere m) 4 i) add, ; \ Destroys dx
: movewrite, ( a u ) cx swap i) mov, bx swap i) mov, lblwriterange abscall, ;
\ Let's go!
@@ -106,6 +110,18 @@ xcode (abort)
si PSTOP i) mov,
wjmp, quit
+xcode rtype wjmp, (abort)
+
+\ During early boot, it's better to halt the machine than to go back to the
+\ mainloop because the mainloop likely sends us to an infinite error loop
+\ through boot<.
+pc ," boot failure"
+xcode abort
+ si 0 d) swap ( pc ) i) mov,
+ ax 12 i) mov,
+ wcall, rtype
+ 0 jmp,
+
\ HAL operands
pc to L1 HBANKCNT CELLSZ * allot
pc to L2 0 ,
@@ -159,7 +175,7 @@ pc to lblrelwr \ bx=abs addr
pc to lblret
ret,
-pc to lblwriterange \ bx=addr cx=u
+pc to lblwriterange \ bx=addr cx=u. destroys cx
di push, si push,
si bx mov,
di lblhere m) mov,
@@ -343,25 +359,7 @@ xcode p! ( n32 port -- )
ax dx out,
ret,
-xcode align4 ( n -- )
- ax lblhere m) add,
- ax 3 i) and,
- lblret abs>rel jz,
- lblhere m) ax sub,
- lblhere m) 4 i) add,
- xdrop, ret,
-
-xcode rtype wjmp, (abort)
-
-\ During early boot, it's better to halt the machine than to go back to the
-\ mainloop because the mainloop likely sends us to an infinite error loop
-\ through boot<.
-pc ," boot failure"
-xcode abort
- si 0 d) swap ( pc ) i) mov,
- ax 12 i) mov,
- wcall, rtype
- 0 jmp,
+\ Interpret loop
0 align4 pc to lblbootptr 0 ,
xcode boot<
@@ -505,7 +503,7 @@ xcode (wnf)
L1 abs>rel jnz, \ fail
ax 2 d) 8b) ''' i) cmp,
L1 abs>rel jnz, \ fail
- ax ax 0 d) 8b) movzx,
+ ax ax 1 d) 8b) movzx,
xdup,
ax 1 i) mov,
ret,
@@ -627,6 +625,40 @@ xcode runword ( str -- ) pc w>e lblsysdict pc>addr !
L2 abscall,
L1 absjmp,
+\ Entry creation
+
+xcode align4 ( n -- ) \ Preserves all except ax
+ ax lblhere m) add,
+ ax 3 i) and,
+ forward8 jz,
+ lblhere m) ax sub,
+ lblhere m) 4 i) add,
+ forward!
+ xdrop, ret,
+
+xcode entry ( 'dict s -- )
+ bx ax mov, \ bx=s
+ cx bx 0 d) 8b) movzx, \ cx=len
+ bx inc,
+ ax cx mov,
+ ax inc,
+ wcall, align4 \ ( 'dict -- )
+ cx push, lblwriterange abscall, cx pop,
+ bx lblnextmeta m) mov, bx dwrite,
+ lblnextmeta m) 0 i) mov,
+ bx ax 0 d) mov, \ ax='dict bx=dict
+ dx lblhere m) mov,
+ ax 0 d) dx mov, xdrop, ( -- )
+ bx dwrite,
+ cl cwrite,
+ lbl[rcnt] m) 0 i) mov,
+ ret,
+
+xcode code
+ wcall, sysdict
+ wcall, word
+ wjmp, entry
+
\ Constants that override compile-time constant names and must come last
PSTOP xconst PSTOP
RSTOP xconst RSTOP