229a50961cee9e7e957338d0b6a072b20f3b4262
[riscv-tests.git] / isa / Makefile
1 #=======================================================================
2 # Makefile for riscv-tests/isa
3 #-----------------------------------------------------------------------
4
5 isa_src_dir := .
6
7 include $(isa_src_dir)/rv64ui/Makefrag
8 include $(isa_src_dir)/rv64uf/Makefrag
9 include $(isa_src_dir)/rv64uv/Makefrag
10 include $(isa_src_dir)/rv64si/Makefrag
11 include $(isa_src_dir)/rv64sv/Makefrag
12 include $(isa_src_dir)/rv64mi/Makefrag
13 include $(isa_src_dir)/rv32ui/Makefrag
14 include $(isa_src_dir)/rv32si/Makefrag
15 include $(isa_src_dir)/rv32mi/Makefrag
16
17 default: all
18
19 #--------------------------------------------------------------------
20 # Build rules
21 #--------------------------------------------------------------------
22
23 RISCV_PREFIX=riscv64-unknown-elf-
24 RISCV_GCC = $(RISCV_PREFIX)gcc
25 RISCV_GCC_OPTS = -static -fpic -fvisibility=hidden -nostdlib -nostartfiles -Wa,-march=RVIMAFDXhwacha
26 RISCV_OBJDUMP = $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
27 RISCV_SIM = spike --extension=hwacha
28
29 vpath %.S $(isa_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 define compile_template
44
45 $$($(1)_p_tests): $(1)-p-%: $(1)/%.S
46 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(isa_src_dir)/../env/p -I$(isa_src_dir)/macros/scalar -T$(isa_src_dir)/../env/p/link.ld $$< -o $$@
47 $(1)_tests += $$($(1)_p_tests)
48
49 $$($(1)_pt_tests): $(1)-pt-%: $(1)/%.S
50 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(isa_src_dir)/../env/pt -I$(isa_src_dir)/macros/scalar -T$(isa_src_dir)/../env/pt/link.ld $$< -o $$@
51 $(1)_tests += $$($(1)_pt_tests)
52
53 $$($(1)_pm_tests): $(1)-pm-%: $(1)/%.S
54 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(isa_src_dir)/../env/pm -I$(isa_src_dir)/macros/scalar -T$(isa_src_dir)/../env/pm/link.ld $$< -o $$@
55 $(1)_tests += $$($(1)_pm_tests)
56
57 $$($(1)_v_tests): $(1)-v-%: $(1)/%.S
58 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -std=gnu99 -O2 -I$(isa_src_dir)/../env/v -I$(isa_src_dir)/macros/scalar -T$(isa_src_dir)/../env/v/link.ld $(isa_src_dir)/../env/v/entry.S $(isa_src_dir)/../env/v/vm.c $$< -lc -o $$@
59 $(1)_tests += $$($(1)_v_tests)
60
61 $$($(1)_p_vec_tests): $(1)-p-vec-%: $(1)/%.S
62 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(isa_src_dir)/../env/p -I$(isa_src_dir)/macros/vector -T$(isa_src_dir)/../env/p/link.ld $$< -o $$@
63 $(1)_tests += $$($(1)_p_vec_tests)
64
65 $$($(1)_pt_vec_tests): $(1)-pt-vec-%: $(1)/%.S
66 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -I$(isa_src_dir)/../env/pt -I$(isa_src_dir)/macros/vector -T$(isa_src_dir)/../env/pt/link.ld $$< -o $$@
67 $(1)_tests += $$($(1)_pt_vec_tests)
68
69 $$($(1)_v_vec_tests): $(1)-v-vec-%: $(1)/%.S
70 $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) -std=gnu99 -O2 -I$(isa_src_dir)/../env/v -I$(isa_src_dir)/macros/vector -T$(isa_src_dir)/../env/v/link.ld $(isa_src_dir)/../env/v/entry.S $(isa_src_dir)/../env/v/vm.c $$< -lc -o $$@
71 $(1)_tests += $$($(1)_v_vec_tests)
72
73 $(1)_tests_dump = $$(addsuffix .dump, $$($(1)_tests))
74 $(1)_tests_hex = $$(addsuffix .hex, $$($(1)_tests))
75
76 $(1): $$($(1)_tests_dump) $$($(1)_tests_hex)
77
78 .PHONY: $(1)
79
80 tests += $$($(1)_tests)
81
82 endef
83
84 $(eval $(call compile_template,rv32ui,-m32))
85 $(eval $(call compile_template,rv32si,-m32))
86 $(eval $(call compile_template,rv32mi,-m32))
87 $(eval $(call compile_template,rv64ui))
88 $(eval $(call compile_template,rv64uf))
89 $(eval $(call compile_template,rv64uv))
90 $(eval $(call compile_template,rv64si))
91 $(eval $(call compile_template,rv64sv))
92 $(eval $(call compile_template,rv64mi))
93
94 tests_dump = $(addsuffix .dump, $(tests))
95 tests_hex = $(addsuffix .hex, $(tests))
96 tests_out = $(addsuffix .out, $(spike_tests))
97
98 run: $(tests_out)
99 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
100 $(tests_out); echo;
101
102 junk += $(tests) $(tests_dump) $(tests_hex) $(tests_out)
103
104 #------------------------------------------------------------
105 # Default
106
107 all: $(tests_dump) $(tests_hex)
108
109 #------------------------------------------------------------
110 # Clean up
111
112 clean:
113 rm -rf $(junk)