142a623c7SBlue Swirl /* 242a623c7SBlue Swirl * User emulator execution 342a623c7SBlue Swirl * 442a623c7SBlue Swirl * Copyright (c) 2003-2005 Fabrice Bellard 542a623c7SBlue Swirl * 642a623c7SBlue Swirl * This library is free software; you can redistribute it and/or 742a623c7SBlue Swirl * modify it under the terms of the GNU Lesser General Public 842a623c7SBlue Swirl * License as published by the Free Software Foundation; either 9*fb0343d5SThomas Huth * version 2.1 of the License, or (at your option) any later version. 1042a623c7SBlue Swirl * 1142a623c7SBlue Swirl * This library is distributed in the hope that it will be useful, 1242a623c7SBlue Swirl * but WITHOUT ANY WARRANTY; without even the implied warranty of 1342a623c7SBlue Swirl * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1442a623c7SBlue Swirl * Lesser General Public License for more details. 1542a623c7SBlue Swirl * 1642a623c7SBlue Swirl * You should have received a copy of the GNU Lesser General Public 1742a623c7SBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 1842a623c7SBlue Swirl */ 19d38ea87aSPeter Maydell #include "qemu/osdep.h" 203e457172SBlue Swirl #include "cpu.h" 2176cad711SPaolo Bonzini #include "disas/disas.h" 2263c91552SPaolo Bonzini #include "exec/exec-all.h" 2342a623c7SBlue Swirl #include "tcg.h" 24023b0ae3SPeter Maydell #include "qemu/bitops.h" 25f08b6170SPaolo Bonzini #include "exec/cpu_ldst.h" 261652b974SPaolo Bonzini #include "translate-all.h" 27a411d296SPhilippe Mathieu-Daudé #include "exec/helper-proto.h" 28e6cd4bb5SRichard Henderson #include "qemu/atomic128.h" 2942a623c7SBlue Swirl 3042a623c7SBlue Swirl #undef EAX 3142a623c7SBlue Swirl #undef ECX 3242a623c7SBlue Swirl #undef EDX 3342a623c7SBlue Swirl #undef EBX 3442a623c7SBlue Swirl #undef ESP 3542a623c7SBlue Swirl #undef EBP 3642a623c7SBlue Swirl #undef ESI 3742a623c7SBlue Swirl #undef EDI 3842a623c7SBlue Swirl #undef EIP 3942a623c7SBlue Swirl #ifdef __linux__ 4042a623c7SBlue Swirl #include <sys/ucontext.h> 4142a623c7SBlue Swirl #endif 4242a623c7SBlue Swirl 43ec603b55SRichard Henderson __thread uintptr_t helper_retaddr; 44ec603b55SRichard Henderson 4542a623c7SBlue Swirl //#define DEBUG_SIGNAL 4642a623c7SBlue Swirl 4742a623c7SBlue Swirl /* exit the current TB from a signal handler. The host registers are 4842a623c7SBlue Swirl restored in a state compatible with the CPU emulator 4942a623c7SBlue Swirl */ 50a5852dc5SPeter Maydell static void cpu_exit_tb_from_sighandler(CPUState *cpu, sigset_t *old_set) 5142a623c7SBlue Swirl { 5242a623c7SBlue Swirl /* XXX: use siglongjmp ? */ 53a5852dc5SPeter Maydell sigprocmask(SIG_SETMASK, old_set, NULL); 546886b980SPeter Maydell cpu_loop_exit_noexc(cpu); 5542a623c7SBlue Swirl } 5642a623c7SBlue Swirl 5742a623c7SBlue Swirl /* 'pc' is the host PC at which the exception was raised. 'address' is 5842a623c7SBlue Swirl the effective address of the memory exception. 'is_write' is 1 if a 5942a623c7SBlue Swirl write caused the exception and otherwise 0'. 'old_set' is the 6042a623c7SBlue Swirl signal set which should be restored */ 61a78b1299SPeter Maydell static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, 62a5852dc5SPeter Maydell int is_write, sigset_t *old_set) 6342a623c7SBlue Swirl { 6402bed6bdSAlex Bennée CPUState *cpu = current_cpu; 657510454eSAndreas Färber CPUClass *cc; 6642a623c7SBlue Swirl int ret; 67a78b1299SPeter Maydell unsigned long address = (unsigned long)info->si_addr; 6842a623c7SBlue Swirl 69ec603b55SRichard Henderson /* We must handle PC addresses from two different sources: 70ec603b55SRichard Henderson * a call return address and a signal frame address. 71ec603b55SRichard Henderson * 72ec603b55SRichard Henderson * Within cpu_restore_state_from_tb we assume the former and adjust 73ec603b55SRichard Henderson * the address by -GETPC_ADJ so that the address is within the call 74ec603b55SRichard Henderson * insn so that addr does not accidentally match the beginning of the 75ec603b55SRichard Henderson * next guest insn. 76ec603b55SRichard Henderson * 77ec603b55SRichard Henderson * However, when the PC comes from the signal frame, it points to 78ec603b55SRichard Henderson * the actual faulting host insn and not a call insn. Subtracting 79ec603b55SRichard Henderson * GETPC_ADJ in that case may accidentally match the previous guest insn. 80ec603b55SRichard Henderson * 81ec603b55SRichard Henderson * So for the later case, adjust forward to compensate for what 82ec603b55SRichard Henderson * will be done later by cpu_restore_state_from_tb. 83ec603b55SRichard Henderson */ 84ec603b55SRichard Henderson if (helper_retaddr) { 85ec603b55SRichard Henderson pc = helper_retaddr; 86ec603b55SRichard Henderson } else { 87ec603b55SRichard Henderson pc += GETPC_ADJ; 88ec603b55SRichard Henderson } 89ec603b55SRichard Henderson 9002bed6bdSAlex Bennée /* For synchronous signals we expect to be coming from the vCPU 9102bed6bdSAlex Bennée * thread (so current_cpu should be valid) and either from running 9202bed6bdSAlex Bennée * code or during translation which can fault as we cross pages. 9302bed6bdSAlex Bennée * 9402bed6bdSAlex Bennée * If neither is true then something has gone wrong and we should 9502bed6bdSAlex Bennée * abort rather than try and restart the vCPU execution. 9602bed6bdSAlex Bennée */ 9702bed6bdSAlex Bennée if (!cpu || !cpu->running) { 9802bed6bdSAlex Bennée printf("qemu:%s received signal outside vCPU context @ pc=0x%" 9902bed6bdSAlex Bennée PRIxPTR "\n", __func__, pc); 10002bed6bdSAlex Bennée abort(); 10102bed6bdSAlex Bennée } 10202bed6bdSAlex Bennée 10342a623c7SBlue Swirl #if defined(DEBUG_SIGNAL) 10471baf787SPeter Maydell printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", 10542a623c7SBlue Swirl pc, address, is_write, *(unsigned long *)old_set); 10642a623c7SBlue Swirl #endif 10742a623c7SBlue Swirl /* XXX: locking issue */ 1089c4bbee9SPeter Maydell /* Note that it is important that we don't call page_unprotect() unless 1099c4bbee9SPeter Maydell * this is really a "write to nonwriteable page" fault, because 1109c4bbee9SPeter Maydell * page_unprotect() assumes that if it is called for an access to 1119c4bbee9SPeter Maydell * a page that's writeable this means we had two threads racing and 1129c4bbee9SPeter Maydell * another thread got there first and already made the page writeable; 1139c4bbee9SPeter Maydell * so we will retry the access. If we were to call page_unprotect() 1149c4bbee9SPeter Maydell * for some other kind of fault that should really be passed to the 1159c4bbee9SPeter Maydell * guest, we'd end up in an infinite loop of retrying the faulting 1169c4bbee9SPeter Maydell * access. 1179c4bbee9SPeter Maydell */ 1189c4bbee9SPeter Maydell if (is_write && info->si_signo == SIGSEGV && info->si_code == SEGV_ACCERR && 1199c4bbee9SPeter Maydell h2g_valid(address)) { 120f213e72fSPeter Maydell switch (page_unprotect(h2g(address), pc)) { 121f213e72fSPeter Maydell case 0: 122f213e72fSPeter Maydell /* Fault not caused by a page marked unwritable to protect 123ec603b55SRichard Henderson * cached translations, must be the guest binary's problem. 124f213e72fSPeter Maydell */ 125f213e72fSPeter Maydell break; 126f213e72fSPeter Maydell case 1: 127f213e72fSPeter Maydell /* Fault caused by protection of cached translation; TBs 128ec603b55SRichard Henderson * invalidated, so resume execution. Retain helper_retaddr 129ec603b55SRichard Henderson * for a possible second fault. 130f213e72fSPeter Maydell */ 13142a623c7SBlue Swirl return 1; 132f213e72fSPeter Maydell case 2: 133f213e72fSPeter Maydell /* Fault caused by protection of cached translation, and the 134f213e72fSPeter Maydell * currently executing TB was modified and must be exited 135ec603b55SRichard Henderson * immediately. Clear helper_retaddr for next execution. 136f213e72fSPeter Maydell */ 137ec603b55SRichard Henderson helper_retaddr = 0; 13802bed6bdSAlex Bennée cpu_exit_tb_from_sighandler(cpu, old_set); 139ec603b55SRichard Henderson /* NORETURN */ 140ec603b55SRichard Henderson 141f213e72fSPeter Maydell default: 142f213e72fSPeter Maydell g_assert_not_reached(); 143f213e72fSPeter Maydell } 14442a623c7SBlue Swirl } 14542a623c7SBlue Swirl 146732f9e89SAlexander Graf /* Convert forcefully to guest address space, invalid addresses 147732f9e89SAlexander Graf are still valid segv ones */ 148732f9e89SAlexander Graf address = h2g_nocheck(address); 149732f9e89SAlexander Graf 1507510454eSAndreas Färber cc = CPU_GET_CLASS(cpu); 15142a623c7SBlue Swirl /* see if it is an MMU fault */ 1527510454eSAndreas Färber g_assert(cc->handle_mmu_fault); 15398670d47SLaurent Vivier ret = cc->handle_mmu_fault(cpu, address, 0, is_write, MMU_USER_IDX); 154ec603b55SRichard Henderson 155ec603b55SRichard Henderson if (ret == 0) { 156ec603b55SRichard Henderson /* The MMU fault was handled without causing real CPU fault. 157ec603b55SRichard Henderson * Retain helper_retaddr for a possible second fault. 158ec603b55SRichard Henderson */ 159ec603b55SRichard Henderson return 1; 160ec603b55SRichard Henderson } 161ec603b55SRichard Henderson 162ec603b55SRichard Henderson /* All other paths lead to cpu_exit; clear helper_retaddr 163ec603b55SRichard Henderson * for next execution. 164ec603b55SRichard Henderson */ 165ec603b55SRichard Henderson helper_retaddr = 0; 166ec603b55SRichard Henderson 16742a623c7SBlue Swirl if (ret < 0) { 16842a623c7SBlue Swirl return 0; /* not an MMU fault */ 16942a623c7SBlue Swirl } 17001ecaf43SRichard Henderson 171ec603b55SRichard Henderson /* Now we have a real cpu fault. */ 172afd46fcaSPavel Dovgalyuk cpu_restore_state(cpu, pc, true); 17342a623c7SBlue Swirl 17442a623c7SBlue Swirl sigprocmask(SIG_SETMASK, old_set, NULL); 1750c33682dSPeter Maydell cpu_loop_exit(cpu); 17642a623c7SBlue Swirl 17742a623c7SBlue Swirl /* never comes here */ 17842a623c7SBlue Swirl return 1; 17942a623c7SBlue Swirl } 18042a623c7SBlue Swirl 18142a623c7SBlue Swirl #if defined(__i386__) 18242a623c7SBlue Swirl 183c5679026SPeter Maydell #if defined(__NetBSD__) 18442a623c7SBlue Swirl #include <ucontext.h> 18542a623c7SBlue Swirl 18642a623c7SBlue Swirl #define EIP_sig(context) ((context)->uc_mcontext.__gregs[_REG_EIP]) 18742a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO]) 18842a623c7SBlue Swirl #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR]) 18942a623c7SBlue Swirl #define MASK_sig(context) ((context)->uc_sigmask) 19042a623c7SBlue Swirl #elif defined(__FreeBSD__) || defined(__DragonFly__) 19142a623c7SBlue Swirl #include <ucontext.h> 19242a623c7SBlue Swirl 19342a623c7SBlue Swirl #define EIP_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_eip)) 19442a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno) 19542a623c7SBlue Swirl #define ERROR_sig(context) ((context)->uc_mcontext.mc_err) 19642a623c7SBlue Swirl #define MASK_sig(context) ((context)->uc_sigmask) 19742a623c7SBlue Swirl #elif defined(__OpenBSD__) 19842a623c7SBlue Swirl #define EIP_sig(context) ((context)->sc_eip) 19942a623c7SBlue Swirl #define TRAP_sig(context) ((context)->sc_trapno) 20042a623c7SBlue Swirl #define ERROR_sig(context) ((context)->sc_err) 20142a623c7SBlue Swirl #define MASK_sig(context) ((context)->sc_mask) 20242a623c7SBlue Swirl #else 20342a623c7SBlue Swirl #define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP]) 20442a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO]) 20542a623c7SBlue Swirl #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR]) 20642a623c7SBlue Swirl #define MASK_sig(context) ((context)->uc_sigmask) 20742a623c7SBlue Swirl #endif 20842a623c7SBlue Swirl 20942a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 21042a623c7SBlue Swirl void *puc) 21142a623c7SBlue Swirl { 21242a623c7SBlue Swirl siginfo_t *info = pinfo; 21342a623c7SBlue Swirl #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) 21442a623c7SBlue Swirl ucontext_t *uc = puc; 21542a623c7SBlue Swirl #elif defined(__OpenBSD__) 21642a623c7SBlue Swirl struct sigcontext *uc = puc; 21742a623c7SBlue Swirl #else 21804b33e21SKhem Raj ucontext_t *uc = puc; 21942a623c7SBlue Swirl #endif 22042a623c7SBlue Swirl unsigned long pc; 22142a623c7SBlue Swirl int trapno; 22242a623c7SBlue Swirl 22342a623c7SBlue Swirl #ifndef REG_EIP 22442a623c7SBlue Swirl /* for glibc 2.1 */ 22542a623c7SBlue Swirl #define REG_EIP EIP 22642a623c7SBlue Swirl #define REG_ERR ERR 22742a623c7SBlue Swirl #define REG_TRAPNO TRAPNO 22842a623c7SBlue Swirl #endif 22942a623c7SBlue Swirl pc = EIP_sig(uc); 23042a623c7SBlue Swirl trapno = TRAP_sig(uc); 231a78b1299SPeter Maydell return handle_cpu_signal(pc, info, 232a78b1299SPeter Maydell trapno == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0, 233a5852dc5SPeter Maydell &MASK_sig(uc)); 23442a623c7SBlue Swirl } 23542a623c7SBlue Swirl 23642a623c7SBlue Swirl #elif defined(__x86_64__) 23742a623c7SBlue Swirl 23842a623c7SBlue Swirl #ifdef __NetBSD__ 23942a623c7SBlue Swirl #define PC_sig(context) _UC_MACHINE_PC(context) 24042a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO]) 24142a623c7SBlue Swirl #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR]) 24242a623c7SBlue Swirl #define MASK_sig(context) ((context)->uc_sigmask) 24342a623c7SBlue Swirl #elif defined(__OpenBSD__) 24442a623c7SBlue Swirl #define PC_sig(context) ((context)->sc_rip) 24542a623c7SBlue Swirl #define TRAP_sig(context) ((context)->sc_trapno) 24642a623c7SBlue Swirl #define ERROR_sig(context) ((context)->sc_err) 24742a623c7SBlue Swirl #define MASK_sig(context) ((context)->sc_mask) 24842a623c7SBlue Swirl #elif defined(__FreeBSD__) || defined(__DragonFly__) 24942a623c7SBlue Swirl #include <ucontext.h> 25042a623c7SBlue Swirl 25142a623c7SBlue Swirl #define PC_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_rip)) 25242a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno) 25342a623c7SBlue Swirl #define ERROR_sig(context) ((context)->uc_mcontext.mc_err) 25442a623c7SBlue Swirl #define MASK_sig(context) ((context)->uc_sigmask) 25542a623c7SBlue Swirl #else 25642a623c7SBlue Swirl #define PC_sig(context) ((context)->uc_mcontext.gregs[REG_RIP]) 25742a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO]) 25842a623c7SBlue Swirl #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR]) 25942a623c7SBlue Swirl #define MASK_sig(context) ((context)->uc_sigmask) 26042a623c7SBlue Swirl #endif 26142a623c7SBlue Swirl 26242a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 26342a623c7SBlue Swirl void *puc) 26442a623c7SBlue Swirl { 26542a623c7SBlue Swirl siginfo_t *info = pinfo; 26642a623c7SBlue Swirl unsigned long pc; 26742a623c7SBlue Swirl #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) 26842a623c7SBlue Swirl ucontext_t *uc = puc; 26942a623c7SBlue Swirl #elif defined(__OpenBSD__) 27042a623c7SBlue Swirl struct sigcontext *uc = puc; 27142a623c7SBlue Swirl #else 27204b33e21SKhem Raj ucontext_t *uc = puc; 27342a623c7SBlue Swirl #endif 27442a623c7SBlue Swirl 27542a623c7SBlue Swirl pc = PC_sig(uc); 276a78b1299SPeter Maydell return handle_cpu_signal(pc, info, 277a78b1299SPeter Maydell TRAP_sig(uc) == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0, 278a5852dc5SPeter Maydell &MASK_sig(uc)); 27942a623c7SBlue Swirl } 28042a623c7SBlue Swirl 28142a623c7SBlue Swirl #elif defined(_ARCH_PPC) 28242a623c7SBlue Swirl 28342a623c7SBlue Swirl /*********************************************************************** 28442a623c7SBlue Swirl * signal context platform-specific definitions 28542a623c7SBlue Swirl * From Wine 28642a623c7SBlue Swirl */ 28742a623c7SBlue Swirl #ifdef linux 28842a623c7SBlue Swirl /* All Registers access - only for local access */ 28942a623c7SBlue Swirl #define REG_sig(reg_name, context) \ 29042a623c7SBlue Swirl ((context)->uc_mcontext.regs->reg_name) 29142a623c7SBlue Swirl /* Gpr Registers access */ 29242a623c7SBlue Swirl #define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context) 29342a623c7SBlue Swirl /* Program counter */ 29442a623c7SBlue Swirl #define IAR_sig(context) REG_sig(nip, context) 29542a623c7SBlue Swirl /* Machine State Register (Supervisor) */ 29642a623c7SBlue Swirl #define MSR_sig(context) REG_sig(msr, context) 29742a623c7SBlue Swirl /* Count register */ 29842a623c7SBlue Swirl #define CTR_sig(context) REG_sig(ctr, context) 29942a623c7SBlue Swirl /* User's integer exception register */ 30042a623c7SBlue Swirl #define XER_sig(context) REG_sig(xer, context) 30142a623c7SBlue Swirl /* Link register */ 30242a623c7SBlue Swirl #define LR_sig(context) REG_sig(link, context) 30342a623c7SBlue Swirl /* Condition register */ 30442a623c7SBlue Swirl #define CR_sig(context) REG_sig(ccr, context) 30542a623c7SBlue Swirl 30642a623c7SBlue Swirl /* Float Registers access */ 30742a623c7SBlue Swirl #define FLOAT_sig(reg_num, context) \ 30842a623c7SBlue Swirl (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num]) 30942a623c7SBlue Swirl #define FPSCR_sig(context) \ 31042a623c7SBlue Swirl (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4))) 31142a623c7SBlue Swirl /* Exception Registers access */ 31242a623c7SBlue Swirl #define DAR_sig(context) REG_sig(dar, context) 31342a623c7SBlue Swirl #define DSISR_sig(context) REG_sig(dsisr, context) 31442a623c7SBlue Swirl #define TRAP_sig(context) REG_sig(trap, context) 31542a623c7SBlue Swirl #endif /* linux */ 31642a623c7SBlue Swirl 31742a623c7SBlue Swirl #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 31842a623c7SBlue Swirl #include <ucontext.h> 31942a623c7SBlue Swirl #define IAR_sig(context) ((context)->uc_mcontext.mc_srr0) 32042a623c7SBlue Swirl #define MSR_sig(context) ((context)->uc_mcontext.mc_srr1) 32142a623c7SBlue Swirl #define CTR_sig(context) ((context)->uc_mcontext.mc_ctr) 32242a623c7SBlue Swirl #define XER_sig(context) ((context)->uc_mcontext.mc_xer) 32342a623c7SBlue Swirl #define LR_sig(context) ((context)->uc_mcontext.mc_lr) 32442a623c7SBlue Swirl #define CR_sig(context) ((context)->uc_mcontext.mc_cr) 32542a623c7SBlue Swirl /* Exception Registers access */ 32642a623c7SBlue Swirl #define DAR_sig(context) ((context)->uc_mcontext.mc_dar) 32742a623c7SBlue Swirl #define DSISR_sig(context) ((context)->uc_mcontext.mc_dsisr) 32842a623c7SBlue Swirl #define TRAP_sig(context) ((context)->uc_mcontext.mc_exc) 32942a623c7SBlue Swirl #endif /* __FreeBSD__|| __FreeBSD_kernel__ */ 33042a623c7SBlue Swirl 33142a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 33242a623c7SBlue Swirl void *puc) 33342a623c7SBlue Swirl { 33442a623c7SBlue Swirl siginfo_t *info = pinfo; 33542a623c7SBlue Swirl #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 33642a623c7SBlue Swirl ucontext_t *uc = puc; 33742a623c7SBlue Swirl #else 33804b33e21SKhem Raj ucontext_t *uc = puc; 33942a623c7SBlue Swirl #endif 34042a623c7SBlue Swirl unsigned long pc; 34142a623c7SBlue Swirl int is_write; 34242a623c7SBlue Swirl 34342a623c7SBlue Swirl pc = IAR_sig(uc); 34442a623c7SBlue Swirl is_write = 0; 34542a623c7SBlue Swirl #if 0 34642a623c7SBlue Swirl /* ppc 4xx case */ 34742a623c7SBlue Swirl if (DSISR_sig(uc) & 0x00800000) { 34842a623c7SBlue Swirl is_write = 1; 34942a623c7SBlue Swirl } 35042a623c7SBlue Swirl #else 35142a623c7SBlue Swirl if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) { 35242a623c7SBlue Swirl is_write = 1; 35342a623c7SBlue Swirl } 35442a623c7SBlue Swirl #endif 355a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 35642a623c7SBlue Swirl } 35742a623c7SBlue Swirl 35842a623c7SBlue Swirl #elif defined(__alpha__) 35942a623c7SBlue Swirl 36042a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 36142a623c7SBlue Swirl void *puc) 36242a623c7SBlue Swirl { 36342a623c7SBlue Swirl siginfo_t *info = pinfo; 36404b33e21SKhem Raj ucontext_t *uc = puc; 36542a623c7SBlue Swirl uint32_t *pc = uc->uc_mcontext.sc_pc; 36642a623c7SBlue Swirl uint32_t insn = *pc; 36742a623c7SBlue Swirl int is_write = 0; 36842a623c7SBlue Swirl 36942a623c7SBlue Swirl /* XXX: need kernel patch to get write flag faster */ 37042a623c7SBlue Swirl switch (insn >> 26) { 37142a623c7SBlue Swirl case 0x0d: /* stw */ 37242a623c7SBlue Swirl case 0x0e: /* stb */ 37342a623c7SBlue Swirl case 0x0f: /* stq_u */ 37442a623c7SBlue Swirl case 0x24: /* stf */ 37542a623c7SBlue Swirl case 0x25: /* stg */ 37642a623c7SBlue Swirl case 0x26: /* sts */ 37742a623c7SBlue Swirl case 0x27: /* stt */ 37842a623c7SBlue Swirl case 0x2c: /* stl */ 37942a623c7SBlue Swirl case 0x2d: /* stq */ 38042a623c7SBlue Swirl case 0x2e: /* stl_c */ 38142a623c7SBlue Swirl case 0x2f: /* stq_c */ 38242a623c7SBlue Swirl is_write = 1; 38342a623c7SBlue Swirl } 38442a623c7SBlue Swirl 385a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 38642a623c7SBlue Swirl } 38742a623c7SBlue Swirl #elif defined(__sparc__) 38842a623c7SBlue Swirl 38942a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 39042a623c7SBlue Swirl void *puc) 39142a623c7SBlue Swirl { 39242a623c7SBlue Swirl siginfo_t *info = pinfo; 39342a623c7SBlue Swirl int is_write; 39442a623c7SBlue Swirl uint32_t insn; 39542a623c7SBlue Swirl #if !defined(__arch64__) || defined(CONFIG_SOLARIS) 39642a623c7SBlue Swirl uint32_t *regs = (uint32_t *)(info + 1); 39742a623c7SBlue Swirl void *sigmask = (regs + 20); 39842a623c7SBlue Swirl /* XXX: is there a standard glibc define ? */ 39942a623c7SBlue Swirl unsigned long pc = regs[1]; 40042a623c7SBlue Swirl #else 40142a623c7SBlue Swirl #ifdef __linux__ 40242a623c7SBlue Swirl struct sigcontext *sc = puc; 40342a623c7SBlue Swirl unsigned long pc = sc->sigc_regs.tpc; 40442a623c7SBlue Swirl void *sigmask = (void *)sc->sigc_mask; 40542a623c7SBlue Swirl #elif defined(__OpenBSD__) 40642a623c7SBlue Swirl struct sigcontext *uc = puc; 40742a623c7SBlue Swirl unsigned long pc = uc->sc_pc; 40842a623c7SBlue Swirl void *sigmask = (void *)(long)uc->sc_mask; 4097ccfb495STobias Nygren #elif defined(__NetBSD__) 4107ccfb495STobias Nygren ucontext_t *uc = puc; 4117ccfb495STobias Nygren unsigned long pc = _UC_MACHINE_PC(uc); 4127ccfb495STobias Nygren void *sigmask = (void *)&uc->uc_sigmask; 41342a623c7SBlue Swirl #endif 41442a623c7SBlue Swirl #endif 41542a623c7SBlue Swirl 41642a623c7SBlue Swirl /* XXX: need kernel patch to get write flag faster */ 41742a623c7SBlue Swirl is_write = 0; 41842a623c7SBlue Swirl insn = *(uint32_t *)pc; 41942a623c7SBlue Swirl if ((insn >> 30) == 3) { 42042a623c7SBlue Swirl switch ((insn >> 19) & 0x3f) { 42142a623c7SBlue Swirl case 0x05: /* stb */ 42242a623c7SBlue Swirl case 0x15: /* stba */ 42342a623c7SBlue Swirl case 0x06: /* sth */ 42442a623c7SBlue Swirl case 0x16: /* stha */ 42542a623c7SBlue Swirl case 0x04: /* st */ 42642a623c7SBlue Swirl case 0x14: /* sta */ 42742a623c7SBlue Swirl case 0x07: /* std */ 42842a623c7SBlue Swirl case 0x17: /* stda */ 42942a623c7SBlue Swirl case 0x0e: /* stx */ 43042a623c7SBlue Swirl case 0x1e: /* stxa */ 43142a623c7SBlue Swirl case 0x24: /* stf */ 43242a623c7SBlue Swirl case 0x34: /* stfa */ 43342a623c7SBlue Swirl case 0x27: /* stdf */ 43442a623c7SBlue Swirl case 0x37: /* stdfa */ 43542a623c7SBlue Swirl case 0x26: /* stqf */ 43642a623c7SBlue Swirl case 0x36: /* stqfa */ 43742a623c7SBlue Swirl case 0x25: /* stfsr */ 43842a623c7SBlue Swirl case 0x3c: /* casa */ 43942a623c7SBlue Swirl case 0x3e: /* casxa */ 44042a623c7SBlue Swirl is_write = 1; 44142a623c7SBlue Swirl break; 44242a623c7SBlue Swirl } 44342a623c7SBlue Swirl } 444a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, sigmask); 44542a623c7SBlue Swirl } 44642a623c7SBlue Swirl 44742a623c7SBlue Swirl #elif defined(__arm__) 44842a623c7SBlue Swirl 4497ccfb495STobias Nygren #if defined(__NetBSD__) 4507ccfb495STobias Nygren #include <ucontext.h> 4517ccfb495STobias Nygren #endif 4527ccfb495STobias Nygren 45342a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 45442a623c7SBlue Swirl void *puc) 45542a623c7SBlue Swirl { 45642a623c7SBlue Swirl siginfo_t *info = pinfo; 4577ccfb495STobias Nygren #if defined(__NetBSD__) 4587ccfb495STobias Nygren ucontext_t *uc = puc; 4597ccfb495STobias Nygren #else 46004b33e21SKhem Raj ucontext_t *uc = puc; 4617ccfb495STobias Nygren #endif 46242a623c7SBlue Swirl unsigned long pc; 46342a623c7SBlue Swirl int is_write; 46442a623c7SBlue Swirl 4657ccfb495STobias Nygren #if defined(__NetBSD__) 4667ccfb495STobias Nygren pc = uc->uc_mcontext.__gregs[_REG_R15]; 4677ccfb495STobias Nygren #elif defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) 46842a623c7SBlue Swirl pc = uc->uc_mcontext.gregs[R15]; 46942a623c7SBlue Swirl #else 47042a623c7SBlue Swirl pc = uc->uc_mcontext.arm_pc; 47142a623c7SBlue Swirl #endif 472023b0ae3SPeter Maydell 473023b0ae3SPeter Maydell /* error_code is the FSR value, in which bit 11 is WnR (assuming a v6 or 474023b0ae3SPeter Maydell * later processor; on v5 we will always report this as a read). 475023b0ae3SPeter Maydell */ 476023b0ae3SPeter Maydell is_write = extract32(uc->uc_mcontext.error_code, 11, 1); 477a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 47842a623c7SBlue Swirl } 47942a623c7SBlue Swirl 480f129061cSClaudio Fontana #elif defined(__aarch64__) 481f129061cSClaudio Fontana 482f454a54fSPeter Maydell #ifndef ESR_MAGIC 483f454a54fSPeter Maydell /* Pre-3.16 kernel headers don't have these, so provide fallback definitions */ 484f454a54fSPeter Maydell #define ESR_MAGIC 0x45535201 485f454a54fSPeter Maydell struct esr_context { 486f454a54fSPeter Maydell struct _aarch64_ctx head; 487f454a54fSPeter Maydell uint64_t esr; 488f454a54fSPeter Maydell }; 489f454a54fSPeter Maydell #endif 490f454a54fSPeter Maydell 491f454a54fSPeter Maydell static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc) 492f454a54fSPeter Maydell { 493f454a54fSPeter Maydell return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved; 494f454a54fSPeter Maydell } 495f454a54fSPeter Maydell 496f454a54fSPeter Maydell static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr) 497f454a54fSPeter Maydell { 498f454a54fSPeter Maydell return (struct _aarch64_ctx *)((char *)hdr + hdr->size); 499f454a54fSPeter Maydell } 500f454a54fSPeter Maydell 501661f7fa4SRichard Henderson int cpu_signal_handler(int host_signum, void *pinfo, void *puc) 502f129061cSClaudio Fontana { 503f129061cSClaudio Fontana siginfo_t *info = pinfo; 50404b33e21SKhem Raj ucontext_t *uc = puc; 505661f7fa4SRichard Henderson uintptr_t pc = uc->uc_mcontext.pc; 506661f7fa4SRichard Henderson bool is_write; 507f454a54fSPeter Maydell struct _aarch64_ctx *hdr; 508f454a54fSPeter Maydell struct esr_context const *esrctx = NULL; 509f129061cSClaudio Fontana 510f454a54fSPeter Maydell /* Find the esr_context, which has the WnR bit in it */ 511f454a54fSPeter Maydell for (hdr = first_ctx(uc); hdr->magic; hdr = next_ctx(hdr)) { 512f454a54fSPeter Maydell if (hdr->magic == ESR_MAGIC) { 513f454a54fSPeter Maydell esrctx = (struct esr_context const *)hdr; 514f454a54fSPeter Maydell break; 515f454a54fSPeter Maydell } 516f454a54fSPeter Maydell } 517f454a54fSPeter Maydell 518f454a54fSPeter Maydell if (esrctx) { 519f454a54fSPeter Maydell /* For data aborts ESR.EC is 0b10010x: then bit 6 is the WnR bit */ 520f454a54fSPeter Maydell uint64_t esr = esrctx->esr; 521f454a54fSPeter Maydell is_write = extract32(esr, 27, 5) == 0x12 && extract32(esr, 6, 1) == 1; 522f454a54fSPeter Maydell } else { 523f454a54fSPeter Maydell /* 524f454a54fSPeter Maydell * Fall back to parsing instructions; will only be needed 525f454a54fSPeter Maydell * for really ancient (pre-3.16) kernels. 526f454a54fSPeter Maydell */ 527f454a54fSPeter Maydell uint32_t insn = *(uint32_t *)pc; 528f454a54fSPeter Maydell 529661f7fa4SRichard Henderson is_write = ((insn & 0xbfff0000) == 0x0c000000 /* C3.3.1 */ 530661f7fa4SRichard Henderson || (insn & 0xbfe00000) == 0x0c800000 /* C3.3.2 */ 531661f7fa4SRichard Henderson || (insn & 0xbfdf0000) == 0x0d000000 /* C3.3.3 */ 532661f7fa4SRichard Henderson || (insn & 0xbfc00000) == 0x0d800000 /* C3.3.4 */ 533661f7fa4SRichard Henderson || (insn & 0x3f400000) == 0x08000000 /* C3.3.6 */ 534661f7fa4SRichard Henderson || (insn & 0x3bc00000) == 0x39000000 /* C3.3.13 */ 535661f7fa4SRichard Henderson || (insn & 0x3fc00000) == 0x3d800000 /* ... 128bit */ 536f454a54fSPeter Maydell /* Ignore bits 10, 11 & 21, controlling indexing. */ 537661f7fa4SRichard Henderson || (insn & 0x3bc00000) == 0x38000000 /* C3.3.8-12 */ 538661f7fa4SRichard Henderson || (insn & 0x3fe00000) == 0x3c800000 /* ... 128bit */ 539661f7fa4SRichard Henderson /* Ignore bits 23 & 24, controlling indexing. */ 540661f7fa4SRichard Henderson || (insn & 0x3a400000) == 0x28000000); /* C3.3.7,14-16 */ 541f454a54fSPeter Maydell } 542a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 543f129061cSClaudio Fontana } 544f129061cSClaudio Fontana 54542a623c7SBlue Swirl #elif defined(__s390__) 54642a623c7SBlue Swirl 54742a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 54842a623c7SBlue Swirl void *puc) 54942a623c7SBlue Swirl { 55042a623c7SBlue Swirl siginfo_t *info = pinfo; 55104b33e21SKhem Raj ucontext_t *uc = puc; 55242a623c7SBlue Swirl unsigned long pc; 55342a623c7SBlue Swirl uint16_t *pinsn; 55442a623c7SBlue Swirl int is_write = 0; 55542a623c7SBlue Swirl 55642a623c7SBlue Swirl pc = uc->uc_mcontext.psw.addr; 55742a623c7SBlue Swirl 55842a623c7SBlue Swirl /* ??? On linux, the non-rt signal handler has 4 (!) arguments instead 55942a623c7SBlue Swirl of the normal 2 arguments. The 3rd argument contains the "int_code" 56042a623c7SBlue Swirl from the hardware which does in fact contain the is_write value. 56142a623c7SBlue Swirl The rt signal handler, as far as I can tell, does not give this value 56242a623c7SBlue Swirl at all. Not that we could get to it from here even if it were. */ 56342a623c7SBlue Swirl /* ??? This is not even close to complete, since it ignores all 56442a623c7SBlue Swirl of the read-modify-write instructions. */ 56542a623c7SBlue Swirl pinsn = (uint16_t *)pc; 56642a623c7SBlue Swirl switch (pinsn[0] >> 8) { 56742a623c7SBlue Swirl case 0x50: /* ST */ 56842a623c7SBlue Swirl case 0x42: /* STC */ 56942a623c7SBlue Swirl case 0x40: /* STH */ 57042a623c7SBlue Swirl is_write = 1; 57142a623c7SBlue Swirl break; 57242a623c7SBlue Swirl case 0xc4: /* RIL format insns */ 57342a623c7SBlue Swirl switch (pinsn[0] & 0xf) { 57442a623c7SBlue Swirl case 0xf: /* STRL */ 57542a623c7SBlue Swirl case 0xb: /* STGRL */ 57642a623c7SBlue Swirl case 0x7: /* STHRL */ 57742a623c7SBlue Swirl is_write = 1; 57842a623c7SBlue Swirl } 57942a623c7SBlue Swirl break; 58042a623c7SBlue Swirl case 0xe3: /* RXY format insns */ 58142a623c7SBlue Swirl switch (pinsn[2] & 0xff) { 58242a623c7SBlue Swirl case 0x50: /* STY */ 58342a623c7SBlue Swirl case 0x24: /* STG */ 58442a623c7SBlue Swirl case 0x72: /* STCY */ 58542a623c7SBlue Swirl case 0x70: /* STHY */ 58642a623c7SBlue Swirl case 0x8e: /* STPQ */ 58742a623c7SBlue Swirl case 0x3f: /* STRVH */ 58842a623c7SBlue Swirl case 0x3e: /* STRV */ 58942a623c7SBlue Swirl case 0x2f: /* STRVG */ 59042a623c7SBlue Swirl is_write = 1; 59142a623c7SBlue Swirl } 59242a623c7SBlue Swirl break; 59342a623c7SBlue Swirl } 594a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 59542a623c7SBlue Swirl } 59642a623c7SBlue Swirl 59742a623c7SBlue Swirl #elif defined(__mips__) 59842a623c7SBlue Swirl 59942a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo, 60042a623c7SBlue Swirl void *puc) 60142a623c7SBlue Swirl { 60242a623c7SBlue Swirl siginfo_t *info = pinfo; 60304b33e21SKhem Raj ucontext_t *uc = puc; 60442a623c7SBlue Swirl greg_t pc = uc->uc_mcontext.pc; 60542a623c7SBlue Swirl int is_write; 60642a623c7SBlue Swirl 60742a623c7SBlue Swirl /* XXX: compute is_write */ 60842a623c7SBlue Swirl is_write = 0; 609a78b1299SPeter Maydell return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 61042a623c7SBlue Swirl } 61142a623c7SBlue Swirl 612464e447aSAlistair Francis #elif defined(__riscv) 613464e447aSAlistair Francis 614464e447aSAlistair Francis int cpu_signal_handler(int host_signum, void *pinfo, 615464e447aSAlistair Francis void *puc) 616464e447aSAlistair Francis { 617464e447aSAlistair Francis siginfo_t *info = pinfo; 618464e447aSAlistair Francis ucontext_t *uc = puc; 619464e447aSAlistair Francis greg_t pc = uc->uc_mcontext.__gregs[REG_PC]; 620464e447aSAlistair Francis uint32_t insn = *(uint32_t *)pc; 621464e447aSAlistair Francis int is_write = 0; 622464e447aSAlistair Francis 623464e447aSAlistair Francis /* Detect store by reading the instruction at the program 624464e447aSAlistair Francis counter. Note: we currently only generate 32-bit 625464e447aSAlistair Francis instructions so we thus only detect 32-bit stores */ 626464e447aSAlistair Francis switch (((insn >> 0) & 0b11)) { 627464e447aSAlistair Francis case 3: 628464e447aSAlistair Francis switch (((insn >> 2) & 0b11111)) { 629464e447aSAlistair Francis case 8: 630464e447aSAlistair Francis switch (((insn >> 12) & 0b111)) { 631464e447aSAlistair Francis case 0: /* sb */ 632464e447aSAlistair Francis case 1: /* sh */ 633464e447aSAlistair Francis case 2: /* sw */ 634464e447aSAlistair Francis case 3: /* sd */ 635464e447aSAlistair Francis case 4: /* sq */ 636464e447aSAlistair Francis is_write = 1; 637464e447aSAlistair Francis break; 638464e447aSAlistair Francis default: 639464e447aSAlistair Francis break; 640464e447aSAlistair Francis } 641464e447aSAlistair Francis break; 642464e447aSAlistair Francis case 9: 643464e447aSAlistair Francis switch (((insn >> 12) & 0b111)) { 644464e447aSAlistair Francis case 2: /* fsw */ 645464e447aSAlistair Francis case 3: /* fsd */ 646464e447aSAlistair Francis case 4: /* fsq */ 647464e447aSAlistair Francis is_write = 1; 648464e447aSAlistair Francis break; 649464e447aSAlistair Francis default: 650464e447aSAlistair Francis break; 651464e447aSAlistair Francis } 652464e447aSAlistair Francis break; 653464e447aSAlistair Francis default: 654464e447aSAlistair Francis break; 655464e447aSAlistair Francis } 656464e447aSAlistair Francis } 657464e447aSAlistair Francis 658464e447aSAlistair Francis /* Check for compressed instructions */ 659464e447aSAlistair Francis switch (((insn >> 13) & 0b111)) { 660464e447aSAlistair Francis case 7: 661464e447aSAlistair Francis switch (insn & 0b11) { 662464e447aSAlistair Francis case 0: /*c.sd */ 663464e447aSAlistair Francis case 2: /* c.sdsp */ 664464e447aSAlistair Francis is_write = 1; 665464e447aSAlistair Francis break; 666464e447aSAlistair Francis default: 667464e447aSAlistair Francis break; 668464e447aSAlistair Francis } 669464e447aSAlistair Francis break; 670464e447aSAlistair Francis case 6: 671464e447aSAlistair Francis switch (insn & 0b11) { 672464e447aSAlistair Francis case 0: /* c.sw */ 673464e447aSAlistair Francis case 3: /* c.swsp */ 674464e447aSAlistair Francis is_write = 1; 675464e447aSAlistair Francis break; 676464e447aSAlistair Francis default: 677464e447aSAlistair Francis break; 678464e447aSAlistair Francis } 679464e447aSAlistair Francis break; 680464e447aSAlistair Francis default: 681464e447aSAlistair Francis break; 682464e447aSAlistair Francis } 683464e447aSAlistair Francis 684464e447aSAlistair Francis return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); 685464e447aSAlistair Francis } 686464e447aSAlistair Francis 68742a623c7SBlue Swirl #else 68842a623c7SBlue Swirl 68942a623c7SBlue Swirl #error host CPU specific signal handler needed 69042a623c7SBlue Swirl 69142a623c7SBlue Swirl #endif 692a411d296SPhilippe Mathieu-Daudé 693a411d296SPhilippe Mathieu-Daudé /* The softmmu versions of these helpers are in cputlb.c. */ 694a411d296SPhilippe Mathieu-Daudé 695a411d296SPhilippe Mathieu-Daudé /* Do not allow unaligned operations to proceed. Return the host address. */ 696a411d296SPhilippe Mathieu-Daudé static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, 697a411d296SPhilippe Mathieu-Daudé int size, uintptr_t retaddr) 698a411d296SPhilippe Mathieu-Daudé { 699a411d296SPhilippe Mathieu-Daudé /* Enforce qemu required alignment. */ 700a411d296SPhilippe Mathieu-Daudé if (unlikely(addr & (size - 1))) { 701a411d296SPhilippe Mathieu-Daudé cpu_loop_exit_atomic(ENV_GET_CPU(env), retaddr); 702a411d296SPhilippe Mathieu-Daudé } 703ec603b55SRichard Henderson helper_retaddr = retaddr; 704a411d296SPhilippe Mathieu-Daudé return g2h(addr); 705a411d296SPhilippe Mathieu-Daudé } 706a411d296SPhilippe Mathieu-Daudé 707a411d296SPhilippe Mathieu-Daudé /* Macro to call the above, with local variables from the use context. */ 70834d49937SPeter Maydell #define ATOMIC_MMU_DECLS do {} while (0) 709a411d296SPhilippe Mathieu-Daudé #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC()) 710ec603b55SRichard Henderson #define ATOMIC_MMU_CLEANUP do { helper_retaddr = 0; } while (0) 711a411d296SPhilippe Mathieu-Daudé 712a411d296SPhilippe Mathieu-Daudé #define ATOMIC_NAME(X) HELPER(glue(glue(atomic_ ## X, SUFFIX), END)) 713a411d296SPhilippe Mathieu-Daudé #define EXTRA_ARGS 714a411d296SPhilippe Mathieu-Daudé 715a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 1 716a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h" 717a411d296SPhilippe Mathieu-Daudé 718a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 2 719a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h" 720a411d296SPhilippe Mathieu-Daudé 721a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 4 722a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h" 723a411d296SPhilippe Mathieu-Daudé 724a411d296SPhilippe Mathieu-Daudé #ifdef CONFIG_ATOMIC64 725a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 8 726a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h" 727a411d296SPhilippe Mathieu-Daudé #endif 728a411d296SPhilippe Mathieu-Daudé 729a411d296SPhilippe Mathieu-Daudé /* The following is only callable from other helpers, and matches up 730a411d296SPhilippe Mathieu-Daudé with the softmmu version. */ 731a411d296SPhilippe Mathieu-Daudé 732e6cd4bb5SRichard Henderson #if HAVE_ATOMIC128 || HAVE_CMPXCHG128 733a411d296SPhilippe Mathieu-Daudé 734a411d296SPhilippe Mathieu-Daudé #undef EXTRA_ARGS 735a411d296SPhilippe Mathieu-Daudé #undef ATOMIC_NAME 736a411d296SPhilippe Mathieu-Daudé #undef ATOMIC_MMU_LOOKUP 737a411d296SPhilippe Mathieu-Daudé 738a411d296SPhilippe Mathieu-Daudé #define EXTRA_ARGS , TCGMemOpIdx oi, uintptr_t retaddr 739a411d296SPhilippe Mathieu-Daudé #define ATOMIC_NAME(X) \ 740a411d296SPhilippe Mathieu-Daudé HELPER(glue(glue(glue(atomic_ ## X, SUFFIX), END), _mmu)) 741a411d296SPhilippe Mathieu-Daudé #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, retaddr) 742a411d296SPhilippe Mathieu-Daudé 743a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 16 744a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h" 745e6cd4bb5SRichard Henderson #endif 746