1/* 2 * Copyright 2016, Chris Smart, IBM Corporation. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 7 * 2 of the License, or (at your option) any later version. 8 * 9 * Common code for copy, copy_first, paste and paste_last unaligned 10 * tests. 11 * 12 */ 13 14#include <signal.h> 15#include <string.h> 16#include <unistd.h> 17#include "utils.h" 18#include "instructions.h" 19#include "copy_paste_unaligned_common.h" 20 21unsigned int expected_instruction; 22unsigned int instruction_mask; 23 24char cacheline_buf[128] __cacheline_aligned; 25 26void signal_action_handler(int signal_num, siginfo_t *info, void *ptr) 27{ 28 ucontext_t *ctx = ptr; 29#if defined(__powerpc64__) 30 unsigned int *pc = (unsigned int *)ctx->uc_mcontext.gp_regs[PT_NIP]; 31#else 32 unsigned int *pc = (unsigned int *)ctx->uc_mcontext.uc_regs->gregs[PT_NIP]; 33#endif 34 35 /* 36 * Check that the signal was on the correct instruction, using a 37 * mask because the compiler assigns the register at RB. 38 */ 39 if ((*pc & instruction_mask) == expected_instruction) 40 _exit(0); /* We hit the right instruction */ 41 42 _exit(1); 43} 44 45void setup_signal_handler(void) 46{ 47 struct sigaction signal_action; 48 49 memset(&signal_action, 0, sizeof(signal_action)); 50 signal_action.sa_sigaction = signal_action_handler; 51 signal_action.sa_flags = SA_SIGINFO; 52 sigaction(SIGBUS, &signal_action, NULL); 53} 54