diff options
| author | Cliff Click <cliffc@acm.org> | 2025-03-18 09:02:20 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-03-18 09:02:20 -0700 |
| commit | efc53c6d4b8d11cb08ba84800d85bc725b2f2d5b (patch) | |
| tree | a37d1aaf1894993a476e2873f74d78be777fae64 /chapter21/src/main/java/com | |
| parent | 5faaadb794ad864ce3e26ed6a5fc4457a8aa2f15 (diff) | |
| download | Simple-efc53c6d4b8d11cb08ba84800d85bc725b2f2d5b.tar.gz Simple-efc53c6d4b8d11cb08ba84800d85bc725b2f2d5b.zip | |
Update CallRISC.java
Diffstat (limited to 'chapter21/src/main/java/com')
| -rw-r--r-- | chapter21/src/main/java/com/seaofnodes/simple/node/cpus/riscv/CallRISC.java | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/riscv/CallRISC.java b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/riscv/CallRISC.java index 538a68be..ec500aa7 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/riscv/CallRISC.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/riscv/CallRISC.java @@ -28,24 +28,28 @@ public class CallRISC extends CallNode implements MachNode, RIPRelSize { @Override public TypeFunPtr tfp() { return _tfp; } @Override public void encoding( Encoding enc ) { + // Short form +/-4K: beq r0,r0,imm12 + // Long form: auipc rX,imm20/32; jal r0,[rX+imm12/32] enc.relo(this); short rpc = enc.reg(this); - //// High half is where the TFP constant used to be, the last input - //short auipc = enc.reg(in(_inputs._len-1)); - //enc.add4(riscv.i_type(0x67, rpc, 0, auipc, 0)); - // TODO: JAL for range - throw Utils.TODO(); + enc.add4(riscv.j_type(riscv.J_JAL, rpc, 0)); } - // Delta is from opcode start, but X86 measures from the end of the 5-byte encoding - @Override public byte encSize(int delta) { return 4; } + // Delta is from opcode start + @Override public byte encSize(int delta) { + if( -(1L<<20) <= delta && delta < (1L<<20) ) return 4; + // 2 word encoding needs a tmp register, must teach RA + throw Utils.TODO(); + } // Delta is from opcode start @Override public void patch( Encoding enc, int opStart, int opLen, int delta ) { short rpc = enc.reg(this); - // High half is where the TFP constant used to be, the last input - short auipc = enc.reg(in(_inputs._len-1)); - enc.patch4(opStart,riscv.i_type(0x67, rpc, 0, auipc, delta&0xFFF)); + if( opLen==4 ) { + enc.patch4(opStart,riscv.j_type(riscv.J_JAL, rpc, delta)); + } else { + throw Utils.TODO(); + } } @Override public void asm(CodeGen code, SB sb) { |
