summaryrefslogtreecommitdiff
path: root/chapter22/src/main/java/com/seaofnodes
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-28 13:30:22 -0700
committerCliff Click <cliffc@acm.org>2026-09-28 13:30:22 -0700
commit586c8f65f2d0c0e1f73aadd0aa8d850aa653bddd (patch)
tree2f539c308452ddf5fa37826da95b17ba557e8352 /chapter22/src/main/java/com/seaofnodes
parent8212a66ff27e56531e0b48807088f1c544d75756 (diff)
downloadSimple-586c8f65f2d0c0e1f73aadd0aa8d850aa653bddd.tar.gz
Simple-586c8f65f2d0c0e1f73aadd0aa8d850aa653bddd.zip
Support extern C ver direct updates
FIx minor RISC encodings.
Diffstat (limited to 'chapter22/src/main/java/com/seaofnodes')
-rw-r--r--chapter22/src/main/java/com/seaofnodes/simple/node/cpus/riscv/TMPRISC.java6
1 files changed, 3 insertions, 3 deletions
diff --git a/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/riscv/TMPRISC.java b/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/riscv/TMPRISC.java
index 860e5eaf..2f7ffe0d 100644
--- a/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/riscv/TMPRISC.java
+++ b/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/riscv/TMPRISC.java
@@ -28,9 +28,9 @@ public class TMPRISC extends ConstantNode implements MachNode, RIPRelSize {
// Delta is from opcode start
@Override public void patch( Encoding enc, int opStart, int opLen, int delta ) {
short dst = enc.reg(this);
- // AUIPC dst,#hi20_constant_pool
- enc.patch4(opStart , riscv.u_type(riscv.OP_AUIPC, dst, delta>>12));
- // Load dst,[dst+#low12_constant_pool]
+ // Round the high part because ADDI's low 12 bits are signed.
+ enc.patch4(opStart , riscv.u_type(riscv.OP_AUIPC, dst, (delta+0x800)>>12));
+ // ADDI dst,dst,#low12_constant_pool
enc.patch4(opStart+4, riscv.i_type(riscv.OP_IMM, dst, 0, dst, delta & 0xFFF));
}