diff options
| author | Cliff Click <cliffc@acm.org> | 2025-05-05 21:24:06 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-05-05 21:24:06 -0700 |
| commit | 31f89ec8f8d2b05e2550b7c6957259380ef21575 (patch) | |
| tree | 0553c3a64f555c5ee641573d35138d8fdab38e8c /chapter22/src/test | |
| parent | 04881a0ea7e84cf8af05054946f10cc6bb14f8fc (diff) | |
| download | Simple-31f89ec8f8d2b05e2550b7c6957259380ef21575.tar.gz Simple-31f89ec8f8d2b05e2550b7c6957259380ef21575.zip | |
Now with risc5
R5 eval handles extern `write` call.
Diffstat (limited to 'chapter22/src/test')
| -rw-r--r-- | chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java | 19 | ||||
| -rw-r--r-- | chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java | 16 |
2 files changed, 30 insertions, 5 deletions
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java index de9c35c7..b441aa4a 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java @@ -105,10 +105,23 @@ return cc.cz; assertEquals("25", Eval2.eval(code, 0)); } - @Test @Ignore + @Test public void testHelloWorld() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/helloWorld.smp")); - TestC.run(src,TestC.CALL_CONVENTION,null,null,"build/objs/helloWorld","","Hello, World!",0); + //String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/helloWorld.smp")); + //TestC.run(src,TestC.CALL_CONVENTION,null,null,"build/objs/helloWorld","","Hello, World!",0); + // + //// Evaluate on RISC5 emulator + //EvalRisc5 R5 = TestRisc5.build("helloWorld", 0, 2, false); + //int trap = R5.step(100); + //assertEquals(0,trap); + //assertEquals(0,R5.regs[riscv.A0]); + + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("helloWorld", 0, 2, false); + int trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java b/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java index fd953342..8fe22bc2 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java @@ -11,6 +11,7 @@ import com.seaofnodes.simple.codegen.Encoding; import com.seaofnodes.simple.node.cpus.riscv.riscv; +import java.io.PrintStream; import java.util.Arrays; public class EvalRisc5 { @@ -100,6 +101,17 @@ import java.util.Arrays; if( (reladdy & 0x00100000)!=0 ) reladdy |= 0xffe00000; // Sign extension. rval = pc + 4; pc = pc + reladdy - 4; + if( pc+4 == Encoding.SENTINAL_WRITE ) { + PrintStream ps = switch((int)regs[10]) { + case 1 -> System.out; + case 2 -> System.err; + default -> throw new IllegalArgumentException(); + }; + ps.write(_buf,(int)regs[11],(int)regs[12]); + regs[10] = regs[12]; + rdid = 0; + pc = (int)(rval - 4); // Unwind PC, as-if returned from write + } break; } case 0x67: { // JALR (0b1100111) @@ -233,11 +245,11 @@ import java.util.Arrays; } else { rval = switch( (ir >> 12) & 7 ) { // These could be either op-immediate or op commands. Be careful. case 0 -> (is_reg && (ir & 0x40000000) != 0) ? (rs1 - rs2) : (rs1 + rs2); - case 1 -> rs1 << (rs2 & 0x1F); + case 1 -> rs1 << (rs2 & 0x3F); case 2 -> (rs1 < rs2) ? 1 : 0; case 3 -> (rs1 < rs2) ? 1 : 0; case 4 -> rs1 ^ rs2; - case 5 -> (ir & 0x40000000) != 0 ? (((int) rs1) >> (rs2 & 0x1F)) : (rs1 >> (rs2 & 0x1F)); + case 5 -> (ir & 0x40000000) != 0 ? (rs1 >>> (rs2 & 0x3F)) : (rs1 >> (rs2 & 0x3F)); case 6 -> rs1 | rs2; case 7 -> rs1 & rs2; default -> rval; |
