xref: /qemu/accel/tcg/user-exec.c (revision da6bbf8513e621a8fc2fd315d77318f36547474d)
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
9fb0343d5SThomas 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;
68*da6bbf85SRichard Henderson     MMUAccessType access_type;
6942a623c7SBlue Swirl 
70ec603b55SRichard Henderson     /* We must handle PC addresses from two different sources:
71ec603b55SRichard Henderson      * a call return address and a signal frame address.
72ec603b55SRichard Henderson      *
73ec603b55SRichard Henderson      * Within cpu_restore_state_from_tb we assume the former and adjust
74ec603b55SRichard Henderson      * the address by -GETPC_ADJ so that the address is within the call
75ec603b55SRichard Henderson      * insn so that addr does not accidentally match the beginning of the
76ec603b55SRichard Henderson      * next guest insn.
77ec603b55SRichard Henderson      *
78ec603b55SRichard Henderson      * However, when the PC comes from the signal frame, it points to
79ec603b55SRichard Henderson      * the actual faulting host insn and not a call insn.  Subtracting
80ec603b55SRichard Henderson      * GETPC_ADJ in that case may accidentally match the previous guest insn.
81ec603b55SRichard Henderson      *
82ec603b55SRichard Henderson      * So for the later case, adjust forward to compensate for what
83ec603b55SRichard Henderson      * will be done later by cpu_restore_state_from_tb.
84ec603b55SRichard Henderson      */
85ec603b55SRichard Henderson     if (helper_retaddr) {
86ec603b55SRichard Henderson         pc = helper_retaddr;
87ec603b55SRichard Henderson     } else {
88ec603b55SRichard Henderson         pc += GETPC_ADJ;
89ec603b55SRichard Henderson     }
90ec603b55SRichard Henderson 
9102bed6bdSAlex Bennée     /* For synchronous signals we expect to be coming from the vCPU
9202bed6bdSAlex Bennée      * thread (so current_cpu should be valid) and either from running
9302bed6bdSAlex Bennée      * code or during translation which can fault as we cross pages.
9402bed6bdSAlex Bennée      *
9502bed6bdSAlex Bennée      * If neither is true then something has gone wrong and we should
9602bed6bdSAlex Bennée      * abort rather than try and restart the vCPU execution.
9702bed6bdSAlex Bennée      */
9802bed6bdSAlex Bennée     if (!cpu || !cpu->running) {
9902bed6bdSAlex Bennée         printf("qemu:%s received signal outside vCPU context @ pc=0x%"
10002bed6bdSAlex Bennée                PRIxPTR "\n",  __func__, pc);
10102bed6bdSAlex Bennée         abort();
10202bed6bdSAlex Bennée     }
10302bed6bdSAlex Bennée 
10442a623c7SBlue Swirl #if defined(DEBUG_SIGNAL)
10571baf787SPeter Maydell     printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
10642a623c7SBlue Swirl            pc, address, is_write, *(unsigned long *)old_set);
10742a623c7SBlue Swirl #endif
10842a623c7SBlue Swirl     /* XXX: locking issue */
1099c4bbee9SPeter Maydell     /* Note that it is important that we don't call page_unprotect() unless
1109c4bbee9SPeter Maydell      * this is really a "write to nonwriteable page" fault, because
1119c4bbee9SPeter Maydell      * page_unprotect() assumes that if it is called for an access to
1129c4bbee9SPeter Maydell      * a page that's writeable this means we had two threads racing and
1139c4bbee9SPeter Maydell      * another thread got there first and already made the page writeable;
1149c4bbee9SPeter Maydell      * so we will retry the access. If we were to call page_unprotect()
1159c4bbee9SPeter Maydell      * for some other kind of fault that should really be passed to the
1169c4bbee9SPeter Maydell      * guest, we'd end up in an infinite loop of retrying the faulting
1179c4bbee9SPeter Maydell      * access.
1189c4bbee9SPeter Maydell      */
1199c4bbee9SPeter Maydell     if (is_write && info->si_signo == SIGSEGV && info->si_code == SEGV_ACCERR &&
1209c4bbee9SPeter Maydell         h2g_valid(address)) {
121f213e72fSPeter Maydell         switch (page_unprotect(h2g(address), pc)) {
122f213e72fSPeter Maydell         case 0:
123f213e72fSPeter Maydell             /* Fault not caused by a page marked unwritable to protect
124ec603b55SRichard Henderson              * cached translations, must be the guest binary's problem.
125f213e72fSPeter Maydell              */
126f213e72fSPeter Maydell             break;
127f213e72fSPeter Maydell         case 1:
128f213e72fSPeter Maydell             /* Fault caused by protection of cached translation; TBs
129ec603b55SRichard Henderson              * invalidated, so resume execution.  Retain helper_retaddr
130ec603b55SRichard Henderson              * for a possible second fault.
131f213e72fSPeter Maydell              */
13242a623c7SBlue Swirl             return 1;
133f213e72fSPeter Maydell         case 2:
134f213e72fSPeter Maydell             /* Fault caused by protection of cached translation, and the
135f213e72fSPeter Maydell              * currently executing TB was modified and must be exited
136ec603b55SRichard Henderson              * immediately.  Clear helper_retaddr for next execution.
137f213e72fSPeter Maydell              */
138ec603b55SRichard Henderson             helper_retaddr = 0;
13902bed6bdSAlex Bennée             cpu_exit_tb_from_sighandler(cpu, old_set);
140ec603b55SRichard Henderson             /* NORETURN */
141ec603b55SRichard Henderson 
142f213e72fSPeter Maydell         default:
143f213e72fSPeter Maydell             g_assert_not_reached();
144f213e72fSPeter Maydell         }
14542a623c7SBlue Swirl     }
14642a623c7SBlue Swirl 
147732f9e89SAlexander Graf     /* Convert forcefully to guest address space, invalid addresses
148732f9e89SAlexander Graf        are still valid segv ones */
149732f9e89SAlexander Graf     address = h2g_nocheck(address);
150732f9e89SAlexander Graf 
151*da6bbf85SRichard Henderson     /*
152*da6bbf85SRichard Henderson      * There is no way the target can handle this other than raising
153*da6bbf85SRichard Henderson      * an exception.  Undo signal and retaddr state prior to longjmp.
154ec603b55SRichard Henderson      */
155*da6bbf85SRichard Henderson     sigprocmask(SIG_SETMASK, old_set, NULL);
156ec603b55SRichard Henderson     helper_retaddr = 0;
157ec603b55SRichard Henderson 
158*da6bbf85SRichard Henderson     cc = CPU_GET_CLASS(cpu);
159*da6bbf85SRichard Henderson     if (cc->tlb_fill) {
160*da6bbf85SRichard Henderson         access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD;
161*da6bbf85SRichard Henderson         cc->tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc);
162*da6bbf85SRichard Henderson         g_assert_not_reached();
163*da6bbf85SRichard Henderson     } else {
164*da6bbf85SRichard Henderson         ret = cc->handle_mmu_fault(cpu, address, 0, is_write, MMU_USER_IDX);
165*da6bbf85SRichard Henderson         g_assert(ret > 0);
166*da6bbf85SRichard Henderson         cpu_loop_exit_restore(cpu, pc);
16742a623c7SBlue Swirl     }
16842a623c7SBlue Swirl }
16942a623c7SBlue Swirl 
17042a623c7SBlue Swirl #if defined(__i386__)
17142a623c7SBlue Swirl 
172c5679026SPeter Maydell #if defined(__NetBSD__)
17342a623c7SBlue Swirl #include <ucontext.h>
17442a623c7SBlue Swirl 
17542a623c7SBlue Swirl #define EIP_sig(context)     ((context)->uc_mcontext.__gregs[_REG_EIP])
17642a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
17742a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->uc_mcontext.__gregs[_REG_ERR])
17842a623c7SBlue Swirl #define MASK_sig(context)    ((context)->uc_sigmask)
17942a623c7SBlue Swirl #elif defined(__FreeBSD__) || defined(__DragonFly__)
18042a623c7SBlue Swirl #include <ucontext.h>
18142a623c7SBlue Swirl 
18242a623c7SBlue Swirl #define EIP_sig(context)  (*((unsigned long *)&(context)->uc_mcontext.mc_eip))
18342a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->uc_mcontext.mc_trapno)
18442a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->uc_mcontext.mc_err)
18542a623c7SBlue Swirl #define MASK_sig(context)    ((context)->uc_sigmask)
18642a623c7SBlue Swirl #elif defined(__OpenBSD__)
18742a623c7SBlue Swirl #define EIP_sig(context)     ((context)->sc_eip)
18842a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->sc_trapno)
18942a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->sc_err)
19042a623c7SBlue Swirl #define MASK_sig(context)    ((context)->sc_mask)
19142a623c7SBlue Swirl #else
19242a623c7SBlue Swirl #define EIP_sig(context)     ((context)->uc_mcontext.gregs[REG_EIP])
19342a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->uc_mcontext.gregs[REG_TRAPNO])
19442a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->uc_mcontext.gregs[REG_ERR])
19542a623c7SBlue Swirl #define MASK_sig(context)    ((context)->uc_sigmask)
19642a623c7SBlue Swirl #endif
19742a623c7SBlue Swirl 
19842a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
19942a623c7SBlue Swirl                        void *puc)
20042a623c7SBlue Swirl {
20142a623c7SBlue Swirl     siginfo_t *info = pinfo;
20242a623c7SBlue Swirl #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
20342a623c7SBlue Swirl     ucontext_t *uc = puc;
20442a623c7SBlue Swirl #elif defined(__OpenBSD__)
20542a623c7SBlue Swirl     struct sigcontext *uc = puc;
20642a623c7SBlue Swirl #else
20704b33e21SKhem Raj     ucontext_t *uc = puc;
20842a623c7SBlue Swirl #endif
20942a623c7SBlue Swirl     unsigned long pc;
21042a623c7SBlue Swirl     int trapno;
21142a623c7SBlue Swirl 
21242a623c7SBlue Swirl #ifndef REG_EIP
21342a623c7SBlue Swirl /* for glibc 2.1 */
21442a623c7SBlue Swirl #define REG_EIP    EIP
21542a623c7SBlue Swirl #define REG_ERR    ERR
21642a623c7SBlue Swirl #define REG_TRAPNO TRAPNO
21742a623c7SBlue Swirl #endif
21842a623c7SBlue Swirl     pc = EIP_sig(uc);
21942a623c7SBlue Swirl     trapno = TRAP_sig(uc);
220a78b1299SPeter Maydell     return handle_cpu_signal(pc, info,
221a78b1299SPeter Maydell                              trapno == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0,
222a5852dc5SPeter Maydell                              &MASK_sig(uc));
22342a623c7SBlue Swirl }
22442a623c7SBlue Swirl 
22542a623c7SBlue Swirl #elif defined(__x86_64__)
22642a623c7SBlue Swirl 
22742a623c7SBlue Swirl #ifdef __NetBSD__
22842a623c7SBlue Swirl #define PC_sig(context)       _UC_MACHINE_PC(context)
22942a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
23042a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->uc_mcontext.__gregs[_REG_ERR])
23142a623c7SBlue Swirl #define MASK_sig(context)     ((context)->uc_sigmask)
23242a623c7SBlue Swirl #elif defined(__OpenBSD__)
23342a623c7SBlue Swirl #define PC_sig(context)       ((context)->sc_rip)
23442a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->sc_trapno)
23542a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->sc_err)
23642a623c7SBlue Swirl #define MASK_sig(context)     ((context)->sc_mask)
23742a623c7SBlue Swirl #elif defined(__FreeBSD__) || defined(__DragonFly__)
23842a623c7SBlue Swirl #include <ucontext.h>
23942a623c7SBlue Swirl 
24042a623c7SBlue Swirl #define PC_sig(context)  (*((unsigned long *)&(context)->uc_mcontext.mc_rip))
24142a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->uc_mcontext.mc_trapno)
24242a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->uc_mcontext.mc_err)
24342a623c7SBlue Swirl #define MASK_sig(context)     ((context)->uc_sigmask)
24442a623c7SBlue Swirl #else
24542a623c7SBlue Swirl #define PC_sig(context)       ((context)->uc_mcontext.gregs[REG_RIP])
24642a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->uc_mcontext.gregs[REG_TRAPNO])
24742a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->uc_mcontext.gregs[REG_ERR])
24842a623c7SBlue Swirl #define MASK_sig(context)     ((context)->uc_sigmask)
24942a623c7SBlue Swirl #endif
25042a623c7SBlue Swirl 
25142a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
25242a623c7SBlue Swirl                        void *puc)
25342a623c7SBlue Swirl {
25442a623c7SBlue Swirl     siginfo_t *info = pinfo;
25542a623c7SBlue Swirl     unsigned long pc;
25642a623c7SBlue Swirl #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
25742a623c7SBlue Swirl     ucontext_t *uc = puc;
25842a623c7SBlue Swirl #elif defined(__OpenBSD__)
25942a623c7SBlue Swirl     struct sigcontext *uc = puc;
26042a623c7SBlue Swirl #else
26104b33e21SKhem Raj     ucontext_t *uc = puc;
26242a623c7SBlue Swirl #endif
26342a623c7SBlue Swirl 
26442a623c7SBlue Swirl     pc = PC_sig(uc);
265a78b1299SPeter Maydell     return handle_cpu_signal(pc, info,
266a78b1299SPeter Maydell                              TRAP_sig(uc) == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0,
267a5852dc5SPeter Maydell                              &MASK_sig(uc));
26842a623c7SBlue Swirl }
26942a623c7SBlue Swirl 
27042a623c7SBlue Swirl #elif defined(_ARCH_PPC)
27142a623c7SBlue Swirl 
27242a623c7SBlue Swirl /***********************************************************************
27342a623c7SBlue Swirl  * signal context platform-specific definitions
27442a623c7SBlue Swirl  * From Wine
27542a623c7SBlue Swirl  */
27642a623c7SBlue Swirl #ifdef linux
27742a623c7SBlue Swirl /* All Registers access - only for local access */
27842a623c7SBlue Swirl #define REG_sig(reg_name, context)              \
27942a623c7SBlue Swirl     ((context)->uc_mcontext.regs->reg_name)
28042a623c7SBlue Swirl /* Gpr Registers access  */
28142a623c7SBlue Swirl #define GPR_sig(reg_num, context)              REG_sig(gpr[reg_num], context)
28242a623c7SBlue Swirl /* Program counter */
28342a623c7SBlue Swirl #define IAR_sig(context)                       REG_sig(nip, context)
28442a623c7SBlue Swirl /* Machine State Register (Supervisor) */
28542a623c7SBlue Swirl #define MSR_sig(context)                       REG_sig(msr, context)
28642a623c7SBlue Swirl /* Count register */
28742a623c7SBlue Swirl #define CTR_sig(context)                       REG_sig(ctr, context)
28842a623c7SBlue Swirl /* User's integer exception register */
28942a623c7SBlue Swirl #define XER_sig(context)                       REG_sig(xer, context)
29042a623c7SBlue Swirl /* Link register */
29142a623c7SBlue Swirl #define LR_sig(context)                        REG_sig(link, context)
29242a623c7SBlue Swirl /* Condition register */
29342a623c7SBlue Swirl #define CR_sig(context)                        REG_sig(ccr, context)
29442a623c7SBlue Swirl 
29542a623c7SBlue Swirl /* Float Registers access  */
29642a623c7SBlue Swirl #define FLOAT_sig(reg_num, context)                                     \
29742a623c7SBlue Swirl     (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num])
29842a623c7SBlue Swirl #define FPSCR_sig(context) \
29942a623c7SBlue Swirl     (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4)))
30042a623c7SBlue Swirl /* Exception Registers access */
30142a623c7SBlue Swirl #define DAR_sig(context)                       REG_sig(dar, context)
30242a623c7SBlue Swirl #define DSISR_sig(context)                     REG_sig(dsisr, context)
30342a623c7SBlue Swirl #define TRAP_sig(context)                      REG_sig(trap, context)
30442a623c7SBlue Swirl #endif /* linux */
30542a623c7SBlue Swirl 
30642a623c7SBlue Swirl #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
30742a623c7SBlue Swirl #include <ucontext.h>
30842a623c7SBlue Swirl #define IAR_sig(context)               ((context)->uc_mcontext.mc_srr0)
30942a623c7SBlue Swirl #define MSR_sig(context)               ((context)->uc_mcontext.mc_srr1)
31042a623c7SBlue Swirl #define CTR_sig(context)               ((context)->uc_mcontext.mc_ctr)
31142a623c7SBlue Swirl #define XER_sig(context)               ((context)->uc_mcontext.mc_xer)
31242a623c7SBlue Swirl #define LR_sig(context)                ((context)->uc_mcontext.mc_lr)
31342a623c7SBlue Swirl #define CR_sig(context)                ((context)->uc_mcontext.mc_cr)
31442a623c7SBlue Swirl /* Exception Registers access */
31542a623c7SBlue Swirl #define DAR_sig(context)               ((context)->uc_mcontext.mc_dar)
31642a623c7SBlue Swirl #define DSISR_sig(context)             ((context)->uc_mcontext.mc_dsisr)
31742a623c7SBlue Swirl #define TRAP_sig(context)              ((context)->uc_mcontext.mc_exc)
31842a623c7SBlue Swirl #endif /* __FreeBSD__|| __FreeBSD_kernel__ */
31942a623c7SBlue Swirl 
32042a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
32142a623c7SBlue Swirl                        void *puc)
32242a623c7SBlue Swirl {
32342a623c7SBlue Swirl     siginfo_t *info = pinfo;
32442a623c7SBlue Swirl #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
32542a623c7SBlue Swirl     ucontext_t *uc = puc;
32642a623c7SBlue Swirl #else
32704b33e21SKhem Raj     ucontext_t *uc = puc;
32842a623c7SBlue Swirl #endif
32942a623c7SBlue Swirl     unsigned long pc;
33042a623c7SBlue Swirl     int is_write;
33142a623c7SBlue Swirl 
33242a623c7SBlue Swirl     pc = IAR_sig(uc);
33342a623c7SBlue Swirl     is_write = 0;
33442a623c7SBlue Swirl #if 0
33542a623c7SBlue Swirl     /* ppc 4xx case */
33642a623c7SBlue Swirl     if (DSISR_sig(uc) & 0x00800000) {
33742a623c7SBlue Swirl         is_write = 1;
33842a623c7SBlue Swirl     }
33942a623c7SBlue Swirl #else
34042a623c7SBlue Swirl     if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) {
34142a623c7SBlue Swirl         is_write = 1;
34242a623c7SBlue Swirl     }
34342a623c7SBlue Swirl #endif
344a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
34542a623c7SBlue Swirl }
34642a623c7SBlue Swirl 
34742a623c7SBlue Swirl #elif defined(__alpha__)
34842a623c7SBlue Swirl 
34942a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
35042a623c7SBlue Swirl                            void *puc)
35142a623c7SBlue Swirl {
35242a623c7SBlue Swirl     siginfo_t *info = pinfo;
35304b33e21SKhem Raj     ucontext_t *uc = puc;
35442a623c7SBlue Swirl     uint32_t *pc = uc->uc_mcontext.sc_pc;
35542a623c7SBlue Swirl     uint32_t insn = *pc;
35642a623c7SBlue Swirl     int is_write = 0;
35742a623c7SBlue Swirl 
35842a623c7SBlue Swirl     /* XXX: need kernel patch to get write flag faster */
35942a623c7SBlue Swirl     switch (insn >> 26) {
36042a623c7SBlue Swirl     case 0x0d: /* stw */
36142a623c7SBlue Swirl     case 0x0e: /* stb */
36242a623c7SBlue Swirl     case 0x0f: /* stq_u */
36342a623c7SBlue Swirl     case 0x24: /* stf */
36442a623c7SBlue Swirl     case 0x25: /* stg */
36542a623c7SBlue Swirl     case 0x26: /* sts */
36642a623c7SBlue Swirl     case 0x27: /* stt */
36742a623c7SBlue Swirl     case 0x2c: /* stl */
36842a623c7SBlue Swirl     case 0x2d: /* stq */
36942a623c7SBlue Swirl     case 0x2e: /* stl_c */
37042a623c7SBlue Swirl     case 0x2f: /* stq_c */
37142a623c7SBlue Swirl         is_write = 1;
37242a623c7SBlue Swirl     }
37342a623c7SBlue Swirl 
374a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
37542a623c7SBlue Swirl }
37642a623c7SBlue Swirl #elif defined(__sparc__)
37742a623c7SBlue Swirl 
37842a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
37942a623c7SBlue Swirl                        void *puc)
38042a623c7SBlue Swirl {
38142a623c7SBlue Swirl     siginfo_t *info = pinfo;
38242a623c7SBlue Swirl     int is_write;
38342a623c7SBlue Swirl     uint32_t insn;
38442a623c7SBlue Swirl #if !defined(__arch64__) || defined(CONFIG_SOLARIS)
38542a623c7SBlue Swirl     uint32_t *regs = (uint32_t *)(info + 1);
38642a623c7SBlue Swirl     void *sigmask = (regs + 20);
38742a623c7SBlue Swirl     /* XXX: is there a standard glibc define ? */
38842a623c7SBlue Swirl     unsigned long pc = regs[1];
38942a623c7SBlue Swirl #else
39042a623c7SBlue Swirl #ifdef __linux__
39142a623c7SBlue Swirl     struct sigcontext *sc = puc;
39242a623c7SBlue Swirl     unsigned long pc = sc->sigc_regs.tpc;
39342a623c7SBlue Swirl     void *sigmask = (void *)sc->sigc_mask;
39442a623c7SBlue Swirl #elif defined(__OpenBSD__)
39542a623c7SBlue Swirl     struct sigcontext *uc = puc;
39642a623c7SBlue Swirl     unsigned long pc = uc->sc_pc;
39742a623c7SBlue Swirl     void *sigmask = (void *)(long)uc->sc_mask;
3987ccfb495STobias Nygren #elif defined(__NetBSD__)
3997ccfb495STobias Nygren     ucontext_t *uc = puc;
4007ccfb495STobias Nygren     unsigned long pc = _UC_MACHINE_PC(uc);
4017ccfb495STobias Nygren     void *sigmask = (void *)&uc->uc_sigmask;
40242a623c7SBlue Swirl #endif
40342a623c7SBlue Swirl #endif
40442a623c7SBlue Swirl 
40542a623c7SBlue Swirl     /* XXX: need kernel patch to get write flag faster */
40642a623c7SBlue Swirl     is_write = 0;
40742a623c7SBlue Swirl     insn = *(uint32_t *)pc;
40842a623c7SBlue Swirl     if ((insn >> 30) == 3) {
40942a623c7SBlue Swirl         switch ((insn >> 19) & 0x3f) {
41042a623c7SBlue Swirl         case 0x05: /* stb */
41142a623c7SBlue Swirl         case 0x15: /* stba */
41242a623c7SBlue Swirl         case 0x06: /* sth */
41342a623c7SBlue Swirl         case 0x16: /* stha */
41442a623c7SBlue Swirl         case 0x04: /* st */
41542a623c7SBlue Swirl         case 0x14: /* sta */
41642a623c7SBlue Swirl         case 0x07: /* std */
41742a623c7SBlue Swirl         case 0x17: /* stda */
41842a623c7SBlue Swirl         case 0x0e: /* stx */
41942a623c7SBlue Swirl         case 0x1e: /* stxa */
42042a623c7SBlue Swirl         case 0x24: /* stf */
42142a623c7SBlue Swirl         case 0x34: /* stfa */
42242a623c7SBlue Swirl         case 0x27: /* stdf */
42342a623c7SBlue Swirl         case 0x37: /* stdfa */
42442a623c7SBlue Swirl         case 0x26: /* stqf */
42542a623c7SBlue Swirl         case 0x36: /* stqfa */
42642a623c7SBlue Swirl         case 0x25: /* stfsr */
42742a623c7SBlue Swirl         case 0x3c: /* casa */
42842a623c7SBlue Swirl         case 0x3e: /* casxa */
42942a623c7SBlue Swirl             is_write = 1;
43042a623c7SBlue Swirl             break;
43142a623c7SBlue Swirl         }
43242a623c7SBlue Swirl     }
433a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, sigmask);
43442a623c7SBlue Swirl }
43542a623c7SBlue Swirl 
43642a623c7SBlue Swirl #elif defined(__arm__)
43742a623c7SBlue Swirl 
4387ccfb495STobias Nygren #if defined(__NetBSD__)
4397ccfb495STobias Nygren #include <ucontext.h>
4407ccfb495STobias Nygren #endif
4417ccfb495STobias Nygren 
44242a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
44342a623c7SBlue Swirl                        void *puc)
44442a623c7SBlue Swirl {
44542a623c7SBlue Swirl     siginfo_t *info = pinfo;
4467ccfb495STobias Nygren #if defined(__NetBSD__)
4477ccfb495STobias Nygren     ucontext_t *uc = puc;
4487ccfb495STobias Nygren #else
44904b33e21SKhem Raj     ucontext_t *uc = puc;
4507ccfb495STobias Nygren #endif
45142a623c7SBlue Swirl     unsigned long pc;
45242a623c7SBlue Swirl     int is_write;
45342a623c7SBlue Swirl 
4547ccfb495STobias Nygren #if defined(__NetBSD__)
4557ccfb495STobias Nygren     pc = uc->uc_mcontext.__gregs[_REG_R15];
4567ccfb495STobias Nygren #elif defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
45742a623c7SBlue Swirl     pc = uc->uc_mcontext.gregs[R15];
45842a623c7SBlue Swirl #else
45942a623c7SBlue Swirl     pc = uc->uc_mcontext.arm_pc;
46042a623c7SBlue Swirl #endif
461023b0ae3SPeter Maydell 
462023b0ae3SPeter Maydell     /* error_code is the FSR value, in which bit 11 is WnR (assuming a v6 or
463023b0ae3SPeter Maydell      * later processor; on v5 we will always report this as a read).
464023b0ae3SPeter Maydell      */
465023b0ae3SPeter Maydell     is_write = extract32(uc->uc_mcontext.error_code, 11, 1);
466a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
46742a623c7SBlue Swirl }
46842a623c7SBlue Swirl 
469f129061cSClaudio Fontana #elif defined(__aarch64__)
470f129061cSClaudio Fontana 
471f454a54fSPeter Maydell #ifndef ESR_MAGIC
472f454a54fSPeter Maydell /* Pre-3.16 kernel headers don't have these, so provide fallback definitions */
473f454a54fSPeter Maydell #define ESR_MAGIC 0x45535201
474f454a54fSPeter Maydell struct esr_context {
475f454a54fSPeter Maydell     struct _aarch64_ctx head;
476f454a54fSPeter Maydell     uint64_t esr;
477f454a54fSPeter Maydell };
478f454a54fSPeter Maydell #endif
479f454a54fSPeter Maydell 
480f454a54fSPeter Maydell static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc)
481f454a54fSPeter Maydell {
482f454a54fSPeter Maydell     return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved;
483f454a54fSPeter Maydell }
484f454a54fSPeter Maydell 
485f454a54fSPeter Maydell static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr)
486f454a54fSPeter Maydell {
487f454a54fSPeter Maydell     return (struct _aarch64_ctx *)((char *)hdr + hdr->size);
488f454a54fSPeter Maydell }
489f454a54fSPeter Maydell 
490661f7fa4SRichard Henderson int cpu_signal_handler(int host_signum, void *pinfo, void *puc)
491f129061cSClaudio Fontana {
492f129061cSClaudio Fontana     siginfo_t *info = pinfo;
49304b33e21SKhem Raj     ucontext_t *uc = puc;
494661f7fa4SRichard Henderson     uintptr_t pc = uc->uc_mcontext.pc;
495661f7fa4SRichard Henderson     bool is_write;
496f454a54fSPeter Maydell     struct _aarch64_ctx *hdr;
497f454a54fSPeter Maydell     struct esr_context const *esrctx = NULL;
498f129061cSClaudio Fontana 
499f454a54fSPeter Maydell     /* Find the esr_context, which has the WnR bit in it */
500f454a54fSPeter Maydell     for (hdr = first_ctx(uc); hdr->magic; hdr = next_ctx(hdr)) {
501f454a54fSPeter Maydell         if (hdr->magic == ESR_MAGIC) {
502f454a54fSPeter Maydell             esrctx = (struct esr_context const *)hdr;
503f454a54fSPeter Maydell             break;
504f454a54fSPeter Maydell         }
505f454a54fSPeter Maydell     }
506f454a54fSPeter Maydell 
507f454a54fSPeter Maydell     if (esrctx) {
508f454a54fSPeter Maydell         /* For data aborts ESR.EC is 0b10010x: then bit 6 is the WnR bit */
509f454a54fSPeter Maydell         uint64_t esr = esrctx->esr;
510f454a54fSPeter Maydell         is_write = extract32(esr, 27, 5) == 0x12 && extract32(esr, 6, 1) == 1;
511f454a54fSPeter Maydell     } else {
512f454a54fSPeter Maydell         /*
513f454a54fSPeter Maydell          * Fall back to parsing instructions; will only be needed
514f454a54fSPeter Maydell          * for really ancient (pre-3.16) kernels.
515f454a54fSPeter Maydell          */
516f454a54fSPeter Maydell         uint32_t insn = *(uint32_t *)pc;
517f454a54fSPeter Maydell 
518661f7fa4SRichard Henderson         is_write = ((insn & 0xbfff0000) == 0x0c000000   /* C3.3.1 */
519661f7fa4SRichard Henderson                     || (insn & 0xbfe00000) == 0x0c800000   /* C3.3.2 */
520661f7fa4SRichard Henderson                     || (insn & 0xbfdf0000) == 0x0d000000   /* C3.3.3 */
521661f7fa4SRichard Henderson                     || (insn & 0xbfc00000) == 0x0d800000   /* C3.3.4 */
522661f7fa4SRichard Henderson                     || (insn & 0x3f400000) == 0x08000000   /* C3.3.6 */
523661f7fa4SRichard Henderson                     || (insn & 0x3bc00000) == 0x39000000   /* C3.3.13 */
524661f7fa4SRichard Henderson                     || (insn & 0x3fc00000) == 0x3d800000   /* ... 128bit */
525f454a54fSPeter Maydell                     /* Ignore bits 10, 11 & 21, controlling indexing.  */
526661f7fa4SRichard Henderson                     || (insn & 0x3bc00000) == 0x38000000   /* C3.3.8-12 */
527661f7fa4SRichard Henderson                     || (insn & 0x3fe00000) == 0x3c800000   /* ... 128bit */
528661f7fa4SRichard Henderson                     /* Ignore bits 23 & 24, controlling indexing.  */
529661f7fa4SRichard Henderson                     || (insn & 0x3a400000) == 0x28000000); /* C3.3.7,14-16 */
530f454a54fSPeter Maydell     }
531a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
532f129061cSClaudio Fontana }
533f129061cSClaudio Fontana 
53442a623c7SBlue Swirl #elif defined(__s390__)
53542a623c7SBlue Swirl 
53642a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
53742a623c7SBlue Swirl                        void *puc)
53842a623c7SBlue Swirl {
53942a623c7SBlue Swirl     siginfo_t *info = pinfo;
54004b33e21SKhem Raj     ucontext_t *uc = puc;
54142a623c7SBlue Swirl     unsigned long pc;
54242a623c7SBlue Swirl     uint16_t *pinsn;
54342a623c7SBlue Swirl     int is_write = 0;
54442a623c7SBlue Swirl 
54542a623c7SBlue Swirl     pc = uc->uc_mcontext.psw.addr;
54642a623c7SBlue Swirl 
54742a623c7SBlue Swirl     /* ??? On linux, the non-rt signal handler has 4 (!) arguments instead
54842a623c7SBlue Swirl        of the normal 2 arguments.  The 3rd argument contains the "int_code"
54942a623c7SBlue Swirl        from the hardware which does in fact contain the is_write value.
55042a623c7SBlue Swirl        The rt signal handler, as far as I can tell, does not give this value
55142a623c7SBlue Swirl        at all.  Not that we could get to it from here even if it were.  */
55242a623c7SBlue Swirl     /* ??? This is not even close to complete, since it ignores all
55342a623c7SBlue Swirl        of the read-modify-write instructions.  */
55442a623c7SBlue Swirl     pinsn = (uint16_t *)pc;
55542a623c7SBlue Swirl     switch (pinsn[0] >> 8) {
55642a623c7SBlue Swirl     case 0x50: /* ST */
55742a623c7SBlue Swirl     case 0x42: /* STC */
55842a623c7SBlue Swirl     case 0x40: /* STH */
55942a623c7SBlue Swirl         is_write = 1;
56042a623c7SBlue Swirl         break;
56142a623c7SBlue Swirl     case 0xc4: /* RIL format insns */
56242a623c7SBlue Swirl         switch (pinsn[0] & 0xf) {
56342a623c7SBlue Swirl         case 0xf: /* STRL */
56442a623c7SBlue Swirl         case 0xb: /* STGRL */
56542a623c7SBlue Swirl         case 0x7: /* STHRL */
56642a623c7SBlue Swirl             is_write = 1;
56742a623c7SBlue Swirl         }
56842a623c7SBlue Swirl         break;
56942a623c7SBlue Swirl     case 0xe3: /* RXY format insns */
57042a623c7SBlue Swirl         switch (pinsn[2] & 0xff) {
57142a623c7SBlue Swirl         case 0x50: /* STY */
57242a623c7SBlue Swirl         case 0x24: /* STG */
57342a623c7SBlue Swirl         case 0x72: /* STCY */
57442a623c7SBlue Swirl         case 0x70: /* STHY */
57542a623c7SBlue Swirl         case 0x8e: /* STPQ */
57642a623c7SBlue Swirl         case 0x3f: /* STRVH */
57742a623c7SBlue Swirl         case 0x3e: /* STRV */
57842a623c7SBlue Swirl         case 0x2f: /* STRVG */
57942a623c7SBlue Swirl             is_write = 1;
58042a623c7SBlue Swirl         }
58142a623c7SBlue Swirl         break;
58242a623c7SBlue Swirl     }
583a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
58442a623c7SBlue Swirl }
58542a623c7SBlue Swirl 
58642a623c7SBlue Swirl #elif defined(__mips__)
58742a623c7SBlue Swirl 
58842a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
58942a623c7SBlue Swirl                        void *puc)
59042a623c7SBlue Swirl {
59142a623c7SBlue Swirl     siginfo_t *info = pinfo;
59204b33e21SKhem Raj     ucontext_t *uc = puc;
59342a623c7SBlue Swirl     greg_t pc = uc->uc_mcontext.pc;
59442a623c7SBlue Swirl     int is_write;
59542a623c7SBlue Swirl 
59642a623c7SBlue Swirl     /* XXX: compute is_write */
59742a623c7SBlue Swirl     is_write = 0;
598a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
59942a623c7SBlue Swirl }
60042a623c7SBlue Swirl 
601464e447aSAlistair Francis #elif defined(__riscv)
602464e447aSAlistair Francis 
603464e447aSAlistair Francis int cpu_signal_handler(int host_signum, void *pinfo,
604464e447aSAlistair Francis                        void *puc)
605464e447aSAlistair Francis {
606464e447aSAlistair Francis     siginfo_t *info = pinfo;
607464e447aSAlistair Francis     ucontext_t *uc = puc;
608464e447aSAlistair Francis     greg_t pc = uc->uc_mcontext.__gregs[REG_PC];
609464e447aSAlistair Francis     uint32_t insn = *(uint32_t *)pc;
610464e447aSAlistair Francis     int is_write = 0;
611464e447aSAlistair Francis 
612464e447aSAlistair Francis     /* Detect store by reading the instruction at the program
613464e447aSAlistair Francis        counter. Note: we currently only generate 32-bit
614464e447aSAlistair Francis        instructions so we thus only detect 32-bit stores */
615464e447aSAlistair Francis     switch (((insn >> 0) & 0b11)) {
616464e447aSAlistair Francis     case 3:
617464e447aSAlistair Francis         switch (((insn >> 2) & 0b11111)) {
618464e447aSAlistair Francis         case 8:
619464e447aSAlistair Francis             switch (((insn >> 12) & 0b111)) {
620464e447aSAlistair Francis             case 0: /* sb */
621464e447aSAlistair Francis             case 1: /* sh */
622464e447aSAlistair Francis             case 2: /* sw */
623464e447aSAlistair Francis             case 3: /* sd */
624464e447aSAlistair Francis             case 4: /* sq */
625464e447aSAlistair Francis                 is_write = 1;
626464e447aSAlistair Francis                 break;
627464e447aSAlistair Francis             default:
628464e447aSAlistair Francis                 break;
629464e447aSAlistair Francis             }
630464e447aSAlistair Francis             break;
631464e447aSAlistair Francis         case 9:
632464e447aSAlistair Francis             switch (((insn >> 12) & 0b111)) {
633464e447aSAlistair Francis             case 2: /* fsw */
634464e447aSAlistair Francis             case 3: /* fsd */
635464e447aSAlistair Francis             case 4: /* fsq */
636464e447aSAlistair Francis                 is_write = 1;
637464e447aSAlistair Francis                 break;
638464e447aSAlistair Francis             default:
639464e447aSAlistair Francis                 break;
640464e447aSAlistair Francis             }
641464e447aSAlistair Francis             break;
642464e447aSAlistair Francis         default:
643464e447aSAlistair Francis             break;
644464e447aSAlistair Francis         }
645464e447aSAlistair Francis     }
646464e447aSAlistair Francis 
647464e447aSAlistair Francis     /* Check for compressed instructions */
648464e447aSAlistair Francis     switch (((insn >> 13) & 0b111)) {
649464e447aSAlistair Francis     case 7:
650464e447aSAlistair Francis         switch (insn & 0b11) {
651464e447aSAlistair Francis         case 0: /*c.sd */
652464e447aSAlistair Francis         case 2: /* c.sdsp */
653464e447aSAlistair Francis             is_write = 1;
654464e447aSAlistair Francis             break;
655464e447aSAlistair Francis         default:
656464e447aSAlistair Francis             break;
657464e447aSAlistair Francis         }
658464e447aSAlistair Francis         break;
659464e447aSAlistair Francis     case 6:
660464e447aSAlistair Francis         switch (insn & 0b11) {
661464e447aSAlistair Francis         case 0: /* c.sw */
662464e447aSAlistair Francis         case 3: /* c.swsp */
663464e447aSAlistair Francis             is_write = 1;
664464e447aSAlistair Francis             break;
665464e447aSAlistair Francis         default:
666464e447aSAlistair Francis             break;
667464e447aSAlistair Francis         }
668464e447aSAlistair Francis         break;
669464e447aSAlistair Francis     default:
670464e447aSAlistair Francis         break;
671464e447aSAlistair Francis     }
672464e447aSAlistair Francis 
673464e447aSAlistair Francis     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
674464e447aSAlistair Francis }
675464e447aSAlistair Francis 
67642a623c7SBlue Swirl #else
67742a623c7SBlue Swirl 
67842a623c7SBlue Swirl #error host CPU specific signal handler needed
67942a623c7SBlue Swirl 
68042a623c7SBlue Swirl #endif
681a411d296SPhilippe Mathieu-Daudé 
682a411d296SPhilippe Mathieu-Daudé /* The softmmu versions of these helpers are in cputlb.c.  */
683a411d296SPhilippe Mathieu-Daudé 
684a411d296SPhilippe Mathieu-Daudé /* Do not allow unaligned operations to proceed.  Return the host address.  */
685a411d296SPhilippe Mathieu-Daudé static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
686a411d296SPhilippe Mathieu-Daudé                                int size, uintptr_t retaddr)
687a411d296SPhilippe Mathieu-Daudé {
688a411d296SPhilippe Mathieu-Daudé     /* Enforce qemu required alignment.  */
689a411d296SPhilippe Mathieu-Daudé     if (unlikely(addr & (size - 1))) {
690a411d296SPhilippe Mathieu-Daudé         cpu_loop_exit_atomic(ENV_GET_CPU(env), retaddr);
691a411d296SPhilippe Mathieu-Daudé     }
692ec603b55SRichard Henderson     helper_retaddr = retaddr;
693a411d296SPhilippe Mathieu-Daudé     return g2h(addr);
694a411d296SPhilippe Mathieu-Daudé }
695a411d296SPhilippe Mathieu-Daudé 
696a411d296SPhilippe Mathieu-Daudé /* Macro to call the above, with local variables from the use context.  */
69734d49937SPeter Maydell #define ATOMIC_MMU_DECLS do {} while (0)
698a411d296SPhilippe Mathieu-Daudé #define ATOMIC_MMU_LOOKUP  atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC())
699ec603b55SRichard Henderson #define ATOMIC_MMU_CLEANUP do { helper_retaddr = 0; } while (0)
700a411d296SPhilippe Mathieu-Daudé 
701a411d296SPhilippe Mathieu-Daudé #define ATOMIC_NAME(X)   HELPER(glue(glue(atomic_ ## X, SUFFIX), END))
702a411d296SPhilippe Mathieu-Daudé #define EXTRA_ARGS
703a411d296SPhilippe Mathieu-Daudé 
704a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 1
705a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
706a411d296SPhilippe Mathieu-Daudé 
707a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 2
708a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
709a411d296SPhilippe Mathieu-Daudé 
710a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 4
711a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
712a411d296SPhilippe Mathieu-Daudé 
713a411d296SPhilippe Mathieu-Daudé #ifdef CONFIG_ATOMIC64
714a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 8
715a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
716a411d296SPhilippe Mathieu-Daudé #endif
717a411d296SPhilippe Mathieu-Daudé 
718a411d296SPhilippe Mathieu-Daudé /* The following is only callable from other helpers, and matches up
719a411d296SPhilippe Mathieu-Daudé    with the softmmu version.  */
720a411d296SPhilippe Mathieu-Daudé 
721e6cd4bb5SRichard Henderson #if HAVE_ATOMIC128 || HAVE_CMPXCHG128
722a411d296SPhilippe Mathieu-Daudé 
723a411d296SPhilippe Mathieu-Daudé #undef EXTRA_ARGS
724a411d296SPhilippe Mathieu-Daudé #undef ATOMIC_NAME
725a411d296SPhilippe Mathieu-Daudé #undef ATOMIC_MMU_LOOKUP
726a411d296SPhilippe Mathieu-Daudé 
727a411d296SPhilippe Mathieu-Daudé #define EXTRA_ARGS     , TCGMemOpIdx oi, uintptr_t retaddr
728a411d296SPhilippe Mathieu-Daudé #define ATOMIC_NAME(X) \
729a411d296SPhilippe Mathieu-Daudé     HELPER(glue(glue(glue(atomic_ ## X, SUFFIX), END), _mmu))
730a411d296SPhilippe Mathieu-Daudé #define ATOMIC_MMU_LOOKUP  atomic_mmu_lookup(env, addr, DATA_SIZE, retaddr)
731a411d296SPhilippe Mathieu-Daudé 
732a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 16
733a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
734e6cd4bb5SRichard Henderson #endif
735