commit de06d2fde39fe0bd385a7a9d9676887de6f3dea4
parent 0f4981c7e4fccf5ce8b23c884e3a3511869ad068
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 5 Jun 2023 15:32:45 -0400
rpi: add addr, << >> lshift rshift
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/fs/xcomp/arm/rpi/kernel.fs b/fs/xcomp/arm/rpi/kernel.fs
@@ -62,6 +62,8 @@ $e4009000 const HALBASE \ Always, 32-bit, Rd=rTOP
0 align4 here to org
forward b) ,) \ coldboot
HERESTART xconst herestart
+PSTOP xconst PSTOP
+RSTOP xconst RSTOP
xcode bye 0 b) ,)
@@ -550,6 +552,16 @@ pc str) 0 +i) ,)
xcode !, ( operand -- )
( pc ) r0 pc@>reg, L3 abs>rel b) ,)
+pc add) 0 i) ,)
+xcode addr, ( operand -- )
+ ( pc ) r0 pc@>reg,
+ lblhbank r1 pc@>reg,
+ bic) rTOP rdn) $04000000 i) ,)
+ tst) rTOP rn) $8 i) ,) \ has offset?
+ bic) rTOP rdn) $3f i) ,)
+ orr) nz) rTOP rdn) r1 rm) ,)
+ L1 abs>rel b) ,)
+
\ operand is 16b and ARM doesn't have a 16b SWP! LDR+STR+MOV...
pc mov) rTOP rd) r0 rm) ,)
pc to L2 ( operand -- )
@@ -708,6 +720,24 @@ xcode xor ( n n -- n )
r0 ppop, eor) rTOP rdn) r0 rm) ,)
exit,
+xcode << ( n -- n )
+ mov) rTOP rd) rTOP rm) 1 lsl) ,)
+ exit,
+
+xcode >> ( n -- n )
+ mov) rTOP rd) rTOP rm) 1 lsr) ,)
+ exit,
+
+xcode lshift ( n u -- n )
+ r0 ppop,
+ mov) rTOP rd) r0 rm) rTOP rlsl) ,)
+ exit,
+
+xcode rshift ( n u -- n )
+ r0 ppop,
+ mov) rTOP rd) r0 rm) rTOP rlsr) ,)
+ exit,
+
pc ," divide by zero" 0 align4
xcode /mod ( a b -- r q )
( pc ) r0 pc>reg,
diff --git a/fs/xcomp/rpiboot.fs b/fs/xcomp/rpiboot.fs
@@ -104,4 +104,23 @@ uartinit \ see the (wnf) if comment is mishandled
: 0< 0>= not ;
: / /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 ) - >= ;
+code neg -W, exit,
+: ^ -1 xor ;
+: 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! -4 rs+, RSP) !, ; immediate
+: r@ dup, RSP) @, ; immediate
+: r> [compile] r@ [compile] rdrop ; immediate
+: >r [compile] r! drop, ; immediate
+code scnt pushret, dup, PSP) addr, ] PSTOP -^ >> >> 1- ;
+code rcnt pushret, dup, RSP) addr, ] RSTOP -^ >> >> ;
prompt interactive!