commit 014942e251ad4b732daf8319eee102e2a3140005
parent 6c38e0cb5299907fabdda579775df14588f1df1b
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 2 Jul 2023 11:12:49 -0400
hal i386: fix [@+], and [!+], with A>) and m)
Diffstat:
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/fs/doc/hal.txt b/fs/doc/hal.txt
@@ -74,7 +74,10 @@ i386 would yield "bx sp 4 +) lea, ax bx add,".
The "&)" word never writes instructions directly, only operator words. The
"lea," above wouldn't be written when "&)" is called, but when "+," is.
-The &) operand can't be used with: 8b) 16b) i)
+The &) operand always results in a 32-bit operation. Don't try to apply 16b) or
+8b) afterwards, this results in undefined behavior.
+
+&) can't be used with i).
### <>) operand modifiers
diff --git a/fs/tests/hal.fs b/fs/tests/hal.fs
@@ -251,4 +251,15 @@ code test27 ( a b c d -- a+d )
PSP) 5 +) 3 +) +, nip, nip, nip, exit,
20 54 12 22 test27 42 #eq
+
+create foo 42 , 54 ,
+create ptr foo ,
+\ [@+] with A>) and m)
+code test28 ( -- n )
+ ptr m) A>) [@+],
+ dup, A) &) @,
+ exit,
+
+test28 42 #eq
+test28 54 #eq
testend
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -291,7 +291,8 @@ pc to lblmodrmwr ( operand -- )
$24 i) cwrite, forward! forward! \ mod=3 and rm=SP? write SIB
dl al mov, dl $c0 i) and, \ dl=mod
dl $40 i) cmp, L2 abs>rel jz, \ disp8
- al $05 i) cmp, L3 abs>rel jz, \ m) means disp32
+ dl al mov, 0 dl reg!,
+ dl $05 i) cmp, L3 abs>rel jz, \ m) means disp32
xdrop, ret,
\ If HALDEREF flag is set operate the necessary changes in opmod to dereference
@@ -346,7 +347,9 @@ xcode !, ( operand -- )
xcode @!, ( operand -- ) \ operand ax xchg,
ax $8600 i) or, lblregularwr absjmp,
+\ TODO: this is broken with 16b) and 8b)
xcode +n, ( n operand -- ) \ operand n i) add,
+ 0 al reg!,
si 0 d) 1 i) cmp, forward8 jnz,
xnip, ax $fe00 i) or, lblregularwr absjmp, forward!
si 0 d) -1 i) cmp, forward8 jnz,
@@ -405,8 +408,8 @@ pc to L2 ( operand -- operand-with-di-src )
di al reg!,
wcall, 32b) wcall, @,
wcall, 32b) wcall, +n,
- ax $20100 i) and, \ Set operand to W) but preserve size flags
- al $07 i) mov, \ keep size, but modrm is for di 0 d) ax mov,
+ ax $20138 i) and, \ Set operand src but preserve size and dst
+ al $07 i) or, \ keep size, but modrm is for di 0 d) dst mov,
ret,
xcode [@+], ( operand -- )