diff --git a/isa/Makefile b/isa/Makefile index bf85e1f8b..5b835b27e 100644 --- a/isa/Makefile +++ b/isa/Makefile @@ -18,6 +18,7 @@ include $(src_dir)/rv64uzba/Makefrag include $(src_dir)/rv64uzbb/Makefrag include $(src_dir)/rv64uzbc/Makefrag include $(src_dir)/rv64uzbs/Makefrag +include $(src_dir)/rv64uzcmp/Makefrag include $(src_dir)/rv64si/Makefrag include $(src_dir)/rv64ssvnapot/Makefrag include $(src_dir)/rv64mi/Makefrag @@ -34,6 +35,7 @@ include $(src_dir)/rv32uzba/Makefrag include $(src_dir)/rv32uzbb/Makefrag include $(src_dir)/rv32uzbc/Makefrag include $(src_dir)/rv32uzbs/Makefrag +include $(src_dir)/rv32uzcmp/Makefrag include $(src_dir)/rv32si/Makefrag include $(src_dir)/rv32mi/Makefrag @@ -43,7 +45,7 @@ default: all # Build rules #-------------------------------------------------------------------- -RISCV_PREFIX ?= riscv$(XLEN)-unknown-elf- +RISCV_PREFIX ?= /home/rez/workbench/riscv-gnu-toolchain/installed-tools/bin/riscv$(XLEN)-unknown-elf- RISCV_GCC ?= $(RISCV_PREFIX)gcc RISCV_GCC_OPTS ?= -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.text.init --section=.data @@ -98,6 +100,7 @@ $(eval $(call compile_template,rv32uzba,-march=rv32g_zba -mabi=ilp32)) $(eval $(call compile_template,rv32uzbb,-march=rv32g_zbb -mabi=ilp32)) $(eval $(call compile_template,rv32uzbc,-march=rv32g_zbc -mabi=ilp32)) $(eval $(call compile_template,rv32uzbs,-march=rv32g_zbs -mabi=ilp32)) +$(eval $(call compile_template,rv32uzcmp,-march=rv32g_zcmp -mabi=ilp32)) $(eval $(call compile_template,rv32si,-march=rv32g -mabi=ilp32)) $(eval $(call compile_template,rv32mi,-march=rv32g -mabi=ilp32)) ifeq ($(XLEN),64) @@ -112,6 +115,7 @@ $(eval $(call compile_template,rv64uzba,-march=rv64g_zba -mabi=lp64)) $(eval $(call compile_template,rv64uzbb,-march=rv64g_zbb -mabi=lp64)) $(eval $(call compile_template,rv64uzbc,-march=rv64g_zbc -mabi=lp64)) $(eval $(call compile_template,rv64uzbs,-march=rv64g_zbs -mabi=lp64)) +$(eval $(call compile_template,rv64uzcmp,-march=rv64g_zca_zcmp -mabi=lp64)) $(eval $(call compile_template,rv64mzicbo,-march=rv64g_zicboz -mabi=lp64)) $(eval $(call compile_template,rv64si,-march=rv64g -mabi=lp64)) $(eval $(call compile_template,rv64ssvnapot,-march=rv64g -mabi=lp64)) diff --git a/isa/rv32uzcmp/Makefrag b/isa/rv32uzcmp/Makefrag new file mode 100644 index 000000000..58ab361e8 --- /dev/null +++ b/isa/rv32uzcmp/Makefrag @@ -0,0 +1,12 @@ +#======================================================================= +# Makefrag for rv32uzbs tests +#----------------------------------------------------------------------- + +rv32uzcmp_sc_tests = \ + cm_push \ + +rv32uzcmp_p_tests = $(addprefix rv32uzcmp-p-, $(rv32uzcmp_sc_tests)) +rv32uzcmp_v_tests = $(addprefix rv32uzcmp-v-, $(rv32uzcmp_sc_tests)) +rv32uzcmp_ps_tests = $(addprefix rv32uzcmp-ps-, $(rv32uzcmp_sc_tests)) + +spike_tests += $(rv32uzcmp_p_tests) $(rv32uzcmp_v_tests) diff --git a/isa/rv32uzcmp/cm_push.S b/isa/rv32uzcmp/cm_push.S new file mode 100644 index 000000000..402525efa --- /dev/null +++ b/isa/rv32uzcmp/cm_push.S @@ -0,0 +1,193 @@ +#include "riscv_test.h" +#include "test_macros.h" + +RVTEST_RV32U +RVTEST_CODE_BEGIN + + # Test cm.push {ra}, -16 +test_1: + li TESTNUM, 1 + + # Set initial sp + la sp, tdat_end # Point sp to end of tdat + + # Set ra to a known value + li x1, 0x12345678 # ra (x1) + + # Record initial sp + mv x5, sp # x5 = initial sp + + # Execute cm.push {ra}, -16 + cm.push {ra}, -16 + + # Calculate expected sp + li x6, 16 + sub x7, x5, x6 # x7 = x5 - 16 + + # Check sp + bne sp, x7, fail + + # Load ra from [sp + 12] (since ra is stored at the top of the stack frame) + lw x8, 12(sp) # x8 = [sp + 12] (ra) + + # Check ra value + bne x8, x1, fail + + # Test cm.push {ra, s0}, -32 +test_2: + li TESTNUM, 2 + + # Restore sp to initial value + mv sp, x5 # sp = initial sp + + # Set ra and s0 to known values + li x1, 0x11111111 # ra (x1) + li x8, 0x88888888 # s0 (x8) + + # Record initial sp + mv x5, sp # x5 = initial sp + + # Execute cm.push {ra, s0}, -32 + cm.push {ra, s0}, -32 + + # Calculate expected sp + li x6, 32 + sub x7, x5, x6 # x7 = x5 - 32 + + # Check sp + bne sp, x7, fail + + # Load ra from [sp + 28] + lw x9, 28(sp) # x9 = [sp + 28] (ra) + bne x9, x8, fail + + # Load s0 from [sp + 24] + lw x10, 24(sp) # x10 = [sp + 24] (s0) + bne x10, x1, fail + + # Test cm.push {ra, s0-s1}, -48 +test_3: + li TESTNUM, 3 + + # Restore sp to initial value + mv sp, x5 # sp = initial sp + + # Set ra, s0, s1 to known values + li x1, 0x11111111 # ra (x1) + li x8, 0x88888888 # s0 (x8) + li x9, 0x99999999 # s1 (x9) + + # Record initial sp + mv x5, sp # x5 = initial sp + + # Execute cm.push {ra, s0-s1}, -48 + cm.push {ra, s0-s1}, -48 + + # Calculate expected sp + li x6, 48 + sub x7, x5, x6 # x7 = x5 - 48 + + # Check sp + bne sp, x7, fail + + # Load ra from [sp + 44] + lw x11, 44(sp) # x11 = [sp + 44] (ra) + bne x11, x9, fail + + # Load s0 from [sp + 40] + lw x12, 40(sp) # x12 = [sp + 40] (s0) + bne x12, x8, fail + + # Load s1 from [sp + 36] + lw x13, 36(sp) # x13 = [sp + 36] (s1) + bne x13, x1, fail + +test_4: + li TESTNUM, 4 + + # Restore sp to initial value + mv sp, x5 # sp = initial sp + + # Set ra, s0, s1 to known values + li x1, 0x11111111 # ra (x1) + li x5, 0x88888888 # s0 (x8) + li x6, 0x99999999 # s1 (x9) + li x7, 0xAAAAAAAA # s2 (x10) + li x10, 0xBBBBBBBB # s3 (x11) + li x11, 0xCCCCCCCC # s4 (x12) + li x12, 0xDDDDDDDD # s5 (x13) + li x13, 0xEEEEEEEE # s6 (x14) + li x14, 0xFFFFFFFF # s7 (x15) + li x15, 0x00000000 # s8 (x16) + li x16, 0x11111111 # s9 (x17) + li x17, 0x22222222 # s10 (x18) + li x28, 0x33333333 # s11 (x19) + + # Record initial sp + mv x5, sp # x5 = initial sp + + cm.push {ra, s0-s11}, -64 + + # Calculate expected sp + li x6, 64 + sub x7, x5, x6 + + # Check sp + bne sp, x7, fail + + lw x11, 60(sp) + bne x11, x28, fail + + lw x11, 56(sp) + bne x11, x17, fail + + lw x11, 52(sp) + bne x11, x16, fail + + lw x11, 48(sp) + bne x11, x15, fail + + lw x11, 44(sp) + bne x11, x14, fail + + lw x11, 40(sp) + bne x11, x13, fail + + lw x11, 36(sp) + bne x11, x12, fail + + lw x11, 32(sp) + bne x11, x11, fail + + lw x11, 28(sp) + bne x11, x10, fail + + lw x11, 24(sp) + bne x11, x7, fail + + lw x11, 20(sp) + bne x11, x6, fail + + lw x11, 16(sp) + bne x11, x5, fail + + lw x11, 12(sp) + bne x11, x1, fail + + # All tests passed + RVTEST_PASS + +fail: + RVTEST_FAIL + +RVTEST_CODE_END + + .data +RVTEST_DATA_BEGIN + + .align 4 +tdat: + .space 256 # Reserve 256 bytes +tdat_end: + +RVTEST_DATA_END diff --git a/isa/rv64uzcmp/Makefrag b/isa/rv64uzcmp/Makefrag new file mode 100644 index 000000000..9ddbdd548 --- /dev/null +++ b/isa/rv64uzcmp/Makefrag @@ -0,0 +1,12 @@ +#======================================================================= +# Makefrag for rv64uzcmp tests +#----------------------------------------------------------------------- + +rv64uzcmp_sc_tests = \ + cm_push \ + +rv64uzcmp_p_tests = $(addprefix rv64uzcmp-p-, $(rv64uzcmp_sc_tests)) +rv64uzcmp_v_tests = $(addprefix rv64uzcmp-v-, $(rv64uzcmp_sc_tests)) +rv64uzcmp_ps_tests = $(addprefix rv64uzcmp-ps-, $(rv64uzcmp_sc_tests)) + +spike_tests += $(rv64uzcmp_p_tests) $(rv64uzcmp_v_tests) diff --git a/isa/rv64uzcmp/cm_pop.S b/isa/rv64uzcmp/cm_pop.S new file mode 100644 index 000000000..91b6ef6a5 --- /dev/null +++ b/isa/rv64uzcmp/cm_pop.S @@ -0,0 +1,55 @@ +#include "riscv_test.h" +#include "test_macros.h" + +RVTEST_RV64U +RVTEST_CODE_BEGIN + +test_1: + li TESTNUM, 1 + + # Set initial sp + la sp, tdat_end # Point sp to end of tdat + + # Prepare data to be pushed + li x1, 0x123456789ABCDEF0 # Value for ra + li x8, 0x8888888888888888 # Value for s0 + li x9, 0x9999999999999999 # Value for s1 + + li x12, 0x123456789ABCDEF0 # Value for ra + li x13, 0x8888888888888888 # Value for s0 + li x14, 0x9999999999999999 # Value for s1 + + mv x15, sp # x15 = initial sp + + # Push values onto the stack + cm.push {ra, s0-s1}, -48 + + li x1, 0x0 + li x8, 0x0 + li x9, 0x0 + + # Now let's pop values back + cm.pop {ra, s0-s1}, 48 + + # Verify values after pop + bne sp, x15, fail # Check sp + bne x1, x12, fail # Check ra + bne x8, x13, fail # Check s0 + bne x9, x14, fail # Check s1 + + RVTEST_PASS + +fail: + RVTEST_FAIL + +RVTEST_CODE_END + + .data +RVTEST_DATA_BEGIN + + .align 8 +tdat: + .space 256 # Reserve 256 bytes +tdat_end: + +RVTEST_DATA_END diff --git a/isa/rv64uzcmp/cm_push.S b/isa/rv64uzcmp/cm_push.S new file mode 100644 index 000000000..0a430ccad --- /dev/null +++ b/isa/rv64uzcmp/cm_push.S @@ -0,0 +1,193 @@ +#include "riscv_test.h" +#include "test_macros.h" + +RVTEST_RV64U +RVTEST_CODE_BEGIN + + # Test cm.push {ra}, -32 +test_1: + li TESTNUM, 1 + + # Set initial sp + la sp, tdat_end # Point sp to end of tdat + + # Set ra to a known 64-bit value + li x1, 0x123456789ABCDEF0 # ra (x1) + + # Record initial sp + mv x5, sp # x5 = initial sp + + # Execute cm.push {ra}, -32 + cm.push {ra}, -16 + + # Calculate expected sp + li x6, 16 + sub x7, x5, x6 # x7 = x5 - 32 + + # Check sp + bne sp, x7, fail + + # Load ra from [sp] + ld x8, 8(sp) # x8 = [sp] (ra) + + # Check ra value + bne x8, x1, fail + + # Test cm.push {ra, s0}, -48 +test_2: + li TESTNUM, 2 + + # Restore sp to initial value + mv sp, x5 # sp = initial sp + + # Set ra and s0 to known 64-bit values + li x1, 0x1111111111111111 # ra (x1) + li x8, 0x8888888888888888 # s0 (x8) + + # Record initial sp + mv x5, sp # x5 = initial sp + + # Execute cm.push {ra, s0}, -48 + cm.push {ra, s0}, -16 + + # Calculate expected sp + li x6, 16 + sub x7, x5, x6 # x7 = x5 - 48 + + # Check sp + bne sp, x7, fail + + # Load ra from [sp] + ld x9, 8(sp) # x9 = [sp] (ra) + bne x9, x8, fail + + # Load s0 from [sp + 8] + ld x10, 0(sp) # x10 = [sp + 8] (s0) + bne x10, x1, fail + + # Test cm.push {ra, s0-s1}, -64 +test_3: + li TESTNUM, 3 + + # Restore sp to initial value + mv sp, x5 # sp = initial sp + + # Set ra, s0, s1 to known 64-bit values + li x1, 0x1111111111111111 # ra (x1) + li x8, 0x8888888888888888 # s0 (x8) + li x9, 0x9999999999999999 # s1 (x9) + + # Record initial sp + mv x5, sp # x5 = initial sp + + # Execute cm.push {ra, s0-s1}, -64 + cm.push {ra, s0-s1}, -48 + + # Calculate expected sp + li x6, 48 + sub x7, x5, x6 + + # Check sp + bne sp, x7, fail + + # Load ra from [sp] + ld x11, 40(sp) + bne x11, x9, fail + + # Load s0 from [sp + 8] + ld x12, 32(sp) + bne x12, x8, fail + + # Load s1 from [sp + 16] + ld x13, 24(sp) + bne x13, x1, fail + +test_4: + li TESTNUM, 4 + + # Restore sp to initial value + mv sp, x5 # sp = initial sp + + # Set ra, s0, s1 to known 64-bit values + li x1, 0x1111111111111111 # ra (x1) + li x8, 0x8888888888888888 # s0 (x8) + li x9, 0x9999999999999999 # s1 (x9) + li x18, 0xAAAAAAAAAAAAAAA0 # s2 (x10) + li x19, 0xBBBBBBBBBBBBBBB0 # s3 (x11) + li x20, 0xCCCCCCCCCCCCCCC0 # s4 (x12) + li x21, 0xDDDDDDDDDDDDDDD0 # s5 (x13) + li x22, 0xEEEEEEEEEEEEEEE0 # s6 (x14) + li x23, 0xFFFFFFFFFFFFFFF0 # s7 (x15) + li x24, 0x0000000000000000 # s8 (x16) + li x25, 0x1111111111111110 # s9 (x17) + li x26, 0x2222222222222220 # s10 (x18) + li x27, 0x3333333333333330 # s11 (x19) + + # Record initial sp + mv x5, sp + + cm.push {ra, s0-s11}, -128 + + # Calculate expected sp + li x6, 128 + sub x7, x5, x6 + + # Check sp + bne sp, x7, fail + + ld x11, 120(sp) + bne x11, x27, fail + + ld x11, 112(sp) + bne x11, x26, fail + + ld x11, 104(sp) + bne x11, x25, fail + + ld x11, 96(sp) + bne x11, x24, fail + + ld x11, 88(sp) + bne x11, x23, fail + + ld x11, 80(sp) + bne x11, x22, fail + + ld x11, 72(sp) + bne x11, x21, fail + + ld x11, 64(sp) + bne x11, x20, fail + + ld x11, 56(sp) + bne x11, x19, fail + + ld x11, 48(sp) + bne x11, x18, fail + + ld x11, 40(sp) + bne x11, x9, fail + + ld x11, 32(sp) + bne x11, x8, fail + + ld x11, 24(sp) + bne x11, x1, fail + + # All tests passed + RVTEST_PASS + +fail: + RVTEST_FAIL + +RVTEST_CODE_END + + .data +RVTEST_DATA_BEGIN + + .align 8 +tdat: + .space 256 # Reserve 256 bytes +tdat_end: + +RVTEST_DATA_END