duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 3f6eb0aa81c8ff0e4418f602c7854cb68c2526c6
parent 8af85ff584454cb304a71ba6b80d12d2216d65dc
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri, 30 Jun 2023 21:41:24 -0400

hal i386: add LEA emitting on &) when appropriate

Diffstat:
Mfs/tests/hal.fs | 7+++++++
Mfs/xcomp/i386/kernel.fs | 59+++++++++++++++++++++++++++++++++++------------------------
2 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/fs/tests/hal.fs b/fs/tests/hal.fs @@ -224,4 +224,11 @@ code test23 ( n -- r q ) exit, 10 test23 3 #eq 1 #eq + +\ &) with offset +code test24 ( -- a ) + dup, PSP) 4 +) &) @, + exit, + +3 2 1 test24 @ 2 #eq 2drop drop testend diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs @@ -43,11 +43,11 @@ \ Constants and labels 0 to realmode : values ( n -- ) for 0 value next ; -23 values lblmainalias lblbootptr lblnextword lblcurword lblnextmeta lblret +24 values lblmainalias lblbootptr lblnextword lblcurword lblnextmeta lblret lblsysdict lblhere lbl[rcnt] lblhbank lblmod lblparsec lblparseh lblparseud lblerrmsg lblfind lblcompiling lblidt - lblwriterange lblrelwr lblcallwr lblderef lblariwr + lblwriterange lblrelwr lblcallwr lblmodrmwr lblderef lblariwr $8000 const HERESTART $500 to binstart @@ -66,6 +66,7 @@ $80000 const HALINV : 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, di swap i) mov, lblwriterange abscall, ; +: reg0, ( 8bopmod -- ) $c7 i) and, ; \ Let's go! here# to org @@ -215,15 +216,6 @@ xcode ps+, ( n -- ) \ si XX i) add, cx $1c6 ( si ) i) mov, L1 abscall, xdrop, ret, -\ If HALDEREF flag is set operate the necessary changes in opmod to dereference -\ it. If a lea, is necessary, write it. TODO: lea, -pc to lblderef ( opmod -- opmod ) - ax HALDEREF i) test, forward8 jnz, ret, forward! - ax $c0 i) test, \ mod - forward8 jnz, \ mod=0, set to mod=3 - ax $c0 i) or, forward! - ret, - pc to L3 ( operand -- ) \ disp32 ax lblhbank m) mov, ax dwrite, @@ -233,6 +225,32 @@ pc to L2 ( operand -- ) \ disp8 al cwrite, xdrop, ret, +\ Write modrm in AL, with disp8/disp32/SIB if appropriate. +pc to lblmodrmwr ( operand -- ) + al cwrite, + dx ax mov, dl $7 i) and, dl $4 i) cmp, + forward8 jnz, $24 i) cwrite, forward! \ 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 + xdrop, ret, + +\ If HALDEREF flag is set operate the necessary changes in opmod to dereference +\ it. If a LEA is necessary, write it to CX, then mangle operand to reference +\ it. +pc to lblderef ( operand -- operand ) + ax HALDEREF i) test, forward8 jnz, ret, forward! + ax $c0 i) test, \ mod + forward8 jnz, \ mod=0, set to mod=3 + ax $c0 i) or, ret, forward! + \ TODO: HAL error on mod=3 + \ Write LEA to CX + xdup, + al reg0, al $08 i) or, \ reg=CX + $8d i) cwrite, lblmodrmwr abscall, \ lea, + al $38 i) and, al $c1 i) or, \ rm=CX + ret, + \ Write operand and code which have already been merged together. \ Opcode is in b15:8 and modrm in b7:0. \ Add 16b prefix when 16b flag is set. @@ -243,15 +261,8 @@ pc to L1 ( operand -- ) lblderef abscall, ax HAL16B i) test, forward8 jz, $66 i) cwrite, forward! ax HALINV i) test, forward8 jz, ax $0200 i) xor, forward! \ inv dir bit - al ah xchg, - ax wwrite, - al ah xchg, - dx ax mov, dl $7 i) and, dl $4 i) cmp, - forward8 jnz, $24 i) cwrite, forward! \ 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 - xdrop, ret, + ah cwrite, + lblmodrmwr absjmp, xcode !, ( operand -- ) \ operand ax mov, ax $8800 i) or, L1 absjmp, @@ -303,12 +314,12 @@ xcode *, ( operand -- ) ax HALINV ^ i) and, $c789 i) wwrite, forward! \ di ax mov, dx ax mov, dl $38 i) and, dl $18 i) cmp, forward8 jnz, \ reg=BX (A>) - $93 i) cwrite, al $c7 i) and, forward! \ ax bx xchg, + $93 i) cwrite, al reg0, forward! \ ax bx xchg, ax $f720 i) or, L1 abscall, dx ax mov, dl $38 i) and, dl $18 i) cmp, forward8 jnz, \ reg=BX (A>) $93 i) cwrite, forward! \ ax bx xchg, ax HALINV i) test, forward8 jz, \ inverted, save AX to src. - al $c7 i) and, \ regid=AX + al reg0, \ regid=AX wcall, @, $f889 i) wwrite, ret, forward! \ ax di mov, @@ -348,7 +359,7 @@ xcode [!+], ( operand -- ) \ operand's src in a register so that the operation is upscaled to 32-bit. pc to L2 ( operand -- ) \ dx=opcodes dx push, xdup, - al $c7 i) and, al $10 i) or, \ reg=DX + al reg0, al $10 i) or, \ reg=DX wcall, @, ( op ) dx pop, ax $38 i) and, \ keep reg only @@ -394,7 +405,7 @@ xcode compare, ( operand -- ) pc to L1 ( operand -- ) \ dx=SHL/SHR regid dx push, ax HALIMM i) test, forward8 jnz, \ not an immediate - xdup, al $c7 i) and, al $08 i) or, \ target CX + xdup, al reg0, al $08 i) or, \ target CX wcall, @, \ mod becomes 3, reg moves to rm and DL is orred into modrm dx pop, al 3 i) shr, al 7 i) and, al $c0 i) or, al dl or,