xref: /openbmc/qemu/tests/tcg/aarch64/bti-3.c (revision a1a62ced)
1 /*
2  * BTI vs PACIASP
3  */
4 
5 #include "bti-crt.c.inc"
6 
7 static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc)
8 {
9     uc->uc_mcontext.pc += 8;
10     uc->uc_mcontext.pstate = 1;
11 }
12 
13 #define BTYPE_1() \
14     asm("mov %0,#1; adr x16, 1f; br x16; 1: hint #25; mov %0,#0" \
15         : "=r"(skipped) : : "x16", "x30")
16 
17 #define BTYPE_2() \
18     asm("mov %0,#1; adr x16, 1f; blr x16; 1: hint #25; mov %0,#0" \
19         : "=r"(skipped) : : "x16", "x30")
20 
21 #define BTYPE_3() \
22     asm("mov %0,#1; adr x15, 1f; br x15; 1: hint #25; mov %0,#0" \
23         : "=r"(skipped) : : "x15", "x30")
24 
25 #define TEST(WHICH, EXPECT) \
26     do { WHICH(); fail += skipped ^ EXPECT; } while (0)
27 
28 int main()
29 {
30     int fail = 0;
31     int skipped;
32 
33     /* Signal-like with SA_SIGINFO.  */
34     signal_info(SIGILL, skip2_sigill);
35 
36     /* With SCTLR_EL1.BT0 set, PACIASP is not compatible with type=3. */
37     TEST(BTYPE_1, 0);
38     TEST(BTYPE_2, 0);
39     TEST(BTYPE_3, 1);
40 
41     return fail;
42 }
43