Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / ppc64 / signal_save_restore_xer.c
blob9227f4f455512623e42221f3988c761171de7e14
1 #include <assert.h>
2 #include <stdint.h>
3 #include <signal.h>
4 #include <sys/user.h>
6 #define XER_SO (1 << 31)
7 #define XER_OV (1 << 30)
8 #define XER_CA (1 << 29)
9 #define XER_OV32 (1 << 19)
10 #define XER_CA32 (1 << 18)
12 uint64_t saved;
14 void sigtrap_handler(int sig, siginfo_t *si, void *ucontext)
16 ucontext_t *uc = ucontext;
17 uc->uc_mcontext.regs->nip += 4;
18 saved = uc->uc_mcontext.regs->xer;
19 uc->uc_mcontext.regs->xer |= XER_OV | XER_OV32;
22 int main(void)
24 uint64_t initial = XER_CA | XER_CA32, restored;
25 struct sigaction sa = {
26 .sa_sigaction = sigtrap_handler,
27 .sa_flags = SA_SIGINFO
30 sigaction(SIGTRAP, &sa, NULL);
32 asm("mtspr 1, %1\n\t"
33 "trap\n\t"
34 "mfspr %0, 1\n\t"
35 : "=r" (restored)
36 : "r" (initial));
38 assert(saved == initial);
39 assert(restored == (XER_OV | XER_OV32 | XER_CA | XER_CA32));
41 return 0;