~vdupras/duskos

d30ff2622a0817d6ff94d9df7aeeddeef33f61aa — Virgil Dupras 3 months ago dc37542
rpi: add 16b support to @!,

This brings us to @! in bootlo.

Also, use immediate modes for LDRH and STRH, which simplifies the code. I simply
hadn't notice its presence yet, I thought I was forced to register-based
offsets.
2 files changed, 23 insertions(+), 9 deletions(-)

M fs/xcomp/arm/rpi/kernel.fs
M fs/xcomp/rpiboot.fs
M fs/xcomp/arm/rpi/kernel.fs => fs/xcomp/arm/rpi/kernel.fs +18 -9
@@ 461,16 461,13 @@ xcode W>A, ( -- )
  ( pc ) r0 pc@>reg, lbldwrite abs>rel b) ,)

\ operand is 16b
pc mov) r0 rd) 0 i) ,)
pc to L2 ( operand -- ) \ r0=base instr r1=off
  orr) r3 rd) r0 rn) $b0 i) ,) \ make into a ldrh/strh op
  bic) r3 rdn) $04000000 i) ,)
  ( pc ) r0 pc@>reg,
  orr) r0 rdn) $b0 i) ,) \ make into a ldrh/strh op
  bic) r0 rdn) $04000000 i) ,)
  orr) r0 rdn) $00400000 i) ,) \ immediate
  \ TODO: support offsets > 0xf
  tst) rTOP rn) $8 i) ,) \ has offset?
  mov) z) r1 rd) 0 i) ,) \ if not, force a 0
  orr) r0 rdn) r1 rm) ,)
  pushret, lbldwrite abs>rel bl) ,) popret, \ copy offset in r0
  mov) r0 rd) r3 rm) ,)
  orr) nz) r0 rdn) r1 rm) ,) \ apply immediate offset
  L1 abs>rel b) ,)

pc to L3 ( operand -- ) \ r0=base instr


@@ 483,15 480,27 @@ pc to L3 ( operand -- ) \ r0=base instr
  L1 abs>rel b) ,)

pc ldr) 0 +i) ,)
xcode @, ( operand -- )
xcode @, ( operand -- ) \ Compiled code preserves r0
  ( pc ) r0 pc@>reg, L3 abs>rel b) ,)

pc str) 0 +i) ,)
xcode !, ( operand -- )
  ( pc ) r0 pc@>reg, L3 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 -- )
  pushret, xdup,
  bic) rTOP rdn) $f000 i) ,) \ Rd=r0
  wcall, @, wcall, !,
  popret,
  ( pc ) r0 pc@>reg,
  lbldwrite abs>rel b) ,)

pc swp) rTOP rd) rTOP rm) ,) add) r0 rd) rPSP rn) 0 i) ,)
xcode @!, pushret, ( operand -- )
  tst) rTOP rn) $04000000 i) ,)
  L2 abs>rel b) z) ,)
  dup ( pc ) 4 + r1 pc@>reg,
  lblhbank r0 pc@>reg,
  orr) r0 rdn) r1 rm) ,) \ r0=add instr

M fs/xcomp/rpiboot.fs => fs/xcomp/rpiboot.fs +5 -0
@@ 32,6 32,11 @@ code8b 1 W) 8b) [+n], drop, exit,
code 1-! -1 W) [+n], drop, exit,
code16b -1 W) 16b) [+n], drop, exit,
code8b -1 W) 8b) [+n], drop, exit,
code @! W>A, drop, A) @!, exit,
code16b HERE @ W>A, drop, A) 16b) @!, exit,
code8b HERE @ W>A, drop, A) 8b) @!, exit,
code c@! branch, drop
code w@! branch, drop

uartinit prompt interactive!