duskos

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

commit 9a617369584329535ecbeacdca89ff9a916487e3
parent 552fbf12c22369ce97bae08fd67f6889071d6317
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 27 Jun 2023 20:06:31 -0400

asm/armh: add i) m) compare,

tests/asm/hal passes tests up to test14

Diffstat:
Mfs/asm/arm.fs | 8++++----
Mfs/asm/armh.fs | 17+++++++++++++----
Mfs/asm/i386.fs | 10+++++-----
Mfs/asm/i386h.fs | 2+-
Mfs/asm/nbank.fs | 4+---
Mfs/tests/asm/hal.fs | 2+-
Mfs/tests/asm/i386.fs | 2+-
Mfs/xcomp/arm/rpi/kernel.fs | 14+++++++-------
8 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/fs/asm/arm.fs b/fs/asm/arm.fs @@ -91,10 +91,10 @@ $90 al) const mul) \ HAL \ "opcode+mod" structure (close to ARM structure) -\ b2:0 Number bank index -\ b3 Has an nonzero offset -\ b4 Rn is an absolute memory addr in bank if set -\ b11:5 Zeroes +\ b3:0 Number bank index +\ b4 Has an nonzero offset +\ b5 Rn is an absolute memory addr in bank if set +\ b11:6 Zeroes \ b15:12 Rd \ b19:16 Rn \ b21:20 Zeroes diff --git a/fs/asm/armh.fs b/fs/asm/armh.fs @@ -3,20 +3,29 @@ ?f<< /asm/arm.fs ?f<< /asm/nbank.fs -:realias bankid@ 7 and ; +: bankid $f and ; :realias oldbank! HBANK ! ; +$e4009000 const HALBASE \ Always, 32-bit, Rd=rTOP : A>) ( halop -- halop ) $ffff0fff and rA 12 lshift or ; : <>) ( halop -- halop ) $00800000 xor ; : &) ( halop -- halop ) $01000000 xor ; -: +) ( halop n -- halop ) bank! $08 or or ; +: +) ( halop n -- halop ) bank! $10 or or ; +: i) ( n -- halop ) dup .x nl> bank! dup .x nl> $02000000 or HALBASE or ; +: imm? $02000000 and bool ; +: m) ( n -- halop ) bank! $20 or HALBASE or ; -: ?disp) ( instr halop -- instr ) dup $08 and if bank@ +i) else drop then ; +: ?disp) ( instr halop -- instr ) + dup $10 and if bankid bank@ +i) else drop then ; : ldrr0, ( halop -- ) - ldr) r0 rd) over 16 rshift $f and rn) swap ?disp) ,) ; + dup imm? if + mov) r0 rd) swap bankid dup .x nl> bank@ dup .x nl> imm) ,) + else ldr) r0 rd) over 16 rshift $f and rn) swap ?disp) ,) then ; : haldst ( halop -- dst ) 12 rshift $f and ; : op doer , does> @ ( halop instr ) over ldrr0, swap haldst rdn) r0 rm) f) ,) ; add) op +, sub) op -, +: compare, dup ldrr0, cmp) swap haldst rn) r0 rm) ,) ; + : *, dup ldrr0, haldst mul) over rd) swap rs) r0 rm) ,) ; diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs @@ -26,7 +26,7 @@ : regid@ 7 and ; : mod@ 6 rshift 3 and ; : modrm@ $c7 and ; -:realias bankid@ 20 rshift $f and ; +: bankid@ 20 rshift $f and ; : newbankedop ( n -- opmod ) bank! 20 lshift ; : sib@ 24 rshift ; : imm? $8000 and bool ; @@ -86,14 +86,14 @@ alias _remsz 8b) : addr, realmode if 16b le, else le, then ; : data, realmode _16b or if 16b le, else le, then ; : ?disp, ( opmod -- ) dup mod@ case ( opmod ) - 0 = of dup ismem? if bank@ addr, else drop then endof - 1 = of bank@ c, endof - 2 = of bank@ addr, endof + 0 = of dup ismem? if bankid@ bank@ addr, else drop then endof + 1 = of bankid@ bank@ c, endof + 2 = of bankid@ bank@ addr, endof 2drop endcase ; : ?8b, ( n f -- ) if c, else data, then ; : ?imm, ( opmod -- ) _imm? if 8b? _imm swap ?8b, else drop then ; : ?sib, ( opmod -- ) dup sib? if sib@ c, else drop then ; -: checkimm ( arg -- f ) dup bank@ to _imm imm? dup to _imm? ; +: checkimm ( arg -- f ) dup bankid@ bank@ to _imm imm? dup to _imm? ; : check16b ( arg -- ) 16b? if 1 to _16b then ; : notimm# ( opmod -- ) checkimm not _assert ; : op, ( opcode -- ) _16b if $66 c, then dup >>8 1 and if $0f c, then c, ; diff --git a/fs/asm/i386h.fs b/fs/asm/i386h.fs @@ -14,7 +14,7 @@ : _& ( opmod -- opmod ) dup &? if - $fffeffff and dup indirect? if dup ismem? if bank@ i) else + $fffeffff and dup indirect? if dup ismem? if bankid@ bank@ i) else dup mod@ 0 = if ( indirect no disp ) $c0 or else ( indirect + disp ) di swap lea, di then then then then ; diff --git a/fs/asm/nbank.fs b/fs/asm/nbank.fs @@ -7,9 +7,7 @@ create _bank $10 CELLSZ * allot 0 value _bankidx : newbankid ( n -- id ) to1+ _bankidx _bankidx $f and ; : bank' ( id -- a ) CELLSZ * _bank + ; -\ This needs to be realiased by the unit using the bank -alias abort bankid@ ( opmod -- id ) -: bank@ ( opmod -- n ) bankid@ bank' @ ; +: bank@ ( id -- n ) bank' @ ; \ This alias is to give the opportunity to HALs to update their kernel-level \ number bank (single) at the same time as the High HAL number bank. This word \ is realiased in High HAL units. diff --git a/fs/tests/asm/hal.fs b/fs/tests/asm/hal.fs @@ -92,7 +92,7 @@ code test9 ( n -- n ) \ returns 42 if arg >= 10, 54 otherwise code test10 ( n -- n-42 ) dup, 42 LIT>W, - ' test1 execute, + pushret, ' test1 execute, popret, exit, 54 test10 12 #eq diff --git a/fs/tests/asm/i386.fs b/fs/tests/asm/i386.fs @@ -8,7 +8,7 @@ testbegin \ binary and can only be ran on i386. cx $1c1 #eq -: chk ( opmod disp expected ) rot tuck $fff and #eq bank@ #eq ; +: chk ( opmod disp expected ) rot tuck $fff and #eq bankid@ bank@ #eq ; $1234 m) $1234 $105 chk dx 0 d) 0 $102 chk dx 42 d) 42 $142 chk diff --git a/fs/xcomp/arm/rpi/kernel.fs b/fs/xcomp/arm/rpi/kernel.fs @@ -425,7 +425,7 @@ HALBASE rSP rn) xconst RSP) pc to lblhbank 0 le, lblhbank xaddr HBANK -pc HALBASE $10 or le, \ b4 is set +pc HALBASE $20 or le, \ b5 is set xcode m) ( a -- operand ) lblhbank r0 pc>reg, str) rTOP rd) r0 rn) ,) @@ -437,7 +437,7 @@ xcode +) ( operand n -- operand ) lblhbank r0 pc>reg, str) rTOP rd) r0 rn) ,) xdrop, - orr) rTOP rdn) $8 imm) ,) + orr) rTOP rdn) $10 imm) ,) exit, xcode 8b) ( operand -- operand ) @@ -530,7 +530,7 @@ pc to lbllitwr ( n -- ) \ r0=Rd lbladdnwr abs>rel b) ,) pc to lblmemwr ( operand -- operand ) \ preserves r0 - tst) rTOP rn) $10 imm) ,) + tst) rTOP rn) $20 imm) ,) return) z) ,) \ not a m) operand r0 push, xdup, lblhbank rTOP pc@>reg, @@ -564,7 +564,7 @@ xcode W<>A, ( -- ) \ conditionally merge hbank with operand, then with instr then write pc to L2 \ rTOP=operand bic) rTOP rdn) $04000000 imm) ,) \ remove 32b flag - tst) rTOP rn) $8 imm) ,) \ has offset? + tst) rTOP rn) $10 imm) ,) \ has offset? bic) rTOP rdn) $3f imm) ,) lblhbank r1 pc@>reg, orr) nz) rTOP rdn) r1 rm) ,) @@ -575,7 +575,7 @@ pc to L3 ( operand -- ) \ r0=base instr orr) r0 rdn) $b0 imm) ,) \ make into a ldrh/strh op bic) r0 rdn) $04000000 imm) ,) orr) r0 rdn) $00400000 imm) ,) \ immediate - tst) rTOP rn) $8 imm) ,) \ has offset? + tst) rTOP rn) $10 imm) ,) \ has offset? lblhbank r1 pc@>reg, bic) nz) rTOP rdn) $3f imm) ,) \ clear offset+imm flags mov) nz) r2 rd) r1 rm) 4 lsl) ,) \ imm high nibble @@ -602,7 +602,7 @@ xcode !, ( operand -- ) pc add) 0 imm) ,) xcode addr, ( operand -- ) lblhbank r0 pc@>reg, - tst) rTOP rn) $10 imm) ,) + tst) rTOP rn) $20 imm) ,) mov) nz) rTOP rd) r0 rm) ,) xwordlbl LIT>W, abs>rel b) nz) ,) \ m) operand? same as LIT>W, ( pc ) r0 pc@>reg, L2 abs>rel b) ,) @@ -623,7 +623,7 @@ xcode @!, ( operand -- ) tst) rTOP rn) $04000000 imm) ,) L2 abs>rel b) z) ,) bic) rTOP rdn) $04000000 imm) ,) \ remove 32b flag - tst) rTOP rn) $8 imm) ,) \ has offset? + tst) rTOP rn) $10 imm) ,) \ has offset? forward b) z) ,) xdup, setrd0) rTOP rdn) ,) pushret, wcall, addr, popret,