2 * User emulator execution
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
21 #include "disas/disas.h"
22 #include "exec/exec-all.h"
24 #include "qemu/bitops.h"
25 #include "exec/cpu_ldst.h"
26 #include "translate-all.h"
27 #include "exec/helper-proto.h"
28 #include "qemu/atomic128.h"
29 #include "trace-root.h"
30 #include "trace/mem.h"
42 #include <sys/ucontext.h>
45 __thread
uintptr_t helper_retaddr
;
47 //#define DEBUG_SIGNAL
49 /* exit the current TB from a signal handler. The host registers are
50 restored in a state compatible with the CPU emulator
52 static void cpu_exit_tb_from_sighandler(CPUState
*cpu
, sigset_t
*old_set
)
54 /* XXX: use siglongjmp ? */
55 sigprocmask(SIG_SETMASK
, old_set
, NULL
);
56 cpu_loop_exit_noexc(cpu
);
59 /* 'pc' is the host PC at which the exception was raised. 'address' is
60 the effective address of the memory exception. 'is_write' is 1 if a
61 write caused the exception and otherwise 0'. 'old_set' is the
62 signal set which should be restored */
63 static inline int handle_cpu_signal(uintptr_t pc
, siginfo_t
*info
,
64 int is_write
, sigset_t
*old_set
)
66 CPUState
*cpu
= current_cpu
;
68 unsigned long address
= (unsigned long)info
->si_addr
;
69 MMUAccessType access_type
= is_write
? MMU_DATA_STORE
: MMU_DATA_LOAD
;
71 switch (helper_retaddr
) {
74 * Fault during host memory operation within a helper function.
75 * The helper's host return address, saved here, gives us a
76 * pointer into the generated code that will unwind to the
84 * Fault during host memory operation within generated code.
85 * (Or, a unrelated bug within qemu, but we can't tell from here).
87 * We take the host pc from the signal frame. However, we cannot
88 * use that value directly. Within cpu_restore_state_from_tb, we
89 * assume PC comes from GETPC(), as used by the helper functions,
90 * so we adjust the address by -GETPC_ADJ to form an address that
91 * is within the call insn, so that the address does not accidentially
92 * match the beginning of the next guest insn. However, when the
93 * pc comes from the signal frame it points to the actual faulting
94 * host memory insn and not the return from a call insn.
96 * Therefore, adjust to compensate for what will be done later
97 * by cpu_restore_state_from_tb.
104 * Fault during host read for translation, or loosely, "execution".
106 * The guest pc is already pointing to the start of the TB for which
107 * code is being generated. If the guest translator manages the
108 * page crossings correctly, this is exactly the correct address
109 * (and if the translator doesn't handle page boundaries correctly
110 * there's little we can do about that here). Therefore, do not
111 * trigger the unwinder.
113 * Like tb_gen_code, release the memory lock before cpu_loop_exit.
116 access_type
= MMU_INST_FETCH
;
121 /* For synchronous signals we expect to be coming from the vCPU
122 * thread (so current_cpu should be valid) and either from running
123 * code or during translation which can fault as we cross pages.
125 * If neither is true then something has gone wrong and we should
126 * abort rather than try and restart the vCPU execution.
128 if (!cpu
|| !cpu
->running
) {
129 printf("qemu:%s received signal outside vCPU context @ pc=0x%"
130 PRIxPTR
"\n", __func__
, pc
);
134 #if defined(DEBUG_SIGNAL)
135 printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
136 pc
, address
, is_write
, *(unsigned long *)old_set
);
138 /* XXX: locking issue */
139 /* Note that it is important that we don't call page_unprotect() unless
140 * this is really a "write to nonwriteable page" fault, because
141 * page_unprotect() assumes that if it is called for an access to
142 * a page that's writeable this means we had two threads racing and
143 * another thread got there first and already made the page writeable;
144 * so we will retry the access. If we were to call page_unprotect()
145 * for some other kind of fault that should really be passed to the
146 * guest, we'd end up in an infinite loop of retrying the faulting
149 if (is_write
&& info
->si_signo
== SIGSEGV
&& info
->si_code
== SEGV_ACCERR
&&
150 h2g_valid(address
)) {
151 switch (page_unprotect(h2g(address
), pc
)) {
153 /* Fault not caused by a page marked unwritable to protect
154 * cached translations, must be the guest binary's problem.
158 /* Fault caused by protection of cached translation; TBs
159 * invalidated, so resume execution. Retain helper_retaddr
160 * for a possible second fault.
164 /* Fault caused by protection of cached translation, and the
165 * currently executing TB was modified and must be exited
166 * immediately. Clear helper_retaddr for next execution.
168 clear_helper_retaddr();
169 cpu_exit_tb_from_sighandler(cpu
, old_set
);
173 g_assert_not_reached();
177 /* Convert forcefully to guest address space, invalid addresses
178 are still valid segv ones */
179 address
= h2g_nocheck(address
);
182 * There is no way the target can handle this other than raising
183 * an exception. Undo signal and retaddr state prior to longjmp.
185 sigprocmask(SIG_SETMASK
, old_set
, NULL
);
186 clear_helper_retaddr();
188 cc
= CPU_GET_CLASS(cpu
);
189 cc
->tlb_fill(cpu
, address
, 0, access_type
, MMU_USER_IDX
, false, pc
);
190 g_assert_not_reached();
193 void *probe_access(CPUArchState
*env
, target_ulong addr
, int size
,
194 MMUAccessType access_type
, int mmu_idx
, uintptr_t retaddr
)
198 g_assert(-(addr
| TARGET_PAGE_MASK
) >= size
);
200 switch (access_type
) {
211 g_assert_not_reached();
214 if (!guest_addr_valid(addr
) || page_check_range(addr
, size
, flags
) < 0) {
215 CPUState
*cpu
= env_cpu(env
);
216 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
217 cc
->tlb_fill(cpu
, addr
, size
, access_type
, MMU_USER_IDX
, false,
219 g_assert_not_reached();
222 return size
? g2h(addr
) : NULL
;
225 #if defined(__i386__)
227 #if defined(__NetBSD__)
228 #include <ucontext.h>
230 #define EIP_sig(context) ((context)->uc_mcontext.__gregs[_REG_EIP])
231 #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
232 #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR])
233 #define MASK_sig(context) ((context)->uc_sigmask)
234 #elif defined(__FreeBSD__) || defined(__DragonFly__)
235 #include <ucontext.h>
237 #define EIP_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_eip))
238 #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno)
239 #define ERROR_sig(context) ((context)->uc_mcontext.mc_err)
240 #define MASK_sig(context) ((context)->uc_sigmask)
241 #elif defined(__OpenBSD__)
242 #define EIP_sig(context) ((context)->sc_eip)
243 #define TRAP_sig(context) ((context)->sc_trapno)
244 #define ERROR_sig(context) ((context)->sc_err)
245 #define MASK_sig(context) ((context)->sc_mask)
247 #define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP])
248 #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
249 #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
250 #define MASK_sig(context) ((context)->uc_sigmask)
253 int cpu_signal_handler(int host_signum
, void *pinfo
,
256 siginfo_t
*info
= pinfo
;
257 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
258 ucontext_t
*uc
= puc
;
259 #elif defined(__OpenBSD__)
260 struct sigcontext
*uc
= puc
;
262 ucontext_t
*uc
= puc
;
271 #define REG_TRAPNO TRAPNO
274 trapno
= TRAP_sig(uc
);
275 return handle_cpu_signal(pc
, info
,
276 trapno
== 0xe ? (ERROR_sig(uc
) >> 1) & 1 : 0,
280 #elif defined(__x86_64__)
283 #define PC_sig(context) _UC_MACHINE_PC(context)
284 #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
285 #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR])
286 #define MASK_sig(context) ((context)->uc_sigmask)
287 #elif defined(__OpenBSD__)
288 #define PC_sig(context) ((context)->sc_rip)
289 #define TRAP_sig(context) ((context)->sc_trapno)
290 #define ERROR_sig(context) ((context)->sc_err)
291 #define MASK_sig(context) ((context)->sc_mask)
292 #elif defined(__FreeBSD__) || defined(__DragonFly__)
293 #include <ucontext.h>
295 #define PC_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_rip))
296 #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno)
297 #define ERROR_sig(context) ((context)->uc_mcontext.mc_err)
298 #define MASK_sig(context) ((context)->uc_sigmask)
300 #define PC_sig(context) ((context)->uc_mcontext.gregs[REG_RIP])
301 #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
302 #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
303 #define MASK_sig(context) ((context)->uc_sigmask)
306 int cpu_signal_handler(int host_signum
, void *pinfo
,
309 siginfo_t
*info
= pinfo
;
311 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
312 ucontext_t
*uc
= puc
;
313 #elif defined(__OpenBSD__)
314 struct sigcontext
*uc
= puc
;
316 ucontext_t
*uc
= puc
;
320 return handle_cpu_signal(pc
, info
,
321 TRAP_sig(uc
) == 0xe ? (ERROR_sig(uc
) >> 1) & 1 : 0,
325 #elif defined(_ARCH_PPC)
327 /***********************************************************************
328 * signal context platform-specific definitions
332 /* All Registers access - only for local access */
333 #define REG_sig(reg_name, context) \
334 ((context)->uc_mcontext.regs->reg_name)
335 /* Gpr Registers access */
336 #define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
337 /* Program counter */
338 #define IAR_sig(context) REG_sig(nip, context)
339 /* Machine State Register (Supervisor) */
340 #define MSR_sig(context) REG_sig(msr, context)
342 #define CTR_sig(context) REG_sig(ctr, context)
343 /* User's integer exception register */
344 #define XER_sig(context) REG_sig(xer, context)
346 #define LR_sig(context) REG_sig(link, context)
347 /* Condition register */
348 #define CR_sig(context) REG_sig(ccr, context)
350 /* Float Registers access */
351 #define FLOAT_sig(reg_num, context) \
352 (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num])
353 #define FPSCR_sig(context) \
354 (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4)))
355 /* Exception Registers access */
356 #define DAR_sig(context) REG_sig(dar, context)
357 #define DSISR_sig(context) REG_sig(dsisr, context)
358 #define TRAP_sig(context) REG_sig(trap, context)
361 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
362 #include <ucontext.h>
363 #define IAR_sig(context) ((context)->uc_mcontext.mc_srr0)
364 #define MSR_sig(context) ((context)->uc_mcontext.mc_srr1)
365 #define CTR_sig(context) ((context)->uc_mcontext.mc_ctr)
366 #define XER_sig(context) ((context)->uc_mcontext.mc_xer)
367 #define LR_sig(context) ((context)->uc_mcontext.mc_lr)
368 #define CR_sig(context) ((context)->uc_mcontext.mc_cr)
369 /* Exception Registers access */
370 #define DAR_sig(context) ((context)->uc_mcontext.mc_dar)
371 #define DSISR_sig(context) ((context)->uc_mcontext.mc_dsisr)
372 #define TRAP_sig(context) ((context)->uc_mcontext.mc_exc)
373 #endif /* __FreeBSD__|| __FreeBSD_kernel__ */
375 int cpu_signal_handler(int host_signum
, void *pinfo
,
378 siginfo_t
*info
= pinfo
;
379 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
380 ucontext_t
*uc
= puc
;
382 ucontext_t
*uc
= puc
;
391 if (DSISR_sig(uc
) & 0x00800000) {
395 if (TRAP_sig(uc
) != 0x400 && (DSISR_sig(uc
) & 0x02000000)) {
399 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
402 #elif defined(__alpha__)
404 int cpu_signal_handler(int host_signum
, void *pinfo
,
407 siginfo_t
*info
= pinfo
;
408 ucontext_t
*uc
= puc
;
409 uint32_t *pc
= uc
->uc_mcontext
.sc_pc
;
413 /* XXX: need kernel patch to get write flag faster */
414 switch (insn
>> 26) {
417 case 0x0f: /* stq_u */
424 case 0x2e: /* stl_c */
425 case 0x2f: /* stq_c */
429 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
431 #elif defined(__sparc__)
433 int cpu_signal_handler(int host_signum
, void *pinfo
,
436 siginfo_t
*info
= pinfo
;
439 #if !defined(__arch64__) || defined(CONFIG_SOLARIS)
440 uint32_t *regs
= (uint32_t *)(info
+ 1);
441 void *sigmask
= (regs
+ 20);
442 /* XXX: is there a standard glibc define ? */
443 unsigned long pc
= regs
[1];
446 struct sigcontext
*sc
= puc
;
447 unsigned long pc
= sc
->sigc_regs
.tpc
;
448 void *sigmask
= (void *)sc
->sigc_mask
;
449 #elif defined(__OpenBSD__)
450 struct sigcontext
*uc
= puc
;
451 unsigned long pc
= uc
->sc_pc
;
452 void *sigmask
= (void *)(long)uc
->sc_mask
;
453 #elif defined(__NetBSD__)
454 ucontext_t
*uc
= puc
;
455 unsigned long pc
= _UC_MACHINE_PC(uc
);
456 void *sigmask
= (void *)&uc
->uc_sigmask
;
460 /* XXX: need kernel patch to get write flag faster */
462 insn
= *(uint32_t *)pc
;
463 if ((insn
>> 30) == 3) {
464 switch ((insn
>> 19) & 0x3f) {
466 case 0x15: /* stba */
468 case 0x16: /* stha */
472 case 0x17: /* stda */
474 case 0x1e: /* stxa */
476 case 0x34: /* stfa */
477 case 0x27: /* stdf */
478 case 0x37: /* stdfa */
479 case 0x26: /* stqf */
480 case 0x36: /* stqfa */
481 case 0x25: /* stfsr */
482 case 0x3c: /* casa */
483 case 0x3e: /* casxa */
488 return handle_cpu_signal(pc
, info
, is_write
, sigmask
);
491 #elif defined(__arm__)
493 #if defined(__NetBSD__)
494 #include <ucontext.h>
497 int cpu_signal_handler(int host_signum
, void *pinfo
,
500 siginfo_t
*info
= pinfo
;
501 #if defined(__NetBSD__)
502 ucontext_t
*uc
= puc
;
504 ucontext_t
*uc
= puc
;
509 #if defined(__NetBSD__)
510 pc
= uc
->uc_mcontext
.__gregs
[_REG_R15
];
511 #elif defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
512 pc
= uc
->uc_mcontext
.gregs
[R15
];
514 pc
= uc
->uc_mcontext
.arm_pc
;
517 /* error_code is the FSR value, in which bit 11 is WnR (assuming a v6 or
518 * later processor; on v5 we will always report this as a read).
520 is_write
= extract32(uc
->uc_mcontext
.error_code
, 11, 1);
521 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
524 #elif defined(__aarch64__)
527 /* Pre-3.16 kernel headers don't have these, so provide fallback definitions */
528 #define ESR_MAGIC 0x45535201
530 struct _aarch64_ctx head
;
535 static inline struct _aarch64_ctx
*first_ctx(ucontext_t
*uc
)
537 return (struct _aarch64_ctx
*)&uc
->uc_mcontext
.__reserved
;
540 static inline struct _aarch64_ctx
*next_ctx(struct _aarch64_ctx
*hdr
)
542 return (struct _aarch64_ctx
*)((char *)hdr
+ hdr
->size
);
545 int cpu_signal_handler(int host_signum
, void *pinfo
, void *puc
)
547 siginfo_t
*info
= pinfo
;
548 ucontext_t
*uc
= puc
;
549 uintptr_t pc
= uc
->uc_mcontext
.pc
;
551 struct _aarch64_ctx
*hdr
;
552 struct esr_context
const *esrctx
= NULL
;
554 /* Find the esr_context, which has the WnR bit in it */
555 for (hdr
= first_ctx(uc
); hdr
->magic
; hdr
= next_ctx(hdr
)) {
556 if (hdr
->magic
== ESR_MAGIC
) {
557 esrctx
= (struct esr_context
const *)hdr
;
563 /* For data aborts ESR.EC is 0b10010x: then bit 6 is the WnR bit */
564 uint64_t esr
= esrctx
->esr
;
565 is_write
= extract32(esr
, 27, 5) == 0x12 && extract32(esr
, 6, 1) == 1;
568 * Fall back to parsing instructions; will only be needed
569 * for really ancient (pre-3.16) kernels.
571 uint32_t insn
= *(uint32_t *)pc
;
573 is_write
= ((insn
& 0xbfff0000) == 0x0c000000 /* C3.3.1 */
574 || (insn
& 0xbfe00000) == 0x0c800000 /* C3.3.2 */
575 || (insn
& 0xbfdf0000) == 0x0d000000 /* C3.3.3 */
576 || (insn
& 0xbfc00000) == 0x0d800000 /* C3.3.4 */
577 || (insn
& 0x3f400000) == 0x08000000 /* C3.3.6 */
578 || (insn
& 0x3bc00000) == 0x39000000 /* C3.3.13 */
579 || (insn
& 0x3fc00000) == 0x3d800000 /* ... 128bit */
580 /* Ignore bits 10, 11 & 21, controlling indexing. */
581 || (insn
& 0x3bc00000) == 0x38000000 /* C3.3.8-12 */
582 || (insn
& 0x3fe00000) == 0x3c800000 /* ... 128bit */
583 /* Ignore bits 23 & 24, controlling indexing. */
584 || (insn
& 0x3a400000) == 0x28000000); /* C3.3.7,14-16 */
586 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
589 #elif defined(__s390__)
591 int cpu_signal_handler(int host_signum
, void *pinfo
,
594 siginfo_t
*info
= pinfo
;
595 ucontext_t
*uc
= puc
;
600 pc
= uc
->uc_mcontext
.psw
.addr
;
602 /* ??? On linux, the non-rt signal handler has 4 (!) arguments instead
603 of the normal 2 arguments. The 3rd argument contains the "int_code"
604 from the hardware which does in fact contain the is_write value.
605 The rt signal handler, as far as I can tell, does not give this value
606 at all. Not that we could get to it from here even if it were. */
607 /* ??? This is not even close to complete, since it ignores all
608 of the read-modify-write instructions. */
609 pinsn
= (uint16_t *)pc
;
610 switch (pinsn
[0] >> 8) {
616 case 0xc4: /* RIL format insns */
617 switch (pinsn
[0] & 0xf) {
619 case 0xb: /* STGRL */
620 case 0x7: /* STHRL */
624 case 0xe3: /* RXY format insns */
625 switch (pinsn
[2] & 0xff) {
628 case 0x72: /* STCY */
629 case 0x70: /* STHY */
630 case 0x8e: /* STPQ */
631 case 0x3f: /* STRVH */
632 case 0x3e: /* STRV */
633 case 0x2f: /* STRVG */
638 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
641 #elif defined(__mips__)
643 int cpu_signal_handler(int host_signum
, void *pinfo
,
646 siginfo_t
*info
= pinfo
;
647 ucontext_t
*uc
= puc
;
648 greg_t pc
= uc
->uc_mcontext
.pc
;
651 /* XXX: compute is_write */
653 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
656 #elif defined(__riscv)
658 int cpu_signal_handler(int host_signum
, void *pinfo
,
661 siginfo_t
*info
= pinfo
;
662 ucontext_t
*uc
= puc
;
663 greg_t pc
= uc
->uc_mcontext
.__gregs
[REG_PC
];
664 uint32_t insn
= *(uint32_t *)pc
;
667 /* Detect store by reading the instruction at the program
668 counter. Note: we currently only generate 32-bit
669 instructions so we thus only detect 32-bit stores */
670 switch (((insn
>> 0) & 0b11)) {
672 switch (((insn
>> 2) & 0b11111)) {
674 switch (((insn
>> 12) & 0b111)) {
687 switch (((insn
>> 12) & 0b111)) {
702 /* Check for compressed instructions */
703 switch (((insn
>> 13) & 0b111)) {
705 switch (insn
& 0b11) {
715 switch (insn
& 0b11) {
728 return handle_cpu_signal(pc
, info
, is_write
, &uc
->uc_sigmask
);
733 #error host CPU specific signal handler needed
737 /* The softmmu versions of these helpers are in cputlb.c. */
739 uint32_t cpu_ldub_data(CPUArchState
*env
, abi_ptr ptr
)
742 uint16_t meminfo
= trace_mem_get_info(MO_UB
, MMU_USER_IDX
, false);
744 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
745 ret
= ldub_p(g2h(ptr
));
746 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
750 int cpu_ldsb_data(CPUArchState
*env
, abi_ptr ptr
)
753 uint16_t meminfo
= trace_mem_get_info(MO_SB
, MMU_USER_IDX
, false);
755 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
756 ret
= ldsb_p(g2h(ptr
));
757 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
761 uint32_t cpu_lduw_data(CPUArchState
*env
, abi_ptr ptr
)
764 uint16_t meminfo
= trace_mem_get_info(MO_TEUW
, MMU_USER_IDX
, false);
766 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
767 ret
= lduw_p(g2h(ptr
));
768 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
772 int cpu_ldsw_data(CPUArchState
*env
, abi_ptr ptr
)
775 uint16_t meminfo
= trace_mem_get_info(MO_TESW
, MMU_USER_IDX
, false);
777 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
778 ret
= ldsw_p(g2h(ptr
));
779 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
783 uint32_t cpu_ldl_data(CPUArchState
*env
, abi_ptr ptr
)
786 uint16_t meminfo
= trace_mem_get_info(MO_TEUL
, MMU_USER_IDX
, false);
788 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
789 ret
= ldl_p(g2h(ptr
));
790 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
794 uint64_t cpu_ldq_data(CPUArchState
*env
, abi_ptr ptr
)
797 uint16_t meminfo
= trace_mem_get_info(MO_TEQ
, MMU_USER_IDX
, false);
799 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
800 ret
= ldq_p(g2h(ptr
));
801 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
805 uint32_t cpu_ldub_data_ra(CPUArchState
*env
, abi_ptr ptr
, uintptr_t retaddr
)
809 set_helper_retaddr(retaddr
);
810 ret
= cpu_ldub_data(env
, ptr
);
811 clear_helper_retaddr();
815 int cpu_ldsb_data_ra(CPUArchState
*env
, abi_ptr ptr
, uintptr_t retaddr
)
819 set_helper_retaddr(retaddr
);
820 ret
= cpu_ldsb_data(env
, ptr
);
821 clear_helper_retaddr();
825 uint32_t cpu_lduw_data_ra(CPUArchState
*env
, abi_ptr ptr
, uintptr_t retaddr
)
829 set_helper_retaddr(retaddr
);
830 ret
= cpu_lduw_data(env
, ptr
);
831 clear_helper_retaddr();
835 int cpu_ldsw_data_ra(CPUArchState
*env
, abi_ptr ptr
, uintptr_t retaddr
)
839 set_helper_retaddr(retaddr
);
840 ret
= cpu_ldsw_data(env
, ptr
);
841 clear_helper_retaddr();
845 uint32_t cpu_ldl_data_ra(CPUArchState
*env
, abi_ptr ptr
, uintptr_t retaddr
)
849 set_helper_retaddr(retaddr
);
850 ret
= cpu_ldl_data(env
, ptr
);
851 clear_helper_retaddr();
855 uint64_t cpu_ldq_data_ra(CPUArchState
*env
, abi_ptr ptr
, uintptr_t retaddr
)
859 set_helper_retaddr(retaddr
);
860 ret
= cpu_ldq_data(env
, ptr
);
861 clear_helper_retaddr();
865 void cpu_stb_data(CPUArchState
*env
, abi_ptr ptr
, uint32_t val
)
867 uint16_t meminfo
= trace_mem_get_info(MO_UB
, MMU_USER_IDX
, true);
869 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
870 stb_p(g2h(ptr
), val
);
871 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
874 void cpu_stw_data(CPUArchState
*env
, abi_ptr ptr
, uint32_t val
)
876 uint16_t meminfo
= trace_mem_get_info(MO_TEUW
, MMU_USER_IDX
, true);
878 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
879 stw_p(g2h(ptr
), val
);
880 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
883 void cpu_stl_data(CPUArchState
*env
, abi_ptr ptr
, uint32_t val
)
885 uint16_t meminfo
= trace_mem_get_info(MO_TEUL
, MMU_USER_IDX
, true);
887 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
888 stl_p(g2h(ptr
), val
);
889 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
892 void cpu_stq_data(CPUArchState
*env
, abi_ptr ptr
, uint64_t val
)
894 uint16_t meminfo
= trace_mem_get_info(MO_TEQ
, MMU_USER_IDX
, true);
896 trace_guest_mem_before_exec(env_cpu(env
), ptr
, meminfo
);
897 stq_p(g2h(ptr
), val
);
898 qemu_plugin_vcpu_mem_cb(env_cpu(env
), ptr
, meminfo
);
901 void cpu_stb_data_ra(CPUArchState
*env
, abi_ptr ptr
,
902 uint32_t val
, uintptr_t retaddr
)
904 set_helper_retaddr(retaddr
);
905 cpu_stb_data(env
, ptr
, val
);
906 clear_helper_retaddr();
909 void cpu_stw_data_ra(CPUArchState
*env
, abi_ptr ptr
,
910 uint32_t val
, uintptr_t retaddr
)
912 set_helper_retaddr(retaddr
);
913 cpu_stw_data(env
, ptr
, val
);
914 clear_helper_retaddr();
917 void cpu_stl_data_ra(CPUArchState
*env
, abi_ptr ptr
,
918 uint32_t val
, uintptr_t retaddr
)
920 set_helper_retaddr(retaddr
);
921 cpu_stl_data(env
, ptr
, val
);
922 clear_helper_retaddr();
925 void cpu_stq_data_ra(CPUArchState
*env
, abi_ptr ptr
,
926 uint64_t val
, uintptr_t retaddr
)
928 set_helper_retaddr(retaddr
);
929 cpu_stq_data(env
, ptr
, val
);
930 clear_helper_retaddr();
933 uint32_t cpu_ldub_code(CPUArchState
*env
, abi_ptr ptr
)
937 set_helper_retaddr(1);
938 ret
= ldub_p(g2h(ptr
));
939 clear_helper_retaddr();
943 uint32_t cpu_lduw_code(CPUArchState
*env
, abi_ptr ptr
)
947 set_helper_retaddr(1);
948 ret
= lduw_p(g2h(ptr
));
949 clear_helper_retaddr();
953 uint32_t cpu_ldl_code(CPUArchState
*env
, abi_ptr ptr
)
957 set_helper_retaddr(1);
958 ret
= ldl_p(g2h(ptr
));
959 clear_helper_retaddr();
963 uint64_t cpu_ldq_code(CPUArchState
*env
, abi_ptr ptr
)
967 set_helper_retaddr(1);
968 ret
= ldq_p(g2h(ptr
));
969 clear_helper_retaddr();
973 /* Do not allow unaligned operations to proceed. Return the host address. */
974 static void *atomic_mmu_lookup(CPUArchState
*env
, target_ulong addr
,
975 int size
, uintptr_t retaddr
)
977 /* Enforce qemu required alignment. */
978 if (unlikely(addr
& (size
- 1))) {
979 cpu_loop_exit_atomic(env_cpu(env
), retaddr
);
981 void *ret
= g2h(addr
);
982 set_helper_retaddr(retaddr
);
986 /* Macro to call the above, with local variables from the use context. */
987 #define ATOMIC_MMU_DECLS do {} while (0)
988 #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC())
989 #define ATOMIC_MMU_CLEANUP do { clear_helper_retaddr(); } while (0)
990 #define ATOMIC_MMU_IDX MMU_USER_IDX
992 #define ATOMIC_NAME(X) HELPER(glue(glue(atomic_ ## X, SUFFIX), END))
995 #include "atomic_common.inc.c"
998 #include "atomic_template.h"
1001 #include "atomic_template.h"
1004 #include "atomic_template.h"
1006 #ifdef CONFIG_ATOMIC64
1008 #include "atomic_template.h"
1011 /* The following is only callable from other helpers, and matches up
1012 with the softmmu version. */
1014 #if HAVE_ATOMIC128 || HAVE_CMPXCHG128
1018 #undef ATOMIC_MMU_LOOKUP
1020 #define EXTRA_ARGS , TCGMemOpIdx oi, uintptr_t retaddr
1021 #define ATOMIC_NAME(X) \
1022 HELPER(glue(glue(glue(atomic_ ## X, SUFFIX), END), _mmu))
1023 #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, retaddr)
1025 #define DATA_SIZE 16
1026 #include "atomic_template.h"