Skip to content

Commit 3ebf3b6

Browse files
committed
Start working on running privileged tests, set mtvec to 0xfffffffc on reset and halt if reached, add instruction breakpoint, load test .text into RAM
1 parent 53cf2fe commit 3ebf3b6

File tree

12 files changed

+174
-67
lines changed

12 files changed

+174
-67
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ The main CPU code is generated from `src/main.mlog.jinja` using a custom Jinja-b
2222
| `0x80000000` | RAM |
2323
| `0xf0000000` | MMIO |
2424

25-
Addresses `0xf0000000` - `0xffffffff` are reserved for MMIO.
26-
27-
| Address | Value |
28-
| ------------ | ----------- |
29-
| `0xf0000000` | `mtime` |
30-
| `0xf0000004` | `mtimeh` |
31-
| `0xf0000008` | `mtimecmp` |
32-
| `0xf000000c` | `mtimecmph` |
25+
Addresses `0xf0000000` - `0xffffffff` are reserved for MMIO and other system purposes.
26+
27+
| Address | Value |
28+
| ------------ | --------------------- |
29+
| `0xf0000000` | `mtime` |
30+
| `0xf0000004` | `mtimeh` |
31+
| `0xf0000008` | `mtimecmp` |
32+
| `0xf000000c` | `mtimecmph` |
33+
| `0xfffffffc` | `mtvec` default value |
34+
35+
The machine trap vector CSR `mtvec` is initialized to `0xfffffffc` at reset. To help catch issues with uninitialized `mtvec`, the processor will halt if code jumps to this address.
3336

3437
## ISA
3538

riscof/mlogv32/env/link.ld

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,45 @@ OUTPUT_ARCH( "riscv" )
22
ENTRY(rvtest_entry_point)
33

44
MEMORY {
5-
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x200000
6-
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x200000
5+
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x480000
6+
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x480000
77
MMIO (rw) : ORIGIN = 0xf0000000, LENGTH = 16
88
}
99

1010
SECTIONS
1111
{
12-
.text : {
13-
KEEP(*(.text.init));
14-
*(.text)
12+
.text.init.rom : ALIGN(4) {
13+
KEEP(*(.text.init.rom));
1514
. = ALIGN(4);
16-
__etext = .;
15+
__etext_rom = .;
1716
} > ROM
1817

18+
.text : ALIGN(4) {
19+
__stext = .;
20+
*(.text.init);
21+
*(.text);
22+
. = ALIGN(4);
23+
__etext = .;
24+
} > RAM AT > ROM
25+
26+
__sitext = LOADADDR(.text);
27+
1928
.data : ALIGN(4) {
2029
__sdata = .;
2130
*(.data);
2231
*(.data.string);
32+
. = ALIGN(4);
33+
__edata = .;
2334
} > RAM AT > ROM
2435

25-
. = ALIGN(4);
26-
__edata = .;
27-
2836
__sidata = LOADADDR(.data);
2937

3038
.bss (NOLOAD) : ALIGN(4) {
31-
. = ALIGN(4);
3239
__sbss = .;
3340
*(.bss);
41+
. = ALIGN(4);
42+
__ebss = .;
3443
} > RAM
3544

36-
. = ALIGN(4);
37-
__ebss = .;
38-
3945
_end = .;
4046
}

riscof/mlogv32/env/model_test.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@
1010
#define RVMODEL_HALT \
1111
.insn i CUSTOM_0, 0, zero, zero, 0;
1212

13-
// initialize icache, .data, and .bss
13+
// initialize icache, .text, .data, and .bss
14+
// see https://github.com/riscv-non-isa/riscv-arch-test/issues/202
1415
#define RVMODEL_BOOT \
1516
.option norelax; \
16-
la t0, __etext; \
17+
.section .text.init.rom; \
18+
\
19+
la t0, __etext_rom; \
1720
.insn i CUSTOM_0, 0, zero, t0, 5; \
21+
\
22+
la t0, __sitext; \
23+
la t1, __stext; \
24+
la t2, __etext; \
25+
mlogv32_load_text: \
26+
bgeu t1, t2, mlogv32_text_done; \
27+
lb t3, 0(t0); \
28+
sb t3, 0(t1); \
29+
addi t0, t0, 1; \
30+
addi t1, t1, 1; \
31+
j mlogv32_load_text; \
32+
mlogv32_text_done: \
33+
\
1834
la t0, __sidata; \
1935
la t1, __sdata; \
2036
la t2, __edata; \
@@ -26,14 +42,17 @@ mlogv32_load_data: \
2642
addi t1, t1, 1; \
2743
j mlogv32_load_data; \
2844
mlogv32_data_done: \
45+
\
2946
la t0, __sbss; \
3047
la t1, __ebss; \
3148
mlogv32_clear_bss: \
3249
bgeu t0, t1, mlogv32_bss_done; \
3350
sb zero, 0(t0); \
3451
addi t0, t0, 1; \
3552
j mlogv32_clear_bss; \
36-
mlogv32_bss_done:
53+
mlogv32_bss_done: \
54+
\
55+
tail rvtest_init;
3756

3857
//RV_COMPLIANCE_DATA_BEGIN
3958
#define RVMODEL_DATA_BEGIN \

riscof/mlogv32/mlogv32_isa.yaml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
# https://riscv-config.readthedocs.io/en/stable/yaml-specs.html
22
hart_ids: [0]
33
hart0:
4-
ISA: RV32IMA
4+
ISA: RV32IMAUZicsr_Zifencei
55
physical_addr_sz: 32
66
User_Spec_Version: '2.3'
7+
Privilege_Spec_Version: '1.11'
8+
hw_data_misaligned_support: false
9+
pmp_granularity: 0
710
supported_xlen: [32]
8-
11+
mtval_update: 0
12+
misa:
13+
# X bit is disabled because riscv-config doesn't seem to like it
14+
# 0b01000000000100000001000100000001
15+
reset-val: 0x40101101
16+
rv32:
17+
accessible: true
18+
extensions:
19+
implemented: true
20+
type:
21+
warl:
22+
legal:
23+
- extensions[25:0] in [0x0101101]
24+
wr_illegal:
25+
- unchanged
26+
cycle:
27+
rv32:
28+
accessible: true
29+
cycleh:
30+
rv32:
31+
accessible: true
32+
time:
33+
rv32:
34+
accessible: true
35+
timeh:
36+
rv32:
37+
accessible: true
38+
instret:
39+
rv32:
40+
accessible: true
41+
instreth:
42+
rv32:
43+
accessible: true

riscof/mlogv32/mlogv32_platform.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ reset:
22
address: 0x0
33
nmi:
44
label: nmi_vector # we don't have an nmi vector, but riscof gets mad if this is removed
5+
mtime:
6+
implemented: true
7+
address: 0xf0000000
8+
mtimecmp:
9+
implemented: true
10+
address: 0xf0000008

riscof/mlogv32/riscof_mlogv32.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ def runTests(self, testlist: dict[str, Any]):
184184

185185
logger.debug(f"Compile command: {compile_cmd}")
186186
if utils.shellCommand(compile_cmd).run(cwd=test_dir) != 0:
187-
raise RuntimeError("Compile failed!")
187+
raise RuntimeError(f"Compile failed: {testname}")
188188

189189
logger.debug(f"Objcopy command: {objcopy_cmd}")
190190
if utils.shellCommand(objcopy_cmd).run(cwd=test_dir) != 0:
191-
raise RuntimeError("Objcopy failed!")
191+
raise RuntimeError(f"Objcopy failed: {testname}")
192192

193-
# logger.debug(f"Objdump command: {objdump_cmd}")
194-
# if utils.shellCommand(objdump_cmd).run(cwd=test_dir) != 0:
195-
# raise RuntimeError("Objdump failed!")
193+
logger.debug(f"Objdump command: {objdump_cmd}")
194+
if utils.shellCommand(objdump_cmd).run(cwd=test_dir) != 0:
195+
raise RuntimeError(f"Objdump failed: {testname}")
196196

197197
if not self.target_run:
198198
continue
@@ -229,8 +229,8 @@ def runTests(self, testlist: dict[str, Any]):
229229
sig.write(word.hex() + "\n")
230230

231231
if msg := processor.status().error_output:
232-
logger.error(f"Processor execution failed: {msg}")
233-
# raise RuntimeError(f"Processor execution failed: {msg}")
232+
# logger.error(f"Processor execution failed: {msg}")
233+
raise RuntimeError(f"Processor execution failed: {msg}")
234234

235235
logger.debug(f"Finished test: {testname}")
236236

riscof/riscv-arch-test

Submodule riscv-arch-test updated 2190 files

src/config.mlog

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# per-world config options
2-
set TARGET_IPT 500000
32

3+
# loaded at reset only
44
set MEMORY_X_OFFSET -11 # x offset from this proc to bottom left memory proc
55
set MEMORY_Y_OFFSET -26 # y offset from this proc to bottom left memory proc
66
set MEMORY_WIDTH 32 # physical width of the memory procs
@@ -9,6 +9,10 @@
99
set RAM_SIZE 0x200000 # RAM size in bytes (rwx)
1010
set ICACHE_SIZE 0x200000 # icache size in variables, or bytes of memory it can represent; 4x less dense than ROM/RAM
1111

12+
# reloaded after unpausing
13+
set TARGET_IPT 500000
14+
set BREAKPOINT_ADDRESS null
15+
1216
# computed values
1317
op add MEMORY_X @thisx MEMORY_X_OFFSET
1418
op add MEMORY_Y @thisy MEMORY_Y_OFFSET

src/debugger.mlog.jinja

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ loop:
200200
op add ret @counter 1
201201
jump mark_memory always
202202

203+
setmarker remove mark_memory_id
204+
op add tmp mark_memory_id 1
205+
setmarker remove tmp
206+
jump loop__no_mark_icache lessThanEq ICACHE_SIZE 0
207+
203208
print "ICACHE_START\n{0}"
204209
set address ICACHE_START
205210
op add ret @counter 1
@@ -209,6 +214,7 @@ loop:
209214
op sub address ICACHE_END 1
210215
op add ret @counter 1
211216
jump mark_memory always
217+
loop__no_mark_icache:
212218

213219
# clear
214220

@@ -356,11 +362,13 @@ loop:
356362
op add ret @counter 1
357363
jump format_bin always
358364

359-
print "mie = {0}\n\n"
365+
print "mie = {0}\n"
360366
set n mie
361367
op add ret @counter 1
362368
jump format_bin always
363369

370+
#{{'\n'}} {{ print(0, 17) }}
371+
364372
print "cycle = {0}\n"
365373
format cycle
366374

@@ -370,7 +378,7 @@ loop:
370378
print "instret = {0}\n\n"
371379
format instret
372380

373-
#{{'\n'}} {{ print(0, 17) }}
381+
#{{'\n'}} {{ print(0, 33) }}
374382

375383
# column 2
376384

src/init.mlog.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ loop:
6363
write 0 CSRS "{{ 'mimpid'|csr }}"
6464

6565
# default values for writable CSRs
66-
write 0 CSRS "{{ 'mtvec'|csr }}"
6766
write 0 CSRS "{{ 'mepc'|csr }}"
6867
write 0 CSRS "{{ 'mscratch'|csr }}"
6968
write 0 CSRS "{{ 'mie'|csr }}"

0 commit comments

Comments
 (0)