commit 1f831dd2f075de86b240870db86e5eac1531d091
parent 257710b3454eb0144428843f40b0b8f9996fa44f
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 17 Mar 2023 08:34:09 -0400
hal i386: add "lea," and ESP modrm encoding
EAX=3 at bye
Diffstat:
2 files changed, 42 insertions(+), 17 deletions(-)
diff --git a/fs/xcomp/bootlo2.fs b/fs/xcomp/bootlo2.fs
@@ -94,4 +94,33 @@ code ?dup W=0>Z, 0 Z) branchC, dup, then exit,
again ; immediate
( hello, another comment! )
-: foo if 42 else 54 then bye ; 1 not foo
+\ Arithmetic
+: > swap < ;
+: 0>= $80000000 < ;
+: 0< 0>= not ;
+: >= < not ;
+: <= > not ;
+: <> = not ;
+: -^ swap - ;
+: / /mod nip ;
+: mod /mod drop ;
+: ?swap ( n n -- l h ) 2dup > if swap then ;
+: min ?swap drop ; : max ?swap nip ;
+: max0 ( n -- n ) dup 0< if drop 0 then ;
+: =><= ( n l h -- f ) over - rot> ( h n l ) - >= ;
+: neg 0 -^ ;
+code ^ -1 xorn, exit,
+: and? bool swap bool and ;
+: or? or bool ;
+: upcase ( c -- c ) dup 'a' - 26 < if $df and then ;
+
+\ Stack
+: rdrop 4 rs+, ; immediate
+: 2rdrop 8 rs+, ; immediate
+: r@ dup, RSP) @, ; immediate
+: r> [compile] r@ [compile] rdrop ; immediate
+: >r -4 rs+, RSP) !, drop, ; immediate
+code scnt dup, PSP) lea, ] PSTOP -^ >> >> 1- ;
+code rcnt dup, RSP) lea, ] RSTOP -^ >> >> ;
+
+: foo rcnt bye ; foo
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -39,15 +39,6 @@ $80000 const PSTOP
$10 const HBANKCNT
PSTOP STACKSZ - const HEREMAX
-$1c0 const MODRM_AX
-$1c7 const MODRM_DI
-$1c6 const MODRM_SI
-$1c4 const MODRM_SP
-$100 const MODRM_[AX]
-$107 const MODRM_[DI]
-$106 const MODRM_[SI]
-$104 const MODRM_[SP]
-
: _ dx lblhere m) mov, dx 0 d) swap mov, ;
: cwrite, ( opmod -- ) _ lblhere m) inc, ; \ Destroys dx
: wwrite, ( opmod -- ) _ lblhere m) 2 i) add, ; \ Destroys dx
@@ -146,10 +137,10 @@ xcode hbank! ( operand n -- operand )
ax bx or,
ret,
-MODRM_[AX] xconst W)
-MODRM_[DI] xconst A)
-MODRM_[SI] xconst PSP)
-MODRM_[SP] xconst RSP)
+$100 xconst W)
+$107 xconst A)
+$106 xconst PSP)
+$104 xconst RSP)
$4 xconst Z)
$5 xconst NZ)
@@ -200,12 +191,12 @@ pc to L1 \ bx=dstmodrm cx=i
$83 i) cwrite, bl cwrite, cl cwrite, ret,
xcode rs+, ( n -- ) \ sp XX i) add,
- bx MODRM_SP i) mov, cx ax mov, L1 abscall,
+ bx $1c4 ( sp ) i) mov, cx ax mov, L1 abscall,
lbl[rcnt] m) ax add,
xdrop, ret,
xcode ps+, ( n -- ) \ si XX i) add,
- bx MODRM_SI i) mov, cx ax mov, L1 abscall,
+ bx $1c6 ( si ) i) mov, cx ax mov, L1 abscall,
xdrop, ret,
pc to L1
@@ -234,6 +225,8 @@ pc to L1 \ ax=opmod
ax $20000 i) test, forward8 jz, $66 i) cwrite, forward! \ 16b?
al ah xchg,
ax wwrite,
+ bx ax mov, bh $7 i) and,
+ bh $4 i) cmp, forward8 jnz, $24 i) cwrite, forward! \ sp? write SIB
ah $40 i) test, forward8 jz, \ disp8
al ah xchg,
wcall, @)
@@ -257,9 +250,12 @@ xcode @, ( operand -- ) \ ax operand mov,
xcode @!, ( operand -- ) \ operand ax xchg,
ax $8600 i) or, L1 absjmp,
-xcode +, ( operand -- ) \ operand ax add,
+xcode +, ( operand -- ) \ ax operand add,
ax $0200 i) or, L1 absjmp,
+xcode lea, ( operand -- ) \ ax operand lea,
+ ax $8d00 i) or, L1 absjmp,
+
xcode [@], ( operand -- ) \ ax 32b) operand mov, ax Xb) ax 0 d) mov,
xdup, wcall, 32b) wcall, @, ( operand -- )
ax $ffffff00 i) and, \ set operand to [eax] but keep size