From 6a4118e42001ef4a27c7fe664e1dbd3de22fd75f Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Sun, 14 Dec 2025 21:38:05 +0000 Subject: [PATCH] Add AUIPC test --- test/invalid_opcodes/rom/rom.c | 7 +++++++ test/invalid_opcodes/rom/shared.h | 6 ++++++ test/invalid_opcodes/test/tests.c | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 test/invalid_opcodes/rom/shared.h diff --git a/test/invalid_opcodes/rom/rom.c b/test/invalid_opcodes/rom/rom.c index e7c0c54..0cb87c9 100644 --- a/test/invalid_opcodes/rom/rom.c +++ b/test/invalid_opcodes/rom/rom.c @@ -1,5 +1,12 @@ #include "uvm32_target.h" +#include "shared.h" void main(void) { + switch(syscall(SYSCALL_PICKTEST, 0, 0)) { + case TEST1: + asm("auipc t0, 0"); // copy pc into t0 + asm("auipc t1, 0"); // copy pc into t1 + break; + } } diff --git a/test/invalid_opcodes/rom/shared.h b/test/invalid_opcodes/rom/shared.h new file mode 100644 index 0000000..c9db0c3 --- /dev/null +++ b/test/invalid_opcodes/rom/shared.h @@ -0,0 +1,6 @@ +#define SYSCALL_BASE 0x200 +#define SYSCALL_PICKTEST SYSCALL_BASE+0 + +enum { + TEST1, +}; diff --git a/test/invalid_opcodes/test/tests.c b/test/invalid_opcodes/test/tests.c index 93448c6..026aa96 100644 --- a/test/invalid_opcodes/test/tests.c +++ b/test/invalid_opcodes/test/tests.c @@ -4,11 +4,14 @@ #include "../common/uvm32_common_custom.h" #include "rom-header.h" +#include "shared.h" static uvm32_state_t vmst; static uvm32_evt_t evt; void setUp(void) { + uvm32_init(&vmst); + uvm32_load(&vmst, rom_bin, rom_bin_len); } void tearDown(void) { @@ -41,3 +44,19 @@ void test_invalid_opcode_rd_extram(void) { } +void test_auipc(void) { + uvm32_run(&vmst, &evt, 100); + // check for picktest syscall + TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL); + TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST); + uvm32_arg_setval(&vmst, &evt, RET, TEST1); + + // run vm to completion + uvm32_run(&vmst, &evt, 100); + TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_END); + + // The two PC values stored by auipc should be adjacent + TEST_ASSERT_EQUAL(vmst._core.regs[6], vmst._core.regs[5] + 4); +} + +