tests/tcg/aarch64/system: Alternative boot object for exception logging
This allows us to record information about exceptions using a small area of memory, and continue with the test so it can verify exceptions have been taken where expected. LOGGING_VECTOR_TABLE is added to switch this on, and vec_logging_boot.o is built from boot.S with this flag. Since boot.o is created for multiple test targets, we have to build a separate object and selectively link this new vec_logging_boot.o into particular test binaries. Signed-off-by: Jim MacArthur <jim.macarthur@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20260618-jmac-gpc3b-v3-5-353e546067e7@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Jim MacArthur committed
Jun 18, 2026 at 17:33 UTC
d4f3c828acf33560018896ba87d4d6aaca272f09
3 files changed
+86
-4
tests/tcg/aarch64/Makefile.softmmu-target
+7
-4
@@ -25,7 +25,7 @@ LDFLAGS=-Wl,-T$(LINK_SCRIPT)
25
TESTS+=$(AARCH64_TESTS) $(MULTIARCH_TESTS)
26
EXTRA_RUNS+=$(MULTIARCH_RUNS)
27
CFLAGS+=-nostdlib -ggdb -O0 $(MINILIB_INC)
28
-LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
28
+LDFLAGS+=-static -nostdlib $(MINILIB_OBJS) -lgcc
29
30
config-cc.mak: Makefile
31
$(quiet-@)( \
@@ -36,17 +36,20 @@ config-cc.mak: Makefile
36
# building head blobs
37
.PRECIOUS: $(CRT_OBJS)
38
39
+vector_log_boot.o: $(CRT_PATH)/boot.S
40
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DLOGGING_VECTOR_TABLE -x assembler-with-cpp -Wa,--noexecstack -c $< -o $@
41
+
42
%.o: $(CRT_PATH)/%.S
43
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -Wa,--noexecstack -c $< -o $@
44
45
# Build and link the tests
46
%: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
44
- $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
47
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) boot.o
48
49
memory: CFLAGS+=-DCHECK_UNALIGNED=1
50
51
memory-sve: memory.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
49
- $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
52
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) boot.o
53
54
memory-sve: CFLAGS+=-DCHECK_UNALIGNED=1 -march=armv8.1-a+sve -O3
55
@@ -107,7 +110,7 @@ QEMU_MTE_ENABLED_MACHINE=-M virt,mte=on -cpu max -display none
110
QEMU_OPTS_WITH_MTE_ON = $(QEMU_MTE_ENABLED_MACHINE) $(QEMU_BASE_ARGS) -kernel
111
mte: CFLAGS+=-march=armv8.5-a+memtag
112
mte: mte.S $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
110
- $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
113
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) boot.o
114
115
run-mte: QEMU_OPTS=$(QEMU_OPTS_WITH_MTE_ON)
116
run-mte: mte
tests/tcg/aarch64/system/boot.S
+65
@@ -60,6 +60,40 @@ curr_sp0_irq:
60
curr_sp0_fiq:
61
curr_sp0_serror:
62
curr_spx_sync:
63
+#ifdef LOGGING_VECTOR_TABLE
64
+ sub sp, sp, #16
65
+ stp x0, x1, [sp, #0]
66
+ mrs x0, ESR_EL3
67
+ lsr x0, x0, #26
68
+ and x0, x0, #0x3f
69
+ cmp x0, #37
70
+ beq data_fault
71
+ cmp x0, #30
72
+ beq gpc_fault
73
+ b generic_exception
74
+
75
+data_fault:
76
+ mrs x0, FAR_EL3
77
+ adrp x1, exception_log
78
+ str x0, [x1]
79
+ ldr x0, =0x1001
80
+ str x0, [x1, #8]
81
+ b skip_return
82
+gpc_fault:
83
+ mrs x0, FAR_EL3
84
+ adrp x1, exception_log
85
+ str x0, [x1]
86
+ ldr x0, =0x1002
87
+ str x0, [x1, #8]
88
+ /* Fall through */
89
+skip_return:
90
+ mrs x0, ELR_EL3
91
+ add x0, x0, #4 /* Skip faulting instruction */
92
+ msr ELR_EL3, x0
93
+ ldp x0, x1, [sp, #0]
94
+ add sp, sp, #16
95
+ eret
96
+#endif
97
curr_spx_irq:
98
curr_spx_fiq:
99
curr_spx_serror:
@@ -71,6 +105,7 @@ lower_a32_sync:
105
lower_a32_irq:
106
lower_a32_fiq:
107
lower_a32_serror:
108
+generic_exception:
109
adr x1, .unexp_excp
110
exit_msg:
111
mov x0, SYS_WRITE0
@@ -404,6 +439,36 @@ ttb_stage2:
439
.space 4096, 0
440
441
.align 12
442
+ .global realms_gpt0
443
+ /* GPT stage 0 table */
444
+realms_gpt0:
445
+ .space 4096, 0
446
+ .align 17
447
+ .global realms_gpt1
448
+ /* GPT stage 1 table, initialised to all 0xFF (full access) */
449
+realms_gpt1:
450
+ .space 524288, 0xFF
451
+#ifdef LOGGING_VECTOR_TABLE
452
+ .align 12
453
+ .global exception_fault_address
454
+ .type exception_fault_address, @object
455
+ .size exception_fault_address, 8
456
+ .global exception_type_code
457
+ .type exception_type_code, @object
458
+ .size exception_type_code, 8
459
+ /*
460
+ * These fields record details of the last exception, if
461
+ * LOGGING_VECTOR_TABLE is defined.
462
+ */
463
+exception_log:
464
+exception_fault_address:
465
+ /* The contents of FAR_EL3 when an exception is taken. */
466
+ .space 8, 0
467
+exception_type_code:
468
+ /* A generic code indicating what type of exception occurred. */
469
+ .space 8, 0
470
+#endif
471
+ .align 12
472
system_stack:
473
.space 4096, 0
474
system_stack_end:
tests/tcg/aarch64/system/boot.h
new
+14
@@ -0,0 +1,14 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
2
+/*
3
+ *
4
+ *
5
+ * Copyright (c) 2026 Linaro Ltd
6
+ *
7
+ */
8
+
9
+
10
+/* Global variables exported in boot.S */
11
+extern volatile uint64_t exception_fault_address; /* Updated by ISR */
12
+extern volatile uint64_t exception_type_code; /* Updated by ISR */
13
+extern uint64_t realms_gpt0[];
14
+extern uint64_t realms_gpt1[];