diff --git a/src/rars/api/Program.java b/src/rars/api/Program.java index 70d41039..cf3c9a1d 100644 --- a/src/rars/api/Program.java +++ b/src/rars/api/Program.java @@ -60,6 +60,10 @@ public Program(Options set){ simulation = new Memory(); } + public Options getOptions() { + return set; + } + /** * Assembles from a list of files * diff --git a/test/RarsTest.java b/test/RarsTest.java index e415fa61..52d8a58b 100644 --- a/test/RarsTest.java +++ b/test/RarsTest.java @@ -48,19 +48,18 @@ Program setupProgram(boolean rv64) { Options opt = new Options(); opt.startAtMain = true; opt.maxSteps = 1000000; - opt.selfModifyingCode = true; return new Program(opt); } public void checkPrograms() { + // 32-bit tests Program p = setupProgram(false); runDirectory("./test", p); runDirectory("./test/riscv-tests", p); - Globals.getSettings().setBooleanSettingNonPersistent(Settings.Bool.RV64_ENABLED,true); - InstructionSet.rv64 = true; - Globals.instructionSet.populate(); + // 64-bit tests + p = setupProgram(true); runDirectory("./test", p); runDirectory("./test/riscv-tests-64", p); @@ -100,6 +99,7 @@ public static String run(String path, Program p){ int exitCode = 0; // TODO: better config system // This is just a temporary solution that should work for the tests I want to write + p.getOptions().selfModifyingCode = false; try { BufferedReader br = new BufferedReader(new FileReader(path)); String line = br.readLine(); @@ -131,6 +131,11 @@ public static String run(String path, Program p){ programArgumentList = new ProgramArgumentList(args).getProgramArgumentList(); } else if (line.startsWith("#error:")) { errorMessage = line.replaceFirst("#error:", ""); + } else if (line.startsWith("#selfmod:")) { + String selfmod = line.replaceFirst("#selfmod:", ""); + if (selfmod.equals("true")) { + p.getOptions().selfModifyingCode = true; + } } line = br.readLine(); } diff --git a/test/selfmod.s b/test/selfmod.s index a317e4c5..8b2f965f 100644 --- a/test/selfmod.s +++ b/test/selfmod.s @@ -1,4 +1,5 @@ #exit:42 +#selfmod:true .text main: la s0, toload diff --git a/test/selfmod_fail.s b/test/selfmod_fail.s new file mode 100644 index 00000000..22b07dd5 --- /dev/null +++ b/test/selfmod_fail.s @@ -0,0 +1,59 @@ +#error:Instruction load access error +.text +main: + la s0, toload + la s1, torun + + li a0, 2 + call toload + + # First copy by word to data + lw t0, (s0) + sw t0, (s1) + lw t0, 4(s0) + sw t0, 4(s1) + + # try running it + call torun + + # Copy by byte to data + mv s2, a0 + mv a0, s0 + mv a1, s1 + call copy + + mv a0, s2 + call torun + + # copy to .text + mv s2, a0 + la a0, torun + la a1, main + call copy + + mv a0, s2 + call main + + + li a7, 93 + ecall + +toload: + addi a0, a0, 10 + ret + +copy: + li t0, 0 + li t3, 8 +loop: + add t1, a0, t0 + lb t1, (t1) + add t2, a1, t0 + sb t1, (t2) + addi t0, t0, 1 + blt t0, t3, loop + ret + +.data +torun: + .space 8 diff --git a/test/selfmod_read.s b/test/selfmod_read.s new file mode 100644 index 00000000..f7e4f742 --- /dev/null +++ b/test/selfmod_read.s @@ -0,0 +1,8 @@ +# Test read-only in the code segment (should not require selfmod to be set) +#stdout:1050771 + .text +foo: li a7, 1 # PrintInt + lw a0, foo + ecall + li a7, 10 + ecall