~vdupras/duskos

eae4a2b1c29786a4005699fda697ced0ba30c9d0 — Virgil Dupras 1 year, 4 months ago ab86276
rpi: add litn and use it in compword
4 files changed, 44 insertions(+), 26 deletions(-)

M fs/asm/arm.fs
M fs/xcomp/arm/rpi/kernel.fs
M fs/xcomp/bootlo.fs
M fs/xcomp/rpiboot.fs
M fs/asm/arm.fs => fs/asm/arm.fs +5 -5
@@ 90,12 90,12 @@ $90 al) const mul)
\ HAL

\ "opcode+mod" structure (close to ARM structure)
\ b3:0   Rm or Rn
\ b7:4   Number bank index
\ b8     Rn is an absolute memory addr in bank if set
\ b11:9  Zeroes
\ b3:0   Number bank index
\ b4     Rn is an absolute memory addr in bank if set
\ b11:5  Zeroes
\ b15:12 Rd
\ b21:16 Zeroes
\ b19:16 Rn
\ b21:20 Zeroes
\ b22    8-bit if set
\ b24:23 Zeroes
\ b25    Immediate if set

M fs/xcomp/arm/rpi/kernel.fs => fs/xcomp/arm/rpi/kernel.fs +32 -15
@@ 379,15 379,15 @@ xcode code pushret,
  popret, wjmp, entry

\ HAL operands
HALBASE rTOP + xconst W)
HALBASE rA + xconst A)
HALBASE rPSP + xconst PSP)
HALBASE rSP + xconst RSP)
HALBASE rTOP rn) xconst W)
HALBASE rA rn) xconst A)
HALBASE rPSP rn) xconst PSP)
HALBASE rSP rn) xconst RSP)
0 eq) xconst Z)
0 ne) xconst NZ)

pc to lblhbank 0 le,
pc HALBASE $100 or le, \ b8 is set
pc HALBASE $10 or le, \ b4 is set
xcode m) ( a -- operand )
  lblhbank r0 pc>reg,
  str) rTOP rd) r0 rn) ,)


@@ 416,24 416,34 @@ xcode 32b) ( operand -- operand )
\ HAL operations
\ r0 is used as the immediate accumulator
\ TODO: add support for immediate > 0xff
pc to L1 ( n -- ) \ r0=base instr

pc to L1 ( operand -- ) \ r0=base instr
  orr) r0 rdn) rTOP rm) ,)
  xdrop,
  lbldwrite abs>rel b) ,)

pc to L2 ( n -- ) \ r0=base instr
  tst) rTOP rn) $80000000 i) ,)
  eor) ne) r0 rdn) $00c00000 i) ,) \ add) to sub)
  rsb) ne) rTOP rdn) 0 i) ,) \ negate rTOP
  and) rTOP rdn) $ff i) ,)
  orr) r0 rdn) rTOP rm) ,)
  xdrop,
  lbldwrite abs>rel b) ,)
  L1 abs>rel b) ,)

pc add) rSP rdn) 0 i) ,)
xcode rs+, ( n -- )
  ( pc ) r0 pc@>reg,
  L1 abs>rel b) ,)
  ( pc ) r0 pc@>reg, L2 abs>rel b) ,)

pc add) rPSP rdn) 0 i) ,)
xcode ps+, ( n -- )
  ( pc ) r0 pc@>reg,
  L1 abs>rel b) ,)
  ( pc ) r0 pc@>reg, L2 abs>rel b) ,)

pc mov) rTOP rd) 0 i) ,)
xcode LIT>W, ( n -- )
  ( pc ) r0 pc@>reg, L1 abs>rel b) ,)

pc ldr) rTOP rd) ,)
xcode @, ( operand -- )
  ( pc ) r0 pc@>reg, L1 abs>rel b) ,)

pc pushret,
xcode pushret,


@@ 459,8 469,11 @@ xcode execute, ( w -- )

pc xdup,
xcode dup,
  ( pc ) r0 pc@>reg,
  lbldwrite abs>rel b) ,)
  ( pc ) r0 pc@>reg, lbldwrite abs>rel b) ,)

xcode litn
  pushret, wcall, dup, popret,
  wjmp, LIT>W,

xcode ; ximm pushret,
  wcall, popret,


@@ 476,6 489,10 @@ pc to L2 pushret, ( str -- w ) \ find in sys dict
  popret, exit,

xcode compword ( str -- )
  pushret, wcall, parse popret,
  cmp) rTOP rn) 0 i) ,)
  xdrop,
  xwordlbl litn abs>rel b) ne) ,) \ literal: jump to litn
  pushret, L2 execute, popret,
  ldr) r0 rd) rTOP rn) 8b) 9 -i) ,)
  tst) r0 rn) $80 i) ,)

M fs/xcomp/bootlo.fs => fs/xcomp/bootlo.fs +3 -3
@@ 1,7 1,5 @@
code : ] code ] ;
: :8b code8b ] ;
: :16b code16b ] ;
: noop ;
code noop exit,
code dup dup, exit,
: swap, PSP) @!, ; code swap swap, exit,
: nip, 4 ps+, ; code nip nip, exit,


@@ 67,6 65,8 @@ code 1- -1 W+n, exit,
: EMETA_16B $11 ; : EMETA_8B $10 ;
: 16b EMETA_16B MOD ! ; immediate
: 8b EMETA_8B MOD ! ; immediate
: :8b code8b ] ;
: :16b code16b ] ;

: , HERE @!+ ; :16b HERE 16b @!+ ; :8b HERE 8b @!+ ; : c, 8b , ;


M fs/xcomp/rpiboot.fs => fs/xcomp/rpiboot.fs +4 -3
@@ 1,5 1,6 @@
code : pushret, ] code ] ;
code hey 42 ps+, exit,
code ho -12 ps+, exit,
code : pushret, ] code pushret, ] ;
code noop exit,
code dup dup, exit,
: hey 42 ;
uartinit prompt interactive!