WIP on priv spec v1.9
[riscv-tests.git] / isa / Makefile
1 #=======================================================================
2 # Makefile for riscv-tests/isa
3 #-----------------------------------------------------------------------
4
5 src_dir := .
6
7 include $(src_dir)/rv64ui/Makefrag
8 include $(src_dir)/rv64uf/Makefrag
9 include $(src_dir)/rv64si/Makefrag
10 include $(src_dir)/rv64mi/Makefrag
11 include $(src_dir)/rv32ui/Makefrag
12 include $(src_dir)/rv32si/Makefrag
13 include $(src_dir)/rv32mi/Makefrag
14
15 default: all
16
17 #--------------------------------------------------------------------
18 # Build rules
19 #--------------------------------------------------------------------
20
21 RISCV_PREFIX ?= riscv64-unknown-elf-
22 RISCV_GCC ?= $(RISCV_PREFIX)gcc
23 ENTROPY ?= -DENTROPY=$(shell echo $$$$)
24 RISCV_GCC_OPTS ?= $(ENTROPY) -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles
25 RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.text.init --section=.data
26 RISCV_SIM ?= spike
27 XLEN ?= 64
28
29 vpath %.S $(src_dir)
30
31 #------------------------------------------------------------
32 # Build assembly tests
33
34 %.hex: %
35 (elf2hex 16 8192 $< 2> /dev/null || elf2hex 16 16384 $<) > $@
36
37 %.dump: %
38 $(RISCV_OBJDUMP) $< > $@
39
40 %.out: %
41 $(RISCV_SIM) $< 2> $@
42
43 %.out32: %
44 $(RISCV_SIM) --isa=RV32 $< 2> $@
45
46 define compile_template
47
48 $$($(1)_p_tests): $(1)-p-%: $(1)/%.S
49 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(src_dir)/../env/p -I$(src_dir)/macros/scalar -T$(src_dir)/../env/p/link.ld $$< -o $$@
50 $(1)_tests += $$($(1)_p_tests)
51
52 $$($(1)_pt_tests): $(1)-pt-%: $(1)/%.S
53 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(src_dir)/../env/pt -I$(src_dir)/macros/scalar -T$(src_dir)/../env/pt/link.ld $$< -o $$@
54 $(1)_tests += $$($(1)_pt_tests)
55
56 $$($(1)_pm_tests): $(1)-pm-%: $(1)/%.S
57 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(src_dir)/../env/pm -I$(src_dir)/macros/scalar -T$(src_dir)/../env/pm/link.ld $$< -o $$@
58 $(1)_tests += $$($(1)_pm_tests)
59
60 $$($(1)_v_tests): $(1)-v-%: $(1)/%.S
61 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -std=gnu99 -O2 -I$(src_dir)/../env/v -I$(src_dir)/macros/scalar -T$(src_dir)/../env/v/link.ld $(src_dir)/../env/v/entry.S $(src_dir)/../env/v/vm.c $$< -lc -o $$@
62 $(1)_tests += $$($(1)_v_tests)
63
64 $(1)_tests_dump = $$(addsuffix .dump, $$($(1)_tests))
65 $(1)_tests_hex = $$(addsuffix .hex, $$($(1)_tests))
66
67 $(1): $$($(1)_tests_dump) $$($(1)_tests_hex)
68
69 .PHONY: $(1)
70
71 tests += $$($(1)_tests)
72
73 endef
74
75 $(eval $(call compile_template,rv32ui,-m32))
76 $(eval $(call compile_template,rv32si,-m32))
77 $(eval $(call compile_template,rv32mi,-m32))
78 ifeq ($(XLEN),64)
79 $(eval $(call compile_template,rv64ui))
80 $(eval $(call compile_template,rv64uf))
81 $(eval $(call compile_template,rv64si))
82 $(eval $(call compile_template,rv64mi))
83 endif
84
85 tests_dump = $(addsuffix .dump, $(tests))
86 tests_hex = $(addsuffix .hex, $(tests))
87 tests_out = $(addsuffix .out, $(spike_tests))
88 tests32_out = $(addsuffix .out32, $(spike32_tests))
89
90 run: $(tests_out) $(tests32_out)
91 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
92 $(tests_out) $(tests32_out); echo;
93
94 junk += $(tests) $(tests_dump) $(tests_hex) $(tests_out) $(tests32_out)
95
96 #------------------------------------------------------------
97 # Default
98
99 all: $(tests_dump) $(tests_hex)
100
101 #------------------------------------------------------------
102 # Clean up
103
104 clean:
105 rm -rf $(junk)