xref: /kvm-unit-tests/s390x/Makefile (revision bb88caeff9dd2ee57511bc9efbb742a8d6197903)
1tests = $(TEST_DIR)/selftest.elf
2tests += $(TEST_DIR)/intercept.elf
3tests += $(TEST_DIR)/emulator.elf
4tests += $(TEST_DIR)/sieve.elf
5tests += $(TEST_DIR)/sthyi.elf
6tests += $(TEST_DIR)/tprot.elf
7tests += $(TEST_DIR)/skey.elf
8tests += $(TEST_DIR)/diag10.elf
9tests += $(TEST_DIR)/diag308.elf
10tests += $(TEST_DIR)/pfmf.elf
11tests += $(TEST_DIR)/cmm.elf
12tests += $(TEST_DIR)/vector.elf
13tests += $(TEST_DIR)/gs.elf
14tests += $(TEST_DIR)/iep.elf
15tests += $(TEST_DIR)/cpumodel.elf
16tests += $(TEST_DIR)/diag288.elf
17tests += $(TEST_DIR)/stsi.elf
18tests += $(TEST_DIR)/skrf.elf
19tests += $(TEST_DIR)/smp.elf
20tests += $(TEST_DIR)/sclp.elf
21tests += $(TEST_DIR)/sck.elf
22tests += $(TEST_DIR)/css.elf
23tests += $(TEST_DIR)/uv-guest.elf
24tests += $(TEST_DIR)/sie.elf
25tests += $(TEST_DIR)/mvpg.elf
26tests += $(TEST_DIR)/uv-host.elf
27tests += $(TEST_DIR)/edat.elf
28tests += $(TEST_DIR)/mvpg-sie.elf
29tests += $(TEST_DIR)/spec_ex-sie.elf
30tests += $(TEST_DIR)/spec_ex.elf
31tests += $(TEST_DIR)/firq.elf
32tests += $(TEST_DIR)/epsw.elf
33tests += $(TEST_DIR)/adtl-status.elf
34tests += $(TEST_DIR)/migration.elf
35tests += $(TEST_DIR)/pv-attest.elf
36tests += $(TEST_DIR)/migration-cmm.elf
37tests += $(TEST_DIR)/migration-skey.elf
38tests += $(TEST_DIR)/panic-loop-extint.elf
39tests += $(TEST_DIR)/panic-loop-pgm.elf
40tests += $(TEST_DIR)/migration-sck.elf
41tests += $(TEST_DIR)/exittime.elf
42tests += $(TEST_DIR)/ex.elf
43tests += $(TEST_DIR)/topology.elf
44tests += $(TEST_DIR)/sie-dat.elf
45
46pv-tests += $(TEST_DIR)/pv-diags.elf
47pv-tests += $(TEST_DIR)/pv-icptcode.elf
48pv-tests += $(TEST_DIR)/pv-ipl.elf
49
50ifneq ($(HOST_KEY_DOCUMENT),)
51ifneq ($(GEN_SE_HEADER),)
52tests += $(pv-tests)
53endif
54endif
55
56tests_binary = $(patsubst %.elf,%.bin,$(tests))
57ifneq ($(HOST_KEY_DOCUMENT),)
58tests_pv_binary = $(patsubst %.bin,%.pv.bin,$(tests_binary))
59else
60tests_pv_binary =
61GEN_SE_HEADER =
62endif
63snippets-obj = $(patsubst %.gbin,%.gobj,$(snippets))
64
65all: directories test_cases test_cases_binary test_cases_pv
66
67test_cases: $(tests)
68test_cases_binary: $(tests_binary)
69test_cases_pv: $(tests_pv_binary)
70
71INCLUDE_PATHS = $(SRCDIR)/lib $(SRCDIR)/lib/s390x $(SRCDIR)/s390x
72# Include generated header files (e.g. in case of out-of-source builds)
73INCLUDE_PATHS += lib
74CPPFLAGS = $(addprefix -I,$(INCLUDE_PATHS))
75
76CFLAGS += -std=gnu99
77CFLAGS += -ffreestanding
78CFLAGS += $(CPPFLAGS)
79CFLAGS += -O2
80CFLAGS += -march=zEC12
81CFLAGS += -mbackchain
82CFLAGS += -fno-delete-null-pointer-checks
83LDFLAGS += -Wl,--build-id=none
84
85# We want to keep intermediate files
86.PRECIOUS: %.o %.lds
87
88asm-offsets = lib/$(ARCH)/asm-offsets.h
89include $(SRCDIR)/scripts/asm-offsets.mak
90
91cflatobjs += lib/util.o
92cflatobjs += lib/alloc.o
93cflatobjs += lib/alloc_phys.o
94cflatobjs += lib/alloc_page.o
95cflatobjs += lib/vmalloc.o
96cflatobjs += lib/alloc_phys.o
97cflatobjs += lib/getchar.o
98cflatobjs += lib/migrate.o
99cflatobjs += lib/s390x/io.o
100cflatobjs += lib/s390x/stack.o
101cflatobjs += lib/s390x/sclp.o
102cflatobjs += lib/s390x/sclp-console.o
103cflatobjs += lib/s390x/interrupt.o
104cflatobjs += lib/s390x/mmu.o
105cflatobjs += lib/s390x/smp.o
106cflatobjs += lib/s390x/hardware.o
107cflatobjs += lib/s390x/css_dump.o
108cflatobjs += lib/s390x/css_lib.o
109cflatobjs += lib/s390x/malloc_io.o
110cflatobjs += lib/s390x/uv.o
111cflatobjs += lib/s390x/sie.o
112cflatobjs += lib/s390x/fault.o
113
114OBJDIRS += lib/s390x
115
116asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o
117
118FLATLIBS = $(libcflat)
119
120SNIPPET_DIR = $(TEST_DIR)/snippets
121snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
122snippet_lib = $(snippet_asmlib) lib/auxinfo.o
123
124# perquisites (=guests) for the snippet hosts.
125# $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
126$(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
127$(TEST_DIR)/sie-dat.elf: snippets = $(SNIPPET_DIR)/c/sie-dat.gbin
128$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
129
130$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin
131$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-288.gbin
132$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-500.gbin
133$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-112.gbin
134$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/icpt-loop.gbin
135$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/loop.gbin
136$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-vir-timing.gbin
137$(TEST_DIR)/pv-ipl.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-308.gbin
138
139ifneq ($(GEN_SE_HEADER),)
140snippets += $(pv-snippets)
141tests += $(pv-tests)
142snippet-hdr-obj = $(patsubst %.gbin,%.hdr.obj,$(pv-snippets))
143else
144snippet-hdr-obj =
145endif
146
147# the asm/c snippets %.o have additional generated files as dependencies
148$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_DIR)/asm/%.S $(asm-offsets)
149	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
150
151$(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets)
152	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
153
154$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds
155	$(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/asm/flat.lds $<
156	$(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@
157	truncate -s '%4096' $@
158
159$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPPET_DIR)/c/flat.lds
160	$(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/c/flat.lds $< $(snippet_lib) $(FLATLIBS)
161	$(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@
162	truncate -s '%4096' $@
163
164%.hdr: %.gbin $(HOST_KEY_DOCUMENT)
165	$(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@
166
167.SECONDARY:
168%.gobj: %.gbin
169	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
170
171.SECONDARY:
172%.hdr.obj: %.hdr
173	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
174
175lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@
176%.lds: %.lds.S $(asm-offsets)
177	$(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
178
179.SECONDEXPANSION:
180%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o
181	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\"
182	@$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \
183		$(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) $(@:.elf=.aux.o) || \
184		{ echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; }
185	$(RM) $(@:.elf=.aux.o)
186	@chmod a-x $@
187
188# Secure Execution Customer Communication Key file
189# 32 bytes of key material, uses existing one if available
190comm-key = $(TEST_DIR)/comm.key
191$(comm-key):
192	dd if=/dev/urandom of=$@ bs=32 count=1 status=none
193
194%.bin: %.elf
195	$(OBJCOPY) -O binary  $< $@
196
197# Will only be filled when dump has been enabled
198GENPROTIMG_COMM_KEY =
199# allow PCKMO
200genprotimg_pcf = 0x000000e0
201
202ifeq ($(CONFIG_DUMP),yes)
203	# The genprotimg arguments for the cck changed over time so we need to
204	# figure out which argument to use in order to set the cck
205	GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes)
206	ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes)
207		GENPROTIMG_COMM_KEY = --comm-key $(comm-key)
208	else
209		GENPROTIMG_COMM_KEY = --x-comm-key $(comm-key)
210	endif
211
212	# allow dumping + PCKMO
213	genprotimg_pcf = 0x200000e0
214endif
215
216# use x-pcf to be compatible with old genprotimg versions
217genprotimg_args = --host-key-document $(HOST_KEY_DOCUMENT) --no-verify $(GENPROTIMG_COMM_KEY) --x-pcf $(genprotimg_pcf)
218
219%selftest.pv.bin: %selftest.bin $(HOST_KEY_DOCUMENT) $(patsubst %.pv.bin,%.parmfile,$@) $(comm-key)
220	$(GENPROTIMG) $(genprotimg_args) --parmfile $(patsubst %.pv.bin,%.parmfile,$@) --image $< -o $@
221
222%.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(comm-key)
223	$(GENPROTIMG) $(genprotimg_args) --image $< -o $@
224
225$(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets)
226	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
227
228
229arch_clean: asm_offsets_clean
230	$(RM) $(TEST_DIR)/*.{o,elf,bin,lds} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr,lds} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
231
232generated-files = $(asm-offsets)
233$(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
234