blob: 1fada8108d22075852bcc172948185db778584c1 [file] [log] [blame]
Richard Henderson1d9ac912020-10-21 10:37:49 -07001/*
2 * Branch target identification, basic notskip cases.
3 */
4
Philippe Mathieu-Daudé0b2d8bd2023-06-06 15:34:08 +02005#include "bti-crt.c.inc"
Richard Henderson1d9ac912020-10-21 10:37:49 -07006
7static 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 NOP "nop"
14#define BTI_N "hint #32"
15#define BTI_C "hint #34"
16#define BTI_J "hint #36"
17#define BTI_JC "hint #38"
18
19#define BTYPE_1(DEST) \
Akihiko Odaki79e73b52024-07-05 09:40:16 +010020 asm("mov %w0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %w0,#0" \
Richard Henderson1d9ac912020-10-21 10:37:49 -070021 : "=r"(skipped) : : "x16")
22
23#define BTYPE_2(DEST) \
Akihiko Odaki79e73b52024-07-05 09:40:16 +010024 asm("mov %w0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %w0,#0" \
Richard Henderson1d9ac912020-10-21 10:37:49 -070025 : "=r"(skipped) : : "x16", "x30")
26
27#define BTYPE_3(DEST) \
Akihiko Odaki79e73b52024-07-05 09:40:16 +010028 asm("mov %w0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %w0,#0" \
Richard Henderson1d9ac912020-10-21 10:37:49 -070029 : "=r"(skipped) : : "x15")
30
31#define TEST(WHICH, DEST, EXPECT) \
32 do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0)
33
34
35int main()
36{
37 int fail = 0;
38 int skipped;
39
40 /* Signal-like with SA_SIGINFO. */
41 signal_info(SIGILL, skip2_sigill);
42
43 TEST(BTYPE_1, NOP, 1);
44 TEST(BTYPE_1, BTI_N, 1);
45 TEST(BTYPE_1, BTI_C, 0);
46 TEST(BTYPE_1, BTI_J, 0);
47 TEST(BTYPE_1, BTI_JC, 0);
48
49 TEST(BTYPE_2, NOP, 1);
50 TEST(BTYPE_2, BTI_N, 1);
51 TEST(BTYPE_2, BTI_C, 0);
52 TEST(BTYPE_2, BTI_J, 1);
53 TEST(BTYPE_2, BTI_JC, 0);
54
55 TEST(BTYPE_3, NOP, 1);
56 TEST(BTYPE_3, BTI_N, 1);
57 TEST(BTYPE_3, BTI_C, 1);
58 TEST(BTYPE_3, BTI_J, 0);
59 TEST(BTYPE_3, BTI_JC, 0);
60
61 return fail;
62}