Compare commits
No commits in common. "72dda9aaeb9ee5ba8c7ad46ebe37bae2dfd08fa7" and "cdf2ed883adbe9a02a24b25b5145a1bf545120fa" have entirely different histories.
72dda9aaeb
...
cdf2ed883a
5
Makefile
5
Makefile
@ -25,8 +25,3 @@ clean:
|
|||||||
.SILENT: run
|
.SILENT: run
|
||||||
run: all
|
run: all
|
||||||
./$(BUILD_DIR)/$(NAME)
|
./$(BUILD_DIR)/$(NAME)
|
||||||
|
|
||||||
.PHONY: tests
|
|
||||||
.SILENT: tests
|
|
||||||
tests: all
|
|
||||||
make -C tests
|
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
# vriscv - a risc-v simulator
|
# vriscv - a risc-v simulator
|
||||||
|
|
||||||
## Unit tests
|
|
||||||
|
|
||||||
Unit tests can be compiled and run using :
|
|
||||||
```
|
|
||||||
make tests
|
|
||||||
```
|
|
||||||
|
|
||||||
## Resources used
|
## Resources used
|
||||||
|
|
||||||
Juraj's Blog, mostly:
|
Juraj's Blog, mostly:
|
||||||
|
@ -814,15 +814,15 @@ static void cpu_print_instruction(instruction_t* instruction)
|
|||||||
{
|
{
|
||||||
case FUNC3_SB:
|
case FUNC3_SB:
|
||||||
// Store Byte (8-bits)
|
// Store Byte (8-bits)
|
||||||
printf("sb x%u, %d(x%u)\n", instruction->rs2, immediate, instruction->rs1);
|
printf("sb x%u, %d(x%u)\n", instruction->rs1, immediate, instruction->rs2);
|
||||||
break;
|
break;
|
||||||
case FUNC3_SH:
|
case FUNC3_SH:
|
||||||
// Store Halfword (16-bits)
|
// Store Halfword (16-bits)
|
||||||
printf("sh x%u, %d(x%u)\n", instruction->rs2, immediate, instruction->rs1);
|
printf("sh x%u, %d(x%u)\n", instruction->rs1, immediate, instruction->rs2);
|
||||||
break;
|
break;
|
||||||
case FUNC3_SW:
|
case FUNC3_SW:
|
||||||
// Store Word (32-bits)
|
// Store Word (32-bits)
|
||||||
printf("sw x%u, %d(x%u)\n", instruction->rs2, immediate, instruction->rs1);
|
printf("sw x%u, %d(x%u)\n", instruction->rs1, immediate, instruction->rs2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Warning: Unknown func3 0x%x for store instruction\n", instruction->func3);
|
fprintf(stderr, "Warning: Unknown func3 0x%x for store instruction\n", instruction->func3);
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
AS=riscv32-elf-as
|
|
||||||
LD=riscv32-elf-ld
|
|
||||||
BUILD_DIR=../build/tests/
|
|
||||||
|
|
||||||
S_FILES := $(shell find ./ -name '*.s')
|
|
||||||
NAMES = $(basename $(S_FILES))
|
|
||||||
OBJECTS=$(patsubst %, $(BUILD_DIR)/%, $(NAMES))
|
|
||||||
|
|
||||||
all: $(OBJECTS) run
|
|
||||||
|
|
||||||
$(BUILD_DIR):
|
|
||||||
mkdir -p $(BUILD_DIR)
|
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.s | $(BUILD_DIR)
|
|
||||||
$(AS) $^ -o $@
|
|
||||||
|
|
||||||
$(BUILD_DIR)/%: $(BUILD_DIR)/%.o | $(BUILD_DIR)
|
|
||||||
$(LD) $^ -o $@ -nostdlib
|
|
||||||
|
|
||||||
.SILENT: run
|
|
||||||
run:
|
|
||||||
bash test.sh
|
|
@ -1,4 +0,0 @@
|
|||||||
.global _start
|
|
||||||
_start:
|
|
||||||
addi a0, zero, 0xBA
|
|
||||||
ebreak
|
|
31
tests/beq.s
31
tests/beq.s
@ -1,31 +0,0 @@
|
|||||||
.global _start
|
|
||||||
_start:
|
|
||||||
# Set base value of a0 to 'test failed'
|
|
||||||
addi a0, zero, 1
|
|
||||||
|
|
||||||
# Set A, B values of t0/t1, to test equality
|
|
||||||
addi t0, zero, 0xA
|
|
||||||
addi t1, zero, 0xB
|
|
||||||
beq t0, t1, eq0
|
|
||||||
|
|
||||||
# Inequality passed, now test equality
|
|
||||||
addi t0, zero, 0xA
|
|
||||||
addi t1, zero, 0xA
|
|
||||||
beq t0, t1, eq1
|
|
||||||
|
|
||||||
# On failure, return
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
eqNeg:
|
|
||||||
# All passed
|
|
||||||
addi a0, zero, 0
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
eq0:
|
|
||||||
# Inequality failed
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
eq1:
|
|
||||||
# Equality passed ; now try to test a negative offset case
|
|
||||||
beq t0, t1, eqNeg
|
|
||||||
ebreak
|
|
21
tests/jal.s
21
tests/jal.s
@ -1,21 +0,0 @@
|
|||||||
.global _start
|
|
||||||
_start:
|
|
||||||
# Set base value of a0 to 'test failed'
|
|
||||||
addi a0, zero, 1
|
|
||||||
|
|
||||||
# Construct value that ra should have in t0
|
|
||||||
auipc t0, 0
|
|
||||||
addi t0, t0, 12
|
|
||||||
# Jump and link
|
|
||||||
jal ra, fn0
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
fn0:
|
|
||||||
# Check ra value with our t0 construct
|
|
||||||
beq t0, ra, eq0
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
eq0:
|
|
||||||
# All good
|
|
||||||
addi a0, zero, 0
|
|
||||||
ebreak
|
|
46
tests/jalr.s
46
tests/jalr.s
@ -1,46 +0,0 @@
|
|||||||
.global _start
|
|
||||||
_start:
|
|
||||||
# Set base value of a0 to 'test failed'
|
|
||||||
addi a0, zero, 1
|
|
||||||
|
|
||||||
# Setup a stack
|
|
||||||
addi sp, sp, 0x100
|
|
||||||
|
|
||||||
# Try to call a simple function
|
|
||||||
jal fn1
|
|
||||||
|
|
||||||
# Try to call two imbricated functions
|
|
||||||
jal fn0
|
|
||||||
|
|
||||||
auipc t0, 0
|
|
||||||
jalr ra, 12(t0)
|
|
||||||
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
# just_after : address is 12 bytes after auipc
|
|
||||||
just_after:
|
|
||||||
addi a0, zero, 0
|
|
||||||
ret
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
# fn0 : function that calls fn1 and returns
|
|
||||||
fn0:
|
|
||||||
# Make space on the stack
|
|
||||||
addi sp, sp, -4
|
|
||||||
# Save ra
|
|
||||||
sw ra, 0(sp)
|
|
||||||
|
|
||||||
# Call fn1
|
|
||||||
jal fn1
|
|
||||||
|
|
||||||
# Restore ra and stack
|
|
||||||
lw ra, 0(sp)
|
|
||||||
addi sp, sp, 4
|
|
||||||
|
|
||||||
ret
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
# fn1 : just return
|
|
||||||
fn1:
|
|
||||||
ret
|
|
||||||
ebreak
|
|
@ -1,5 +0,0 @@
|
|||||||
.global _start
|
|
||||||
_start:
|
|
||||||
addi a1, zero, 0xBA
|
|
||||||
mv a0, a1
|
|
||||||
ebreak
|
|
21
tests/swlw.s
21
tests/swlw.s
@ -1,21 +0,0 @@
|
|||||||
.global _start
|
|
||||||
_start:
|
|
||||||
# Set base value of a0 to 'test failed'
|
|
||||||
addi a0, zero, 1
|
|
||||||
|
|
||||||
# Store Word 0xBA at 0x104
|
|
||||||
addi t0, zero, 0x100
|
|
||||||
addi t1, zero, 0xBA
|
|
||||||
sw t1, 4(t0)
|
|
||||||
|
|
||||||
# Load Word at 0x104 in t0
|
|
||||||
lw t0, 4(t0)
|
|
||||||
|
|
||||||
# Compare
|
|
||||||
beq t0, t1, good
|
|
||||||
|
|
||||||
ebreak
|
|
||||||
|
|
||||||
good:
|
|
||||||
addi a0, zero, 0
|
|
||||||
ebreak
|
|
@ -1,30 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
GREEN="\e[32m"
|
|
||||||
RED="\e[31m"
|
|
||||||
CEND="\e[39m"
|
|
||||||
|
|
||||||
VRISCV=../build/vriscv
|
|
||||||
|
|
||||||
# test executes a test
|
|
||||||
# Arguments: test(name, executable, expected)
|
|
||||||
test() {
|
|
||||||
NAME=$1
|
|
||||||
TEST=$2
|
|
||||||
RESULT=$3
|
|
||||||
|
|
||||||
echo -ne "${NAME}""\t\t\t\t\t\t"
|
|
||||||
$VRISCV $TEST >/dev/null 2>&1
|
|
||||||
if [ $? -eq $RESULT ]; then
|
|
||||||
echo -e $GREEN"PASSED"$CEND
|
|
||||||
else
|
|
||||||
echo -e $RED"FAILED"$CEND
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
test "ADDI : Add Immediate " "../build/tests/addi " 186
|
|
||||||
test "MV : Move registers " "../build/tests/mv " 186
|
|
||||||
test "BEQ : Branch EQual " "../build/tests/beq " 0
|
|
||||||
test "JAL : Jump And Link " "../build/tests/jal " 0
|
|
||||||
test "SWLW : Store Word Load Word " "../build/tests/swlw " 0
|
|
||||||
test "JALR : Jump And Link Register " "../build/tests/jalr " 0
|
|
Loading…
Reference in New Issue
Block a user