Skip to content

Commit 91b04f9

Browse files
author
Mario
committed
Add tohost and adapt existing tests
* cv32e20/bsp/crt0.s: add tohost symbol declaration * cv32e20/bsp/link.ld: add tohost symbol linking address * cv32e20/bsp/syscalls.c: add tohost store in the exit function * cv32e20/env/corev-dv/cv32e20_instr_gen_config.sv: add rule to enforce not ZERO reg used in the scratch reg. This constraint was already implemented but not working with vsim * cv32e20/env/uvme/uvme_cv32e20_env.sv: add mechanism to load symbols from the binary for the execution exit. * cv32e20/env/uvme/vseq/uvme_cv32e20_vp_status_flags_seq.sv: Adapt code to host format ( {exit_value, 1} ) * cv32e40p/env/uvme/uvme_rv32isa_covg_trn.sv: substitute uvm_objects_utils(begin/end) for a simple uvm_object_utils * lib/corev-dv/corev_asm_program_gen.sv: delete wfi for locking the core and add tohost mechanism * lib/uvm_agents/uvma_obi_memory/src/comps/uvma_obi_memory_mon.sv: vsim complaining for using passive_mp * lib/uvm_libs/uvml_sb/uvml_sb_cntxt.sv: delete T_TRN type for event as it causes vsim to fail simulation * mk/Common.mk: add compilation for elfloader vendor * mk/uvmt/vsim.mk: add comilation for elfloader vendor and delete clean_riscv-dv on each corev-dv generation * vendor/elfloader/Makefile: add elfloader vendor * vendor/elfloader/elfloader.cc: add elfloader vendor * lib/corev-dv/corev_asm_program_gen.sv: delete wfi and add syscall on ecall * cv32e20/tests/programs/custom/riscv_arithmetic_basic_test_*: change align of trap handler to 8
1 parent 5f94dd4 commit 91b04f9

File tree

45 files changed

+1955
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1955
-935
lines changed

cv32e20/bsp/Makefile

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@ RISCV ?= $(CV_SW_TOOLCHAIN)
1010
RISCV_EXE_PREFIX ?= $(RISCV)/bin/riscv32-unknown-elf-
1111
RISCV_GCC = $(RISCV_EXE_PREFIX)gcc
1212
RISCV_AR = $(RISCV_EXE_PREFIX)ar
13-
SRC = crt0.S handlers.S syscalls.c vectors.S
14-
OBJ = crt0.o handlers.o syscalls.o vectors.o
15-
LIBCV-VERIF = libcv-verif.a
13+
C_FILES = syscalls_kernel.c csr.c csr.h syscalls.c syscalls.h
14+
SRC = crt0.S handlers.S syscalls.c syscalls_kernel.c vectors.S csr.c
15+
OBJ = crt0.o handlers.o syscalls.o syscalls_kernel.o vectors.o csr.o
16+
LIBCV-VERIF = libcv-verif.a
1617
CFLAGS ?= -Os -g -static -mabi=ilp32 -march=$(CV_SW_MARCH) -Wall -pedantic
1718

1819
all: $(LIBCV-VERIF)
1920

20-
$(LIBCV-VERIF): $(OBJ)
21+
$(LIBCV-VERIF): $(OBJ)
2122
$(RISCV_AR) rcs $@ $(OBJ)
2223

2324
%.o : %.c
2425
$(RISCV_GCC) $(CFLAGS) -c $< -o $@
25-
26+
2627
%.o : %.S
2728
$(RISCV_GCC) $(CFLAGS) -c $< -o $@
2829

2930
clean:
3031
rm -f $(OBJ) $(LIBCV-VERIF)
3132

33+
format:
34+
clang-format -i --style=llvm $(C_FILES)
35+
3236

3337
vars:
3438
@echo "make bsp variables:"

cv32e20/bsp/crt0.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ _start:
5555
li a2, 0
5656

5757
call main
58-
tail exit
58+
tail _exit
5959

6060
.size _start, .-_start
6161

cv32e20/bsp/csr.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "csr.h"
2+
3+
void return_to_machine() {
4+
char *argv[] = {"return_to_machine"};
5+
execve("return_to_machine", argv, NULL);
6+
}
7+
8+
inline void set_status_pp(priv_e new_mode) {
9+
10+
csr_set_mask(mstatus, CSR_MSTATUS_MPP, new_mode);
11+
asm volatile("la t0, 1f;"
12+
"csrrw t0, mepc, t0;"
13+
"mret;"
14+
"1:");
15+
}
16+
17+
void test_fail() { exit(1); }
18+
19+
void test_pass() { exit(0); }

cv32e20/bsp/csr.h

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef CSR_H
2+
#define CSR_H
3+
4+
#include "csr_encoding.h"
5+
#include "syscalls.h"
6+
#include <assert.h>
7+
#include <errno.h>
8+
#include <machine/syscall.h>
9+
#include <newlib.h>
10+
#include <sys/stat.h>
11+
#include <sys/timeb.h>
12+
#include <sys/times.h>
13+
#include <sys/utime.h>
14+
#include <unistd.h>
15+
16+
#undef errno
17+
#ifndef __ASSEMBLER__
18+
19+
extern int errno;
20+
21+
typedef enum priv_enum { PRIV_M = 0x3, PRIV_S = 0x1, PRIV_U = 0x0 } priv_e;
22+
23+
inline const char *priv_to_string(priv_e val) {
24+
switch (val) {
25+
case PRIV_M:
26+
return "PRIV_M";
27+
case PRIV_S:
28+
return "PRIV_S";
29+
case PRIV_U:
30+
return "PRIV_U";
31+
default:
32+
return "PRIV";
33+
}
34+
}
35+
36+
void set_status_pp(priv_e new_mode);
37+
38+
void return_to_machine();
39+
40+
void test_fail();
41+
42+
void test_pass();
43+
44+
#define BITS2SHIFT(mask) (mask & -mask)
45+
46+
#define csr_read(reg) \
47+
({ \
48+
unsigned long __tmp; \
49+
asm volatile("csrr %0, " #reg : "=r"(__tmp)); \
50+
__tmp; \
51+
})
52+
53+
#define csr_write(reg, val) ({ asm volatile("csrw " #reg ", %0" ::"rK"(val)); })
54+
55+
#define csr_swap(reg, val) \
56+
({ \
57+
unsigned long __tmp; \
58+
asm volatile("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "rK"(val)); \
59+
__tmp; \
60+
})
61+
62+
#define csr_set(reg, bit) \
63+
({ \
64+
unsigned long __tmp; \
65+
asm volatile("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \
66+
__tmp; \
67+
})
68+
69+
#define csr_clear(reg, bit) \
70+
({ \
71+
unsigned long __tmp; \
72+
asm volatile("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \
73+
__tmp; \
74+
})
75+
76+
#define csr_clear_mask(reg, mask) csr_clear(reg, BITS2SHIFT(mask))
77+
78+
#define csr_set_mask(reg, mask, value) \
79+
({ \
80+
unsigned long __tmp = csr_read(reg); \
81+
__tmp = __tmp & mask; \
82+
__tmp |= (value << BITS2SHIFT(mask)); \
83+
csr_write(reg, __tmp); \
84+
__tmp; \
85+
})
86+
87+
#define rdtime() csr_read(time)
88+
#define rdcycle() csr_read(cycle)
89+
#define rdinstret() csr_read(instret)
90+
91+
#endif
92+
93+
#endif

0 commit comments

Comments
 (0)