Skip to content

Commit 937c2ab

Browse files
committed
Update Complaince Testing framework for ibex
1 parent fb32236 commit 937c2ab

15 files changed

+440
-44
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ __pycache__
2121
# This is generated by Questa tool when running DV simulations
2222
modelsim.ini
2323

24+
# This is generated by RISCOF after running compliance tests.
25+
riscof_work

config.ini

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[RISCOF]
2+
ReferencePlugin=sail_cSim
3+
ReferencePluginPath=./dv/riscv_compliance/plugin-sail_cSim
4+
DUTPlugin=ibex
5+
DUTPluginPath=./dv/riscv_compliance/plugin-ibex
6+
7+
[ibex]
8+
pluginpath=./dv/riscv_compliance/plugin-ibex
9+
ispec=./dv/riscv_compliance/plugin-ibex/ibex_isa.yaml
10+
pspec=./dv/riscv_compliance/plugin-ibex/ibex_platform.yaml
11+
target_run=1
12+
13+
[sail_cSim]
14+
pluginpath=./dv/riscv_compliance/plugin-sail_cSim

dv/riscv_compliance/README.md

+20-39
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,36 @@ How to run RISC-V Compliance on Ibex
1919
- Verilator
2020
- fusesoc
2121
- srecord (for `srec_cat`)
22-
- A RV32 compiler
22+
- RISC-V Compiler toolchain (RV64)
23+
- RISC-V SAIL Model
2324

2425
On Ubuntu/Debian, install the required tools like this:
2526

2627
```sh
27-
sudo apt-get install srecord python3-pip
28+
sudo apt-get install -y srecord python3-pip gcc-riscv64-unknown-elf
2829
pip3 install --user -U fusesoc
30+
pip3 install -U riscof
2931
```
3032

3133
We recommend installing Verilator from source as versions from Linux
32-
distributions are often outdated. See
33-
https://www.veripool.org/projects/verilator/wiki/Installing for installation
34-
instructions.
34+
distributions are often outdated. Follow [this](https://www.veripool.org/projects/verilator/wiki/Installing) link for installation instructions. Pre-build SAIL RISCV model is available in [bin](/dv/riscv_compliance/bin/) directory, along with the instructions.
3535

36-
1. Build a simulation of Ibex
36+
:warning: Run the following commands from base of the Ibex repo.
3737

38-
```sh
39-
cd $IBEX_REPO_BASE
40-
fusesoc --cores-root=. run --target=sim --setup --build lowrisc:ibex:ibex_riscv_compliance --RV32E=0 --RV32M=ibex_pkg::RV32MNone
41-
```
42-
43-
You can use the two compile-time options `--RV32M` and `--RV32E` to
44-
enable/disable the M and E ISA extensions, respectively.
45-
46-
You can now find the compiled simulation at `build/lowrisc_ibex_ibex_riscv_compliance_0.1/sim-verilator/Vibex_riscv_compliance`.
47-
48-
2. Get the RISC-V Compliance test suite
49-
50-
The upstream RISC-V compliance test suite supports Ibex out of the box.
38+
1. Get the RISC-V Architecture Compatibility test
5139

5240
```
53-
git clone https://github.com/riscv/riscv-compliance.git
54-
cd riscv-compliance
41+
git clone https://github.com/riscv-non-isa/riscv-arch-test
5542
```
5643

57-
3. Run the test suite
44+
2. Run the test suite
45+
46+
The following commnad will run all tests of `rv32i_m` for supported ISA extensions of ibex. To run the tests for specific extensio (`I`, `M`, `C`, `Zifencei`, `privilege`), provide the path of respective extension test directory to the `--suite` flag.
47+
5848
```sh
59-
cd $RISCV_COMPLIANCE_REPO_BASE
60-
# adjust to match your compiler name
61-
export RISCV_PREFIX=riscv32-unknown-elf-
62-
# give the absolute path to the simulation binary compiled in step 1
63-
export TARGET_SIM=/path/to/your/Vibex_riscv_compliance
64-
65-
export RISCV_DEVICE=rv32imc
66-
export RISCV_TARGET=ibex
67-
68-
# Note: rv32imc does not include the I and M extension tests
69-
make RISCV_ISA=rv32i && make RISCV_ISA=rv32im && make RISCV_ISA=rv32imc && \
70-
make RISCV_ISA=rv32Zicsr && make RISCV_ISA=rv32Zifencei
49+
riscof run --config=config.ini \
50+
--suite=riscv-arch-test/riscv-test-suite/rv32i_m/ \
51+
--env=riscv-arch-test/riscv-test-suite/env
7152
```
7253

7354
Compliance test suite system
@@ -81,18 +62,18 @@ suite. The system consists of
8162
- a single-port memory for data and instructions,
8263
- a bus-attached test utility.
8364

84-
The CPU core boots from SRAM at address 0x0.
65+
The CPU core boots from SRAM at address 0x80000080.
8566

8667
The test utility is used by the software to end the simulation, and to inform
8768
the simulator of the memory region where the test signature is stored.
8869
The bus host reads the test signature from memory.
8970

9071
The memory map of the whole system is as follows:
9172

92-
| Start | End | Size | Device |
93-
|---------|---------|-------|--------------------------------|
94-
| 0x0 | 0xFFFF | 64 kB | shared instruction/data memory |
95-
| 0x20000 | 0x203FF | 1 kB | test utility |
73+
| Start | End | Size | Device |
74+
|-----------|------------|--------|--------------------------------|
75+
| 0x0 | 0x1FFFFF | 2 MB | shared instruction/data memory |
76+
| 0x2000000 | 0x20003FF | 1 kB | test utility |
9677

9778

9879
The test utility provides the following registers relative to the base address.

dv/riscv_compliance/bin/Readme.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Pre-build SAIL RISC-V Model Binaries
2+
3+
SAIL RISC-V is the Golden reference model simulator for the formal specification of the RISC-V Architecture. The binaries are build by following the [instructions](https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models) available in RISCOF documentation.
4+
5+
These binaries are build for both 32-bit and 64-bit architecture:
6+
7+
- `riscv_sim_RV32`
8+
- `riscv_sim_RV64`
9+
10+
> :warning: SAIL model binaries must be available in the `$PATH` variable. To do that:
11+
- Extract `sail-riscv.tar.gz` using
12+
13+
tar -xzf sail-riscv.tar.gz sail-riscv
14+
- Binaries will be extracted in the directory named `sail-riscv`. Export the path of this directory to `$PATH` variable
15+
16+
export PATH=/path/to/sail-riscv:$PATH
7.55 MB
Binary file not shown.

dv/riscv_compliance/ibex_riscv_compliance.core

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CAPI=2:
22
# Copyright lowRISC contributors.
33
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
44
# SPDX-License-Identifier: Apache-2.0
5-
name: "lowrisc:ibex:ibex_riscv_compliance:0.1"
5+
name: "lowrisc:ibex:ibex_riscv_compliance:3.5"
66
description: "Ibex simulation for RISC-V compliance testing (using Verilator)"
77
filesets:
88
files_sim:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
OUTPUT_ARCH( "riscv" )
2+
ENTRY(rvtest_entry_point)
3+
4+
SECTIONS
5+
{
6+
. = 0x80000000;
7+
.text.init : { *(.text.init) }
8+
. = ALIGN(0x1000);
9+
.tohost : { *(.tohost) }
10+
. = ALIGN(0x1000);
11+
.text : { *(.text) }
12+
. = ALIGN(0x1000);
13+
.data : { *(.data) }
14+
.data.string : { *(.data.string)}
15+
.bss : { *(.bss) }
16+
_end = .;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef _COMPLIANCE_MODEL_H
2+
#define _COMPLIANCE_MODEL_H
3+
4+
#define TESTUTIL_BASE 0x2000000
5+
#define TESTUTIL_ADDR_HALT (TESTUTIL_BASE + 0x0)
6+
#define TESTUTIL_ADDR_BEGIN_SIGNATURE (TESTUTIL_BASE + 0x4)
7+
#define TESTUTIL_ADDR_END_SIGNATURE (TESTUTIL_BASE + 0x8)
8+
9+
10+
//RV_COMPLIANCE_HALT
11+
#define RVMODEL_HALT \
12+
/* tell simulation about location of begin_signature */ \
13+
la t0, begin_signature; \
14+
li t1, TESTUTIL_ADDR_BEGIN_SIGNATURE; \
15+
sw t0, 0(t1); \
16+
/* tell simulation about location of end_signature */ \
17+
la t0, end_signature; \
18+
li t1, TESTUTIL_ADDR_END_SIGNATURE; \
19+
sw t0, 0(t1); \
20+
/* dump signature and terminate simulation */ \
21+
li t0, 1; \
22+
li t1, TESTUTIL_ADDR_HALT; \
23+
sw t0, 0(t1); \
24+
nop ; \
25+
li gp, 1; \
26+
SWSIG (0, TESTNUM); \
27+
ecall;
28+
29+
// #define RVMODEL_BOOT \
30+
// .fill 31, 4, 0x00000013;
31+
32+
33+
#define RVMODEL_DATA_BEGIN \
34+
.align 4; .global begin_signature; begin_signature: \
35+
36+
#define RVMODEL_DATA_END \
37+
.align 4; .global end_signature; end_signature: \
38+
39+
40+
#define RVMODEL_BOOT \
41+
.section .text.init; \
42+
.align 4; \
43+
.fill 31, 4, 0x00000013; \
44+
.globl _start; \
45+
_start:
46+
47+
48+
#define LOCAL_IO_WRITE_STR(_STR) RVMODEL_IO_WRITE_STR(x31, _STR)
49+
#define RVMODEL_IO_WRITE_STR(_SP, _STR)
50+
#define LOCAL_IO_PUSH(_SP)
51+
#define LOCAL_IO_POP(_SP)
52+
#define RVMODEL_IO_ASSERT_GPR_EQ(_SP, _R, _I)
53+
#define RVMODEL_IO_ASSERT_SFPR_EQ(_F, _R, _I)
54+
#define RVMODEL_IO_ASSERT_DFPR_EQ(_D, _R, _I)
55+
56+
#define RVMODEL_SET_MSW_INT
57+
#define RVMODEL_CLEAR_MSW_INT
58+
#define RVMODEL_CLEAR_MTIMER_INT
59+
#define RVMODEL_CLEAR_MEXT_INT
60+
61+
#endif // _COMPLIANCE_MODEL_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
hart_ids: [0]
2+
hart0:
3+
ISA: RV32IMCZicsr_Zifencei
4+
physical_addr_sz: 32
5+
User_Spec_Version: '2.3'
6+
supported_xlen: [32]
7+
misa:
8+
reset-val: 0x40001104
9+
rv32:
10+
accessible: true
11+
mxl:
12+
implemented: true
13+
type:
14+
warl:
15+
dependency_fields: []
16+
legal:
17+
- mxl[1:0] in [0x1]
18+
wr_illegal:
19+
- Unchanged
20+
extensions:
21+
implemented: true
22+
type:
23+
warl:
24+
dependency_fields: []
25+
legal:
26+
- extensions[25:0] bitmask [0x0001104, 0x0000000]
27+
wr_illegal:
28+
- Unchanged
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
nmi:
2+
label: nmi_vector
3+
reset:
4+
label: reset_vector
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import os
2+
import logging
3+
4+
import riscof.utils as utils
5+
from riscof.pluginTemplate import pluginTemplate
6+
7+
logger = logging.getLogger()
8+
9+
class ibex(pluginTemplate):
10+
__model__ = "ibex"
11+
__version__ = "XXX"
12+
13+
def __init__(self, *args, **kwargs):
14+
sclass = super().__init__(*args, **kwargs)
15+
config = kwargs.get('config')
16+
if config is None:
17+
print("Please enter input file paths in configuration.")
18+
raise SystemExit(1)
19+
#self.dut_exe = os.path.join(config['PATH'] if 'PATH' in config else "","serv")
20+
#self.num_jobs = str(config['jobs'] if 'jobs' in config else 1)
21+
self.pluginpath=os.path.abspath(config['pluginpath'])
22+
self.isa_spec = os.path.abspath(config['ispec'])
23+
self.platform_spec = os.path.abspath(config['pspec'])
24+
if 'target_run' in config and config['target_run']=='0':
25+
self.target_run = False
26+
else:
27+
self.target_run = True
28+
return sclass
29+
30+
def initialise(self, suite, work_dir, archtest_env):
31+
self.compile_cmd = 'riscv64-unknown-elf-gcc -march={0} \
32+
-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -g\
33+
-T '+self.pluginpath+'/env/link.ld\
34+
-I '+self.pluginpath+'/env/\
35+
-I ' + archtest_env + ' {1} -o {2} {3}'
36+
self.objcopy_cmd = 'riscv64-unknown-elf-objcopy -O binary {0} {1}.bin'
37+
self.objdump_cmd = 'riscv64-unknown-elf-objdump -D {0} > {1}.disass'
38+
self.vmem_cmd = 'srec_cat {0}.bin -binary -offset 0x0000 -byte-swap 4 -o {0}.vmem -vmem'
39+
self.simulate_cmd = './build/lowrisc_ibex_ibex_riscv_compliance_3.5/sim-verilator/Vibex_riscv_compliance \
40+
--term-after-cycles=100000 \
41+
--raminit={0}/{1}.vmem \
42+
> {0}/signature.stdout'
43+
self.sigdump_cmd = 'grep \"^SIGNATURE: \" signature.stdout | sed \'s/SIGNATURE: 0x//\' > DUT-ibex.signature'
44+
45+
buil_ibex = 'fusesoc --cores-root=. run --target=sim --setup --build lowrisc:ibex:ibex_riscv_compliance --RV32E=0 --RV32M=ibex_pkg::RV32MNone'
46+
utils.shellCommand(buil_ibex).run()
47+
48+
def build(self, isa_yaml, platform_yaml):
49+
ispec = utils.load_yaml(isa_yaml)['hart0']
50+
self.xlen = ('64' if 64 in ispec['supported_xlen'] else '32')
51+
self.isa = 'rv' + self.xlen
52+
if "I" in ispec["ISA"]:
53+
self.isa += 'i'
54+
if "M" in ispec["ISA"]:
55+
self.isa += 'm'
56+
if "F" in ispec["ISA"]:
57+
self.isa += 'f'
58+
if "D" in ispec["ISA"]:
59+
self.isa += 'd'
60+
if "C" in ispec["ISA"]:
61+
self.isa += 'c'
62+
self.compile_cmd = self.compile_cmd+' -mabi='+('lp64 ' if 64 in ispec['supported_xlen'] else 'ilp32 ')
63+
64+
def runTests(self, testList):
65+
for testname in testList:
66+
testentry = testList[testname]
67+
test = testentry['test_path']
68+
test_dir = testentry['work_dir']
69+
file_name = 'ibex-{0}'.format(test.rsplit('/',1)[1][:-2])
70+
71+
elf = '{0}.elf'.format(file_name)
72+
compile_macros= ' -D' + " -D".join(testentry['macros'])
73+
marchstr = testentry['isa'].lower()
74+
75+
compile_run = self.compile_cmd.format(marchstr, test, elf, compile_macros)
76+
utils.shellCommand(compile_run).run(cwd=test_dir)
77+
78+
objcopy_run = self.objcopy_cmd.format(elf,file_name)
79+
utils.shellCommand(objcopy_run).run(cwd=test_dir)
80+
81+
objdump_run = self.objdump_cmd.format(elf,file_name)
82+
utils.shellCommand(objdump_run).run(cwd=test_dir)
83+
84+
vmem_run = self.vmem_cmd.format(file_name)
85+
utils.shellCommand(vmem_run).run(cwd=test_dir)
86+
87+
sim_run = self.simulate_cmd.format(test_dir,file_name)
88+
utils.shellCommand(sim_run).run()
89+
90+
utils.shellCommand(self.sigdump_cmd).run(cwd=test_dir)
91+
if not self.target_run:
92+
raise SystemExit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
OUTPUT_ARCH( "riscv" )
2+
ENTRY(rvtest_entry_point)
3+
4+
SECTIONS
5+
{
6+
. = 0x80000000;
7+
.text.init : { *(.text.init) }
8+
. = ALIGN(0x1000);
9+
.tohost : { *(.tohost) }
10+
. = ALIGN(0x1000);
11+
.text : { *(.text) }
12+
. = ALIGN(0x1000);
13+
.data : { *(.data) }
14+
.data.string : { *(.data.string)}
15+
.bss : { *(.bss) }
16+
_end = .;
17+
}

0 commit comments

Comments
 (0)