commit c85446209bf0fc74332ee72165e0488899c40608
parent 487ca796bec35e346c3d2b5a6d715121b893ff0c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 13 Oct 2022 08:21:06 -0400
asm/i386: fix forward8 jumps
Diffstat:
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -204,10 +204,14 @@ $e2 op loop, $e1 op loopz, $e0 op loopnz,
: jmpfar, ( seg16 absaddr ) $ea op, addr, w, ;
: callfar, ( seg16 absaddr ) $9a op, addr, w, ;
-\ TODO: this is broken when used with forward8!
+: _jmpop@ ( a -- a+n is8? )
+ c@+ dup $0f = if \ 16 bit jcc
+ drop 1+ 0 else ( a op )
+ dup $eb = swap $f0 and $70 = or then ( a is8? ) ;
+
: forward! ( jmpaddr -- )
- c@+ $0f = if 1+ then here over - ( a rel )
- realmode if 2 - swap w! else 4 - swap ! then ;
+ _jmpop@ ( a is8? ) swap here over - ( is8? a rel )
+ rot if 1- swap c! else realmode if 2 - swap w! else 4 - swap ! then then ;
\ Single operand
\ opcode format 00000000 00000rrr mmmmmmmm mmmmmmmm
diff --git a/fs/cc/vm/i386.fs b/fs/cc/vm/i386.fs
@@ -240,7 +240,7 @@ unaryop vmnot, not, ( ~ )
: vm>=, _ vmop :compile vmop type typeunsigned? if setae, else setge, then ;
: vm==, _ vmop :compile setz, ;
: vm!=, _ vmop :compile setnz, ;
-: vm&&, vmop :>reg vmop :compile vmop :compile test, nop, forward jz,
+: vm&&, vmop :>reg vmop :compile vmop :compile test, nop, forward8 jz,
vmop :compile vmop^ :compile or, vmop^ :init vmboolify, forward! ;
: vm||, vmop :>reg vmop :compile vmop^ :compile or, vmop^ :init vmboolify, ;
diff --git a/fs/tests/asm/i386.fs b/fs/tests/asm/i386.fs
@@ -89,4 +89,20 @@ code foo8
ret,
foo8 42 #eq
+
+\ forward jumps
+code foo9 ( n -- n )
+ bp 0 d) 42 i) cmp,
+ forward8 jnz,
+ bp 0 d) inc,
+ forward!
+ bp 0 d) 54 i) cmp,
+ forward jnz,
+ bp 0 d) inc,
+ forward!
+ ret,
+
+12 foo9 12 #eq
+42 foo9 43 #eq
+54 foo9 55 #eq
testend