Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cm.push test file #592

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion isa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions isa/rv32uzcmp/Makefrag
Original file line number Diff line number Diff line change
@@ -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)
193 changes: 193 additions & 0 deletions isa/rv32uzcmp/cm_push.S
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions isa/rv64uzcmp/Makefrag
Original file line number Diff line number Diff line change
@@ -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)
55 changes: 55 additions & 0 deletions isa/rv64uzcmp/cm_pop.S
Original file line number Diff line number Diff line change
@@ -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
Loading