commit a949b562d342bb6ace67f324a29e97dcee4291a8
parent 3fc5769f387b188d35c2eac8223a3cfd290fb0ab
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 24 Jul 2022 12:05:03 -0400
i386: add find
Diffstat:
3 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -157,7 +157,8 @@ ES _ es SS _ ss DS _ ds FS _ fs GS _ gs
\ Inherent
: op ( opcode -- ) doer c, does> ( a -- ) c@ c, asm$ ;
$c3 op ret, $90 op nop, $fa op cli, $fc op cld,
-$ac op lodsb, $ad op lods,
+$ac op lodsb, $ad op lods, $a6 op cmpsb, $a7 op cmps,
+$f3 op repz, $f2 op repnz,
\ Jumps and relative addresses
\ i386 jumps and calls in their immediate modes are relative. We keep it that
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -11,6 +11,7 @@
0 to realmode
0 value L1
+0 value L2
0 value lblmainalias
0 value lbltoptr
0 value lbltoexec
@@ -18,6 +19,8 @@
0 value lblin<
0 value lblcurword
0 value lblret \ label for whenever you need to return early
+0 value lblcurrent
+0 value lblemit
$8000 to binstart \ This code lives at $8000.
$6000 const RSTOP
$8000 const PSTOP
@@ -137,10 +140,11 @@ xcode !
pc $b8000 ,
xcode emit \ temporary, this is going in /drv/pc
+ AX pspop,
+pc to lblemit
di dup ( pc ) m) mov,
dup ( pc ) m) inc,
( pc ) m) inc,
- AX pspop,
di 0 d) al mov,
di 1 d) 7 i) mov,
ret,
@@ -225,6 +229,43 @@ xcode word
lblret abs>rel jnz,
0 jmp, \ TODO add error message
+xcode current
+ xwordlbl (val) abs>rel call,
+ pc to lblcurrent 0 ,
+
+xcode find ( str -- word-or-0 ) pc lblcurrent pc>addr !
+ si bp 0 d) mov,
+ cx cx xor,
+ cl si 0 d) mov,
+ bp 0 d) inc,
+ dx lblcurrent m) mov,
+pc ( loop )
+ di dx mov,
+ di dec,
+ al di 0 d) mov,
+ al $3f i) and, \ 3f instead of 7f? we reserve space for another flag.
+ al cl cmp,
+ forward jnz, to L1 ( skip1 )
+ \ same length
+ di 4 i) sub,
+ di cx sub,
+ si bp 0 d) mov,
+ repz, cmpsb,
+ forward jnz, to L2 ( skip2 )
+ \ same contents
+ bp 0 d) dx mov,
+ ret,
+L2 forward! ( skip2 )
+ cl al mov,
+L1 forward! ( skip1 )
+ dx 5 i) sub,
+ dx dx 0 d) mov,
+ dx dx test,
+ ( pc ) abs>rel jnz, ( loop )
+ \ not found
+ bp 0 d) 0 i) mov,
+ ret,
+
pc lblmainalias pc>addr !
xwordlbl (s) abs>rel call,
6 c, ," Hello "
@@ -241,7 +282,10 @@ pc lblmainalias pc>addr !
xwordlbl swap abs>rel call,
xwordlbl c@ abs>rel call,
xwordlbl rtype abs>rel call,
- xwordlbl bye abs>rel call,
+ xwordlbl word abs>rel call,
+ xwordlbl find abs>rel call,
+ AX pspop,
+ ax call,
pc lblbootptr pc>addr !
xbindict orgifydict
diff --git a/fs/xcomp/pc/boot.fs b/fs/xcomp/pc/boot.fs
@@ -1,2 +1,2 @@
-World! dontprint
+World! bye