xref: /qemu/accel/tcg/user-exec.c (revision 08b97f7ff299df35c61bc74b8e53dbe23d59470b)
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;
66a78b1299SPeter Maydell     unsigned long address = (unsigned long)info->si_addr;
67da6bbf85SRichard Henderson     MMUAccessType access_type;
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              */
137*08b97f7fSRichard Henderson             clear_helper_retaddr();
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 
150da6bbf85SRichard Henderson     /*
151da6bbf85SRichard Henderson      * There is no way the target can handle this other than raising
152da6bbf85SRichard Henderson      * an exception.  Undo signal and retaddr state prior to longjmp.
153ec603b55SRichard Henderson      */
154da6bbf85SRichard Henderson     sigprocmask(SIG_SETMASK, old_set, NULL);
155*08b97f7fSRichard Henderson     clear_helper_retaddr();
156ec603b55SRichard Henderson 
157da6bbf85SRichard Henderson     cc = CPU_GET_CLASS(cpu);
158da6bbf85SRichard Henderson     access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD;
159da6bbf85SRichard Henderson     cc->tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc);
160da6bbf85SRichard Henderson     g_assert_not_reached();
16142a623c7SBlue Swirl }
16242a623c7SBlue Swirl 
16342a623c7SBlue Swirl #if defined(__i386__)
16442a623c7SBlue Swirl 
165c5679026SPeter Maydell #if defined(__NetBSD__)
16642a623c7SBlue Swirl #include <ucontext.h>
16742a623c7SBlue Swirl 
16842a623c7SBlue Swirl #define EIP_sig(context)     ((context)->uc_mcontext.__gregs[_REG_EIP])
16942a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
17042a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->uc_mcontext.__gregs[_REG_ERR])
17142a623c7SBlue Swirl #define MASK_sig(context)    ((context)->uc_sigmask)
17242a623c7SBlue Swirl #elif defined(__FreeBSD__) || defined(__DragonFly__)
17342a623c7SBlue Swirl #include <ucontext.h>
17442a623c7SBlue Swirl 
17542a623c7SBlue Swirl #define EIP_sig(context)  (*((unsigned long *)&(context)->uc_mcontext.mc_eip))
17642a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->uc_mcontext.mc_trapno)
17742a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->uc_mcontext.mc_err)
17842a623c7SBlue Swirl #define MASK_sig(context)    ((context)->uc_sigmask)
17942a623c7SBlue Swirl #elif defined(__OpenBSD__)
18042a623c7SBlue Swirl #define EIP_sig(context)     ((context)->sc_eip)
18142a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->sc_trapno)
18242a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->sc_err)
18342a623c7SBlue Swirl #define MASK_sig(context)    ((context)->sc_mask)
18442a623c7SBlue Swirl #else
18542a623c7SBlue Swirl #define EIP_sig(context)     ((context)->uc_mcontext.gregs[REG_EIP])
18642a623c7SBlue Swirl #define TRAP_sig(context)    ((context)->uc_mcontext.gregs[REG_TRAPNO])
18742a623c7SBlue Swirl #define ERROR_sig(context)   ((context)->uc_mcontext.gregs[REG_ERR])
18842a623c7SBlue Swirl #define MASK_sig(context)    ((context)->uc_sigmask)
18942a623c7SBlue Swirl #endif
19042a623c7SBlue Swirl 
19142a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
19242a623c7SBlue Swirl                        void *puc)
19342a623c7SBlue Swirl {
19442a623c7SBlue Swirl     siginfo_t *info = pinfo;
19542a623c7SBlue Swirl #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
19642a623c7SBlue Swirl     ucontext_t *uc = puc;
19742a623c7SBlue Swirl #elif defined(__OpenBSD__)
19842a623c7SBlue Swirl     struct sigcontext *uc = puc;
19942a623c7SBlue Swirl #else
20004b33e21SKhem Raj     ucontext_t *uc = puc;
20142a623c7SBlue Swirl #endif
20242a623c7SBlue Swirl     unsigned long pc;
20342a623c7SBlue Swirl     int trapno;
20442a623c7SBlue Swirl 
20542a623c7SBlue Swirl #ifndef REG_EIP
20642a623c7SBlue Swirl /* for glibc 2.1 */
20742a623c7SBlue Swirl #define REG_EIP    EIP
20842a623c7SBlue Swirl #define REG_ERR    ERR
20942a623c7SBlue Swirl #define REG_TRAPNO TRAPNO
21042a623c7SBlue Swirl #endif
21142a623c7SBlue Swirl     pc = EIP_sig(uc);
21242a623c7SBlue Swirl     trapno = TRAP_sig(uc);
213a78b1299SPeter Maydell     return handle_cpu_signal(pc, info,
214a78b1299SPeter Maydell                              trapno == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0,
215a5852dc5SPeter Maydell                              &MASK_sig(uc));
21642a623c7SBlue Swirl }
21742a623c7SBlue Swirl 
21842a623c7SBlue Swirl #elif defined(__x86_64__)
21942a623c7SBlue Swirl 
22042a623c7SBlue Swirl #ifdef __NetBSD__
22142a623c7SBlue Swirl #define PC_sig(context)       _UC_MACHINE_PC(context)
22242a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
22342a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->uc_mcontext.__gregs[_REG_ERR])
22442a623c7SBlue Swirl #define MASK_sig(context)     ((context)->uc_sigmask)
22542a623c7SBlue Swirl #elif defined(__OpenBSD__)
22642a623c7SBlue Swirl #define PC_sig(context)       ((context)->sc_rip)
22742a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->sc_trapno)
22842a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->sc_err)
22942a623c7SBlue Swirl #define MASK_sig(context)     ((context)->sc_mask)
23042a623c7SBlue Swirl #elif defined(__FreeBSD__) || defined(__DragonFly__)
23142a623c7SBlue Swirl #include <ucontext.h>
23242a623c7SBlue Swirl 
23342a623c7SBlue Swirl #define PC_sig(context)  (*((unsigned long *)&(context)->uc_mcontext.mc_rip))
23442a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->uc_mcontext.mc_trapno)
23542a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->uc_mcontext.mc_err)
23642a623c7SBlue Swirl #define MASK_sig(context)     ((context)->uc_sigmask)
23742a623c7SBlue Swirl #else
23842a623c7SBlue Swirl #define PC_sig(context)       ((context)->uc_mcontext.gregs[REG_RIP])
23942a623c7SBlue Swirl #define TRAP_sig(context)     ((context)->uc_mcontext.gregs[REG_TRAPNO])
24042a623c7SBlue Swirl #define ERROR_sig(context)    ((context)->uc_mcontext.gregs[REG_ERR])
24142a623c7SBlue Swirl #define MASK_sig(context)     ((context)->uc_sigmask)
24242a623c7SBlue Swirl #endif
24342a623c7SBlue Swirl 
24442a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
24542a623c7SBlue Swirl                        void *puc)
24642a623c7SBlue Swirl {
24742a623c7SBlue Swirl     siginfo_t *info = pinfo;
24842a623c7SBlue Swirl     unsigned long pc;
24942a623c7SBlue Swirl #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
25042a623c7SBlue Swirl     ucontext_t *uc = puc;
25142a623c7SBlue Swirl #elif defined(__OpenBSD__)
25242a623c7SBlue Swirl     struct sigcontext *uc = puc;
25342a623c7SBlue Swirl #else
25404b33e21SKhem Raj     ucontext_t *uc = puc;
25542a623c7SBlue Swirl #endif
25642a623c7SBlue Swirl 
25742a623c7SBlue Swirl     pc = PC_sig(uc);
258a78b1299SPeter Maydell     return handle_cpu_signal(pc, info,
259a78b1299SPeter Maydell                              TRAP_sig(uc) == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0,
260a5852dc5SPeter Maydell                              &MASK_sig(uc));
26142a623c7SBlue Swirl }
26242a623c7SBlue Swirl 
26342a623c7SBlue Swirl #elif defined(_ARCH_PPC)
26442a623c7SBlue Swirl 
26542a623c7SBlue Swirl /***********************************************************************
26642a623c7SBlue Swirl  * signal context platform-specific definitions
26742a623c7SBlue Swirl  * From Wine
26842a623c7SBlue Swirl  */
26942a623c7SBlue Swirl #ifdef linux
27042a623c7SBlue Swirl /* All Registers access - only for local access */
27142a623c7SBlue Swirl #define REG_sig(reg_name, context)              \
27242a623c7SBlue Swirl     ((context)->uc_mcontext.regs->reg_name)
27342a623c7SBlue Swirl /* Gpr Registers access  */
27442a623c7SBlue Swirl #define GPR_sig(reg_num, context)              REG_sig(gpr[reg_num], context)
27542a623c7SBlue Swirl /* Program counter */
27642a623c7SBlue Swirl #define IAR_sig(context)                       REG_sig(nip, context)
27742a623c7SBlue Swirl /* Machine State Register (Supervisor) */
27842a623c7SBlue Swirl #define MSR_sig(context)                       REG_sig(msr, context)
27942a623c7SBlue Swirl /* Count register */
28042a623c7SBlue Swirl #define CTR_sig(context)                       REG_sig(ctr, context)
28142a623c7SBlue Swirl /* User's integer exception register */
28242a623c7SBlue Swirl #define XER_sig(context)                       REG_sig(xer, context)
28342a623c7SBlue Swirl /* Link register */
28442a623c7SBlue Swirl #define LR_sig(context)                        REG_sig(link, context)
28542a623c7SBlue Swirl /* Condition register */
28642a623c7SBlue Swirl #define CR_sig(context)                        REG_sig(ccr, context)
28742a623c7SBlue Swirl 
28842a623c7SBlue Swirl /* Float Registers access  */
28942a623c7SBlue Swirl #define FLOAT_sig(reg_num, context)                                     \
29042a623c7SBlue Swirl     (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num])
29142a623c7SBlue Swirl #define FPSCR_sig(context) \
29242a623c7SBlue Swirl     (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4)))
29342a623c7SBlue Swirl /* Exception Registers access */
29442a623c7SBlue Swirl #define DAR_sig(context)                       REG_sig(dar, context)
29542a623c7SBlue Swirl #define DSISR_sig(context)                     REG_sig(dsisr, context)
29642a623c7SBlue Swirl #define TRAP_sig(context)                      REG_sig(trap, context)
29742a623c7SBlue Swirl #endif /* linux */
29842a623c7SBlue Swirl 
29942a623c7SBlue Swirl #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
30042a623c7SBlue Swirl #include <ucontext.h>
30142a623c7SBlue Swirl #define IAR_sig(context)               ((context)->uc_mcontext.mc_srr0)
30242a623c7SBlue Swirl #define MSR_sig(context)               ((context)->uc_mcontext.mc_srr1)
30342a623c7SBlue Swirl #define CTR_sig(context)               ((context)->uc_mcontext.mc_ctr)
30442a623c7SBlue Swirl #define XER_sig(context)               ((context)->uc_mcontext.mc_xer)
30542a623c7SBlue Swirl #define LR_sig(context)                ((context)->uc_mcontext.mc_lr)
30642a623c7SBlue Swirl #define CR_sig(context)                ((context)->uc_mcontext.mc_cr)
30742a623c7SBlue Swirl /* Exception Registers access */
30842a623c7SBlue Swirl #define DAR_sig(context)               ((context)->uc_mcontext.mc_dar)
30942a623c7SBlue Swirl #define DSISR_sig(context)             ((context)->uc_mcontext.mc_dsisr)
31042a623c7SBlue Swirl #define TRAP_sig(context)              ((context)->uc_mcontext.mc_exc)
31142a623c7SBlue Swirl #endif /* __FreeBSD__|| __FreeBSD_kernel__ */
31242a623c7SBlue Swirl 
31342a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
31442a623c7SBlue Swirl                        void *puc)
31542a623c7SBlue Swirl {
31642a623c7SBlue Swirl     siginfo_t *info = pinfo;
31742a623c7SBlue Swirl #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
31842a623c7SBlue Swirl     ucontext_t *uc = puc;
31942a623c7SBlue Swirl #else
32004b33e21SKhem Raj     ucontext_t *uc = puc;
32142a623c7SBlue Swirl #endif
32242a623c7SBlue Swirl     unsigned long pc;
32342a623c7SBlue Swirl     int is_write;
32442a623c7SBlue Swirl 
32542a623c7SBlue Swirl     pc = IAR_sig(uc);
32642a623c7SBlue Swirl     is_write = 0;
32742a623c7SBlue Swirl #if 0
32842a623c7SBlue Swirl     /* ppc 4xx case */
32942a623c7SBlue Swirl     if (DSISR_sig(uc) & 0x00800000) {
33042a623c7SBlue Swirl         is_write = 1;
33142a623c7SBlue Swirl     }
33242a623c7SBlue Swirl #else
33342a623c7SBlue Swirl     if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) {
33442a623c7SBlue Swirl         is_write = 1;
33542a623c7SBlue Swirl     }
33642a623c7SBlue Swirl #endif
337a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
33842a623c7SBlue Swirl }
33942a623c7SBlue Swirl 
34042a623c7SBlue Swirl #elif defined(__alpha__)
34142a623c7SBlue Swirl 
34242a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
34342a623c7SBlue Swirl                            void *puc)
34442a623c7SBlue Swirl {
34542a623c7SBlue Swirl     siginfo_t *info = pinfo;
34604b33e21SKhem Raj     ucontext_t *uc = puc;
34742a623c7SBlue Swirl     uint32_t *pc = uc->uc_mcontext.sc_pc;
34842a623c7SBlue Swirl     uint32_t insn = *pc;
34942a623c7SBlue Swirl     int is_write = 0;
35042a623c7SBlue Swirl 
35142a623c7SBlue Swirl     /* XXX: need kernel patch to get write flag faster */
35242a623c7SBlue Swirl     switch (insn >> 26) {
35342a623c7SBlue Swirl     case 0x0d: /* stw */
35442a623c7SBlue Swirl     case 0x0e: /* stb */
35542a623c7SBlue Swirl     case 0x0f: /* stq_u */
35642a623c7SBlue Swirl     case 0x24: /* stf */
35742a623c7SBlue Swirl     case 0x25: /* stg */
35842a623c7SBlue Swirl     case 0x26: /* sts */
35942a623c7SBlue Swirl     case 0x27: /* stt */
36042a623c7SBlue Swirl     case 0x2c: /* stl */
36142a623c7SBlue Swirl     case 0x2d: /* stq */
36242a623c7SBlue Swirl     case 0x2e: /* stl_c */
36342a623c7SBlue Swirl     case 0x2f: /* stq_c */
36442a623c7SBlue Swirl         is_write = 1;
36542a623c7SBlue Swirl     }
36642a623c7SBlue Swirl 
367a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
36842a623c7SBlue Swirl }
36942a623c7SBlue Swirl #elif defined(__sparc__)
37042a623c7SBlue Swirl 
37142a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
37242a623c7SBlue Swirl                        void *puc)
37342a623c7SBlue Swirl {
37442a623c7SBlue Swirl     siginfo_t *info = pinfo;
37542a623c7SBlue Swirl     int is_write;
37642a623c7SBlue Swirl     uint32_t insn;
37742a623c7SBlue Swirl #if !defined(__arch64__) || defined(CONFIG_SOLARIS)
37842a623c7SBlue Swirl     uint32_t *regs = (uint32_t *)(info + 1);
37942a623c7SBlue Swirl     void *sigmask = (regs + 20);
38042a623c7SBlue Swirl     /* XXX: is there a standard glibc define ? */
38142a623c7SBlue Swirl     unsigned long pc = regs[1];
38242a623c7SBlue Swirl #else
38342a623c7SBlue Swirl #ifdef __linux__
38442a623c7SBlue Swirl     struct sigcontext *sc = puc;
38542a623c7SBlue Swirl     unsigned long pc = sc->sigc_regs.tpc;
38642a623c7SBlue Swirl     void *sigmask = (void *)sc->sigc_mask;
38742a623c7SBlue Swirl #elif defined(__OpenBSD__)
38842a623c7SBlue Swirl     struct sigcontext *uc = puc;
38942a623c7SBlue Swirl     unsigned long pc = uc->sc_pc;
39042a623c7SBlue Swirl     void *sigmask = (void *)(long)uc->sc_mask;
3917ccfb495STobias Nygren #elif defined(__NetBSD__)
3927ccfb495STobias Nygren     ucontext_t *uc = puc;
3937ccfb495STobias Nygren     unsigned long pc = _UC_MACHINE_PC(uc);
3947ccfb495STobias Nygren     void *sigmask = (void *)&uc->uc_sigmask;
39542a623c7SBlue Swirl #endif
39642a623c7SBlue Swirl #endif
39742a623c7SBlue Swirl 
39842a623c7SBlue Swirl     /* XXX: need kernel patch to get write flag faster */
39942a623c7SBlue Swirl     is_write = 0;
40042a623c7SBlue Swirl     insn = *(uint32_t *)pc;
40142a623c7SBlue Swirl     if ((insn >> 30) == 3) {
40242a623c7SBlue Swirl         switch ((insn >> 19) & 0x3f) {
40342a623c7SBlue Swirl         case 0x05: /* stb */
40442a623c7SBlue Swirl         case 0x15: /* stba */
40542a623c7SBlue Swirl         case 0x06: /* sth */
40642a623c7SBlue Swirl         case 0x16: /* stha */
40742a623c7SBlue Swirl         case 0x04: /* st */
40842a623c7SBlue Swirl         case 0x14: /* sta */
40942a623c7SBlue Swirl         case 0x07: /* std */
41042a623c7SBlue Swirl         case 0x17: /* stda */
41142a623c7SBlue Swirl         case 0x0e: /* stx */
41242a623c7SBlue Swirl         case 0x1e: /* stxa */
41342a623c7SBlue Swirl         case 0x24: /* stf */
41442a623c7SBlue Swirl         case 0x34: /* stfa */
41542a623c7SBlue Swirl         case 0x27: /* stdf */
41642a623c7SBlue Swirl         case 0x37: /* stdfa */
41742a623c7SBlue Swirl         case 0x26: /* stqf */
41842a623c7SBlue Swirl         case 0x36: /* stqfa */
41942a623c7SBlue Swirl         case 0x25: /* stfsr */
42042a623c7SBlue Swirl         case 0x3c: /* casa */
42142a623c7SBlue Swirl         case 0x3e: /* casxa */
42242a623c7SBlue Swirl             is_write = 1;
42342a623c7SBlue Swirl             break;
42442a623c7SBlue Swirl         }
42542a623c7SBlue Swirl     }
426a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, sigmask);
42742a623c7SBlue Swirl }
42842a623c7SBlue Swirl 
42942a623c7SBlue Swirl #elif defined(__arm__)
43042a623c7SBlue Swirl 
4317ccfb495STobias Nygren #if defined(__NetBSD__)
4327ccfb495STobias Nygren #include <ucontext.h>
4337ccfb495STobias Nygren #endif
4347ccfb495STobias Nygren 
43542a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
43642a623c7SBlue Swirl                        void *puc)
43742a623c7SBlue Swirl {
43842a623c7SBlue Swirl     siginfo_t *info = pinfo;
4397ccfb495STobias Nygren #if defined(__NetBSD__)
4407ccfb495STobias Nygren     ucontext_t *uc = puc;
4417ccfb495STobias Nygren #else
44204b33e21SKhem Raj     ucontext_t *uc = puc;
4437ccfb495STobias Nygren #endif
44442a623c7SBlue Swirl     unsigned long pc;
44542a623c7SBlue Swirl     int is_write;
44642a623c7SBlue Swirl 
4477ccfb495STobias Nygren #if defined(__NetBSD__)
4487ccfb495STobias Nygren     pc = uc->uc_mcontext.__gregs[_REG_R15];
4497ccfb495STobias Nygren #elif defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
45042a623c7SBlue Swirl     pc = uc->uc_mcontext.gregs[R15];
45142a623c7SBlue Swirl #else
45242a623c7SBlue Swirl     pc = uc->uc_mcontext.arm_pc;
45342a623c7SBlue Swirl #endif
454023b0ae3SPeter Maydell 
455023b0ae3SPeter Maydell     /* error_code is the FSR value, in which bit 11 is WnR (assuming a v6 or
456023b0ae3SPeter Maydell      * later processor; on v5 we will always report this as a read).
457023b0ae3SPeter Maydell      */
458023b0ae3SPeter Maydell     is_write = extract32(uc->uc_mcontext.error_code, 11, 1);
459a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
46042a623c7SBlue Swirl }
46142a623c7SBlue Swirl 
462f129061cSClaudio Fontana #elif defined(__aarch64__)
463f129061cSClaudio Fontana 
464f454a54fSPeter Maydell #ifndef ESR_MAGIC
465f454a54fSPeter Maydell /* Pre-3.16 kernel headers don't have these, so provide fallback definitions */
466f454a54fSPeter Maydell #define ESR_MAGIC 0x45535201
467f454a54fSPeter Maydell struct esr_context {
468f454a54fSPeter Maydell     struct _aarch64_ctx head;
469f454a54fSPeter Maydell     uint64_t esr;
470f454a54fSPeter Maydell };
471f454a54fSPeter Maydell #endif
472f454a54fSPeter Maydell 
473f454a54fSPeter Maydell static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc)
474f454a54fSPeter Maydell {
475f454a54fSPeter Maydell     return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved;
476f454a54fSPeter Maydell }
477f454a54fSPeter Maydell 
478f454a54fSPeter Maydell static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr)
479f454a54fSPeter Maydell {
480f454a54fSPeter Maydell     return (struct _aarch64_ctx *)((char *)hdr + hdr->size);
481f454a54fSPeter Maydell }
482f454a54fSPeter Maydell 
483661f7fa4SRichard Henderson int cpu_signal_handler(int host_signum, void *pinfo, void *puc)
484f129061cSClaudio Fontana {
485f129061cSClaudio Fontana     siginfo_t *info = pinfo;
48604b33e21SKhem Raj     ucontext_t *uc = puc;
487661f7fa4SRichard Henderson     uintptr_t pc = uc->uc_mcontext.pc;
488661f7fa4SRichard Henderson     bool is_write;
489f454a54fSPeter Maydell     struct _aarch64_ctx *hdr;
490f454a54fSPeter Maydell     struct esr_context const *esrctx = NULL;
491f129061cSClaudio Fontana 
492f454a54fSPeter Maydell     /* Find the esr_context, which has the WnR bit in it */
493f454a54fSPeter Maydell     for (hdr = first_ctx(uc); hdr->magic; hdr = next_ctx(hdr)) {
494f454a54fSPeter Maydell         if (hdr->magic == ESR_MAGIC) {
495f454a54fSPeter Maydell             esrctx = (struct esr_context const *)hdr;
496f454a54fSPeter Maydell             break;
497f454a54fSPeter Maydell         }
498f454a54fSPeter Maydell     }
499f454a54fSPeter Maydell 
500f454a54fSPeter Maydell     if (esrctx) {
501f454a54fSPeter Maydell         /* For data aborts ESR.EC is 0b10010x: then bit 6 is the WnR bit */
502f454a54fSPeter Maydell         uint64_t esr = esrctx->esr;
503f454a54fSPeter Maydell         is_write = extract32(esr, 27, 5) == 0x12 && extract32(esr, 6, 1) == 1;
504f454a54fSPeter Maydell     } else {
505f454a54fSPeter Maydell         /*
506f454a54fSPeter Maydell          * Fall back to parsing instructions; will only be needed
507f454a54fSPeter Maydell          * for really ancient (pre-3.16) kernels.
508f454a54fSPeter Maydell          */
509f454a54fSPeter Maydell         uint32_t insn = *(uint32_t *)pc;
510f454a54fSPeter Maydell 
511661f7fa4SRichard Henderson         is_write = ((insn & 0xbfff0000) == 0x0c000000   /* C3.3.1 */
512661f7fa4SRichard Henderson                     || (insn & 0xbfe00000) == 0x0c800000   /* C3.3.2 */
513661f7fa4SRichard Henderson                     || (insn & 0xbfdf0000) == 0x0d000000   /* C3.3.3 */
514661f7fa4SRichard Henderson                     || (insn & 0xbfc00000) == 0x0d800000   /* C3.3.4 */
515661f7fa4SRichard Henderson                     || (insn & 0x3f400000) == 0x08000000   /* C3.3.6 */
516661f7fa4SRichard Henderson                     || (insn & 0x3bc00000) == 0x39000000   /* C3.3.13 */
517661f7fa4SRichard Henderson                     || (insn & 0x3fc00000) == 0x3d800000   /* ... 128bit */
518f454a54fSPeter Maydell                     /* Ignore bits 10, 11 & 21, controlling indexing.  */
519661f7fa4SRichard Henderson                     || (insn & 0x3bc00000) == 0x38000000   /* C3.3.8-12 */
520661f7fa4SRichard Henderson                     || (insn & 0x3fe00000) == 0x3c800000   /* ... 128bit */
521661f7fa4SRichard Henderson                     /* Ignore bits 23 & 24, controlling indexing.  */
522661f7fa4SRichard Henderson                     || (insn & 0x3a400000) == 0x28000000); /* C3.3.7,14-16 */
523f454a54fSPeter Maydell     }
524a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
525f129061cSClaudio Fontana }
526f129061cSClaudio Fontana 
52742a623c7SBlue Swirl #elif defined(__s390__)
52842a623c7SBlue Swirl 
52942a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
53042a623c7SBlue Swirl                        void *puc)
53142a623c7SBlue Swirl {
53242a623c7SBlue Swirl     siginfo_t *info = pinfo;
53304b33e21SKhem Raj     ucontext_t *uc = puc;
53442a623c7SBlue Swirl     unsigned long pc;
53542a623c7SBlue Swirl     uint16_t *pinsn;
53642a623c7SBlue Swirl     int is_write = 0;
53742a623c7SBlue Swirl 
53842a623c7SBlue Swirl     pc = uc->uc_mcontext.psw.addr;
53942a623c7SBlue Swirl 
54042a623c7SBlue Swirl     /* ??? On linux, the non-rt signal handler has 4 (!) arguments instead
54142a623c7SBlue Swirl        of the normal 2 arguments.  The 3rd argument contains the "int_code"
54242a623c7SBlue Swirl        from the hardware which does in fact contain the is_write value.
54342a623c7SBlue Swirl        The rt signal handler, as far as I can tell, does not give this value
54442a623c7SBlue Swirl        at all.  Not that we could get to it from here even if it were.  */
54542a623c7SBlue Swirl     /* ??? This is not even close to complete, since it ignores all
54642a623c7SBlue Swirl        of the read-modify-write instructions.  */
54742a623c7SBlue Swirl     pinsn = (uint16_t *)pc;
54842a623c7SBlue Swirl     switch (pinsn[0] >> 8) {
54942a623c7SBlue Swirl     case 0x50: /* ST */
55042a623c7SBlue Swirl     case 0x42: /* STC */
55142a623c7SBlue Swirl     case 0x40: /* STH */
55242a623c7SBlue Swirl         is_write = 1;
55342a623c7SBlue Swirl         break;
55442a623c7SBlue Swirl     case 0xc4: /* RIL format insns */
55542a623c7SBlue Swirl         switch (pinsn[0] & 0xf) {
55642a623c7SBlue Swirl         case 0xf: /* STRL */
55742a623c7SBlue Swirl         case 0xb: /* STGRL */
55842a623c7SBlue Swirl         case 0x7: /* STHRL */
55942a623c7SBlue Swirl             is_write = 1;
56042a623c7SBlue Swirl         }
56142a623c7SBlue Swirl         break;
56242a623c7SBlue Swirl     case 0xe3: /* RXY format insns */
56342a623c7SBlue Swirl         switch (pinsn[2] & 0xff) {
56442a623c7SBlue Swirl         case 0x50: /* STY */
56542a623c7SBlue Swirl         case 0x24: /* STG */
56642a623c7SBlue Swirl         case 0x72: /* STCY */
56742a623c7SBlue Swirl         case 0x70: /* STHY */
56842a623c7SBlue Swirl         case 0x8e: /* STPQ */
56942a623c7SBlue Swirl         case 0x3f: /* STRVH */
57042a623c7SBlue Swirl         case 0x3e: /* STRV */
57142a623c7SBlue Swirl         case 0x2f: /* STRVG */
57242a623c7SBlue Swirl             is_write = 1;
57342a623c7SBlue Swirl         }
57442a623c7SBlue Swirl         break;
57542a623c7SBlue Swirl     }
576a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
57742a623c7SBlue Swirl }
57842a623c7SBlue Swirl 
57942a623c7SBlue Swirl #elif defined(__mips__)
58042a623c7SBlue Swirl 
58142a623c7SBlue Swirl int cpu_signal_handler(int host_signum, void *pinfo,
58242a623c7SBlue Swirl                        void *puc)
58342a623c7SBlue Swirl {
58442a623c7SBlue Swirl     siginfo_t *info = pinfo;
58504b33e21SKhem Raj     ucontext_t *uc = puc;
58642a623c7SBlue Swirl     greg_t pc = uc->uc_mcontext.pc;
58742a623c7SBlue Swirl     int is_write;
58842a623c7SBlue Swirl 
58942a623c7SBlue Swirl     /* XXX: compute is_write */
59042a623c7SBlue Swirl     is_write = 0;
591a78b1299SPeter Maydell     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
59242a623c7SBlue Swirl }
59342a623c7SBlue Swirl 
594464e447aSAlistair Francis #elif defined(__riscv)
595464e447aSAlistair Francis 
596464e447aSAlistair Francis int cpu_signal_handler(int host_signum, void *pinfo,
597464e447aSAlistair Francis                        void *puc)
598464e447aSAlistair Francis {
599464e447aSAlistair Francis     siginfo_t *info = pinfo;
600464e447aSAlistair Francis     ucontext_t *uc = puc;
601464e447aSAlistair Francis     greg_t pc = uc->uc_mcontext.__gregs[REG_PC];
602464e447aSAlistair Francis     uint32_t insn = *(uint32_t *)pc;
603464e447aSAlistair Francis     int is_write = 0;
604464e447aSAlistair Francis 
605464e447aSAlistair Francis     /* Detect store by reading the instruction at the program
606464e447aSAlistair Francis        counter. Note: we currently only generate 32-bit
607464e447aSAlistair Francis        instructions so we thus only detect 32-bit stores */
608464e447aSAlistair Francis     switch (((insn >> 0) & 0b11)) {
609464e447aSAlistair Francis     case 3:
610464e447aSAlistair Francis         switch (((insn >> 2) & 0b11111)) {
611464e447aSAlistair Francis         case 8:
612464e447aSAlistair Francis             switch (((insn >> 12) & 0b111)) {
613464e447aSAlistair Francis             case 0: /* sb */
614464e447aSAlistair Francis             case 1: /* sh */
615464e447aSAlistair Francis             case 2: /* sw */
616464e447aSAlistair Francis             case 3: /* sd */
617464e447aSAlistair Francis             case 4: /* sq */
618464e447aSAlistair Francis                 is_write = 1;
619464e447aSAlistair Francis                 break;
620464e447aSAlistair Francis             default:
621464e447aSAlistair Francis                 break;
622464e447aSAlistair Francis             }
623464e447aSAlistair Francis             break;
624464e447aSAlistair Francis         case 9:
625464e447aSAlistair Francis             switch (((insn >> 12) & 0b111)) {
626464e447aSAlistair Francis             case 2: /* fsw */
627464e447aSAlistair Francis             case 3: /* fsd */
628464e447aSAlistair Francis             case 4: /* fsq */
629464e447aSAlistair Francis                 is_write = 1;
630464e447aSAlistair Francis                 break;
631464e447aSAlistair Francis             default:
632464e447aSAlistair Francis                 break;
633464e447aSAlistair Francis             }
634464e447aSAlistair Francis             break;
635464e447aSAlistair Francis         default:
636464e447aSAlistair Francis             break;
637464e447aSAlistair Francis         }
638464e447aSAlistair Francis     }
639464e447aSAlistair Francis 
640464e447aSAlistair Francis     /* Check for compressed instructions */
641464e447aSAlistair Francis     switch (((insn >> 13) & 0b111)) {
642464e447aSAlistair Francis     case 7:
643464e447aSAlistair Francis         switch (insn & 0b11) {
644464e447aSAlistair Francis         case 0: /*c.sd */
645464e447aSAlistair Francis         case 2: /* c.sdsp */
646464e447aSAlistair Francis             is_write = 1;
647464e447aSAlistair Francis             break;
648464e447aSAlistair Francis         default:
649464e447aSAlistair Francis             break;
650464e447aSAlistair Francis         }
651464e447aSAlistair Francis         break;
652464e447aSAlistair Francis     case 6:
653464e447aSAlistair Francis         switch (insn & 0b11) {
654464e447aSAlistair Francis         case 0: /* c.sw */
655464e447aSAlistair Francis         case 3: /* c.swsp */
656464e447aSAlistair Francis             is_write = 1;
657464e447aSAlistair Francis             break;
658464e447aSAlistair Francis         default:
659464e447aSAlistair Francis             break;
660464e447aSAlistair Francis         }
661464e447aSAlistair Francis         break;
662464e447aSAlistair Francis     default:
663464e447aSAlistair Francis         break;
664464e447aSAlistair Francis     }
665464e447aSAlistair Francis 
666464e447aSAlistair Francis     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
667464e447aSAlistair Francis }
668464e447aSAlistair Francis 
66942a623c7SBlue Swirl #else
67042a623c7SBlue Swirl 
67142a623c7SBlue Swirl #error host CPU specific signal handler needed
67242a623c7SBlue Swirl 
67342a623c7SBlue Swirl #endif
674a411d296SPhilippe Mathieu-Daudé 
675a411d296SPhilippe Mathieu-Daudé /* The softmmu versions of these helpers are in cputlb.c.  */
676a411d296SPhilippe Mathieu-Daudé 
677a411d296SPhilippe Mathieu-Daudé /* Do not allow unaligned operations to proceed.  Return the host address.  */
678a411d296SPhilippe Mathieu-Daudé static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
679a411d296SPhilippe Mathieu-Daudé                                int size, uintptr_t retaddr)
680a411d296SPhilippe Mathieu-Daudé {
681a411d296SPhilippe Mathieu-Daudé     /* Enforce qemu required alignment.  */
682a411d296SPhilippe Mathieu-Daudé     if (unlikely(addr & (size - 1))) {
68329a0af61SRichard Henderson         cpu_loop_exit_atomic(env_cpu(env), retaddr);
684a411d296SPhilippe Mathieu-Daudé     }
685*08b97f7fSRichard Henderson     void *ret = g2h(addr);
686*08b97f7fSRichard Henderson     set_helper_retaddr(retaddr);
687*08b97f7fSRichard Henderson     return ret;
688a411d296SPhilippe Mathieu-Daudé }
689a411d296SPhilippe Mathieu-Daudé 
690a411d296SPhilippe Mathieu-Daudé /* Macro to call the above, with local variables from the use context.  */
69134d49937SPeter Maydell #define ATOMIC_MMU_DECLS do {} while (0)
692a411d296SPhilippe Mathieu-Daudé #define ATOMIC_MMU_LOOKUP  atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC())
693*08b97f7fSRichard Henderson #define ATOMIC_MMU_CLEANUP do { clear_helper_retaddr(); } while (0)
694a411d296SPhilippe Mathieu-Daudé 
695a411d296SPhilippe Mathieu-Daudé #define ATOMIC_NAME(X)   HELPER(glue(glue(atomic_ ## X, SUFFIX), END))
696a411d296SPhilippe Mathieu-Daudé #define EXTRA_ARGS
697a411d296SPhilippe Mathieu-Daudé 
698a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 1
699a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
700a411d296SPhilippe Mathieu-Daudé 
701a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 2
702a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
703a411d296SPhilippe Mathieu-Daudé 
704a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 4
705a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
706a411d296SPhilippe Mathieu-Daudé 
707a411d296SPhilippe Mathieu-Daudé #ifdef CONFIG_ATOMIC64
708a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 8
709a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
710a411d296SPhilippe Mathieu-Daudé #endif
711a411d296SPhilippe Mathieu-Daudé 
712a411d296SPhilippe Mathieu-Daudé /* The following is only callable from other helpers, and matches up
713a411d296SPhilippe Mathieu-Daudé    with the softmmu version.  */
714a411d296SPhilippe Mathieu-Daudé 
715e6cd4bb5SRichard Henderson #if HAVE_ATOMIC128 || HAVE_CMPXCHG128
716a411d296SPhilippe Mathieu-Daudé 
717a411d296SPhilippe Mathieu-Daudé #undef EXTRA_ARGS
718a411d296SPhilippe Mathieu-Daudé #undef ATOMIC_NAME
719a411d296SPhilippe Mathieu-Daudé #undef ATOMIC_MMU_LOOKUP
720a411d296SPhilippe Mathieu-Daudé 
721a411d296SPhilippe Mathieu-Daudé #define EXTRA_ARGS     , TCGMemOpIdx oi, uintptr_t retaddr
722a411d296SPhilippe Mathieu-Daudé #define ATOMIC_NAME(X) \
723a411d296SPhilippe Mathieu-Daudé     HELPER(glue(glue(glue(atomic_ ## X, SUFFIX), END), _mmu))
724a411d296SPhilippe Mathieu-Daudé #define ATOMIC_MMU_LOOKUP  atomic_mmu_lookup(env, addr, DATA_SIZE, retaddr)
725a411d296SPhilippe Mathieu-Daudé 
726a411d296SPhilippe Mathieu-Daudé #define DATA_SIZE 16
727a411d296SPhilippe Mathieu-Daudé #include "atomic_template.h"
728e6cd4bb5SRichard Henderson #endif
729