Skip to content

Commit 0008616

Browse files
committed
arcv: Add support of nSIM simulator
Signed-off-by: Yuriy Kolerov <[email protected]>
1 parent 66b658a commit 0008616

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

Makefile.in

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,25 @@ report-binutils: report-binutils-@default_target@
238238
report-gdb: report-gdb-@default_target@
239239

240240
.PHONY: build-sim
241+
ifeq ($(SIM), nsim)
242+
# Using nsim simulator.
243+
ifeq (@default_target@, linux)
244+
$(error nSIM not supported)
245+
endif
246+
ifeq ($(shell command -v nsimdrv),)
247+
$(error nsimdrv is not detected)
248+
endif
249+
DEJAGNU_SIM_LINK_FLAGS := \
250+
-specs=semihost.specs -specs=arcv.specs \
251+
-Wl,-defsym=txtmem_addr=0x0 -Wl,-defsym=datamem_addr=0x10000000 \
252+
-Wl,-defsym=txtmem_len=32M -Wl,-defsym=datamem_len=32M
253+
DEJAGNU_SIM_LDSCRIPT := -Tarcv.ld
254+
SIM_PATH:=$(srcdir)/scripts/wrapper/nsim:$(srcdir)/scripts
255+
SIM_PREPARE:=PATH="$(SIM_PATH):$(INSTALL_DIR)/bin:$(PATH)" RISC_V_SYSROOT="$(SYSROOT)" \
256+
DEJAGNU_SIM_LINK_FLAGS="$(DEJAGNU_SIM_LINK_FLAGS)"; export DEJAGNU_SIM_LINK_FLAGS; \
257+
DEJAGNU_SIM_LDSCRIPT="$(DEJAGNU_SIM_LDSCRIPT)"; export DEJAGNU_SIM_LDSCRIPT;
258+
SIM_STAMP:=
259+
else
241260
ifeq ($(SIM),qemu)
242261
SIM_PATH:=$(srcdir)/scripts/wrapper/qemu:$(srcdir)/scripts
243262
SIM_PREPARE:=PATH="$(SIM_PATH):$(INSTALL_DIR)/bin:$(PATH)" RISC_V_SYSROOT="$(SYSROOT)"
@@ -260,7 +279,8 @@ ifeq ($(SIM),gdb)
260279
SIM_PATH:=$(INSTALL_DIR)/bin
261280
SIM_PREPARE:=
262281
else
263-
$(error "Only support SIM=spike, SIM=gdb or SIM=qemu (default).")
282+
$(error "Only support SIM=spike, SIM=gdb, SIM=nsim or SIM=qemu (default).")
283+
endif
264284
endif
265285
endif
266286
endif

scripts/march-to-cpu-opt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,45 @@ SPIKE_EXT_NOT_ALLOWED = [
3838
"zvl4096b",
3939
]
4040

41+
NSIM_EXT_ALLOWED = [
42+
"i", "m", "a", "f", "d", "c", "e", "h", "v",
43+
"zfh",
44+
"zfhmin",
45+
"zhinx",
46+
"zhinxmin",
47+
"zfinx",
48+
"zdinx",
49+
"zfa",
50+
"zicsr",
51+
"zifencei",
52+
"zicond",
53+
"zihintpause",
54+
"zba",
55+
"zbb",
56+
"zbc",
57+
"zbs",
58+
"zca",
59+
"zcb",
60+
"zcf",
61+
"zcd",
62+
"zcmp",
63+
"zcmt",
64+
"zicbom",
65+
"zicboz",
66+
"zicbop",
67+
"zvl32b",
68+
"zvl64b",
69+
"zvl128b",
70+
"zvl256b",
71+
"zvl512b",
72+
"zvl1024b",
73+
"zve32x",
74+
"zve32f",
75+
"zve64x",
76+
"zve64f",
77+
"zve64d"
78+
]
79+
4180
CPU_OPTIONS = {
4281
"xlen": "",
4382
"vlen": "",
@@ -59,6 +98,8 @@ def parse_opt(argv):
5998
parser.add_argument('--print-spike-isa', action='store_true', default=False)
6099
parser.add_argument('--print-spike-varch', action='store_true',
61100
default=False)
101+
parser.add_argument('--print-nsim-family', action='store_true', default=False)
102+
parser.add_argument('--print-nsim-isa', action='store_true', default=False)
62103
opt = parser.parse_args()
63104
return opt
64105

@@ -203,6 +244,18 @@ def print_spike_varch():
203244

204245
return "vlen:{0},elen:{1}".format(CPU_OPTIONS['vlen'], CPU_OPTIONS['elen'])
205246

247+
def print_nsim_family():
248+
return "rv{0}".format(CPU_OPTIONS['xlen'])
249+
250+
def print_nsim_isa():
251+
cpu_options = ["-all"]
252+
253+
for ext in CPU_OPTIONS['extensions']:
254+
if ext in NSIM_EXT_ALLOWED:
255+
cpu_options.append(ext)
256+
257+
return ".".join(cpu_options)
258+
206259
class TestArchStringParse(unittest.TestCase):
207260
def _test(self, arch, expected_arch_list, expected_vlen=0):
208261
exts = parse_march(arch)
@@ -301,5 +354,11 @@ def main(argv):
301354
if opt.print_spike_varch:
302355
print(print_spike_varch())
303356

357+
if opt.print_nsim_family:
358+
print(print_nsim_family())
359+
360+
if opt.print_nsim_isa:
361+
print(print_nsim_isa())
362+
304363
if __name__ == '__main__':
305364
sys.exit(main(sys.argv))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
riscv32-unknown-elf-run
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
family="$(march-to-cpu-opt --elf-file-path $1 --print-nsim-family)"
4+
isa="$(march-to-cpu-opt --elf-file-path $1 --print-nsim-isa)"
5+
6+
nsimdrv \
7+
-p nsim_isa_family=${family} \
8+
-p nsim_isa_ext=${isa} \
9+
-p nsim_semihosting=1 \
10+
-p enable_exceptions=0 \
11+
"$@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
riscv32-unknown-elf-run
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
riscv32-unknown-elf-run

0 commit comments

Comments
 (0)