From a5305d64dc78bcd0ccf3017181334b17730ca5c4 Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Sun, 14 Dec 2025 01:21:42 +0000 Subject: [PATCH] Test that invalid lX opcodes trigger mini-rv32 internal core error --- test/Makefile | 3 ++- test/invalid_opcodes/Makefile | 2 ++ test/invalid_opcodes/rom/Makefile | 2 ++ test/invalid_opcodes/rom/rom.c | 5 ++++ test/invalid_opcodes/test/tests.c | 43 +++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/invalid_opcodes/Makefile create mode 100644 test/invalid_opcodes/rom/Makefile create mode 100644 test/invalid_opcodes/rom/rom.c create mode 100644 test/invalid_opcodes/test/tests.c diff --git a/test/Makefile b/test/Makefile index 9652b2d..da0bf05 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,7 +5,8 @@ TESTS = \ syscall_args \ meter \ extram \ - badcode + badcode \ + invalid_opcodes RUNCMD = $(foreach TEST,${TESTS},make -C ${TEST} &&) CLEANCMD = $(foreach TEST,${TESTS},make -C ${TEST} clean &&) diff --git a/test/invalid_opcodes/Makefile b/test/invalid_opcodes/Makefile new file mode 100644 index 0000000..dc44dd1 --- /dev/null +++ b/test/invalid_opcodes/Makefile @@ -0,0 +1,2 @@ +TOPDIR=../.. +include ${TOPDIR}/test/common/makefile.common diff --git a/test/invalid_opcodes/rom/Makefile b/test/invalid_opcodes/rom/Makefile new file mode 100644 index 0000000..4cd3f50 --- /dev/null +++ b/test/invalid_opcodes/rom/Makefile @@ -0,0 +1,2 @@ +TOPDIR=../../.. +include ${TOPDIR}/test/common/makefile-rom.common diff --git a/test/invalid_opcodes/rom/rom.c b/test/invalid_opcodes/rom/rom.c new file mode 100644 index 0000000..e7c0c54 --- /dev/null +++ b/test/invalid_opcodes/rom/rom.c @@ -0,0 +1,5 @@ +#include "uvm32_target.h" + +void main(void) { +} + diff --git a/test/invalid_opcodes/test/tests.c b/test/invalid_opcodes/test/tests.c new file mode 100644 index 0000000..93448c6 --- /dev/null +++ b/test/invalid_opcodes/test/tests.c @@ -0,0 +1,43 @@ +#include +#include "unity.h" +#include "uvm32.h" +#include "../common/uvm32_common_custom.h" + +#include "rom-header.h" + +static uvm32_state_t vmst; +static uvm32_evt_t evt; + +void setUp(void) { +} + +void tearDown(void) { +} + +void test_invalid_opcode_rd_extram(void) { + // https://www.cs.sfu.ca/~ashriram/Courses/CS295/assets/notebooks/RISCV/RISCV_CARD.pdf + // lb,lbu etc only have funct3 values of 0,1,2,4,5 + uint8_t bad_funct3_3[] = { + 0xb7, 0x0f, 0x00, 0x10, // lui t6,0x10000 + 0x83, 0xB2, 0x0f, 0x00 // l? t0,0(t6) + }; + + uvm32_init(&vmst); + uvm32_load(&vmst, bad_funct3_3, 8); + uvm32_run(&vmst, &evt, 100); + TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_ERR); + TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_INTERNAL_CORE); + + uint8_t bad_funct3_6[] = { + 0xb7, 0x0f, 0x00, 0x10, // lui t6,0x10000 + 0x83, 0xE2, 0x0f, 0x00 // l? t0,0(t6) + }; + + uvm32_init(&vmst); + uvm32_load(&vmst, bad_funct3_6, 8); + uvm32_run(&vmst, &evt, 100); + TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_ERR); + TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_INTERNAL_CORE); +} + +