Richard Henderson | 1d9ac91 | 2020-10-21 10:37:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Branch target identification, basic notskip cases. |
| 3 | */ |
| 4 | |
Philippe Mathieu-Daudé | 0b2d8bd | 2023-06-06 15:34:08 +0200 | [diff] [blame] | 5 | #include "bti-crt.c.inc" |
Richard Henderson | 1d9ac91 | 2020-10-21 10:37:49 -0700 | [diff] [blame] | 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 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 Odaki | 79e73b5 | 2024-07-05 09:40:16 +0100 | [diff] [blame] | 20 | asm("mov %w0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %w0,#0" \ |
Richard Henderson | 1d9ac91 | 2020-10-21 10:37:49 -0700 | [diff] [blame] | 21 | : "=r"(skipped) : : "x16") |
| 22 | |
| 23 | #define BTYPE_2(DEST) \ |
Akihiko Odaki | 79e73b5 | 2024-07-05 09:40:16 +0100 | [diff] [blame] | 24 | asm("mov %w0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %w0,#0" \ |
Richard Henderson | 1d9ac91 | 2020-10-21 10:37:49 -0700 | [diff] [blame] | 25 | : "=r"(skipped) : : "x16", "x30") |
| 26 | |
| 27 | #define BTYPE_3(DEST) \ |
Akihiko Odaki | 79e73b5 | 2024-07-05 09:40:16 +0100 | [diff] [blame] | 28 | asm("mov %w0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %w0,#0" \ |
Richard Henderson | 1d9ac91 | 2020-10-21 10:37:49 -0700 | [diff] [blame] | 29 | : "=r"(skipped) : : "x15") |
| 30 | |
| 31 | #define TEST(WHICH, DEST, EXPECT) \ |
| 32 | do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0) |
| 33 | |
| 34 | |
| 35 | int 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 | } |