1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2016, Chris Smart, IBM Corporation.
5 * Calls to copy_first which are not 128-byte aligned should be
6 * caught and sent a SIGBUS.
13 #include "instructions.h"
15 unsigned int expected_instruction
= PPC_INST_COPY_FIRST
;
16 unsigned int instruction_mask
= 0xfc2007fe;
18 void signal_action_handler(int signal_num
, siginfo_t
*info
, void *ptr
)
20 ucontext_t
*ctx
= ptr
;
22 unsigned int *pc
= (unsigned int *)ctx
->uc_mcontext
.gp_regs
[PT_NIP
];
24 unsigned int *pc
= (unsigned int *)ctx
->uc_mcontext
.uc_regs
->gregs
[PT_NIP
];
28 * Check that the signal was on the correct instruction, using a
29 * mask because the compiler assigns the register at RB.
31 if ((*pc
& instruction_mask
) == expected_instruction
)
32 _exit(0); /* We hit the right instruction */
37 void setup_signal_handler(void)
39 struct sigaction signal_action
;
41 memset(&signal_action
, 0, sizeof(signal_action
));
42 signal_action
.sa_sigaction
= signal_action_handler
;
43 signal_action
.sa_flags
= SA_SIGINFO
;
44 sigaction(SIGBUS
, &signal_action
, NULL
);
47 char cacheline_buf
[128] __cacheline_aligned
;
49 int test_copy_first_unaligned(void)
51 /* Only run this test on a P9 or later */
52 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_00
));
54 /* Register our signal handler with SIGBUS */
55 setup_signal_handler();
57 /* +1 makes buf unaligned */
58 copy_first(cacheline_buf
+1);
60 /* We should not get here */
64 int main(int argc
, char *argv
[])
66 return test_harness(test_copy_first_unaligned
, "test_copy_first_unaligned");