4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
20 #include "qemu-version.h"
21 #include <sys/syscall.h>
22 #include <sys/resource.h>
24 #include "qapi/error.h"
26 #include "qemu/path.h"
27 #include "qemu/config-file.h"
28 #include "qemu/cutils.h"
29 #include "qemu/help_option.h"
31 #include "exec/exec-all.h"
33 #include "qemu/timer.h"
34 #include "qemu/envlist.h"
37 #include "trace/control.h"
38 #include "target_elf.h"
43 static const char *filename
;
44 static const char *argv0
;
45 static int gdbstub_port
;
46 static envlist_t
*envlist
;
47 static const char *cpu_model
;
48 static const char *cpu_type
;
49 unsigned long mmap_min_addr
;
50 unsigned long guest_base
;
53 #define EXCP_DUMP(env, fmt, ...) \
55 CPUState *cs = ENV_GET_CPU(env); \
56 fprintf(stderr, fmt , ## __VA_ARGS__); \
57 cpu_dump_state(cs, stderr, fprintf, 0); \
58 if (qemu_log_separate()) { \
59 qemu_log(fmt, ## __VA_ARGS__); \
60 log_cpu_state(cs, 0); \
65 * When running 32-on-64 we should make sure we can fit all of the possible
66 * guest address space into a contiguous chunk of virtual host memory.
68 * This way we will never overlap with our own libraries or binaries or stack
69 * or anything else that QEMU maps.
71 * Many cpus reserve the high bit (or more than one for some 64-bit cpus)
72 * of the address for the kernel. Some cpus rely on this and user space
73 * uses the high bit(s) for pointer tagging and the like. For them, we
74 * must preserve the expected address space.
76 #ifndef MAX_RESERVED_VA
77 # if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
78 # if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \
79 (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32))
80 /* There are a number of places where we assign reserved_va to a variable
81 of type abi_ulong and expect it to fit. Avoid the last page. */
82 # define MAX_RESERVED_VA (0xfffffffful & TARGET_PAGE_MASK)
84 # define MAX_RESERVED_VA (1ul << TARGET_VIRT_ADDR_SPACE_BITS)
87 # define MAX_RESERVED_VA 0
91 /* That said, reserving *too* much vm space via mmap can run into problems
92 with rlimits, oom due to page table creation, etc. We will still try it,
93 if directed by the command-line option, but not by default. */
94 #if HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32
95 unsigned long reserved_va
= MAX_RESERVED_VA
;
97 unsigned long reserved_va
;
100 static void usage(int exitcode
);
102 static const char *interp_prefix
= CONFIG_QEMU_INTERP_PREFIX
;
103 const char *qemu_uname_release
;
105 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
106 we allocate a bigger stack. Need a better solution, for example
107 by remapping the process stack directly at the right place */
108 unsigned long guest_stack_size
= 8 * 1024 * 1024UL;
110 void gemu_log(const char *fmt
, ...)
115 vfprintf(stderr
, fmt
, ap
);
119 #if defined(TARGET_I386)
120 int cpu_get_pic_interrupt(CPUX86State
*env
)
126 /***********************************************************/
127 /* Helper routines for implementing atomic operations. */
129 /* Make sure everything is in a consistent state for calling fork(). */
130 void fork_start(void)
134 qemu_mutex_lock(&tb_ctx
.tb_lock
);
138 void fork_end(int child
)
140 mmap_fork_end(child
);
142 CPUState
*cpu
, *next_cpu
;
143 /* Child processes created by fork() only have a single thread.
144 Discard information about the parent threads. */
145 CPU_FOREACH_SAFE(cpu
, next_cpu
) {
146 if (cpu
!= thread_cpu
) {
147 QTAILQ_REMOVE(&cpus
, cpu
, node
);
150 qemu_mutex_init(&tb_ctx
.tb_lock
);
151 qemu_init_cpu_list();
152 gdbserver_fork(thread_cpu
);
153 /* qemu_init_cpu_list() takes care of reinitializing the
154 * exclusive state, so we don't need to end_exclusive() here.
157 qemu_mutex_unlock(&tb_ctx
.tb_lock
);
164 /***********************************************************/
165 /* CPUX86 core interface */
167 uint64_t cpu_get_tsc(CPUX86State
*env
)
169 return cpu_get_host_ticks();
172 static void write_dt(void *ptr
, unsigned long addr
, unsigned long limit
,
177 e1
= (addr
<< 16) | (limit
& 0xffff);
178 e2
= ((addr
>> 16) & 0xff) | (addr
& 0xff000000) | (limit
& 0x000f0000);
185 static uint64_t *idt_table
;
187 static void set_gate64(void *ptr
, unsigned int type
, unsigned int dpl
,
188 uint64_t addr
, unsigned int sel
)
191 e1
= (addr
& 0xffff) | (sel
<< 16);
192 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
196 p
[2] = tswap32(addr
>> 32);
199 /* only dpl matters as we do only user space emulation */
200 static void set_idt(int n
, unsigned int dpl
)
202 set_gate64(idt_table
+ n
* 2, 0, dpl
, 0, 0);
205 static void set_gate(void *ptr
, unsigned int type
, unsigned int dpl
,
206 uint32_t addr
, unsigned int sel
)
209 e1
= (addr
& 0xffff) | (sel
<< 16);
210 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
216 /* only dpl matters as we do only user space emulation */
217 static void set_idt(int n
, unsigned int dpl
)
219 set_gate(idt_table
+ n
, 0, dpl
, 0, 0);
223 void cpu_loop(CPUX86State
*env
)
225 CPUState
*cs
= CPU(x86_env_get_cpu(env
));
229 target_siginfo_t info
;
233 trapnr
= cpu_exec(cs
);
235 process_queued_cpu_work(cs
);
239 /* linux syscall from int $0x80 */
240 ret
= do_syscall(env
,
249 if (ret
== -TARGET_ERESTARTSYS
) {
251 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
252 env
->regs
[R_EAX
] = ret
;
257 /* linux syscall from syscall instruction */
258 ret
= do_syscall(env
,
267 if (ret
== -TARGET_ERESTARTSYS
) {
269 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
270 env
->regs
[R_EAX
] = ret
;
276 info
.si_signo
= TARGET_SIGBUS
;
278 info
.si_code
= TARGET_SI_KERNEL
;
279 info
._sifields
._sigfault
._addr
= 0;
280 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
283 /* XXX: potential problem if ABI32 */
284 #ifndef TARGET_X86_64
285 if (env
->eflags
& VM_MASK
) {
286 handle_vm86_fault(env
);
290 info
.si_signo
= TARGET_SIGSEGV
;
292 info
.si_code
= TARGET_SI_KERNEL
;
293 info
._sifields
._sigfault
._addr
= 0;
294 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
298 info
.si_signo
= TARGET_SIGSEGV
;
300 if (!(env
->error_code
& 1))
301 info
.si_code
= TARGET_SEGV_MAPERR
;
303 info
.si_code
= TARGET_SEGV_ACCERR
;
304 info
._sifields
._sigfault
._addr
= env
->cr
[2];
305 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
308 #ifndef TARGET_X86_64
309 if (env
->eflags
& VM_MASK
) {
310 handle_vm86_trap(env
, trapnr
);
314 /* division by zero */
315 info
.si_signo
= TARGET_SIGFPE
;
317 info
.si_code
= TARGET_FPE_INTDIV
;
318 info
._sifields
._sigfault
._addr
= env
->eip
;
319 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
324 #ifndef TARGET_X86_64
325 if (env
->eflags
& VM_MASK
) {
326 handle_vm86_trap(env
, trapnr
);
330 info
.si_signo
= TARGET_SIGTRAP
;
332 if (trapnr
== EXCP01_DB
) {
333 info
.si_code
= TARGET_TRAP_BRKPT
;
334 info
._sifields
._sigfault
._addr
= env
->eip
;
336 info
.si_code
= TARGET_SI_KERNEL
;
337 info
._sifields
._sigfault
._addr
= 0;
339 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
344 #ifndef TARGET_X86_64
345 if (env
->eflags
& VM_MASK
) {
346 handle_vm86_trap(env
, trapnr
);
350 info
.si_signo
= TARGET_SIGSEGV
;
352 info
.si_code
= TARGET_SI_KERNEL
;
353 info
._sifields
._sigfault
._addr
= 0;
354 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
358 info
.si_signo
= TARGET_SIGILL
;
360 info
.si_code
= TARGET_ILL_ILLOPN
;
361 info
._sifields
._sigfault
._addr
= env
->eip
;
362 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
365 /* just indicate that signals should be handled asap */
371 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
376 info
.si_code
= TARGET_TRAP_BRKPT
;
377 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
382 cpu_exec_step_atomic(cs
);
385 pc
= env
->segs
[R_CS
].base
+ env
->eip
;
386 EXCP_DUMP(env
, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
390 process_pending_signals(env
);
397 #define get_user_code_u32(x, gaddr, env) \
398 ({ abi_long __r = get_user_u32((x), (gaddr)); \
399 if (!__r && bswap_code(arm_sctlr_b(env))) { \
405 #define get_user_code_u16(x, gaddr, env) \
406 ({ abi_long __r = get_user_u16((x), (gaddr)); \
407 if (!__r && bswap_code(arm_sctlr_b(env))) { \
413 #define get_user_data_u32(x, gaddr, env) \
414 ({ abi_long __r = get_user_u32((x), (gaddr)); \
415 if (!__r && arm_cpu_bswap_data(env)) { \
421 #define get_user_data_u16(x, gaddr, env) \
422 ({ abi_long __r = get_user_u16((x), (gaddr)); \
423 if (!__r && arm_cpu_bswap_data(env)) { \
429 #define put_user_data_u32(x, gaddr, env) \
430 ({ typeof(x) __x = (x); \
431 if (arm_cpu_bswap_data(env)) { \
432 __x = bswap32(__x); \
434 put_user_u32(__x, (gaddr)); \
437 #define put_user_data_u16(x, gaddr, env) \
438 ({ typeof(x) __x = (x); \
439 if (arm_cpu_bswap_data(env)) { \
440 __x = bswap16(__x); \
442 put_user_u16(__x, (gaddr)); \
446 /* Commpage handling -- there is no commpage for AArch64 */
449 * See the Linux kernel's Documentation/arm/kernel_user_helpers.txt
451 * r0 = pointer to oldval
452 * r1 = pointer to newval
453 * r2 = pointer to target value
456 * r0 = 0 if *ptr was changed, non-0 if no exchange happened
457 * C set if *ptr was changed, clear if no exchange happened
459 * Note segv's in kernel helpers are a bit tricky, we can set the
460 * data address sensibly but the PC address is just the entry point.
462 static void arm_kernel_cmpxchg64_helper(CPUARMState
*env
)
464 uint64_t oldval
, newval
, val
;
466 target_siginfo_t info
;
468 /* Based on the 32 bit code in do_kernel_trap */
470 /* XXX: This only works between threads, not between processes.
471 It's probably possible to implement this with native host
472 operations. However things like ldrex/strex are much harder so
473 there's not much point trying. */
475 cpsr
= cpsr_read(env
);
478 if (get_user_u64(oldval
, env
->regs
[0])) {
479 env
->exception
.vaddress
= env
->regs
[0];
483 if (get_user_u64(newval
, env
->regs
[1])) {
484 env
->exception
.vaddress
= env
->regs
[1];
488 if (get_user_u64(val
, addr
)) {
489 env
->exception
.vaddress
= addr
;
496 if (put_user_u64(val
, addr
)) {
497 env
->exception
.vaddress
= addr
;
507 cpsr_write(env
, cpsr
, CPSR_C
, CPSRWriteByInstr
);
513 /* We get the PC of the entry address - which is as good as anything,
514 on a real kernel what you get depends on which mode it uses. */
515 info
.si_signo
= TARGET_SIGSEGV
;
517 /* XXX: check env->error_code */
518 info
.si_code
= TARGET_SEGV_MAPERR
;
519 info
._sifields
._sigfault
._addr
= env
->exception
.vaddress
;
520 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
523 /* Handle a jump to the kernel code page. */
525 do_kernel_trap(CPUARMState
*env
)
531 switch (env
->regs
[15]) {
532 case 0xffff0fa0: /* __kernel_memory_barrier */
533 /* ??? No-op. Will need to do better for SMP. */
535 case 0xffff0fc0: /* __kernel_cmpxchg */
536 /* XXX: This only works between threads, not between processes.
537 It's probably possible to implement this with native host
538 operations. However things like ldrex/strex are much harder so
539 there's not much point trying. */
541 cpsr
= cpsr_read(env
);
543 /* FIXME: This should SEGV if the access fails. */
544 if (get_user_u32(val
, addr
))
546 if (val
== env
->regs
[0]) {
548 /* FIXME: Check for segfaults. */
549 put_user_u32(val
, addr
);
556 cpsr_write(env
, cpsr
, CPSR_C
, CPSRWriteByInstr
);
559 case 0xffff0fe0: /* __kernel_get_tls */
560 env
->regs
[0] = cpu_get_tls(env
);
562 case 0xffff0f60: /* __kernel_cmpxchg64 */
563 arm_kernel_cmpxchg64_helper(env
);
569 /* Jump back to the caller. */
570 addr
= env
->regs
[14];
575 env
->regs
[15] = addr
;
580 void cpu_loop(CPUARMState
*env
)
582 CPUState
*cs
= CPU(arm_env_get_cpu(env
));
584 unsigned int n
, insn
;
585 target_siginfo_t info
;
591 trapnr
= cpu_exec(cs
);
593 process_queued_cpu_work(cs
);
600 TaskState
*ts
= cs
->opaque
;
604 /* we handle the FPU emulation here, as Linux */
605 /* we get the opcode */
606 /* FIXME - what to do if get_user() fails? */
607 get_user_code_u32(opcode
, env
->regs
[15], env
);
609 rc
= EmulateAll(opcode
, &ts
->fpa
, env
);
610 if (rc
== 0) { /* illegal instruction */
611 info
.si_signo
= TARGET_SIGILL
;
613 info
.si_code
= TARGET_ILL_ILLOPN
;
614 info
._sifields
._sigfault
._addr
= env
->regs
[15];
615 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
616 } else if (rc
< 0) { /* FP exception */
619 /* translate softfloat flags to FPSR flags */
620 if (-rc
& float_flag_invalid
)
622 if (-rc
& float_flag_divbyzero
)
624 if (-rc
& float_flag_overflow
)
626 if (-rc
& float_flag_underflow
)
628 if (-rc
& float_flag_inexact
)
631 FPSR fpsr
= ts
->fpa
.fpsr
;
632 //printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe);
634 if (fpsr
& (arm_fpe
<< 16)) { /* exception enabled? */
635 info
.si_signo
= TARGET_SIGFPE
;
638 /* ordered by priority, least first */
639 if (arm_fpe
& BIT_IXC
) info
.si_code
= TARGET_FPE_FLTRES
;
640 if (arm_fpe
& BIT_UFC
) info
.si_code
= TARGET_FPE_FLTUND
;
641 if (arm_fpe
& BIT_OFC
) info
.si_code
= TARGET_FPE_FLTOVF
;
642 if (arm_fpe
& BIT_DZC
) info
.si_code
= TARGET_FPE_FLTDIV
;
643 if (arm_fpe
& BIT_IOC
) info
.si_code
= TARGET_FPE_FLTINV
;
645 info
._sifields
._sigfault
._addr
= env
->regs
[15];
646 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
651 /* accumulate unenabled exceptions */
652 if ((!(fpsr
& BIT_IXE
)) && (arm_fpe
& BIT_IXC
))
654 if ((!(fpsr
& BIT_UFE
)) && (arm_fpe
& BIT_UFC
))
656 if ((!(fpsr
& BIT_OFE
)) && (arm_fpe
& BIT_OFC
))
658 if ((!(fpsr
& BIT_DZE
)) && (arm_fpe
& BIT_DZC
))
660 if ((!(fpsr
& BIT_IOE
)) && (arm_fpe
& BIT_IOC
))
663 } else { /* everything OK */
674 if (trapnr
== EXCP_BKPT
) {
676 /* FIXME - what to do if get_user() fails? */
677 get_user_code_u16(insn
, env
->regs
[15], env
);
681 /* FIXME - what to do if get_user() fails? */
682 get_user_code_u32(insn
, env
->regs
[15], env
);
683 n
= (insn
& 0xf) | ((insn
>> 4) & 0xff0);
688 /* FIXME - what to do if get_user() fails? */
689 get_user_code_u16(insn
, env
->regs
[15] - 2, env
);
692 /* FIXME - what to do if get_user() fails? */
693 get_user_code_u32(insn
, env
->regs
[15] - 4, env
);
698 if (n
== ARM_NR_cacheflush
) {
700 } else if (n
== ARM_NR_semihosting
701 || n
== ARM_NR_thumb_semihosting
) {
702 env
->regs
[0] = do_arm_semihosting (env
);
703 } else if (n
== 0 || n
>= ARM_SYSCALL_BASE
|| env
->thumb
) {
705 if (env
->thumb
|| n
== 0) {
708 n
-= ARM_SYSCALL_BASE
;
711 if ( n
> ARM_NR_BASE
) {
713 case ARM_NR_cacheflush
:
717 cpu_set_tls(env
, env
->regs
[0]);
720 case ARM_NR_breakpoint
:
721 env
->regs
[15] -= env
->thumb
? 2 : 4;
724 gemu_log("qemu: Unsupported ARM syscall: 0x%x\n",
726 env
->regs
[0] = -TARGET_ENOSYS
;
730 ret
= do_syscall(env
,
739 if (ret
== -TARGET_ERESTARTSYS
) {
740 env
->regs
[15] -= env
->thumb
? 2 : 4;
741 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
751 env
->regs
[0] = do_arm_semihosting(env
);
754 /* just indicate that signals should be handled asap */
756 case EXCP_PREFETCH_ABORT
:
757 case EXCP_DATA_ABORT
:
758 addr
= env
->exception
.vaddress
;
760 info
.si_signo
= TARGET_SIGSEGV
;
762 /* XXX: check env->error_code */
763 info
.si_code
= TARGET_SEGV_MAPERR
;
764 info
._sifields
._sigfault
._addr
= addr
;
765 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
773 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
778 info
.si_code
= TARGET_TRAP_BRKPT
;
779 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
783 case EXCP_KERNEL_TRAP
:
784 if (do_kernel_trap(env
))
788 /* nothing to do here for user-mode, just resume guest code */
791 cpu_exec_step_atomic(cs
);
795 EXCP_DUMP(env
, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr
);
798 process_pending_signals(env
);
804 /* AArch64 main loop */
805 void cpu_loop(CPUARMState
*env
)
807 CPUState
*cs
= CPU(arm_env_get_cpu(env
));
810 target_siginfo_t info
;
814 trapnr
= cpu_exec(cs
);
816 process_queued_cpu_work(cs
);
820 ret
= do_syscall(env
,
829 if (ret
== -TARGET_ERESTARTSYS
) {
831 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
836 /* just indicate that signals should be handled asap */
839 info
.si_signo
= TARGET_SIGILL
;
841 info
.si_code
= TARGET_ILL_ILLOPN
;
842 info
._sifields
._sigfault
._addr
= env
->pc
;
843 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
845 case EXCP_PREFETCH_ABORT
:
846 case EXCP_DATA_ABORT
:
847 info
.si_signo
= TARGET_SIGSEGV
;
849 /* XXX: check env->error_code */
850 info
.si_code
= TARGET_SEGV_MAPERR
;
851 info
._sifields
._sigfault
._addr
= env
->exception
.vaddress
;
852 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
856 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
860 info
.si_code
= TARGET_TRAP_BRKPT
;
861 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
865 env
->xregs
[0] = do_arm_semihosting(env
);
868 /* nothing to do here for user-mode, just resume guest code */
871 cpu_exec_step_atomic(cs
);
874 EXCP_DUMP(env
, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr
);
877 process_pending_signals(env
);
878 /* Exception return on AArch64 always clears the exclusive monitor,
879 * so any return to running guest code implies this.
881 env
->exclusive_addr
= -1;
884 #endif /* ndef TARGET_ABI32 */
889 #define SPARC64_STACK_BIAS 2047
893 /* WARNING: dealing with register windows _is_ complicated. More info
894 can be found at http://www.sics.se/~psm/sparcstack.html */
895 static inline int get_reg_index(CPUSPARCState
*env
, int cwp
, int index
)
897 index
= (index
+ cwp
* 16) % (16 * env
->nwindows
);
898 /* wrap handling : if cwp is on the last window, then we use the
899 registers 'after' the end */
900 if (index
< 8 && env
->cwp
== env
->nwindows
- 1)
901 index
+= 16 * env
->nwindows
;
905 /* save the register window 'cwp1' */
906 static inline void save_window_offset(CPUSPARCState
*env
, int cwp1
)
911 sp_ptr
= env
->regbase
[get_reg_index(env
, cwp1
, 6)];
912 #ifdef TARGET_SPARC64
914 sp_ptr
+= SPARC64_STACK_BIAS
;
916 #if defined(DEBUG_WIN)
917 printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx
" save_cwp=%d\n",
920 for(i
= 0; i
< 16; i
++) {
921 /* FIXME - what to do if put_user() fails? */
922 put_user_ual(env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)], sp_ptr
);
923 sp_ptr
+= sizeof(abi_ulong
);
927 static void save_window(CPUSPARCState
*env
)
929 #ifndef TARGET_SPARC64
930 unsigned int new_wim
;
931 new_wim
= ((env
->wim
>> 1) | (env
->wim
<< (env
->nwindows
- 1))) &
932 ((1LL << env
->nwindows
) - 1);
933 save_window_offset(env
, cpu_cwp_dec(env
, env
->cwp
- 2));
936 save_window_offset(env
, cpu_cwp_dec(env
, env
->cwp
- 2));
942 static void restore_window(CPUSPARCState
*env
)
944 #ifndef TARGET_SPARC64
945 unsigned int new_wim
;
947 unsigned int i
, cwp1
;
950 #ifndef TARGET_SPARC64
951 new_wim
= ((env
->wim
<< 1) | (env
->wim
>> (env
->nwindows
- 1))) &
952 ((1LL << env
->nwindows
) - 1);
955 /* restore the invalid window */
956 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ 1);
957 sp_ptr
= env
->regbase
[get_reg_index(env
, cwp1
, 6)];
958 #ifdef TARGET_SPARC64
960 sp_ptr
+= SPARC64_STACK_BIAS
;
962 #if defined(DEBUG_WIN)
963 printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx
" load_cwp=%d\n",
966 for(i
= 0; i
< 16; i
++) {
967 /* FIXME - what to do if get_user() fails? */
968 get_user_ual(env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)], sp_ptr
);
969 sp_ptr
+= sizeof(abi_ulong
);
971 #ifdef TARGET_SPARC64
973 if (env
->cleanwin
< env
->nwindows
- 1)
981 static void flush_windows(CPUSPARCState
*env
)
987 /* if restore would invoke restore_window(), then we can stop */
988 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ offset
);
989 #ifndef TARGET_SPARC64
990 if (env
->wim
& (1 << cwp1
))
993 if (env
->canrestore
== 0)
998 save_window_offset(env
, cwp1
);
1001 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ 1);
1002 #ifndef TARGET_SPARC64
1003 /* set wim so that restore will reload the registers */
1004 env
->wim
= 1 << cwp1
;
1006 #if defined(DEBUG_WIN)
1007 printf("flush_windows: nb=%d\n", offset
- 1);
1011 void cpu_loop (CPUSPARCState
*env
)
1013 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
1016 target_siginfo_t info
;
1020 trapnr
= cpu_exec(cs
);
1022 process_queued_cpu_work(cs
);
1024 /* Compute PSR before exposing state. */
1025 if (env
->cc_op
!= CC_OP_FLAGS
) {
1030 #ifndef TARGET_SPARC64
1037 ret
= do_syscall (env
, env
->gregs
[1],
1038 env
->regwptr
[0], env
->regwptr
[1],
1039 env
->regwptr
[2], env
->regwptr
[3],
1040 env
->regwptr
[4], env
->regwptr
[5],
1042 if (ret
== -TARGET_ERESTARTSYS
|| ret
== -TARGET_QEMU_ESIGRETURN
) {
1045 if ((abi_ulong
)ret
>= (abi_ulong
)(-515)) {
1046 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1047 env
->xcc
|= PSR_CARRY
;
1049 env
->psr
|= PSR_CARRY
;
1053 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1054 env
->xcc
&= ~PSR_CARRY
;
1056 env
->psr
&= ~PSR_CARRY
;
1059 env
->regwptr
[0] = ret
;
1060 /* next instruction */
1062 env
->npc
= env
->npc
+ 4;
1064 case 0x83: /* flush windows */
1069 /* next instruction */
1071 env
->npc
= env
->npc
+ 4;
1073 #ifndef TARGET_SPARC64
1074 case TT_WIN_OVF
: /* window overflow */
1077 case TT_WIN_UNF
: /* window underflow */
1078 restore_window(env
);
1083 info
.si_signo
= TARGET_SIGSEGV
;
1085 /* XXX: check env->error_code */
1086 info
.si_code
= TARGET_SEGV_MAPERR
;
1087 info
._sifields
._sigfault
._addr
= env
->mmuregs
[4];
1088 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1092 case TT_SPILL
: /* window overflow */
1095 case TT_FILL
: /* window underflow */
1096 restore_window(env
);
1101 info
.si_signo
= TARGET_SIGSEGV
;
1103 /* XXX: check env->error_code */
1104 info
.si_code
= TARGET_SEGV_MAPERR
;
1105 if (trapnr
== TT_DFAULT
)
1106 info
._sifields
._sigfault
._addr
= env
->dmmu
.mmuregs
[4];
1108 info
._sifields
._sigfault
._addr
= cpu_tsptr(env
)->tpc
;
1109 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1112 #ifndef TARGET_ABI32
1115 sparc64_get_context(env
);
1119 sparc64_set_context(env
);
1123 case EXCP_INTERRUPT
:
1124 /* just indicate that signals should be handled asap */
1128 info
.si_signo
= TARGET_SIGILL
;
1130 info
.si_code
= TARGET_ILL_ILLOPC
;
1131 info
._sifields
._sigfault
._addr
= env
->pc
;
1132 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1139 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
1142 info
.si_signo
= sig
;
1144 info
.si_code
= TARGET_TRAP_BRKPT
;
1145 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1150 cpu_exec_step_atomic(cs
);
1153 printf ("Unhandled trap: 0x%x\n", trapnr
);
1154 cpu_dump_state(cs
, stderr
, fprintf
, 0);
1157 process_pending_signals (env
);
1164 static inline uint64_t cpu_ppc_get_tb(CPUPPCState
*env
)
1166 return cpu_get_host_ticks();
1169 uint64_t cpu_ppc_load_tbl(CPUPPCState
*env
)
1171 return cpu_ppc_get_tb(env
);
1174 uint32_t cpu_ppc_load_tbu(CPUPPCState
*env
)
1176 return cpu_ppc_get_tb(env
) >> 32;
1179 uint64_t cpu_ppc_load_atbl(CPUPPCState
*env
)
1181 return cpu_ppc_get_tb(env
);
1184 uint32_t cpu_ppc_load_atbu(CPUPPCState
*env
)
1186 return cpu_ppc_get_tb(env
) >> 32;
1189 uint32_t cpu_ppc601_load_rtcu(CPUPPCState
*env
)
1190 __attribute__ (( alias ("cpu_ppc_load_tbu") ));
1192 uint32_t cpu_ppc601_load_rtcl(CPUPPCState
*env
)
1194 return cpu_ppc_load_tbl(env
) & 0x3FFFFF80;
1197 /* XXX: to be fixed */
1198 int ppc_dcr_read (ppc_dcr_t
*dcr_env
, int dcrn
, uint32_t *valp
)
1203 int ppc_dcr_write (ppc_dcr_t
*dcr_env
, int dcrn
, uint32_t val
)
1208 static int do_store_exclusive(CPUPPCState
*env
)
1211 target_ulong page_addr
;
1212 target_ulong val
, val2
__attribute__((unused
)) = 0;
1216 addr
= env
->reserve_ea
;
1217 page_addr
= addr
& TARGET_PAGE_MASK
;
1220 flags
= page_get_flags(page_addr
);
1221 if ((flags
& PAGE_READ
) == 0) {
1224 int reg
= env
->reserve_info
& 0x1f;
1225 int size
= env
->reserve_info
>> 5;
1228 if (addr
== env
->reserve_addr
) {
1230 case 1: segv
= get_user_u8(val
, addr
); break;
1231 case 2: segv
= get_user_u16(val
, addr
); break;
1232 case 4: segv
= get_user_u32(val
, addr
); break;
1233 #if defined(TARGET_PPC64)
1234 case 8: segv
= get_user_u64(val
, addr
); break;
1236 segv
= get_user_u64(val
, addr
);
1238 segv
= get_user_u64(val2
, addr
+ 8);
1245 if (!segv
&& val
== env
->reserve_val
) {
1246 val
= env
->gpr
[reg
];
1248 case 1: segv
= put_user_u8(val
, addr
); break;
1249 case 2: segv
= put_user_u16(val
, addr
); break;
1250 case 4: segv
= put_user_u32(val
, addr
); break;
1251 #if defined(TARGET_PPC64)
1252 case 8: segv
= put_user_u64(val
, addr
); break;
1254 if (val2
== env
->reserve_val2
) {
1257 val
= env
->gpr
[reg
+1];
1259 val2
= env
->gpr
[reg
+1];
1261 segv
= put_user_u64(val
, addr
);
1263 segv
= put_user_u64(val2
, addr
+ 8);
1276 env
->crf
[0] = (stored
<< 1) | xer_so
;
1277 env
->reserve_addr
= (target_ulong
)-1;
1287 void cpu_loop(CPUPPCState
*env
)
1289 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
1290 target_siginfo_t info
;
1296 trapnr
= cpu_exec(cs
);
1298 process_queued_cpu_work(cs
);
1301 case POWERPC_EXCP_NONE
:
1304 case POWERPC_EXCP_CRITICAL
: /* Critical input */
1305 cpu_abort(cs
, "Critical interrupt while in user mode. "
1308 case POWERPC_EXCP_MCHECK
: /* Machine check exception */
1309 cpu_abort(cs
, "Machine check exception while in user mode. "
1312 case POWERPC_EXCP_DSI
: /* Data storage exception */
1313 /* XXX: check this. Seems bugged */
1314 switch (env
->error_code
& 0xFF000000) {
1317 info
.si_signo
= TARGET_SIGSEGV
;
1319 info
.si_code
= TARGET_SEGV_MAPERR
;
1322 info
.si_signo
= TARGET_SIGILL
;
1324 info
.si_code
= TARGET_ILL_ILLADR
;
1327 info
.si_signo
= TARGET_SIGSEGV
;
1329 info
.si_code
= TARGET_SEGV_ACCERR
;
1332 /* Let's send a regular segfault... */
1333 EXCP_DUMP(env
, "Invalid segfault errno (%02x)\n",
1335 info
.si_signo
= TARGET_SIGSEGV
;
1337 info
.si_code
= TARGET_SEGV_MAPERR
;
1340 info
._sifields
._sigfault
._addr
= env
->spr
[SPR_DAR
];
1341 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1343 case POWERPC_EXCP_ISI
: /* Instruction storage exception */
1344 /* XXX: check this */
1345 switch (env
->error_code
& 0xFF000000) {
1347 info
.si_signo
= TARGET_SIGSEGV
;
1349 info
.si_code
= TARGET_SEGV_MAPERR
;
1353 info
.si_signo
= TARGET_SIGSEGV
;
1355 info
.si_code
= TARGET_SEGV_ACCERR
;
1358 /* Let's send a regular segfault... */
1359 EXCP_DUMP(env
, "Invalid segfault errno (%02x)\n",
1361 info
.si_signo
= TARGET_SIGSEGV
;
1363 info
.si_code
= TARGET_SEGV_MAPERR
;
1366 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1367 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1369 case POWERPC_EXCP_EXTERNAL
: /* External input */
1370 cpu_abort(cs
, "External interrupt while in user mode. "
1373 case POWERPC_EXCP_ALIGN
: /* Alignment exception */
1374 /* XXX: check this */
1375 info
.si_signo
= TARGET_SIGBUS
;
1377 info
.si_code
= TARGET_BUS_ADRALN
;
1378 info
._sifields
._sigfault
._addr
= env
->nip
;
1379 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1381 case POWERPC_EXCP_PROGRAM
: /* Program exception */
1382 case POWERPC_EXCP_HV_EMU
: /* HV emulation */
1383 /* XXX: check this */
1384 switch (env
->error_code
& ~0xF) {
1385 case POWERPC_EXCP_FP
:
1386 info
.si_signo
= TARGET_SIGFPE
;
1388 switch (env
->error_code
& 0xF) {
1389 case POWERPC_EXCP_FP_OX
:
1390 info
.si_code
= TARGET_FPE_FLTOVF
;
1392 case POWERPC_EXCP_FP_UX
:
1393 info
.si_code
= TARGET_FPE_FLTUND
;
1395 case POWERPC_EXCP_FP_ZX
:
1396 case POWERPC_EXCP_FP_VXZDZ
:
1397 info
.si_code
= TARGET_FPE_FLTDIV
;
1399 case POWERPC_EXCP_FP_XX
:
1400 info
.si_code
= TARGET_FPE_FLTRES
;
1402 case POWERPC_EXCP_FP_VXSOFT
:
1403 info
.si_code
= TARGET_FPE_FLTINV
;
1405 case POWERPC_EXCP_FP_VXSNAN
:
1406 case POWERPC_EXCP_FP_VXISI
:
1407 case POWERPC_EXCP_FP_VXIDI
:
1408 case POWERPC_EXCP_FP_VXIMZ
:
1409 case POWERPC_EXCP_FP_VXVC
:
1410 case POWERPC_EXCP_FP_VXSQRT
:
1411 case POWERPC_EXCP_FP_VXCVI
:
1412 info
.si_code
= TARGET_FPE_FLTSUB
;
1415 EXCP_DUMP(env
, "Unknown floating point exception (%02x)\n",
1420 case POWERPC_EXCP_INVAL
:
1421 info
.si_signo
= TARGET_SIGILL
;
1423 switch (env
->error_code
& 0xF) {
1424 case POWERPC_EXCP_INVAL_INVAL
:
1425 info
.si_code
= TARGET_ILL_ILLOPC
;
1427 case POWERPC_EXCP_INVAL_LSWX
:
1428 info
.si_code
= TARGET_ILL_ILLOPN
;
1430 case POWERPC_EXCP_INVAL_SPR
:
1431 info
.si_code
= TARGET_ILL_PRVREG
;
1433 case POWERPC_EXCP_INVAL_FP
:
1434 info
.si_code
= TARGET_ILL_COPROC
;
1437 EXCP_DUMP(env
, "Unknown invalid operation (%02x)\n",
1438 env
->error_code
& 0xF);
1439 info
.si_code
= TARGET_ILL_ILLADR
;
1443 case POWERPC_EXCP_PRIV
:
1444 info
.si_signo
= TARGET_SIGILL
;
1446 switch (env
->error_code
& 0xF) {
1447 case POWERPC_EXCP_PRIV_OPC
:
1448 info
.si_code
= TARGET_ILL_PRVOPC
;
1450 case POWERPC_EXCP_PRIV_REG
:
1451 info
.si_code
= TARGET_ILL_PRVREG
;
1454 EXCP_DUMP(env
, "Unknown privilege violation (%02x)\n",
1455 env
->error_code
& 0xF);
1456 info
.si_code
= TARGET_ILL_PRVOPC
;
1460 case POWERPC_EXCP_TRAP
:
1461 cpu_abort(cs
, "Tried to call a TRAP\n");
1464 /* Should not happen ! */
1465 cpu_abort(cs
, "Unknown program exception (%02x)\n",
1469 info
._sifields
._sigfault
._addr
= env
->nip
;
1470 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1472 case POWERPC_EXCP_FPU
: /* Floating-point unavailable exception */
1473 info
.si_signo
= TARGET_SIGILL
;
1475 info
.si_code
= TARGET_ILL_COPROC
;
1476 info
._sifields
._sigfault
._addr
= env
->nip
;
1477 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1479 case POWERPC_EXCP_SYSCALL
: /* System call exception */
1480 cpu_abort(cs
, "Syscall exception while in user mode. "
1483 case POWERPC_EXCP_APU
: /* Auxiliary processor unavailable */
1484 info
.si_signo
= TARGET_SIGILL
;
1486 info
.si_code
= TARGET_ILL_COPROC
;
1487 info
._sifields
._sigfault
._addr
= env
->nip
;
1488 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1490 case POWERPC_EXCP_DECR
: /* Decrementer exception */
1491 cpu_abort(cs
, "Decrementer interrupt while in user mode. "
1494 case POWERPC_EXCP_FIT
: /* Fixed-interval timer interrupt */
1495 cpu_abort(cs
, "Fix interval timer interrupt while in user mode. "
1498 case POWERPC_EXCP_WDT
: /* Watchdog timer interrupt */
1499 cpu_abort(cs
, "Watchdog timer interrupt while in user mode. "
1502 case POWERPC_EXCP_DTLB
: /* Data TLB error */
1503 cpu_abort(cs
, "Data TLB exception while in user mode. "
1506 case POWERPC_EXCP_ITLB
: /* Instruction TLB error */
1507 cpu_abort(cs
, "Instruction TLB exception while in user mode. "
1510 case POWERPC_EXCP_SPEU
: /* SPE/embedded floating-point unavail. */
1511 info
.si_signo
= TARGET_SIGILL
;
1513 info
.si_code
= TARGET_ILL_COPROC
;
1514 info
._sifields
._sigfault
._addr
= env
->nip
;
1515 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1517 case POWERPC_EXCP_EFPDI
: /* Embedded floating-point data IRQ */
1518 cpu_abort(cs
, "Embedded floating-point data IRQ not handled\n");
1520 case POWERPC_EXCP_EFPRI
: /* Embedded floating-point round IRQ */
1521 cpu_abort(cs
, "Embedded floating-point round IRQ not handled\n");
1523 case POWERPC_EXCP_EPERFM
: /* Embedded performance monitor IRQ */
1524 cpu_abort(cs
, "Performance monitor exception not handled\n");
1526 case POWERPC_EXCP_DOORI
: /* Embedded doorbell interrupt */
1527 cpu_abort(cs
, "Doorbell interrupt while in user mode. "
1530 case POWERPC_EXCP_DOORCI
: /* Embedded doorbell critical interrupt */
1531 cpu_abort(cs
, "Doorbell critical interrupt while in user mode. "
1534 case POWERPC_EXCP_RESET
: /* System reset exception */
1535 cpu_abort(cs
, "Reset interrupt while in user mode. "
1538 case POWERPC_EXCP_DSEG
: /* Data segment exception */
1539 cpu_abort(cs
, "Data segment exception while in user mode. "
1542 case POWERPC_EXCP_ISEG
: /* Instruction segment exception */
1543 cpu_abort(cs
, "Instruction segment exception "
1544 "while in user mode. Aborting\n");
1546 /* PowerPC 64 with hypervisor mode support */
1547 case POWERPC_EXCP_HDECR
: /* Hypervisor decrementer exception */
1548 cpu_abort(cs
, "Hypervisor decrementer interrupt "
1549 "while in user mode. Aborting\n");
1551 case POWERPC_EXCP_TRACE
: /* Trace exception */
1553 * we use this exception to emulate step-by-step execution mode.
1556 /* PowerPC 64 with hypervisor mode support */
1557 case POWERPC_EXCP_HDSI
: /* Hypervisor data storage exception */
1558 cpu_abort(cs
, "Hypervisor data storage exception "
1559 "while in user mode. Aborting\n");
1561 case POWERPC_EXCP_HISI
: /* Hypervisor instruction storage excp */
1562 cpu_abort(cs
, "Hypervisor instruction storage exception "
1563 "while in user mode. Aborting\n");
1565 case POWERPC_EXCP_HDSEG
: /* Hypervisor data segment exception */
1566 cpu_abort(cs
, "Hypervisor data segment exception "
1567 "while in user mode. Aborting\n");
1569 case POWERPC_EXCP_HISEG
: /* Hypervisor instruction segment excp */
1570 cpu_abort(cs
, "Hypervisor instruction segment exception "
1571 "while in user mode. Aborting\n");
1573 case POWERPC_EXCP_VPU
: /* Vector unavailable exception */
1574 info
.si_signo
= TARGET_SIGILL
;
1576 info
.si_code
= TARGET_ILL_COPROC
;
1577 info
._sifields
._sigfault
._addr
= env
->nip
;
1578 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1580 case POWERPC_EXCP_PIT
: /* Programmable interval timer IRQ */
1581 cpu_abort(cs
, "Programmable interval timer interrupt "
1582 "while in user mode. Aborting\n");
1584 case POWERPC_EXCP_IO
: /* IO error exception */
1585 cpu_abort(cs
, "IO error exception while in user mode. "
1588 case POWERPC_EXCP_RUNM
: /* Run mode exception */
1589 cpu_abort(cs
, "Run mode exception while in user mode. "
1592 case POWERPC_EXCP_EMUL
: /* Emulation trap exception */
1593 cpu_abort(cs
, "Emulation trap exception not handled\n");
1595 case POWERPC_EXCP_IFTLB
: /* Instruction fetch TLB error */
1596 cpu_abort(cs
, "Instruction fetch TLB exception "
1597 "while in user-mode. Aborting");
1599 case POWERPC_EXCP_DLTLB
: /* Data load TLB miss */
1600 cpu_abort(cs
, "Data load TLB exception while in user-mode. "
1603 case POWERPC_EXCP_DSTLB
: /* Data store TLB miss */
1604 cpu_abort(cs
, "Data store TLB exception while in user-mode. "
1607 case POWERPC_EXCP_FPA
: /* Floating-point assist exception */
1608 cpu_abort(cs
, "Floating-point assist exception not handled\n");
1610 case POWERPC_EXCP_IABR
: /* Instruction address breakpoint */
1611 cpu_abort(cs
, "Instruction address breakpoint exception "
1614 case POWERPC_EXCP_SMI
: /* System management interrupt */
1615 cpu_abort(cs
, "System management interrupt while in user mode. "
1618 case POWERPC_EXCP_THERM
: /* Thermal interrupt */
1619 cpu_abort(cs
, "Thermal interrupt interrupt while in user mode. "
1622 case POWERPC_EXCP_PERFM
: /* Embedded performance monitor IRQ */
1623 cpu_abort(cs
, "Performance monitor exception not handled\n");
1625 case POWERPC_EXCP_VPUA
: /* Vector assist exception */
1626 cpu_abort(cs
, "Vector assist exception not handled\n");
1628 case POWERPC_EXCP_SOFTP
: /* Soft patch exception */
1629 cpu_abort(cs
, "Soft patch exception not handled\n");
1631 case POWERPC_EXCP_MAINT
: /* Maintenance exception */
1632 cpu_abort(cs
, "Maintenance exception while in user mode. "
1635 case POWERPC_EXCP_STOP
: /* stop translation */
1636 /* We did invalidate the instruction cache. Go on */
1638 case POWERPC_EXCP_BRANCH
: /* branch instruction: */
1639 /* We just stopped because of a branch. Go on */
1641 case POWERPC_EXCP_SYSCALL_USER
:
1642 /* system call in user-mode emulation */
1644 * PPC ABI uses overflow flag in cr0 to signal an error
1647 env
->crf
[0] &= ~0x1;
1649 ret
= do_syscall(env
, env
->gpr
[0], env
->gpr
[3], env
->gpr
[4],
1650 env
->gpr
[5], env
->gpr
[6], env
->gpr
[7],
1652 if (ret
== -TARGET_ERESTARTSYS
) {
1656 if (ret
== (target_ulong
)(-TARGET_QEMU_ESIGRETURN
)) {
1657 /* Returning from a successful sigreturn syscall.
1658 Avoid corrupting register state. */
1661 if (ret
> (target_ulong
)(-515)) {
1667 case POWERPC_EXCP_STCX
:
1668 if (do_store_exclusive(env
)) {
1669 info
.si_signo
= TARGET_SIGSEGV
;
1671 info
.si_code
= TARGET_SEGV_MAPERR
;
1672 info
._sifields
._sigfault
._addr
= env
->nip
;
1673 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1680 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
1682 info
.si_signo
= sig
;
1684 info
.si_code
= TARGET_TRAP_BRKPT
;
1685 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
1689 case EXCP_INTERRUPT
:
1690 /* just indicate that signals should be handled asap */
1693 cpu_exec_step_atomic(cs
);
1696 cpu_abort(cs
, "Unknown exception 0x%x. Aborting\n", trapnr
);
1699 process_pending_signals(env
);
1706 # ifdef TARGET_ABI_MIPSO32
1707 # define MIPS_SYS(name, args) args,
1708 static const uint8_t mips_syscall_args
[] = {
1709 MIPS_SYS(sys_syscall
, 8) /* 4000 */
1710 MIPS_SYS(sys_exit
, 1)
1711 MIPS_SYS(sys_fork
, 0)
1712 MIPS_SYS(sys_read
, 3)
1713 MIPS_SYS(sys_write
, 3)
1714 MIPS_SYS(sys_open
, 3) /* 4005 */
1715 MIPS_SYS(sys_close
, 1)
1716 MIPS_SYS(sys_waitpid
, 3)
1717 MIPS_SYS(sys_creat
, 2)
1718 MIPS_SYS(sys_link
, 2)
1719 MIPS_SYS(sys_unlink
, 1) /* 4010 */
1720 MIPS_SYS(sys_execve
, 0)
1721 MIPS_SYS(sys_chdir
, 1)
1722 MIPS_SYS(sys_time
, 1)
1723 MIPS_SYS(sys_mknod
, 3)
1724 MIPS_SYS(sys_chmod
, 2) /* 4015 */
1725 MIPS_SYS(sys_lchown
, 3)
1726 MIPS_SYS(sys_ni_syscall
, 0)
1727 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_stat */
1728 MIPS_SYS(sys_lseek
, 3)
1729 MIPS_SYS(sys_getpid
, 0) /* 4020 */
1730 MIPS_SYS(sys_mount
, 5)
1731 MIPS_SYS(sys_umount
, 1)
1732 MIPS_SYS(sys_setuid
, 1)
1733 MIPS_SYS(sys_getuid
, 0)
1734 MIPS_SYS(sys_stime
, 1) /* 4025 */
1735 MIPS_SYS(sys_ptrace
, 4)
1736 MIPS_SYS(sys_alarm
, 1)
1737 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_fstat */
1738 MIPS_SYS(sys_pause
, 0)
1739 MIPS_SYS(sys_utime
, 2) /* 4030 */
1740 MIPS_SYS(sys_ni_syscall
, 0)
1741 MIPS_SYS(sys_ni_syscall
, 0)
1742 MIPS_SYS(sys_access
, 2)
1743 MIPS_SYS(sys_nice
, 1)
1744 MIPS_SYS(sys_ni_syscall
, 0) /* 4035 */
1745 MIPS_SYS(sys_sync
, 0)
1746 MIPS_SYS(sys_kill
, 2)
1747 MIPS_SYS(sys_rename
, 2)
1748 MIPS_SYS(sys_mkdir
, 2)
1749 MIPS_SYS(sys_rmdir
, 1) /* 4040 */
1750 MIPS_SYS(sys_dup
, 1)
1751 MIPS_SYS(sys_pipe
, 0)
1752 MIPS_SYS(sys_times
, 1)
1753 MIPS_SYS(sys_ni_syscall
, 0)
1754 MIPS_SYS(sys_brk
, 1) /* 4045 */
1755 MIPS_SYS(sys_setgid
, 1)
1756 MIPS_SYS(sys_getgid
, 0)
1757 MIPS_SYS(sys_ni_syscall
, 0) /* was signal(2) */
1758 MIPS_SYS(sys_geteuid
, 0)
1759 MIPS_SYS(sys_getegid
, 0) /* 4050 */
1760 MIPS_SYS(sys_acct
, 0)
1761 MIPS_SYS(sys_umount2
, 2)
1762 MIPS_SYS(sys_ni_syscall
, 0)
1763 MIPS_SYS(sys_ioctl
, 3)
1764 MIPS_SYS(sys_fcntl
, 3) /* 4055 */
1765 MIPS_SYS(sys_ni_syscall
, 2)
1766 MIPS_SYS(sys_setpgid
, 2)
1767 MIPS_SYS(sys_ni_syscall
, 0)
1768 MIPS_SYS(sys_olduname
, 1)
1769 MIPS_SYS(sys_umask
, 1) /* 4060 */
1770 MIPS_SYS(sys_chroot
, 1)
1771 MIPS_SYS(sys_ustat
, 2)
1772 MIPS_SYS(sys_dup2
, 2)
1773 MIPS_SYS(sys_getppid
, 0)
1774 MIPS_SYS(sys_getpgrp
, 0) /* 4065 */
1775 MIPS_SYS(sys_setsid
, 0)
1776 MIPS_SYS(sys_sigaction
, 3)
1777 MIPS_SYS(sys_sgetmask
, 0)
1778 MIPS_SYS(sys_ssetmask
, 1)
1779 MIPS_SYS(sys_setreuid
, 2) /* 4070 */
1780 MIPS_SYS(sys_setregid
, 2)
1781 MIPS_SYS(sys_sigsuspend
, 0)
1782 MIPS_SYS(sys_sigpending
, 1)
1783 MIPS_SYS(sys_sethostname
, 2)
1784 MIPS_SYS(sys_setrlimit
, 2) /* 4075 */
1785 MIPS_SYS(sys_getrlimit
, 2)
1786 MIPS_SYS(sys_getrusage
, 2)
1787 MIPS_SYS(sys_gettimeofday
, 2)
1788 MIPS_SYS(sys_settimeofday
, 2)
1789 MIPS_SYS(sys_getgroups
, 2) /* 4080 */
1790 MIPS_SYS(sys_setgroups
, 2)
1791 MIPS_SYS(sys_ni_syscall
, 0) /* old_select */
1792 MIPS_SYS(sys_symlink
, 2)
1793 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_lstat */
1794 MIPS_SYS(sys_readlink
, 3) /* 4085 */
1795 MIPS_SYS(sys_uselib
, 1)
1796 MIPS_SYS(sys_swapon
, 2)
1797 MIPS_SYS(sys_reboot
, 3)
1798 MIPS_SYS(old_readdir
, 3)
1799 MIPS_SYS(old_mmap
, 6) /* 4090 */
1800 MIPS_SYS(sys_munmap
, 2)
1801 MIPS_SYS(sys_truncate
, 2)
1802 MIPS_SYS(sys_ftruncate
, 2)
1803 MIPS_SYS(sys_fchmod
, 2)
1804 MIPS_SYS(sys_fchown
, 3) /* 4095 */
1805 MIPS_SYS(sys_getpriority
, 2)
1806 MIPS_SYS(sys_setpriority
, 3)
1807 MIPS_SYS(sys_ni_syscall
, 0)
1808 MIPS_SYS(sys_statfs
, 2)
1809 MIPS_SYS(sys_fstatfs
, 2) /* 4100 */
1810 MIPS_SYS(sys_ni_syscall
, 0) /* was ioperm(2) */
1811 MIPS_SYS(sys_socketcall
, 2)
1812 MIPS_SYS(sys_syslog
, 3)
1813 MIPS_SYS(sys_setitimer
, 3)
1814 MIPS_SYS(sys_getitimer
, 2) /* 4105 */
1815 MIPS_SYS(sys_newstat
, 2)
1816 MIPS_SYS(sys_newlstat
, 2)
1817 MIPS_SYS(sys_newfstat
, 2)
1818 MIPS_SYS(sys_uname
, 1)
1819 MIPS_SYS(sys_ni_syscall
, 0) /* 4110 was iopl(2) */
1820 MIPS_SYS(sys_vhangup
, 0)
1821 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_idle() */
1822 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_vm86 */
1823 MIPS_SYS(sys_wait4
, 4)
1824 MIPS_SYS(sys_swapoff
, 1) /* 4115 */
1825 MIPS_SYS(sys_sysinfo
, 1)
1826 MIPS_SYS(sys_ipc
, 6)
1827 MIPS_SYS(sys_fsync
, 1)
1828 MIPS_SYS(sys_sigreturn
, 0)
1829 MIPS_SYS(sys_clone
, 6) /* 4120 */
1830 MIPS_SYS(sys_setdomainname
, 2)
1831 MIPS_SYS(sys_newuname
, 1)
1832 MIPS_SYS(sys_ni_syscall
, 0) /* sys_modify_ldt */
1833 MIPS_SYS(sys_adjtimex
, 1)
1834 MIPS_SYS(sys_mprotect
, 3) /* 4125 */
1835 MIPS_SYS(sys_sigprocmask
, 3)
1836 MIPS_SYS(sys_ni_syscall
, 0) /* was create_module */
1837 MIPS_SYS(sys_init_module
, 5)
1838 MIPS_SYS(sys_delete_module
, 1)
1839 MIPS_SYS(sys_ni_syscall
, 0) /* 4130 was get_kernel_syms */
1840 MIPS_SYS(sys_quotactl
, 0)
1841 MIPS_SYS(sys_getpgid
, 1)
1842 MIPS_SYS(sys_fchdir
, 1)
1843 MIPS_SYS(sys_bdflush
, 2)
1844 MIPS_SYS(sys_sysfs
, 3) /* 4135 */
1845 MIPS_SYS(sys_personality
, 1)
1846 MIPS_SYS(sys_ni_syscall
, 0) /* for afs_syscall */
1847 MIPS_SYS(sys_setfsuid
, 1)
1848 MIPS_SYS(sys_setfsgid
, 1)
1849 MIPS_SYS(sys_llseek
, 5) /* 4140 */
1850 MIPS_SYS(sys_getdents
, 3)
1851 MIPS_SYS(sys_select
, 5)
1852 MIPS_SYS(sys_flock
, 2)
1853 MIPS_SYS(sys_msync
, 3)
1854 MIPS_SYS(sys_readv
, 3) /* 4145 */
1855 MIPS_SYS(sys_writev
, 3)
1856 MIPS_SYS(sys_cacheflush
, 3)
1857 MIPS_SYS(sys_cachectl
, 3)
1858 MIPS_SYS(sys_sysmips
, 4)
1859 MIPS_SYS(sys_ni_syscall
, 0) /* 4150 */
1860 MIPS_SYS(sys_getsid
, 1)
1861 MIPS_SYS(sys_fdatasync
, 0)
1862 MIPS_SYS(sys_sysctl
, 1)
1863 MIPS_SYS(sys_mlock
, 2)
1864 MIPS_SYS(sys_munlock
, 2) /* 4155 */
1865 MIPS_SYS(sys_mlockall
, 1)
1866 MIPS_SYS(sys_munlockall
, 0)
1867 MIPS_SYS(sys_sched_setparam
, 2)
1868 MIPS_SYS(sys_sched_getparam
, 2)
1869 MIPS_SYS(sys_sched_setscheduler
, 3) /* 4160 */
1870 MIPS_SYS(sys_sched_getscheduler
, 1)
1871 MIPS_SYS(sys_sched_yield
, 0)
1872 MIPS_SYS(sys_sched_get_priority_max
, 1)
1873 MIPS_SYS(sys_sched_get_priority_min
, 1)
1874 MIPS_SYS(sys_sched_rr_get_interval
, 2) /* 4165 */
1875 MIPS_SYS(sys_nanosleep
, 2)
1876 MIPS_SYS(sys_mremap
, 5)
1877 MIPS_SYS(sys_accept
, 3)
1878 MIPS_SYS(sys_bind
, 3)
1879 MIPS_SYS(sys_connect
, 3) /* 4170 */
1880 MIPS_SYS(sys_getpeername
, 3)
1881 MIPS_SYS(sys_getsockname
, 3)
1882 MIPS_SYS(sys_getsockopt
, 5)
1883 MIPS_SYS(sys_listen
, 2)
1884 MIPS_SYS(sys_recv
, 4) /* 4175 */
1885 MIPS_SYS(sys_recvfrom
, 6)
1886 MIPS_SYS(sys_recvmsg
, 3)
1887 MIPS_SYS(sys_send
, 4)
1888 MIPS_SYS(sys_sendmsg
, 3)
1889 MIPS_SYS(sys_sendto
, 6) /* 4180 */
1890 MIPS_SYS(sys_setsockopt
, 5)
1891 MIPS_SYS(sys_shutdown
, 2)
1892 MIPS_SYS(sys_socket
, 3)
1893 MIPS_SYS(sys_socketpair
, 4)
1894 MIPS_SYS(sys_setresuid
, 3) /* 4185 */
1895 MIPS_SYS(sys_getresuid
, 3)
1896 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_query_module */
1897 MIPS_SYS(sys_poll
, 3)
1898 MIPS_SYS(sys_nfsservctl
, 3)
1899 MIPS_SYS(sys_setresgid
, 3) /* 4190 */
1900 MIPS_SYS(sys_getresgid
, 3)
1901 MIPS_SYS(sys_prctl
, 5)
1902 MIPS_SYS(sys_rt_sigreturn
, 0)
1903 MIPS_SYS(sys_rt_sigaction
, 4)
1904 MIPS_SYS(sys_rt_sigprocmask
, 4) /* 4195 */
1905 MIPS_SYS(sys_rt_sigpending
, 2)
1906 MIPS_SYS(sys_rt_sigtimedwait
, 4)
1907 MIPS_SYS(sys_rt_sigqueueinfo
, 3)
1908 MIPS_SYS(sys_rt_sigsuspend
, 0)
1909 MIPS_SYS(sys_pread64
, 6) /* 4200 */
1910 MIPS_SYS(sys_pwrite64
, 6)
1911 MIPS_SYS(sys_chown
, 3)
1912 MIPS_SYS(sys_getcwd
, 2)
1913 MIPS_SYS(sys_capget
, 2)
1914 MIPS_SYS(sys_capset
, 2) /* 4205 */
1915 MIPS_SYS(sys_sigaltstack
, 2)
1916 MIPS_SYS(sys_sendfile
, 4)
1917 MIPS_SYS(sys_ni_syscall
, 0)
1918 MIPS_SYS(sys_ni_syscall
, 0)
1919 MIPS_SYS(sys_mmap2
, 6) /* 4210 */
1920 MIPS_SYS(sys_truncate64
, 4)
1921 MIPS_SYS(sys_ftruncate64
, 4)
1922 MIPS_SYS(sys_stat64
, 2)
1923 MIPS_SYS(sys_lstat64
, 2)
1924 MIPS_SYS(sys_fstat64
, 2) /* 4215 */
1925 MIPS_SYS(sys_pivot_root
, 2)
1926 MIPS_SYS(sys_mincore
, 3)
1927 MIPS_SYS(sys_madvise
, 3)
1928 MIPS_SYS(sys_getdents64
, 3)
1929 MIPS_SYS(sys_fcntl64
, 3) /* 4220 */
1930 MIPS_SYS(sys_ni_syscall
, 0)
1931 MIPS_SYS(sys_gettid
, 0)
1932 MIPS_SYS(sys_readahead
, 5)
1933 MIPS_SYS(sys_setxattr
, 5)
1934 MIPS_SYS(sys_lsetxattr
, 5) /* 4225 */
1935 MIPS_SYS(sys_fsetxattr
, 5)
1936 MIPS_SYS(sys_getxattr
, 4)
1937 MIPS_SYS(sys_lgetxattr
, 4)
1938 MIPS_SYS(sys_fgetxattr
, 4)
1939 MIPS_SYS(sys_listxattr
, 3) /* 4230 */
1940 MIPS_SYS(sys_llistxattr
, 3)
1941 MIPS_SYS(sys_flistxattr
, 3)
1942 MIPS_SYS(sys_removexattr
, 2)
1943 MIPS_SYS(sys_lremovexattr
, 2)
1944 MIPS_SYS(sys_fremovexattr
, 2) /* 4235 */
1945 MIPS_SYS(sys_tkill
, 2)
1946 MIPS_SYS(sys_sendfile64
, 5)
1947 MIPS_SYS(sys_futex
, 6)
1948 MIPS_SYS(sys_sched_setaffinity
, 3)
1949 MIPS_SYS(sys_sched_getaffinity
, 3) /* 4240 */
1950 MIPS_SYS(sys_io_setup
, 2)
1951 MIPS_SYS(sys_io_destroy
, 1)
1952 MIPS_SYS(sys_io_getevents
, 5)
1953 MIPS_SYS(sys_io_submit
, 3)
1954 MIPS_SYS(sys_io_cancel
, 3) /* 4245 */
1955 MIPS_SYS(sys_exit_group
, 1)
1956 MIPS_SYS(sys_lookup_dcookie
, 3)
1957 MIPS_SYS(sys_epoll_create
, 1)
1958 MIPS_SYS(sys_epoll_ctl
, 4)
1959 MIPS_SYS(sys_epoll_wait
, 3) /* 4250 */
1960 MIPS_SYS(sys_remap_file_pages
, 5)
1961 MIPS_SYS(sys_set_tid_address
, 1)
1962 MIPS_SYS(sys_restart_syscall
, 0)
1963 MIPS_SYS(sys_fadvise64_64
, 7)
1964 MIPS_SYS(sys_statfs64
, 3) /* 4255 */
1965 MIPS_SYS(sys_fstatfs64
, 2)
1966 MIPS_SYS(sys_timer_create
, 3)
1967 MIPS_SYS(sys_timer_settime
, 4)
1968 MIPS_SYS(sys_timer_gettime
, 2)
1969 MIPS_SYS(sys_timer_getoverrun
, 1) /* 4260 */
1970 MIPS_SYS(sys_timer_delete
, 1)
1971 MIPS_SYS(sys_clock_settime
, 2)
1972 MIPS_SYS(sys_clock_gettime
, 2)
1973 MIPS_SYS(sys_clock_getres
, 2)
1974 MIPS_SYS(sys_clock_nanosleep
, 4) /* 4265 */
1975 MIPS_SYS(sys_tgkill
, 3)
1976 MIPS_SYS(sys_utimes
, 2)
1977 MIPS_SYS(sys_mbind
, 4)
1978 MIPS_SYS(sys_ni_syscall
, 0) /* sys_get_mempolicy */
1979 MIPS_SYS(sys_ni_syscall
, 0) /* 4270 sys_set_mempolicy */
1980 MIPS_SYS(sys_mq_open
, 4)
1981 MIPS_SYS(sys_mq_unlink
, 1)
1982 MIPS_SYS(sys_mq_timedsend
, 5)
1983 MIPS_SYS(sys_mq_timedreceive
, 5)
1984 MIPS_SYS(sys_mq_notify
, 2) /* 4275 */
1985 MIPS_SYS(sys_mq_getsetattr
, 3)
1986 MIPS_SYS(sys_ni_syscall
, 0) /* sys_vserver */
1987 MIPS_SYS(sys_waitid
, 4)
1988 MIPS_SYS(sys_ni_syscall
, 0) /* available, was setaltroot */
1989 MIPS_SYS(sys_add_key
, 5)
1990 MIPS_SYS(sys_request_key
, 4)
1991 MIPS_SYS(sys_keyctl
, 5)
1992 MIPS_SYS(sys_set_thread_area
, 1)
1993 MIPS_SYS(sys_inotify_init
, 0)
1994 MIPS_SYS(sys_inotify_add_watch
, 3) /* 4285 */
1995 MIPS_SYS(sys_inotify_rm_watch
, 2)
1996 MIPS_SYS(sys_migrate_pages
, 4)
1997 MIPS_SYS(sys_openat
, 4)
1998 MIPS_SYS(sys_mkdirat
, 3)
1999 MIPS_SYS(sys_mknodat
, 4) /* 4290 */
2000 MIPS_SYS(sys_fchownat
, 5)
2001 MIPS_SYS(sys_futimesat
, 3)
2002 MIPS_SYS(sys_fstatat64
, 4)
2003 MIPS_SYS(sys_unlinkat
, 3)
2004 MIPS_SYS(sys_renameat
, 4) /* 4295 */
2005 MIPS_SYS(sys_linkat
, 5)
2006 MIPS_SYS(sys_symlinkat
, 3)
2007 MIPS_SYS(sys_readlinkat
, 4)
2008 MIPS_SYS(sys_fchmodat
, 3)
2009 MIPS_SYS(sys_faccessat
, 3) /* 4300 */
2010 MIPS_SYS(sys_pselect6
, 6)
2011 MIPS_SYS(sys_ppoll
, 5)
2012 MIPS_SYS(sys_unshare
, 1)
2013 MIPS_SYS(sys_splice
, 6)
2014 MIPS_SYS(sys_sync_file_range
, 7) /* 4305 */
2015 MIPS_SYS(sys_tee
, 4)
2016 MIPS_SYS(sys_vmsplice
, 4)
2017 MIPS_SYS(sys_move_pages
, 6)
2018 MIPS_SYS(sys_set_robust_list
, 2)
2019 MIPS_SYS(sys_get_robust_list
, 3) /* 4310 */
2020 MIPS_SYS(sys_kexec_load
, 4)
2021 MIPS_SYS(sys_getcpu
, 3)
2022 MIPS_SYS(sys_epoll_pwait
, 6)
2023 MIPS_SYS(sys_ioprio_set
, 3)
2024 MIPS_SYS(sys_ioprio_get
, 2)
2025 MIPS_SYS(sys_utimensat
, 4)
2026 MIPS_SYS(sys_signalfd
, 3)
2027 MIPS_SYS(sys_ni_syscall
, 0) /* was timerfd */
2028 MIPS_SYS(sys_eventfd
, 1)
2029 MIPS_SYS(sys_fallocate
, 6) /* 4320 */
2030 MIPS_SYS(sys_timerfd_create
, 2)
2031 MIPS_SYS(sys_timerfd_gettime
, 2)
2032 MIPS_SYS(sys_timerfd_settime
, 4)
2033 MIPS_SYS(sys_signalfd4
, 4)
2034 MIPS_SYS(sys_eventfd2
, 2) /* 4325 */
2035 MIPS_SYS(sys_epoll_create1
, 1)
2036 MIPS_SYS(sys_dup3
, 3)
2037 MIPS_SYS(sys_pipe2
, 2)
2038 MIPS_SYS(sys_inotify_init1
, 1)
2039 MIPS_SYS(sys_preadv
, 5) /* 4330 */
2040 MIPS_SYS(sys_pwritev
, 5)
2041 MIPS_SYS(sys_rt_tgsigqueueinfo
, 4)
2042 MIPS_SYS(sys_perf_event_open
, 5)
2043 MIPS_SYS(sys_accept4
, 4)
2044 MIPS_SYS(sys_recvmmsg
, 5) /* 4335 */
2045 MIPS_SYS(sys_fanotify_init
, 2)
2046 MIPS_SYS(sys_fanotify_mark
, 6)
2047 MIPS_SYS(sys_prlimit64
, 4)
2048 MIPS_SYS(sys_name_to_handle_at
, 5)
2049 MIPS_SYS(sys_open_by_handle_at
, 3) /* 4340 */
2050 MIPS_SYS(sys_clock_adjtime
, 2)
2051 MIPS_SYS(sys_syncfs
, 1)
2052 MIPS_SYS(sys_sendmmsg
, 4)
2053 MIPS_SYS(sys_setns
, 2)
2054 MIPS_SYS(sys_process_vm_readv
, 6) /* 345 */
2055 MIPS_SYS(sys_process_vm_writev
, 6)
2056 MIPS_SYS(sys_kcmp
, 5)
2057 MIPS_SYS(sys_finit_module
, 3)
2058 MIPS_SYS(sys_sched_setattr
, 2)
2059 MIPS_SYS(sys_sched_getattr
, 3) /* 350 */
2060 MIPS_SYS(sys_renameat2
, 5)
2061 MIPS_SYS(sys_seccomp
, 3)
2062 MIPS_SYS(sys_getrandom
, 3)
2063 MIPS_SYS(sys_memfd_create
, 2)
2064 MIPS_SYS(sys_bpf
, 3) /* 355 */
2065 MIPS_SYS(sys_execveat
, 5)
2066 MIPS_SYS(sys_userfaultfd
, 1)
2067 MIPS_SYS(sys_membarrier
, 2)
2068 MIPS_SYS(sys_mlock2
, 3)
2069 MIPS_SYS(sys_copy_file_range
, 6) /* 360 */
2070 MIPS_SYS(sys_preadv2
, 6)
2071 MIPS_SYS(sys_pwritev2
, 6)
2076 static int do_store_exclusive(CPUMIPSState
*env
)
2079 target_ulong page_addr
;
2087 page_addr
= addr
& TARGET_PAGE_MASK
;
2090 flags
= page_get_flags(page_addr
);
2091 if ((flags
& PAGE_READ
) == 0) {
2094 reg
= env
->llreg
& 0x1f;
2095 d
= (env
->llreg
& 0x20) != 0;
2097 segv
= get_user_s64(val
, addr
);
2099 segv
= get_user_s32(val
, addr
);
2102 if (val
!= env
->llval
) {
2103 env
->active_tc
.gpr
[reg
] = 0;
2106 segv
= put_user_u64(env
->llnewval
, addr
);
2108 segv
= put_user_u32(env
->llnewval
, addr
);
2111 env
->active_tc
.gpr
[reg
] = 1;
2118 env
->active_tc
.PC
+= 4;
2131 static int do_break(CPUMIPSState
*env
, target_siginfo_t
*info
,
2139 info
->si_signo
= TARGET_SIGFPE
;
2141 info
->si_code
= (code
== BRK_OVERFLOW
) ? FPE_INTOVF
: FPE_INTDIV
;
2142 queue_signal(env
, info
->si_signo
, QEMU_SI_FAULT
, &*info
);
2146 info
->si_signo
= TARGET_SIGTRAP
;
2148 queue_signal(env
, info
->si_signo
, QEMU_SI_FAULT
, &*info
);
2156 void cpu_loop(CPUMIPSState
*env
)
2158 CPUState
*cs
= CPU(mips_env_get_cpu(env
));
2159 target_siginfo_t info
;
2162 # ifdef TARGET_ABI_MIPSO32
2163 unsigned int syscall_num
;
2168 trapnr
= cpu_exec(cs
);
2170 process_queued_cpu_work(cs
);
2174 env
->active_tc
.PC
+= 4;
2175 # ifdef TARGET_ABI_MIPSO32
2176 syscall_num
= env
->active_tc
.gpr
[2] - 4000;
2177 if (syscall_num
>= sizeof(mips_syscall_args
)) {
2178 ret
= -TARGET_ENOSYS
;
2182 abi_ulong arg5
= 0, arg6
= 0, arg7
= 0, arg8
= 0;
2184 nb_args
= mips_syscall_args
[syscall_num
];
2185 sp_reg
= env
->active_tc
.gpr
[29];
2187 /* these arguments are taken from the stack */
2189 if ((ret
= get_user_ual(arg8
, sp_reg
+ 28)) != 0) {
2193 if ((ret
= get_user_ual(arg7
, sp_reg
+ 24)) != 0) {
2197 if ((ret
= get_user_ual(arg6
, sp_reg
+ 20)) != 0) {
2201 if ((ret
= get_user_ual(arg5
, sp_reg
+ 16)) != 0) {
2207 ret
= do_syscall(env
, env
->active_tc
.gpr
[2],
2208 env
->active_tc
.gpr
[4],
2209 env
->active_tc
.gpr
[5],
2210 env
->active_tc
.gpr
[6],
2211 env
->active_tc
.gpr
[7],
2212 arg5
, arg6
, arg7
, arg8
);
2216 ret
= do_syscall(env
, env
->active_tc
.gpr
[2],
2217 env
->active_tc
.gpr
[4], env
->active_tc
.gpr
[5],
2218 env
->active_tc
.gpr
[6], env
->active_tc
.gpr
[7],
2219 env
->active_tc
.gpr
[8], env
->active_tc
.gpr
[9],
2220 env
->active_tc
.gpr
[10], env
->active_tc
.gpr
[11]);
2222 if (ret
== -TARGET_ERESTARTSYS
) {
2223 env
->active_tc
.PC
-= 4;
2226 if (ret
== -TARGET_QEMU_ESIGRETURN
) {
2227 /* Returning from a successful sigreturn syscall.
2228 Avoid clobbering register state. */
2231 if ((abi_ulong
)ret
>= (abi_ulong
)-1133) {
2232 env
->active_tc
.gpr
[7] = 1; /* error flag */
2235 env
->active_tc
.gpr
[7] = 0; /* error flag */
2237 env
->active_tc
.gpr
[2] = ret
;
2243 info
.si_signo
= TARGET_SIGSEGV
;
2245 /* XXX: check env->error_code */
2246 info
.si_code
= TARGET_SEGV_MAPERR
;
2247 info
._sifields
._sigfault
._addr
= env
->CP0_BadVAddr
;
2248 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2252 info
.si_signo
= TARGET_SIGILL
;
2255 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2257 case EXCP_INTERRUPT
:
2258 /* just indicate that signals should be handled asap */
2264 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
2267 info
.si_signo
= sig
;
2269 info
.si_code
= TARGET_TRAP_BRKPT
;
2270 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2275 if (do_store_exclusive(env
)) {
2276 info
.si_signo
= TARGET_SIGSEGV
;
2278 info
.si_code
= TARGET_SEGV_MAPERR
;
2279 info
._sifields
._sigfault
._addr
= env
->active_tc
.PC
;
2280 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2284 info
.si_signo
= TARGET_SIGILL
;
2286 info
.si_code
= TARGET_ILL_ILLOPC
;
2287 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2289 /* The code below was inspired by the MIPS Linux kernel trap
2290 * handling code in arch/mips/kernel/traps.c.
2294 abi_ulong trap_instr
;
2297 if (env
->hflags
& MIPS_HFLAG_M16
) {
2298 if (env
->insn_flags
& ASE_MICROMIPS
) {
2299 /* microMIPS mode */
2300 ret
= get_user_u16(trap_instr
, env
->active_tc
.PC
);
2305 if ((trap_instr
>> 10) == 0x11) {
2306 /* 16-bit instruction */
2307 code
= trap_instr
& 0xf;
2309 /* 32-bit instruction */
2312 ret
= get_user_u16(instr_lo
,
2313 env
->active_tc
.PC
+ 2);
2317 trap_instr
= (trap_instr
<< 16) | instr_lo
;
2318 code
= ((trap_instr
>> 6) & ((1 << 20) - 1));
2319 /* Unfortunately, microMIPS also suffers from
2320 the old assembler bug... */
2321 if (code
>= (1 << 10)) {
2327 ret
= get_user_u16(trap_instr
, env
->active_tc
.PC
);
2331 code
= (trap_instr
>> 6) & 0x3f;
2334 ret
= get_user_u32(trap_instr
, env
->active_tc
.PC
);
2339 /* As described in the original Linux kernel code, the
2340 * below checks on 'code' are to work around an old
2343 code
= ((trap_instr
>> 6) & ((1 << 20) - 1));
2344 if (code
>= (1 << 10)) {
2349 if (do_break(env
, &info
, code
) != 0) {
2356 abi_ulong trap_instr
;
2357 unsigned int code
= 0;
2359 if (env
->hflags
& MIPS_HFLAG_M16
) {
2360 /* microMIPS mode */
2363 ret
= get_user_u16(instr
[0], env
->active_tc
.PC
) ||
2364 get_user_u16(instr
[1], env
->active_tc
.PC
+ 2);
2366 trap_instr
= (instr
[0] << 16) | instr
[1];
2368 ret
= get_user_u32(trap_instr
, env
->active_tc
.PC
);
2375 /* The immediate versions don't provide a code. */
2376 if (!(trap_instr
& 0xFC000000)) {
2377 if (env
->hflags
& MIPS_HFLAG_M16
) {
2378 /* microMIPS mode */
2379 code
= ((trap_instr
>> 12) & ((1 << 4) - 1));
2381 code
= ((trap_instr
>> 6) & ((1 << 10) - 1));
2385 if (do_break(env
, &info
, code
) != 0) {
2391 cpu_exec_step_atomic(cs
);
2395 EXCP_DUMP(env
, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr
);
2398 process_pending_signals(env
);
2405 void cpu_loop(CPUNios2State
*env
)
2407 CPUState
*cs
= ENV_GET_CPU(env
);
2408 Nios2CPU
*cpu
= NIOS2_CPU(cs
);
2409 target_siginfo_t info
;
2410 int trapnr
, gdbsig
, ret
;
2414 trapnr
= cpu_exec(cs
);
2419 case EXCP_INTERRUPT
:
2420 /* just indicate that signals should be handled asap */
2423 if (env
->regs
[R_AT
] == 0) {
2425 qemu_log_mask(CPU_LOG_INT
, "\nSyscall\n");
2427 ret
= do_syscall(env
, env
->regs
[2],
2428 env
->regs
[4], env
->regs
[5], env
->regs
[6],
2429 env
->regs
[7], env
->regs
[8], env
->regs
[9],
2432 if (env
->regs
[2] == 0) { /* FIXME: syscall 0 workaround */
2436 env
->regs
[2] = abs(ret
);
2437 /* Return value is 0..4096 */
2438 env
->regs
[7] = (ret
> 0xfffffffffffff000ULL
);
2439 env
->regs
[CR_ESTATUS
] = env
->regs
[CR_STATUS
];
2440 env
->regs
[CR_STATUS
] &= ~0x3;
2441 env
->regs
[R_EA
] = env
->regs
[R_PC
] + 4;
2442 env
->regs
[R_PC
] += 4;
2445 qemu_log_mask(CPU_LOG_INT
, "\nTrap\n");
2447 env
->regs
[CR_ESTATUS
] = env
->regs
[CR_STATUS
];
2448 env
->regs
[CR_STATUS
] &= ~0x3;
2449 env
->regs
[R_EA
] = env
->regs
[R_PC
] + 4;
2450 env
->regs
[R_PC
] = cpu
->exception_addr
;
2452 gdbsig
= TARGET_SIGTRAP
;
2456 switch (env
->regs
[R_PC
]) {
2457 /*case 0x1000:*/ /* TODO:__kuser_helper_version */
2458 case 0x1004: /* __kuser_cmpxchg */
2460 if (env
->regs
[4] & 0x3) {
2463 ret
= get_user_u32(env
->regs
[2], env
->regs
[4]);
2468 env
->regs
[2] -= env
->regs
[5];
2469 if (env
->regs
[2] == 0) {
2470 put_user_u32(env
->regs
[6], env
->regs
[4]);
2473 env
->regs
[R_PC
] = env
->regs
[R_RA
];
2475 /*case 0x1040:*/ /* TODO:__kuser_sigtramp */
2479 info
.si_signo
= TARGET_SIGSEGV
;
2481 /* TODO: check env->error_code */
2482 info
.si_code
= TARGET_SEGV_MAPERR
;
2483 info
._sifields
._sigfault
._addr
= env
->regs
[R_PC
];
2484 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2488 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
2490 gdbsig
= TARGET_SIGILL
;
2494 gdb_handlesig(cs
, gdbsig
);
2495 if (gdbsig
!= TARGET_SIGTRAP
) {
2500 process_pending_signals(env
);
2504 #endif /* TARGET_NIOS2 */
2506 #ifdef TARGET_OPENRISC
2508 void cpu_loop(CPUOpenRISCState
*env
)
2510 CPUState
*cs
= CPU(openrisc_env_get_cpu(env
));
2513 target_siginfo_t info
;
2517 trapnr
= cpu_exec(cs
);
2519 process_queued_cpu_work(cs
);
2523 env
->pc
+= 4; /* 0xc00; */
2524 ret
= do_syscall(env
,
2525 cpu_get_gpr(env
, 11), /* return value */
2526 cpu_get_gpr(env
, 3), /* r3 - r7 are params */
2527 cpu_get_gpr(env
, 4),
2528 cpu_get_gpr(env
, 5),
2529 cpu_get_gpr(env
, 6),
2530 cpu_get_gpr(env
, 7),
2531 cpu_get_gpr(env
, 8), 0, 0);
2532 if (ret
== -TARGET_ERESTARTSYS
) {
2534 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
2535 cpu_set_gpr(env
, 11, ret
);
2541 info
.si_signo
= TARGET_SIGSEGV
;
2543 info
.si_code
= TARGET_SEGV_MAPERR
;
2544 info
._sifields
._sigfault
._addr
= env
->pc
;
2545 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2548 info
.si_signo
= TARGET_SIGBUS
;
2550 info
.si_code
= TARGET_BUS_ADRALN
;
2551 info
._sifields
._sigfault
._addr
= env
->pc
;
2552 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2555 info
.si_signo
= TARGET_SIGILL
;
2557 info
.si_code
= TARGET_ILL_ILLOPC
;
2558 info
._sifields
._sigfault
._addr
= env
->pc
;
2559 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2562 info
.si_signo
= TARGET_SIGFPE
;
2565 info
._sifields
._sigfault
._addr
= env
->pc
;
2566 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2568 case EXCP_INTERRUPT
:
2569 /* We processed the pending cpu work above. */
2572 trapnr
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
2574 info
.si_signo
= trapnr
;
2576 info
.si_code
= TARGET_TRAP_BRKPT
;
2577 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2581 cpu_exec_step_atomic(cs
);
2584 g_assert_not_reached();
2586 process_pending_signals(env
);
2590 #endif /* TARGET_OPENRISC */
2593 void cpu_loop(CPUSH4State
*env
)
2595 CPUState
*cs
= CPU(sh_env_get_cpu(env
));
2597 target_siginfo_t info
;
2600 bool arch_interrupt
= true;
2603 trapnr
= cpu_exec(cs
);
2605 process_queued_cpu_work(cs
);
2610 ret
= do_syscall(env
,
2619 if (ret
== -TARGET_ERESTARTSYS
) {
2621 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
2622 env
->gregs
[0] = ret
;
2625 case EXCP_INTERRUPT
:
2626 /* just indicate that signals should be handled asap */
2632 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
2634 info
.si_signo
= sig
;
2636 info
.si_code
= TARGET_TRAP_BRKPT
;
2637 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2639 arch_interrupt
= false;
2645 info
.si_signo
= TARGET_SIGSEGV
;
2647 info
.si_code
= TARGET_SEGV_MAPERR
;
2648 info
._sifields
._sigfault
._addr
= env
->tea
;
2649 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2652 cpu_exec_step_atomic(cs
);
2653 arch_interrupt
= false;
2656 printf ("Unhandled trap: 0x%x\n", trapnr
);
2657 cpu_dump_state(cs
, stderr
, fprintf
, 0);
2660 process_pending_signals (env
);
2662 /* Most of the traps imply an exception or interrupt, which
2663 implies an REI instruction has been executed. Which means
2664 that LDST (aka LOK_ADDR) should be cleared. But there are
2665 a few exceptions for traps internal to QEMU. */
2666 if (arch_interrupt
) {
2667 env
->lock_addr
= -1;
2674 void cpu_loop(CPUCRISState
*env
)
2676 CPUState
*cs
= CPU(cris_env_get_cpu(env
));
2678 target_siginfo_t info
;
2682 trapnr
= cpu_exec(cs
);
2684 process_queued_cpu_work(cs
);
2689 info
.si_signo
= TARGET_SIGSEGV
;
2691 /* XXX: check env->error_code */
2692 info
.si_code
= TARGET_SEGV_MAPERR
;
2693 info
._sifields
._sigfault
._addr
= env
->pregs
[PR_EDA
];
2694 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2697 case EXCP_INTERRUPT
:
2698 /* just indicate that signals should be handled asap */
2701 ret
= do_syscall(env
,
2710 if (ret
== -TARGET_ERESTARTSYS
) {
2712 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
2713 env
->regs
[10] = ret
;
2720 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
2723 info
.si_signo
= sig
;
2725 info
.si_code
= TARGET_TRAP_BRKPT
;
2726 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2731 cpu_exec_step_atomic(cs
);
2734 printf ("Unhandled trap: 0x%x\n", trapnr
);
2735 cpu_dump_state(cs
, stderr
, fprintf
, 0);
2738 process_pending_signals (env
);
2743 #ifdef TARGET_MICROBLAZE
2744 void cpu_loop(CPUMBState
*env
)
2746 CPUState
*cs
= CPU(mb_env_get_cpu(env
));
2748 target_siginfo_t info
;
2752 trapnr
= cpu_exec(cs
);
2754 process_queued_cpu_work(cs
);
2759 info
.si_signo
= TARGET_SIGSEGV
;
2761 /* XXX: check env->error_code */
2762 info
.si_code
= TARGET_SEGV_MAPERR
;
2763 info
._sifields
._sigfault
._addr
= 0;
2764 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2767 case EXCP_INTERRUPT
:
2768 /* just indicate that signals should be handled asap */
2771 /* Return address is 4 bytes after the call. */
2773 env
->sregs
[SR_PC
] = env
->regs
[14];
2774 ret
= do_syscall(env
,
2783 if (ret
== -TARGET_ERESTARTSYS
) {
2784 /* Wind back to before the syscall. */
2785 env
->sregs
[SR_PC
] -= 4;
2786 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
2789 /* All syscall exits result in guest r14 being equal to the
2790 * PC we return to, because the kernel syscall exit "rtbd" does
2791 * this. (This is true even for sigreturn(); note that r14 is
2792 * not a userspace-usable register, as the kernel may clobber it
2795 env
->regs
[14] = env
->sregs
[SR_PC
];
2798 env
->regs
[17] = env
->sregs
[SR_PC
] + 4;
2799 if (env
->iflags
& D_FLAG
) {
2800 env
->sregs
[SR_ESR
] |= 1 << 12;
2801 env
->sregs
[SR_PC
] -= 4;
2802 /* FIXME: if branch was immed, replay the imm as well. */
2805 env
->iflags
&= ~(IMM_FLAG
| D_FLAG
);
2807 switch (env
->sregs
[SR_ESR
] & 31) {
2808 case ESR_EC_DIVZERO
:
2809 info
.si_signo
= TARGET_SIGFPE
;
2811 info
.si_code
= TARGET_FPE_FLTDIV
;
2812 info
._sifields
._sigfault
._addr
= 0;
2813 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2816 info
.si_signo
= TARGET_SIGFPE
;
2818 if (env
->sregs
[SR_FSR
] & FSR_IO
) {
2819 info
.si_code
= TARGET_FPE_FLTINV
;
2821 if (env
->sregs
[SR_FSR
] & FSR_DZ
) {
2822 info
.si_code
= TARGET_FPE_FLTDIV
;
2824 info
._sifields
._sigfault
._addr
= 0;
2825 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2828 printf ("Unhandled hw-exception: 0x%x\n",
2829 env
->sregs
[SR_ESR
] & ESR_EC_MASK
);
2830 cpu_dump_state(cs
, stderr
, fprintf
, 0);
2839 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
2842 info
.si_signo
= sig
;
2844 info
.si_code
= TARGET_TRAP_BRKPT
;
2845 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2850 cpu_exec_step_atomic(cs
);
2853 printf ("Unhandled trap: 0x%x\n", trapnr
);
2854 cpu_dump_state(cs
, stderr
, fprintf
, 0);
2857 process_pending_signals (env
);
2864 void cpu_loop(CPUM68KState
*env
)
2866 CPUState
*cs
= CPU(m68k_env_get_cpu(env
));
2869 target_siginfo_t info
;
2870 TaskState
*ts
= cs
->opaque
;
2874 trapnr
= cpu_exec(cs
);
2876 process_queued_cpu_work(cs
);
2881 if (ts
->sim_syscalls
) {
2883 get_user_u16(nr
, env
->pc
+ 2);
2885 do_m68k_simcall(env
, nr
);
2891 case EXCP_HALT_INSN
:
2892 /* Semihosing syscall. */
2894 do_m68k_semihosting(env
, env
->dregs
[0]);
2898 case EXCP_UNSUPPORTED
:
2900 info
.si_signo
= TARGET_SIGILL
;
2902 info
.si_code
= TARGET_ILL_ILLOPN
;
2903 info
._sifields
._sigfault
._addr
= env
->pc
;
2904 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2907 info
.si_signo
= TARGET_SIGFPE
;
2909 info
.si_code
= TARGET_FPE_INTOVF
;
2910 info
._sifields
._sigfault
._addr
= env
->pc
;
2911 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2914 info
.si_signo
= TARGET_SIGFPE
;
2916 info
.si_code
= TARGET_FPE_INTDIV
;
2917 info
._sifields
._sigfault
._addr
= env
->pc
;
2918 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2923 ts
->sim_syscalls
= 0;
2926 ret
= do_syscall(env
,
2935 if (ret
== -TARGET_ERESTARTSYS
) {
2937 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
2938 env
->dregs
[0] = ret
;
2942 case EXCP_INTERRUPT
:
2943 /* just indicate that signals should be handled asap */
2947 info
.si_signo
= TARGET_SIGSEGV
;
2949 /* XXX: check env->error_code */
2950 info
.si_code
= TARGET_SEGV_MAPERR
;
2951 info
._sifields
._sigfault
._addr
= env
->mmu
.ar
;
2952 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2959 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
2962 info
.si_signo
= sig
;
2964 info
.si_code
= TARGET_TRAP_BRKPT
;
2965 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
2970 cpu_exec_step_atomic(cs
);
2973 EXCP_DUMP(env
, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr
);
2976 process_pending_signals(env
);
2979 #endif /* TARGET_M68K */
2982 void cpu_loop(CPUAlphaState
*env
)
2984 CPUState
*cs
= CPU(alpha_env_get_cpu(env
));
2986 target_siginfo_t info
;
2990 bool arch_interrupt
= true;
2993 trapnr
= cpu_exec(cs
);
2995 process_queued_cpu_work(cs
);
2999 fprintf(stderr
, "Reset requested. Exit\n");
3003 fprintf(stderr
, "Machine check exception. Exit\n");
3006 case EXCP_SMP_INTERRUPT
:
3007 case EXCP_CLK_INTERRUPT
:
3008 case EXCP_DEV_INTERRUPT
:
3009 fprintf(stderr
, "External interrupt. Exit\n");
3013 info
.si_signo
= TARGET_SIGSEGV
;
3015 info
.si_code
= (page_get_flags(env
->trap_arg0
) & PAGE_VALID
3016 ? TARGET_SEGV_ACCERR
: TARGET_SEGV_MAPERR
);
3017 info
._sifields
._sigfault
._addr
= env
->trap_arg0
;
3018 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3021 info
.si_signo
= TARGET_SIGBUS
;
3023 info
.si_code
= TARGET_BUS_ADRALN
;
3024 info
._sifields
._sigfault
._addr
= env
->trap_arg0
;
3025 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3029 info
.si_signo
= TARGET_SIGILL
;
3031 info
.si_code
= TARGET_ILL_ILLOPC
;
3032 info
._sifields
._sigfault
._addr
= env
->pc
;
3033 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3036 info
.si_signo
= TARGET_SIGFPE
;
3038 info
.si_code
= TARGET_FPE_FLTINV
;
3039 info
._sifields
._sigfault
._addr
= env
->pc
;
3040 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3043 /* No-op. Linux simply re-enables the FPU. */
3046 switch (env
->error_code
) {
3049 info
.si_signo
= TARGET_SIGTRAP
;
3051 info
.si_code
= TARGET_TRAP_BRKPT
;
3052 info
._sifields
._sigfault
._addr
= env
->pc
;
3053 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3057 info
.si_signo
= TARGET_SIGTRAP
;
3060 info
._sifields
._sigfault
._addr
= env
->pc
;
3061 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3065 trapnr
= env
->ir
[IR_V0
];
3066 sysret
= do_syscall(env
, trapnr
,
3067 env
->ir
[IR_A0
], env
->ir
[IR_A1
],
3068 env
->ir
[IR_A2
], env
->ir
[IR_A3
],
3069 env
->ir
[IR_A4
], env
->ir
[IR_A5
],
3071 if (sysret
== -TARGET_ERESTARTSYS
) {
3075 if (sysret
== -TARGET_QEMU_ESIGRETURN
) {
3078 /* Syscall writes 0 to V0 to bypass error check, similar
3079 to how this is handled internal to Linux kernel.
3080 (Ab)use trapnr temporarily as boolean indicating error. */
3081 trapnr
= (env
->ir
[IR_V0
] != 0 && sysret
< 0);
3082 env
->ir
[IR_V0
] = (trapnr
? -sysret
: sysret
);
3083 env
->ir
[IR_A3
] = trapnr
;
3087 /* ??? We can probably elide the code using page_unprotect
3088 that is checking for self-modifying code. Instead we
3089 could simply call tb_flush here. Until we work out the
3090 changes required to turn off the extra write protection,
3091 this can be a no-op. */
3095 /* Handled in the translator for usermode. */
3099 /* Handled in the translator for usermode. */
3103 info
.si_signo
= TARGET_SIGFPE
;
3104 switch (env
->ir
[IR_A0
]) {
3105 case TARGET_GEN_INTOVF
:
3106 info
.si_code
= TARGET_FPE_INTOVF
;
3108 case TARGET_GEN_INTDIV
:
3109 info
.si_code
= TARGET_FPE_INTDIV
;
3111 case TARGET_GEN_FLTOVF
:
3112 info
.si_code
= TARGET_FPE_FLTOVF
;
3114 case TARGET_GEN_FLTUND
:
3115 info
.si_code
= TARGET_FPE_FLTUND
;
3117 case TARGET_GEN_FLTINV
:
3118 info
.si_code
= TARGET_FPE_FLTINV
;
3120 case TARGET_GEN_FLTINE
:
3121 info
.si_code
= TARGET_FPE_FLTRES
;
3123 case TARGET_GEN_ROPRAND
:
3127 info
.si_signo
= TARGET_SIGTRAP
;
3132 info
._sifields
._sigfault
._addr
= env
->pc
;
3133 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3140 info
.si_signo
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
3141 if (info
.si_signo
) {
3143 info
.si_code
= TARGET_TRAP_BRKPT
;
3144 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3146 arch_interrupt
= false;
3149 case EXCP_INTERRUPT
:
3150 /* Just indicate that signals should be handled asap. */
3153 cpu_exec_step_atomic(cs
);
3154 arch_interrupt
= false;
3157 printf ("Unhandled trap: 0x%x\n", trapnr
);
3158 cpu_dump_state(cs
, stderr
, fprintf
, 0);
3161 process_pending_signals (env
);
3163 /* Most of the traps imply a transition through PALcode, which
3164 implies an REI instruction has been executed. Which means
3165 that RX and LOCK_ADDR should be cleared. But there are a
3166 few exceptions for traps internal to QEMU. */
3167 if (arch_interrupt
) {
3168 env
->flags
&= ~ENV_FLAG_RX_FLAG
;
3169 env
->lock_addr
= -1;
3173 #endif /* TARGET_ALPHA */
3177 /* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */
3178 #define S390X_FAIL_ADDR_MASK -4096LL
3180 void cpu_loop(CPUS390XState
*env
)
3182 CPUState
*cs
= CPU(s390_env_get_cpu(env
));
3184 target_siginfo_t info
;
3190 trapnr
= cpu_exec(cs
);
3192 process_queued_cpu_work(cs
);
3195 case EXCP_INTERRUPT
:
3196 /* Just indicate that signals should be handled asap. */
3200 n
= env
->int_svc_code
;
3202 /* syscalls > 255 */
3205 env
->psw
.addr
+= env
->int_svc_ilen
;
3206 ret
= do_syscall(env
, n
, env
->regs
[2], env
->regs
[3],
3207 env
->regs
[4], env
->regs
[5],
3208 env
->regs
[6], env
->regs
[7], 0, 0);
3209 if (ret
== -TARGET_ERESTARTSYS
) {
3210 env
->psw
.addr
-= env
->int_svc_ilen
;
3211 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
3217 sig
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
3219 n
= TARGET_TRAP_BRKPT
;
3224 n
= env
->int_pgm_code
;
3227 case PGM_PRIVILEGED
:
3228 sig
= TARGET_SIGILL
;
3229 n
= TARGET_ILL_ILLOPC
;
3231 case PGM_PROTECTION
:
3232 case PGM_ADDRESSING
:
3233 sig
= TARGET_SIGSEGV
;
3234 /* XXX: check env->error_code */
3235 n
= TARGET_SEGV_MAPERR
;
3236 addr
= env
->__excp_addr
& S390X_FAIL_ADDR_MASK
;
3239 case PGM_SPECIFICATION
:
3240 case PGM_SPECIAL_OP
:
3243 sig
= TARGET_SIGILL
;
3244 n
= TARGET_ILL_ILLOPN
;
3247 case PGM_FIXPT_OVERFLOW
:
3248 sig
= TARGET_SIGFPE
;
3249 n
= TARGET_FPE_INTOVF
;
3251 case PGM_FIXPT_DIVIDE
:
3252 sig
= TARGET_SIGFPE
;
3253 n
= TARGET_FPE_INTDIV
;
3257 n
= (env
->fpc
>> 8) & 0xff;
3259 /* compare-and-trap */
3262 /* An IEEE exception, simulated or otherwise. */
3264 n
= TARGET_FPE_FLTINV
;
3265 } else if (n
& 0x40) {
3266 n
= TARGET_FPE_FLTDIV
;
3267 } else if (n
& 0x20) {
3268 n
= TARGET_FPE_FLTOVF
;
3269 } else if (n
& 0x10) {
3270 n
= TARGET_FPE_FLTUND
;
3271 } else if (n
& 0x08) {
3272 n
= TARGET_FPE_FLTRES
;
3274 /* ??? Quantum exception; BFP, DFP error. */
3277 sig
= TARGET_SIGFPE
;
3282 fprintf(stderr
, "Unhandled program exception: %#x\n", n
);
3283 cpu_dump_state(cs
, stderr
, fprintf
, 0);
3289 addr
= env
->psw
.addr
;
3291 info
.si_signo
= sig
;
3294 info
._sifields
._sigfault
._addr
= addr
;
3295 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3299 cpu_exec_step_atomic(cs
);
3302 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
3303 cpu_dump_state(cs
, stderr
, fprintf
, 0);
3306 process_pending_signals (env
);
3310 #endif /* TARGET_S390X */
3312 #ifdef TARGET_TILEGX
3314 static void gen_sigill_reg(CPUTLGState
*env
)
3316 target_siginfo_t info
;
3318 info
.si_signo
= TARGET_SIGILL
;
3320 info
.si_code
= TARGET_ILL_PRVREG
;
3321 info
._sifields
._sigfault
._addr
= env
->pc
;
3322 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3325 static void do_signal(CPUTLGState
*env
, int signo
, int sigcode
)
3327 target_siginfo_t info
;
3329 info
.si_signo
= signo
;
3331 info
._sifields
._sigfault
._addr
= env
->pc
;
3333 if (signo
== TARGET_SIGSEGV
) {
3334 /* The passed in sigcode is a dummy; check for a page mapping
3335 and pass either MAPERR or ACCERR. */
3336 target_ulong addr
= env
->excaddr
;
3337 info
._sifields
._sigfault
._addr
= addr
;
3338 if (page_check_range(addr
, 1, PAGE_VALID
) < 0) {
3339 sigcode
= TARGET_SEGV_MAPERR
;
3341 sigcode
= TARGET_SEGV_ACCERR
;
3344 info
.si_code
= sigcode
;
3346 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3349 static void gen_sigsegv_maperr(CPUTLGState
*env
, target_ulong addr
)
3351 env
->excaddr
= addr
;
3352 do_signal(env
, TARGET_SIGSEGV
, 0);
3355 static void set_regval(CPUTLGState
*env
, uint8_t reg
, uint64_t val
)
3357 if (unlikely(reg
>= TILEGX_R_COUNT
)) {
3368 gen_sigill_reg(env
);
3371 g_assert_not_reached();
3374 env
->regs
[reg
] = val
;
3378 * Compare the 8-byte contents of the CmpValue SPR with the 8-byte value in
3379 * memory at the address held in the first source register. If the values are
3380 * not equal, then no memory operation is performed. If the values are equal,
3381 * the 8-byte quantity from the second source register is written into memory
3382 * at the address held in the first source register. In either case, the result
3383 * of the instruction is the value read from memory. The compare and write to
3384 * memory are atomic and thus can be used for synchronization purposes. This
3385 * instruction only operates for addresses aligned to a 8-byte boundary.
3386 * Unaligned memory access causes an Unaligned Data Reference interrupt.
3388 * Functional Description (64-bit)
3389 * uint64_t memVal = memoryReadDoubleWord (rf[SrcA]);
3390 * rf[Dest] = memVal;
3391 * if (memVal == SPR[CmpValueSPR])
3392 * memoryWriteDoubleWord (rf[SrcA], rf[SrcB]);
3394 * Functional Description (32-bit)
3395 * uint64_t memVal = signExtend32 (memoryReadWord (rf[SrcA]));
3396 * rf[Dest] = memVal;
3397 * if (memVal == signExtend32 (SPR[CmpValueSPR]))
3398 * memoryWriteWord (rf[SrcA], rf[SrcB]);
3401 * This function also processes exch and exch4 which need not process SPR.
3403 static void do_exch(CPUTLGState
*env
, bool quad
, bool cmp
)
3406 target_long val
, sprval
;
3410 addr
= env
->atomic_srca
;
3411 if (quad
? get_user_s64(val
, addr
) : get_user_s32(val
, addr
)) {
3412 goto sigsegv_maperr
;
3417 sprval
= env
->spregs
[TILEGX_SPR_CMPEXCH
];
3419 sprval
= sextract64(env
->spregs
[TILEGX_SPR_CMPEXCH
], 0, 32);
3423 if (!cmp
|| val
== sprval
) {
3424 target_long valb
= env
->atomic_srcb
;
3425 if (quad
? put_user_u64(valb
, addr
) : put_user_u32(valb
, addr
)) {
3426 goto sigsegv_maperr
;
3430 set_regval(env
, env
->atomic_dstr
, val
);
3436 gen_sigsegv_maperr(env
, addr
);
3439 static void do_fetch(CPUTLGState
*env
, int trapnr
, bool quad
)
3443 target_long val
, valb
;
3447 addr
= env
->atomic_srca
;
3448 valb
= env
->atomic_srcb
;
3449 if (quad
? get_user_s64(val
, addr
) : get_user_s32(val
, addr
)) {
3450 goto sigsegv_maperr
;
3454 case TILEGX_EXCP_OPCODE_FETCHADD
:
3455 case TILEGX_EXCP_OPCODE_FETCHADD4
:
3458 case TILEGX_EXCP_OPCODE_FETCHADDGEZ
:
3464 case TILEGX_EXCP_OPCODE_FETCHADDGEZ4
:
3466 if ((int32_t)valb
< 0) {
3470 case TILEGX_EXCP_OPCODE_FETCHAND
:
3471 case TILEGX_EXCP_OPCODE_FETCHAND4
:
3474 case TILEGX_EXCP_OPCODE_FETCHOR
:
3475 case TILEGX_EXCP_OPCODE_FETCHOR4
:
3479 g_assert_not_reached();
3483 if (quad
? put_user_u64(valb
, addr
) : put_user_u32(valb
, addr
)) {
3484 goto sigsegv_maperr
;
3488 set_regval(env
, env
->atomic_dstr
, val
);
3494 gen_sigsegv_maperr(env
, addr
);
3497 void cpu_loop(CPUTLGState
*env
)
3499 CPUState
*cs
= CPU(tilegx_env_get_cpu(env
));
3504 trapnr
= cpu_exec(cs
);
3506 process_queued_cpu_work(cs
);
3509 case TILEGX_EXCP_SYSCALL
:
3511 abi_ulong ret
= do_syscall(env
, env
->regs
[TILEGX_R_NR
],
3512 env
->regs
[0], env
->regs
[1],
3513 env
->regs
[2], env
->regs
[3],
3514 env
->regs
[4], env
->regs
[5],
3515 env
->regs
[6], env
->regs
[7]);
3516 if (ret
== -TARGET_ERESTARTSYS
) {
3518 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
3519 env
->regs
[TILEGX_R_RE
] = ret
;
3520 env
->regs
[TILEGX_R_ERR
] = TILEGX_IS_ERRNO(ret
) ? -ret
: 0;
3524 case TILEGX_EXCP_OPCODE_EXCH
:
3525 do_exch(env
, true, false);
3527 case TILEGX_EXCP_OPCODE_EXCH4
:
3528 do_exch(env
, false, false);
3530 case TILEGX_EXCP_OPCODE_CMPEXCH
:
3531 do_exch(env
, true, true);
3533 case TILEGX_EXCP_OPCODE_CMPEXCH4
:
3534 do_exch(env
, false, true);
3536 case TILEGX_EXCP_OPCODE_FETCHADD
:
3537 case TILEGX_EXCP_OPCODE_FETCHADDGEZ
:
3538 case TILEGX_EXCP_OPCODE_FETCHAND
:
3539 case TILEGX_EXCP_OPCODE_FETCHOR
:
3540 do_fetch(env
, trapnr
, true);
3542 case TILEGX_EXCP_OPCODE_FETCHADD4
:
3543 case TILEGX_EXCP_OPCODE_FETCHADDGEZ4
:
3544 case TILEGX_EXCP_OPCODE_FETCHAND4
:
3545 case TILEGX_EXCP_OPCODE_FETCHOR4
:
3546 do_fetch(env
, trapnr
, false);
3548 case TILEGX_EXCP_SIGNAL
:
3549 do_signal(env
, env
->signo
, env
->sigcode
);
3551 case TILEGX_EXCP_REG_IDN_ACCESS
:
3552 case TILEGX_EXCP_REG_UDN_ACCESS
:
3553 gen_sigill_reg(env
);
3556 cpu_exec_step_atomic(cs
);
3559 fprintf(stderr
, "trapnr is %d[0x%x].\n", trapnr
, trapnr
);
3560 g_assert_not_reached();
3562 process_pending_signals(env
);
3570 void cpu_loop(CPURISCVState
*env
)
3572 CPUState
*cs
= CPU(riscv_env_get_cpu(env
));
3573 int trapnr
, signum
, sigcode
;
3574 target_ulong sigaddr
;
3579 trapnr
= cpu_exec(cs
);
3581 process_queued_cpu_work(cs
);
3588 case EXCP_INTERRUPT
:
3589 /* just indicate that signals should be handled asap */
3592 cpu_exec_step_atomic(cs
);
3594 case RISCV_EXCP_U_ECALL
:
3596 if (env
->gpr
[xA7
] == TARGET_NR_arch_specific_syscall
+ 15) {
3597 /* riscv_flush_icache_syscall is a no-op in QEMU as
3598 self-modifying code is automatically detected */
3601 ret
= do_syscall(env
,
3611 if (ret
== -TARGET_ERESTARTSYS
) {
3613 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
3614 env
->gpr
[xA0
] = ret
;
3616 if (cs
->singlestep_enabled
) {
3620 case RISCV_EXCP_ILLEGAL_INST
:
3621 signum
= TARGET_SIGILL
;
3622 sigcode
= TARGET_ILL_ILLOPC
;
3624 case RISCV_EXCP_BREAKPOINT
:
3625 signum
= TARGET_SIGTRAP
;
3626 sigcode
= TARGET_TRAP_BRKPT
;
3629 case RISCV_EXCP_INST_PAGE_FAULT
:
3630 case RISCV_EXCP_LOAD_PAGE_FAULT
:
3631 case RISCV_EXCP_STORE_PAGE_FAULT
:
3632 signum
= TARGET_SIGSEGV
;
3633 sigcode
= TARGET_SEGV_MAPERR
;
3637 signum
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
3638 sigcode
= TARGET_TRAP_BRKPT
;
3641 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
3647 target_siginfo_t info
= {
3651 ._sifields
._sigfault
._addr
= sigaddr
3653 queue_signal(env
, info
.si_signo
, QEMU_SI_KILL
, &info
);
3656 process_pending_signals(env
);
3660 #endif /* TARGET_RISCV */
3664 static abi_ulong
hppa_lws(CPUHPPAState
*env
)
3666 uint32_t which
= env
->gr
[20];
3667 abi_ulong addr
= env
->gr
[26];
3668 abi_ulong old
= env
->gr
[25];
3669 abi_ulong
new = env
->gr
[24];
3670 abi_ulong size
, ret
;
3674 return -TARGET_ENOSYS
;
3676 case 0: /* elf32 atomic 32bit cmpxchg */
3677 if ((addr
& 3) || !access_ok(VERIFY_WRITE
, addr
, 4)) {
3678 return -TARGET_EFAULT
;
3682 ret
= atomic_cmpxchg((uint32_t *)g2h(addr
), old
, new);
3686 case 2: /* elf32 atomic "new" cmpxchg */
3689 return -TARGET_ENOSYS
;
3691 if (((addr
| old
| new) & ((1 << size
) - 1))
3692 || !access_ok(VERIFY_WRITE
, addr
, 1 << size
)
3693 || !access_ok(VERIFY_READ
, old
, 1 << size
)
3694 || !access_ok(VERIFY_READ
, new, 1 << size
)) {
3695 return -TARGET_EFAULT
;
3697 /* Note that below we use host-endian loads so that the cmpxchg
3698 can be host-endian as well. */
3701 old
= *(uint8_t *)g2h(old
);
3702 new = *(uint8_t *)g2h(new);
3703 ret
= atomic_cmpxchg((uint8_t *)g2h(addr
), old
, new);
3707 old
= *(uint16_t *)g2h(old
);
3708 new = *(uint16_t *)g2h(new);
3709 ret
= atomic_cmpxchg((uint16_t *)g2h(addr
), old
, new);
3713 old
= *(uint32_t *)g2h(old
);
3714 new = *(uint32_t *)g2h(new);
3715 ret
= atomic_cmpxchg((uint32_t *)g2h(addr
), old
, new);
3720 uint64_t o64
, n64
, r64
;
3721 o64
= *(uint64_t *)g2h(old
);
3722 n64
= *(uint64_t *)g2h(new);
3723 #ifdef CONFIG_ATOMIC64
3724 r64
= atomic_cmpxchg__nocheck((uint64_t *)g2h(addr
), o64
, n64
);
3728 r64
= *(uint64_t *)g2h(addr
);
3731 *(uint64_t *)g2h(addr
) = n64
;
3746 void cpu_loop(CPUHPPAState
*env
)
3748 CPUState
*cs
= CPU(hppa_env_get_cpu(env
));
3749 target_siginfo_t info
;
3755 trapnr
= cpu_exec(cs
);
3757 process_queued_cpu_work(cs
);
3761 ret
= do_syscall(env
, env
->gr
[20],
3762 env
->gr
[26], env
->gr
[25],
3763 env
->gr
[24], env
->gr
[23],
3764 env
->gr
[22], env
->gr
[21], 0, 0);
3768 /* We arrived here by faking the gateway page. Return. */
3769 env
->iaoq_f
= env
->gr
[31];
3770 env
->iaoq_b
= env
->gr
[31] + 4;
3772 case -TARGET_ERESTARTSYS
:
3773 case -TARGET_QEMU_ESIGRETURN
:
3777 case EXCP_SYSCALL_LWS
:
3778 env
->gr
[21] = hppa_lws(env
);
3779 /* We arrived here by faking the gateway page. Return. */
3780 env
->iaoq_f
= env
->gr
[31];
3781 env
->iaoq_b
= env
->gr
[31] + 4;
3783 case EXCP_ITLB_MISS
:
3784 case EXCP_DTLB_MISS
:
3785 case EXCP_NA_ITLB_MISS
:
3786 case EXCP_NA_DTLB_MISS
:
3793 info
.si_signo
= TARGET_SIGSEGV
;
3795 info
.si_code
= TARGET_SEGV_ACCERR
;
3796 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
3797 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3800 info
.si_signo
= TARGET_SIGBUS
;
3803 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
3804 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3809 info
.si_signo
= TARGET_SIGILL
;
3811 info
.si_code
= TARGET_ILL_ILLOPN
;
3812 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
3813 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3818 info
.si_signo
= TARGET_SIGFPE
;
3821 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
3822 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3825 trapnr
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
3827 info
.si_signo
= trapnr
;
3829 info
.si_code
= TARGET_TRAP_BRKPT
;
3830 queue_signal(env
, trapnr
, QEMU_SI_FAULT
, &info
);
3833 case EXCP_INTERRUPT
:
3834 /* just indicate that signals should be handled asap */
3837 g_assert_not_reached();
3839 process_pending_signals(env
);
3843 #endif /* TARGET_HPPA */
3845 #ifdef TARGET_XTENSA
3847 static void xtensa_rfw(CPUXtensaState
*env
)
3849 xtensa_restore_owb(env
);
3850 env
->pc
= env
->sregs
[EPC1
];
3853 static void xtensa_rfwu(CPUXtensaState
*env
)
3855 env
->sregs
[WINDOW_START
] |= (1 << env
->sregs
[WINDOW_BASE
]);
3859 static void xtensa_rfwo(CPUXtensaState
*env
)
3861 env
->sregs
[WINDOW_START
] &= ~(1 << env
->sregs
[WINDOW_BASE
]);
3865 static void xtensa_overflow4(CPUXtensaState
*env
)
3867 put_user_ual(env
->regs
[0], env
->regs
[5] - 16);
3868 put_user_ual(env
->regs
[1], env
->regs
[5] - 12);
3869 put_user_ual(env
->regs
[2], env
->regs
[5] - 8);
3870 put_user_ual(env
->regs
[3], env
->regs
[5] - 4);
3874 static void xtensa_underflow4(CPUXtensaState
*env
)
3876 get_user_ual(env
->regs
[0], env
->regs
[5] - 16);
3877 get_user_ual(env
->regs
[1], env
->regs
[5] - 12);
3878 get_user_ual(env
->regs
[2], env
->regs
[5] - 8);
3879 get_user_ual(env
->regs
[3], env
->regs
[5] - 4);
3883 static void xtensa_overflow8(CPUXtensaState
*env
)
3885 put_user_ual(env
->regs
[0], env
->regs
[9] - 16);
3886 get_user_ual(env
->regs
[0], env
->regs
[1] - 12);
3887 put_user_ual(env
->regs
[1], env
->regs
[9] - 12);
3888 put_user_ual(env
->regs
[2], env
->regs
[9] - 8);
3889 put_user_ual(env
->regs
[3], env
->regs
[9] - 4);
3890 put_user_ual(env
->regs
[4], env
->regs
[0] - 32);
3891 put_user_ual(env
->regs
[5], env
->regs
[0] - 28);
3892 put_user_ual(env
->regs
[6], env
->regs
[0] - 24);
3893 put_user_ual(env
->regs
[7], env
->regs
[0] - 20);
3897 static void xtensa_underflow8(CPUXtensaState
*env
)
3899 get_user_ual(env
->regs
[0], env
->regs
[9] - 16);
3900 get_user_ual(env
->regs
[1], env
->regs
[9] - 12);
3901 get_user_ual(env
->regs
[2], env
->regs
[9] - 8);
3902 get_user_ual(env
->regs
[7], env
->regs
[1] - 12);
3903 get_user_ual(env
->regs
[3], env
->regs
[9] - 4);
3904 get_user_ual(env
->regs
[4], env
->regs
[7] - 32);
3905 get_user_ual(env
->regs
[5], env
->regs
[7] - 28);
3906 get_user_ual(env
->regs
[6], env
->regs
[7] - 24);
3907 get_user_ual(env
->regs
[7], env
->regs
[7] - 20);
3911 static void xtensa_overflow12(CPUXtensaState
*env
)
3913 put_user_ual(env
->regs
[0], env
->regs
[13] - 16);
3914 get_user_ual(env
->regs
[0], env
->regs
[1] - 12);
3915 put_user_ual(env
->regs
[1], env
->regs
[13] - 12);
3916 put_user_ual(env
->regs
[2], env
->regs
[13] - 8);
3917 put_user_ual(env
->regs
[3], env
->regs
[13] - 4);
3918 put_user_ual(env
->regs
[4], env
->regs
[0] - 48);
3919 put_user_ual(env
->regs
[5], env
->regs
[0] - 44);
3920 put_user_ual(env
->regs
[6], env
->regs
[0] - 40);
3921 put_user_ual(env
->regs
[7], env
->regs
[0] - 36);
3922 put_user_ual(env
->regs
[8], env
->regs
[0] - 32);
3923 put_user_ual(env
->regs
[9], env
->regs
[0] - 28);
3924 put_user_ual(env
->regs
[10], env
->regs
[0] - 24);
3925 put_user_ual(env
->regs
[11], env
->regs
[0] - 20);
3929 static void xtensa_underflow12(CPUXtensaState
*env
)
3931 get_user_ual(env
->regs
[0], env
->regs
[13] - 16);
3932 get_user_ual(env
->regs
[1], env
->regs
[13] - 12);
3933 get_user_ual(env
->regs
[2], env
->regs
[13] - 8);
3934 get_user_ual(env
->regs
[11], env
->regs
[1] - 12);
3935 get_user_ual(env
->regs
[3], env
->regs
[13] - 4);
3936 get_user_ual(env
->regs
[4], env
->regs
[11] - 48);
3937 get_user_ual(env
->regs
[5], env
->regs
[11] - 44);
3938 get_user_ual(env
->regs
[6], env
->regs
[11] - 40);
3939 get_user_ual(env
->regs
[7], env
->regs
[11] - 36);
3940 get_user_ual(env
->regs
[8], env
->regs
[11] - 32);
3941 get_user_ual(env
->regs
[9], env
->regs
[11] - 28);
3942 get_user_ual(env
->regs
[10], env
->regs
[11] - 24);
3943 get_user_ual(env
->regs
[11], env
->regs
[11] - 20);
3947 void cpu_loop(CPUXtensaState
*env
)
3949 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
3950 target_siginfo_t info
;
3956 trapnr
= cpu_exec(cs
);
3958 process_queued_cpu_work(cs
);
3960 env
->sregs
[PS
] &= ~PS_EXCM
;
3962 case EXCP_INTERRUPT
:
3965 case EXC_WINDOW_OVERFLOW4
:
3966 xtensa_overflow4(env
);
3968 case EXC_WINDOW_UNDERFLOW4
:
3969 xtensa_underflow4(env
);
3971 case EXC_WINDOW_OVERFLOW8
:
3972 xtensa_overflow8(env
);
3974 case EXC_WINDOW_UNDERFLOW8
:
3975 xtensa_underflow8(env
);
3977 case EXC_WINDOW_OVERFLOW12
:
3978 xtensa_overflow12(env
);
3980 case EXC_WINDOW_UNDERFLOW12
:
3981 xtensa_underflow12(env
);
3985 switch (env
->sregs
[EXCCAUSE
]) {
3986 case ILLEGAL_INSTRUCTION_CAUSE
:
3987 case PRIVILEGED_CAUSE
:
3988 info
.si_signo
= TARGET_SIGILL
;
3991 env
->sregs
[EXCCAUSE
] == ILLEGAL_INSTRUCTION_CAUSE
?
3992 TARGET_ILL_ILLOPC
: TARGET_ILL_PRVOPC
;
3993 info
._sifields
._sigfault
._addr
= env
->sregs
[EPC1
];
3994 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
3999 ret
= do_syscall(env
, env
->regs
[2],
4000 env
->regs
[6], env
->regs
[3],
4001 env
->regs
[4], env
->regs
[5],
4002 env
->regs
[8], env
->regs
[9], 0, 0);
4008 case -TARGET_ERESTARTSYS
:
4009 case -TARGET_QEMU_ESIGRETURN
:
4015 env
->sregs
[PS
] = deposit32(env
->sregs
[PS
],
4018 env
->sregs
[WINDOW_BASE
]);
4020 switch (env
->regs
[0] & 0xc0000000) {
4023 xtensa_rotate_window(env
, -1);
4024 xtensa_underflow4(env
);
4028 xtensa_rotate_window(env
, -2);
4029 xtensa_underflow8(env
);
4033 xtensa_rotate_window(env
, -3);
4034 xtensa_underflow12(env
);
4039 case INTEGER_DIVIDE_BY_ZERO_CAUSE
:
4040 info
.si_signo
= TARGET_SIGFPE
;
4042 info
.si_code
= TARGET_FPE_INTDIV
;
4043 info
._sifields
._sigfault
._addr
= env
->sregs
[EPC1
];
4044 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
4047 case LOAD_PROHIBITED_CAUSE
:
4048 case STORE_PROHIBITED_CAUSE
:
4049 info
.si_signo
= TARGET_SIGSEGV
;
4051 info
.si_code
= TARGET_SEGV_ACCERR
;
4052 info
._sifields
._sigfault
._addr
= env
->sregs
[EXCVADDR
];
4053 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
4057 fprintf(stderr
, "exccause = %d\n", env
->sregs
[EXCCAUSE
]);
4058 g_assert_not_reached();
4062 trapnr
= gdb_handlesig(cs
, TARGET_SIGTRAP
);
4064 info
.si_signo
= trapnr
;
4066 info
.si_code
= TARGET_TRAP_BRKPT
;
4067 queue_signal(env
, trapnr
, QEMU_SI_FAULT
, &info
);
4072 fprintf(stderr
, "trapnr = %d\n", trapnr
);
4073 g_assert_not_reached();
4075 process_pending_signals(env
);
4079 #endif /* TARGET_XTENSA */
4081 __thread CPUState
*thread_cpu
;
4083 bool qemu_cpu_is_self(CPUState
*cpu
)
4085 return thread_cpu
== cpu
;
4088 void qemu_cpu_kick(CPUState
*cpu
)
4093 void task_settid(TaskState
*ts
)
4095 if (ts
->ts_tid
== 0) {
4096 ts
->ts_tid
= (pid_t
)syscall(SYS_gettid
);
4100 void stop_all_tasks(void)
4103 * We trust that when using NPTL, start_exclusive()
4104 * handles thread stopping correctly.
4109 /* Assumes contents are already zeroed. */
4110 void init_task_state(TaskState
*ts
)
4115 CPUArchState
*cpu_copy(CPUArchState
*env
)
4117 CPUState
*cpu
= ENV_GET_CPU(env
);
4118 CPUState
*new_cpu
= cpu_create(cpu_type
);
4119 CPUArchState
*new_env
= new_cpu
->env_ptr
;
4123 /* Reset non arch specific state */
4126 memcpy(new_env
, env
, sizeof(CPUArchState
));
4128 /* Clone all break/watchpoints.
4129 Note: Once we support ptrace with hw-debug register access, make sure
4130 BP_CPU break/watchpoints are handled correctly on clone. */
4131 QTAILQ_INIT(&new_cpu
->breakpoints
);
4132 QTAILQ_INIT(&new_cpu
->watchpoints
);
4133 QTAILQ_FOREACH(bp
, &cpu
->breakpoints
, entry
) {
4134 cpu_breakpoint_insert(new_cpu
, bp
->pc
, bp
->flags
, NULL
);
4136 QTAILQ_FOREACH(wp
, &cpu
->watchpoints
, entry
) {
4137 cpu_watchpoint_insert(new_cpu
, wp
->vaddr
, wp
->len
, wp
->flags
, NULL
);
4143 static void handle_arg_help(const char *arg
)
4145 usage(EXIT_SUCCESS
);
4148 static void handle_arg_log(const char *arg
)
4152 mask
= qemu_str_to_log_mask(arg
);
4154 qemu_print_log_usage(stdout
);
4157 qemu_log_needs_buffers();
4161 static void handle_arg_dfilter(const char *arg
)
4163 qemu_set_dfilter_ranges(arg
, NULL
);
4166 static void handle_arg_log_filename(const char *arg
)
4168 qemu_set_log_filename(arg
, &error_fatal
);
4171 static void handle_arg_set_env(const char *arg
)
4173 char *r
, *p
, *token
;
4174 r
= p
= strdup(arg
);
4175 while ((token
= strsep(&p
, ",")) != NULL
) {
4176 if (envlist_setenv(envlist
, token
) != 0) {
4177 usage(EXIT_FAILURE
);
4183 static void handle_arg_unset_env(const char *arg
)
4185 char *r
, *p
, *token
;
4186 r
= p
= strdup(arg
);
4187 while ((token
= strsep(&p
, ",")) != NULL
) {
4188 if (envlist_unsetenv(envlist
, token
) != 0) {
4189 usage(EXIT_FAILURE
);
4195 static void handle_arg_argv0(const char *arg
)
4197 argv0
= strdup(arg
);
4200 static void handle_arg_stack_size(const char *arg
)
4203 guest_stack_size
= strtoul(arg
, &p
, 0);
4204 if (guest_stack_size
== 0) {
4205 usage(EXIT_FAILURE
);
4209 guest_stack_size
*= 1024 * 1024;
4210 } else if (*p
== 'k' || *p
== 'K') {
4211 guest_stack_size
*= 1024;
4215 static void handle_arg_ld_prefix(const char *arg
)
4217 interp_prefix
= strdup(arg
);
4220 static void handle_arg_pagesize(const char *arg
)
4222 qemu_host_page_size
= atoi(arg
);
4223 if (qemu_host_page_size
== 0 ||
4224 (qemu_host_page_size
& (qemu_host_page_size
- 1)) != 0) {
4225 fprintf(stderr
, "page size must be a power of two\n");
4230 static void handle_arg_randseed(const char *arg
)
4232 unsigned long long seed
;
4234 if (parse_uint_full(arg
, &seed
, 0) != 0 || seed
> UINT_MAX
) {
4235 fprintf(stderr
, "Invalid seed number: %s\n", arg
);
4241 static void handle_arg_gdb(const char *arg
)
4243 gdbstub_port
= atoi(arg
);
4246 static void handle_arg_uname(const char *arg
)
4248 qemu_uname_release
= strdup(arg
);
4251 static void handle_arg_cpu(const char *arg
)
4253 cpu_model
= strdup(arg
);
4254 if (cpu_model
== NULL
|| is_help_option(cpu_model
)) {
4255 /* XXX: implement xxx_cpu_list for targets that still miss it */
4256 #if defined(cpu_list)
4257 cpu_list(stdout
, &fprintf
);
4263 static void handle_arg_guest_base(const char *arg
)
4265 guest_base
= strtol(arg
, NULL
, 0);
4266 have_guest_base
= 1;
4269 static void handle_arg_reserved_va(const char *arg
)
4273 reserved_va
= strtoul(arg
, &p
, 0);
4287 unsigned long unshifted
= reserved_va
;
4289 reserved_va
<<= shift
;
4290 if (reserved_va
>> shift
!= unshifted
4291 || (MAX_RESERVED_VA
&& reserved_va
> MAX_RESERVED_VA
)) {
4292 fprintf(stderr
, "Reserved virtual address too big\n");
4297 fprintf(stderr
, "Unrecognised -R size suffix '%s'\n", p
);
4302 static void handle_arg_singlestep(const char *arg
)
4307 static void handle_arg_strace(const char *arg
)
4312 static void handle_arg_version(const char *arg
)
4314 printf("qemu-" TARGET_NAME
" version " QEMU_FULL_VERSION
4315 "\n" QEMU_COPYRIGHT
"\n");
4319 static char *trace_file
;
4320 static void handle_arg_trace(const char *arg
)
4323 trace_file
= trace_opt_parse(arg
);
4326 struct qemu_argument
{
4330 void (*handle_opt
)(const char *arg
);
4331 const char *example
;
4335 static const struct qemu_argument arg_table
[] = {
4336 {"h", "", false, handle_arg_help
,
4337 "", "print this help"},
4338 {"help", "", false, handle_arg_help
,
4340 {"g", "QEMU_GDB", true, handle_arg_gdb
,
4341 "port", "wait gdb connection to 'port'"},
4342 {"L", "QEMU_LD_PREFIX", true, handle_arg_ld_prefix
,
4343 "path", "set the elf interpreter prefix to 'path'"},
4344 {"s", "QEMU_STACK_SIZE", true, handle_arg_stack_size
,
4345 "size", "set the stack size to 'size' bytes"},
4346 {"cpu", "QEMU_CPU", true, handle_arg_cpu
,
4347 "model", "select CPU (-cpu help for list)"},
4348 {"E", "QEMU_SET_ENV", true, handle_arg_set_env
,
4349 "var=value", "sets targets environment variable (see below)"},
4350 {"U", "QEMU_UNSET_ENV", true, handle_arg_unset_env
,
4351 "var", "unsets targets environment variable (see below)"},
4352 {"0", "QEMU_ARGV0", true, handle_arg_argv0
,
4353 "argv0", "forces target process argv[0] to be 'argv0'"},
4354 {"r", "QEMU_UNAME", true, handle_arg_uname
,
4355 "uname", "set qemu uname release string to 'uname'"},
4356 {"B", "QEMU_GUEST_BASE", true, handle_arg_guest_base
,
4357 "address", "set guest_base address to 'address'"},
4358 {"R", "QEMU_RESERVED_VA", true, handle_arg_reserved_va
,
4359 "size", "reserve 'size' bytes for guest virtual address space"},
4360 {"d", "QEMU_LOG", true, handle_arg_log
,
4361 "item[,...]", "enable logging of specified items "
4362 "(use '-d help' for a list of items)"},
4363 {"dfilter", "QEMU_DFILTER", true, handle_arg_dfilter
,
4364 "range[,...]","filter logging based on address range"},
4365 {"D", "QEMU_LOG_FILENAME", true, handle_arg_log_filename
,
4366 "logfile", "write logs to 'logfile' (default stderr)"},
4367 {"p", "QEMU_PAGESIZE", true, handle_arg_pagesize
,
4368 "pagesize", "set the host page size to 'pagesize'"},
4369 {"singlestep", "QEMU_SINGLESTEP", false, handle_arg_singlestep
,
4370 "", "run in singlestep mode"},
4371 {"strace", "QEMU_STRACE", false, handle_arg_strace
,
4372 "", "log system calls"},
4373 {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed
,
4374 "", "Seed for pseudo-random number generator"},
4375 {"trace", "QEMU_TRACE", true, handle_arg_trace
,
4376 "", "[[enable=]<pattern>][,events=<file>][,file=<file>]"},
4377 {"version", "QEMU_VERSION", false, handle_arg_version
,
4378 "", "display version information and exit"},
4379 {NULL
, NULL
, false, NULL
, NULL
, NULL
}
4382 static void usage(int exitcode
)
4384 const struct qemu_argument
*arginfo
;
4388 printf("usage: qemu-" TARGET_NAME
" [options] program [arguments...]\n"
4389 "Linux CPU emulator (compiled for " TARGET_NAME
" emulation)\n"
4391 "Options and associated environment variables:\n"
4394 /* Calculate column widths. We must always have at least enough space
4395 * for the column header.
4397 maxarglen
= strlen("Argument");
4398 maxenvlen
= strlen("Env-variable");
4400 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
4401 int arglen
= strlen(arginfo
->argv
);
4402 if (arginfo
->has_arg
) {
4403 arglen
+= strlen(arginfo
->example
) + 1;
4405 if (strlen(arginfo
->env
) > maxenvlen
) {
4406 maxenvlen
= strlen(arginfo
->env
);
4408 if (arglen
> maxarglen
) {
4413 printf("%-*s %-*s Description\n", maxarglen
+1, "Argument",
4414 maxenvlen
, "Env-variable");
4416 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
4417 if (arginfo
->has_arg
) {
4418 printf("-%s %-*s %-*s %s\n", arginfo
->argv
,
4419 (int)(maxarglen
- strlen(arginfo
->argv
) - 1),
4420 arginfo
->example
, maxenvlen
, arginfo
->env
, arginfo
->help
);
4422 printf("-%-*s %-*s %s\n", maxarglen
, arginfo
->argv
,
4423 maxenvlen
, arginfo
->env
,
4430 "QEMU_LD_PREFIX = %s\n"
4431 "QEMU_STACK_SIZE = %ld byte\n",
4436 "You can use -E and -U options or the QEMU_SET_ENV and\n"
4437 "QEMU_UNSET_ENV environment variables to set and unset\n"
4438 "environment variables for the target process.\n"
4439 "It is possible to provide several variables by separating them\n"
4440 "by commas in getsubopt(3) style. Additionally it is possible to\n"
4441 "provide the -E and -U options multiple times.\n"
4442 "The following lines are equivalent:\n"
4443 " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n"
4444 " -E var1=val2,var2=val2 -U LD_PRELOAD,LD_DEBUG\n"
4445 " QEMU_SET_ENV=var1=val2,var2=val2 QEMU_UNSET_ENV=LD_PRELOAD,LD_DEBUG\n"
4446 "Note that if you provide several changes to a single variable\n"
4447 "the last change will stay in effect.\n"
4449 QEMU_HELP_BOTTOM
"\n");
4454 static int parse_args(int argc
, char **argv
)
4458 const struct qemu_argument
*arginfo
;
4460 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
4461 if (arginfo
->env
== NULL
) {
4465 r
= getenv(arginfo
->env
);
4467 arginfo
->handle_opt(r
);
4473 if (optind
>= argc
) {
4482 if (!strcmp(r
, "-")) {
4485 /* Treat --foo the same as -foo. */
4490 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
4491 if (!strcmp(r
, arginfo
->argv
)) {
4492 if (arginfo
->has_arg
) {
4493 if (optind
>= argc
) {
4494 (void) fprintf(stderr
,
4495 "qemu: missing argument for option '%s'\n", r
);
4498 arginfo
->handle_opt(argv
[optind
]);
4501 arginfo
->handle_opt(NULL
);
4507 /* no option matched the current argv */
4508 if (arginfo
->handle_opt
== NULL
) {
4509 (void) fprintf(stderr
, "qemu: unknown option '%s'\n", r
);
4514 if (optind
>= argc
) {
4515 (void) fprintf(stderr
, "qemu: no user program specified\n");
4519 filename
= argv
[optind
];
4520 exec_path
= argv
[optind
];
4525 int main(int argc
, char **argv
, char **envp
)
4527 struct target_pt_regs regs1
, *regs
= ®s1
;
4528 struct image_info info1
, *info
= &info1
;
4529 struct linux_binprm bprm
;
4534 char **target_environ
, **wrk
;
4541 module_call_init(MODULE_INIT_TRACE
);
4542 qemu_init_cpu_list();
4543 module_call_init(MODULE_INIT_QOM
);
4545 envlist
= envlist_create();
4547 /* add current environment into the list */
4548 for (wrk
= environ
; *wrk
!= NULL
; wrk
++) {
4549 (void) envlist_setenv(envlist
, *wrk
);
4552 /* Read the stack limit from the kernel. If it's "unlimited",
4553 then we can do little else besides use the default. */
4556 if (getrlimit(RLIMIT_STACK
, &lim
) == 0
4557 && lim
.rlim_cur
!= RLIM_INFINITY
4558 && lim
.rlim_cur
== (target_long
)lim
.rlim_cur
) {
4559 guest_stack_size
= lim
.rlim_cur
;
4567 qemu_add_opts(&qemu_trace_opts
);
4569 optind
= parse_args(argc
, argv
);
4571 if (!trace_init_backends()) {
4574 trace_init_file(trace_file
);
4577 memset(regs
, 0, sizeof(struct target_pt_regs
));
4579 /* Zero out image_info */
4580 memset(info
, 0, sizeof(struct image_info
));
4582 memset(&bprm
, 0, sizeof (bprm
));
4584 /* Scan interp_prefix dir for replacement files. */
4585 init_paths(interp_prefix
);
4587 init_qemu_uname_release();
4589 execfd
= qemu_getauxval(AT_EXECFD
);
4591 execfd
= open(filename
, O_RDONLY
);
4593 printf("Error while loading %s: %s\n", filename
, strerror(errno
));
4594 _exit(EXIT_FAILURE
);
4598 if (cpu_model
== NULL
) {
4599 cpu_model
= cpu_get_model(get_elf_eflags(execfd
));
4601 cpu_type
= parse_cpu_model(cpu_model
);
4604 /* NOTE: we need to init the CPU at this stage to get
4605 qemu_host_page_size */
4607 cpu
= cpu_create(cpu_type
);
4613 if (getenv("QEMU_STRACE")) {
4617 if (getenv("QEMU_RAND_SEED")) {
4618 handle_arg_randseed(getenv("QEMU_RAND_SEED"));
4621 target_environ
= envlist_to_environ(envlist
, NULL
);
4622 envlist_free(envlist
);
4625 * Now that page sizes are configured in cpu_init() we can do
4626 * proper page alignment for guest_base.
4628 guest_base
= HOST_PAGE_ALIGN(guest_base
);
4630 if (reserved_va
|| have_guest_base
) {
4631 guest_base
= init_guest_space(guest_base
, reserved_va
, 0,
4633 if (guest_base
== (unsigned long)-1) {
4634 fprintf(stderr
, "Unable to reserve 0x%lx bytes of virtual address "
4635 "space for use as guest address space (check your virtual "
4636 "memory ulimit setting or reserve less using -R option)\n",
4642 mmap_next_start
= reserved_va
;
4647 * Read in mmap_min_addr kernel parameter. This value is used
4648 * When loading the ELF image to determine whether guest_base
4649 * is needed. It is also used in mmap_find_vma.
4654 if ((fp
= fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL
) {
4656 if (fscanf(fp
, "%lu", &tmp
) == 1) {
4657 mmap_min_addr
= tmp
;
4658 qemu_log_mask(CPU_LOG_PAGE
, "host mmap_min_addr=0x%lx\n", mmap_min_addr
);
4665 * Prepare copy of argv vector for target.
4667 target_argc
= argc
- optind
;
4668 target_argv
= calloc(target_argc
+ 1, sizeof (char *));
4669 if (target_argv
== NULL
) {
4670 (void) fprintf(stderr
, "Unable to allocate memory for target_argv\n");
4675 * If argv0 is specified (using '-0' switch) we replace
4676 * argv[0] pointer with the given one.
4679 if (argv0
!= NULL
) {
4680 target_argv
[i
++] = strdup(argv0
);
4682 for (; i
< target_argc
; i
++) {
4683 target_argv
[i
] = strdup(argv
[optind
+ i
]);
4685 target_argv
[target_argc
] = NULL
;
4687 ts
= g_new0(TaskState
, 1);
4688 init_task_state(ts
);
4689 /* build Task State */
4695 ret
= loader_exec(execfd
, filename
, target_argv
, target_environ
, regs
,
4698 printf("Error while loading %s: %s\n", filename
, strerror(-ret
));
4699 _exit(EXIT_FAILURE
);
4702 for (wrk
= target_environ
; *wrk
; wrk
++) {
4706 g_free(target_environ
);
4708 if (qemu_loglevel_mask(CPU_LOG_PAGE
)) {
4709 qemu_log("guest_base 0x%lx\n", guest_base
);
4712 qemu_log("start_brk 0x" TARGET_ABI_FMT_lx
"\n", info
->start_brk
);
4713 qemu_log("end_code 0x" TARGET_ABI_FMT_lx
"\n", info
->end_code
);
4714 qemu_log("start_code 0x" TARGET_ABI_FMT_lx
"\n", info
->start_code
);
4715 qemu_log("start_data 0x" TARGET_ABI_FMT_lx
"\n", info
->start_data
);
4716 qemu_log("end_data 0x" TARGET_ABI_FMT_lx
"\n", info
->end_data
);
4717 qemu_log("start_stack 0x" TARGET_ABI_FMT_lx
"\n", info
->start_stack
);
4718 qemu_log("brk 0x" TARGET_ABI_FMT_lx
"\n", info
->brk
);
4719 qemu_log("entry 0x" TARGET_ABI_FMT_lx
"\n", info
->entry
);
4720 qemu_log("argv_start 0x" TARGET_ABI_FMT_lx
"\n", info
->arg_start
);
4721 qemu_log("env_start 0x" TARGET_ABI_FMT_lx
"\n",
4722 info
->arg_end
+ (abi_ulong
)sizeof(abi_ulong
));
4723 qemu_log("auxv_start 0x" TARGET_ABI_FMT_lx
"\n", info
->saved_auxv
);
4726 target_set_brk(info
->brk
);
4730 /* Now that we've loaded the binary, GUEST_BASE is fixed. Delay
4731 generating the prologue until now so that the prologue can take
4732 the real value of GUEST_BASE into account. */
4733 tcg_prologue_init(tcg_ctx
);
4736 #if defined(TARGET_I386)
4737 env
->cr
[0] = CR0_PG_MASK
| CR0_WP_MASK
| CR0_PE_MASK
;
4738 env
->hflags
|= HF_PE_MASK
| HF_CPL_MASK
;
4739 if (env
->features
[FEAT_1_EDX
] & CPUID_SSE
) {
4740 env
->cr
[4] |= CR4_OSFXSR_MASK
;
4741 env
->hflags
|= HF_OSFXSR_MASK
;
4743 #ifndef TARGET_ABI32
4744 /* enable 64 bit mode if possible */
4745 if (!(env
->features
[FEAT_8000_0001_EDX
] & CPUID_EXT2_LM
)) {
4746 fprintf(stderr
, "The selected x86 CPU does not support 64 bit mode\n");
4749 env
->cr
[4] |= CR4_PAE_MASK
;
4750 env
->efer
|= MSR_EFER_LMA
| MSR_EFER_LME
;
4751 env
->hflags
|= HF_LMA_MASK
;
4754 /* flags setup : we activate the IRQs by default as in user mode */
4755 env
->eflags
|= IF_MASK
;
4757 /* linux register setup */
4758 #ifndef TARGET_ABI32
4759 env
->regs
[R_EAX
] = regs
->rax
;
4760 env
->regs
[R_EBX
] = regs
->rbx
;
4761 env
->regs
[R_ECX
] = regs
->rcx
;
4762 env
->regs
[R_EDX
] = regs
->rdx
;
4763 env
->regs
[R_ESI
] = regs
->rsi
;
4764 env
->regs
[R_EDI
] = regs
->rdi
;
4765 env
->regs
[R_EBP
] = regs
->rbp
;
4766 env
->regs
[R_ESP
] = regs
->rsp
;
4767 env
->eip
= regs
->rip
;
4769 env
->regs
[R_EAX
] = regs
->eax
;
4770 env
->regs
[R_EBX
] = regs
->ebx
;
4771 env
->regs
[R_ECX
] = regs
->ecx
;
4772 env
->regs
[R_EDX
] = regs
->edx
;
4773 env
->regs
[R_ESI
] = regs
->esi
;
4774 env
->regs
[R_EDI
] = regs
->edi
;
4775 env
->regs
[R_EBP
] = regs
->ebp
;
4776 env
->regs
[R_ESP
] = regs
->esp
;
4777 env
->eip
= regs
->eip
;
4780 /* linux interrupt setup */
4781 #ifndef TARGET_ABI32
4782 env
->idt
.limit
= 511;
4784 env
->idt
.limit
= 255;
4786 env
->idt
.base
= target_mmap(0, sizeof(uint64_t) * (env
->idt
.limit
+ 1),
4787 PROT_READ
|PROT_WRITE
,
4788 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
4789 idt_table
= g2h(env
->idt
.base
);
4812 /* linux segment setup */
4814 uint64_t *gdt_table
;
4815 env
->gdt
.base
= target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES
,
4816 PROT_READ
|PROT_WRITE
,
4817 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
4818 env
->gdt
.limit
= sizeof(uint64_t) * TARGET_GDT_ENTRIES
- 1;
4819 gdt_table
= g2h(env
->gdt
.base
);
4821 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
4822 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
4823 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
4825 /* 64 bit code segment */
4826 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
4827 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
4829 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
4831 write_dt(&gdt_table
[__USER_DS
>> 3], 0, 0xfffff,
4832 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
4833 (3 << DESC_DPL_SHIFT
) | (0x2 << DESC_TYPE_SHIFT
));
4835 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
4836 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
4838 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
4839 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
4840 cpu_x86_load_seg(env
, R_FS
, __USER_DS
);
4841 cpu_x86_load_seg(env
, R_GS
, __USER_DS
);
4842 /* This hack makes Wine work... */
4843 env
->segs
[R_FS
].selector
= 0;
4845 cpu_x86_load_seg(env
, R_DS
, 0);
4846 cpu_x86_load_seg(env
, R_ES
, 0);
4847 cpu_x86_load_seg(env
, R_FS
, 0);
4848 cpu_x86_load_seg(env
, R_GS
, 0);
4850 #elif defined(TARGET_AARCH64)
4854 if (!(arm_feature(env
, ARM_FEATURE_AARCH64
))) {
4856 "The selected ARM CPU does not support 64 bit mode\n");
4860 for (i
= 0; i
< 31; i
++) {
4861 env
->xregs
[i
] = regs
->regs
[i
];
4864 env
->xregs
[31] = regs
->sp
;
4865 #ifdef TARGET_WORDS_BIGENDIAN
4866 env
->cp15
.sctlr_el
[1] |= SCTLR_E0E
;
4867 for (i
= 1; i
< 4; ++i
) {
4868 env
->cp15
.sctlr_el
[i
] |= SCTLR_EE
;
4872 #elif defined(TARGET_ARM)
4875 cpsr_write(env
, regs
->uregs
[16], CPSR_USER
| CPSR_EXEC
,
4877 for(i
= 0; i
< 16; i
++) {
4878 env
->regs
[i
] = regs
->uregs
[i
];
4880 #ifdef TARGET_WORDS_BIGENDIAN
4882 if (EF_ARM_EABI_VERSION(info
->elf_flags
) >= EF_ARM_EABI_VER4
4883 && (info
->elf_flags
& EF_ARM_BE8
)) {
4884 env
->uncached_cpsr
|= CPSR_E
;
4885 env
->cp15
.sctlr_el
[1] |= SCTLR_E0E
;
4887 env
->cp15
.sctlr_el
[1] |= SCTLR_B
;
4891 #elif defined(TARGET_SPARC)
4895 env
->npc
= regs
->npc
;
4897 for(i
= 0; i
< 8; i
++)
4898 env
->gregs
[i
] = regs
->u_regs
[i
];
4899 for(i
= 0; i
< 8; i
++)
4900 env
->regwptr
[i
] = regs
->u_regs
[i
+ 8];
4902 #elif defined(TARGET_PPC)
4906 #if defined(TARGET_PPC64)
4907 int flag
= (env
->insns_flags2
& PPC2_BOOKE206
) ? MSR_CM
: MSR_SF
;
4908 #if defined(TARGET_ABI32)
4909 env
->msr
&= ~((target_ulong
)1 << flag
);
4911 env
->msr
|= (target_ulong
)1 << flag
;
4914 env
->nip
= regs
->nip
;
4915 for(i
= 0; i
< 32; i
++) {
4916 env
->gpr
[i
] = regs
->gpr
[i
];
4919 #elif defined(TARGET_M68K)
4922 env
->dregs
[0] = regs
->d0
;
4923 env
->dregs
[1] = regs
->d1
;
4924 env
->dregs
[2] = regs
->d2
;
4925 env
->dregs
[3] = regs
->d3
;
4926 env
->dregs
[4] = regs
->d4
;
4927 env
->dregs
[5] = regs
->d5
;
4928 env
->dregs
[6] = regs
->d6
;
4929 env
->dregs
[7] = regs
->d7
;
4930 env
->aregs
[0] = regs
->a0
;
4931 env
->aregs
[1] = regs
->a1
;
4932 env
->aregs
[2] = regs
->a2
;
4933 env
->aregs
[3] = regs
->a3
;
4934 env
->aregs
[4] = regs
->a4
;
4935 env
->aregs
[5] = regs
->a5
;
4936 env
->aregs
[6] = regs
->a6
;
4937 env
->aregs
[7] = regs
->usp
;
4939 ts
->sim_syscalls
= 1;
4941 #elif defined(TARGET_MICROBLAZE)
4943 env
->regs
[0] = regs
->r0
;
4944 env
->regs
[1] = regs
->r1
;
4945 env
->regs
[2] = regs
->r2
;
4946 env
->regs
[3] = regs
->r3
;
4947 env
->regs
[4] = regs
->r4
;
4948 env
->regs
[5] = regs
->r5
;
4949 env
->regs
[6] = regs
->r6
;
4950 env
->regs
[7] = regs
->r7
;
4951 env
->regs
[8] = regs
->r8
;
4952 env
->regs
[9] = regs
->r9
;
4953 env
->regs
[10] = regs
->r10
;
4954 env
->regs
[11] = regs
->r11
;
4955 env
->regs
[12] = regs
->r12
;
4956 env
->regs
[13] = regs
->r13
;
4957 env
->regs
[14] = regs
->r14
;
4958 env
->regs
[15] = regs
->r15
;
4959 env
->regs
[16] = regs
->r16
;
4960 env
->regs
[17] = regs
->r17
;
4961 env
->regs
[18] = regs
->r18
;
4962 env
->regs
[19] = regs
->r19
;
4963 env
->regs
[20] = regs
->r20
;
4964 env
->regs
[21] = regs
->r21
;
4965 env
->regs
[22] = regs
->r22
;
4966 env
->regs
[23] = regs
->r23
;
4967 env
->regs
[24] = regs
->r24
;
4968 env
->regs
[25] = regs
->r25
;
4969 env
->regs
[26] = regs
->r26
;
4970 env
->regs
[27] = regs
->r27
;
4971 env
->regs
[28] = regs
->r28
;
4972 env
->regs
[29] = regs
->r29
;
4973 env
->regs
[30] = regs
->r30
;
4974 env
->regs
[31] = regs
->r31
;
4975 env
->sregs
[SR_PC
] = regs
->pc
;
4977 #elif defined(TARGET_MIPS)
4981 for(i
= 0; i
< 32; i
++) {
4982 env
->active_tc
.gpr
[i
] = regs
->regs
[i
];
4984 env
->active_tc
.PC
= regs
->cp0_epc
& ~(target_ulong
)1;
4985 if (regs
->cp0_epc
& 1) {
4986 env
->hflags
|= MIPS_HFLAG_M16
;
4988 if (((info
->elf_flags
& EF_MIPS_NAN2008
) != 0) !=
4989 ((env
->active_fpu
.fcr31
& (1 << FCR31_NAN2008
)) != 0)) {
4990 if ((env
->active_fpu
.fcr31_rw_bitmask
&
4991 (1 << FCR31_NAN2008
)) == 0) {
4992 fprintf(stderr
, "ELF binary's NaN mode not supported by CPU\n");
4995 if ((info
->elf_flags
& EF_MIPS_NAN2008
) != 0) {
4996 env
->active_fpu
.fcr31
|= (1 << FCR31_NAN2008
);
4998 env
->active_fpu
.fcr31
&= ~(1 << FCR31_NAN2008
);
5000 restore_snan_bit_mode(env
);
5003 #elif defined(TARGET_NIOS2)
5006 env
->regs
[1] = regs
->r1
;
5007 env
->regs
[2] = regs
->r2
;
5008 env
->regs
[3] = regs
->r3
;
5009 env
->regs
[4] = regs
->r4
;
5010 env
->regs
[5] = regs
->r5
;
5011 env
->regs
[6] = regs
->r6
;
5012 env
->regs
[7] = regs
->r7
;
5013 env
->regs
[8] = regs
->r8
;
5014 env
->regs
[9] = regs
->r9
;
5015 env
->regs
[10] = regs
->r10
;
5016 env
->regs
[11] = regs
->r11
;
5017 env
->regs
[12] = regs
->r12
;
5018 env
->regs
[13] = regs
->r13
;
5019 env
->regs
[14] = regs
->r14
;
5020 env
->regs
[15] = regs
->r15
;
5021 /* TODO: unsigned long orig_r2; */
5022 env
->regs
[R_RA
] = regs
->ra
;
5023 env
->regs
[R_FP
] = regs
->fp
;
5024 env
->regs
[R_SP
] = regs
->sp
;
5025 env
->regs
[R_GP
] = regs
->gp
;
5026 env
->regs
[CR_ESTATUS
] = regs
->estatus
;
5027 env
->regs
[R_EA
] = regs
->ea
;
5028 /* TODO: unsigned long orig_r7; */
5030 /* Emulate eret when starting thread. */
5031 env
->regs
[R_PC
] = regs
->ea
;
5033 #elif defined(TARGET_OPENRISC)
5037 for (i
= 0; i
< 32; i
++) {
5038 cpu_set_gpr(env
, i
, regs
->gpr
[i
]);
5041 cpu_set_sr(env
, regs
->sr
);
5043 #elif defined(TARGET_RISCV)
5045 env
->pc
= regs
->sepc
;
5046 env
->gpr
[xSP
] = regs
->sp
;
5048 #elif defined(TARGET_SH4)
5052 for(i
= 0; i
< 16; i
++) {
5053 env
->gregs
[i
] = regs
->regs
[i
];
5057 #elif defined(TARGET_ALPHA)
5061 for(i
= 0; i
< 28; i
++) {
5062 env
->ir
[i
] = ((abi_ulong
*)regs
)[i
];
5064 env
->ir
[IR_SP
] = regs
->usp
;
5067 #elif defined(TARGET_CRIS)
5069 env
->regs
[0] = regs
->r0
;
5070 env
->regs
[1] = regs
->r1
;
5071 env
->regs
[2] = regs
->r2
;
5072 env
->regs
[3] = regs
->r3
;
5073 env
->regs
[4] = regs
->r4
;
5074 env
->regs
[5] = regs
->r5
;
5075 env
->regs
[6] = regs
->r6
;
5076 env
->regs
[7] = regs
->r7
;
5077 env
->regs
[8] = regs
->r8
;
5078 env
->regs
[9] = regs
->r9
;
5079 env
->regs
[10] = regs
->r10
;
5080 env
->regs
[11] = regs
->r11
;
5081 env
->regs
[12] = regs
->r12
;
5082 env
->regs
[13] = regs
->r13
;
5083 env
->regs
[14] = info
->start_stack
;
5084 env
->regs
[15] = regs
->acr
;
5085 env
->pc
= regs
->erp
;
5087 #elif defined(TARGET_S390X)
5090 for (i
= 0; i
< 16; i
++) {
5091 env
->regs
[i
] = regs
->gprs
[i
];
5093 env
->psw
.mask
= regs
->psw
.mask
;
5094 env
->psw
.addr
= regs
->psw
.addr
;
5096 #elif defined(TARGET_TILEGX)
5099 for (i
= 0; i
< TILEGX_R_COUNT
; i
++) {
5100 env
->regs
[i
] = regs
->regs
[i
];
5102 for (i
= 0; i
< TILEGX_SPR_COUNT
; i
++) {
5107 #elif defined(TARGET_HPPA)
5110 for (i
= 1; i
< 32; i
++) {
5111 env
->gr
[i
] = regs
->gr
[i
];
5113 env
->iaoq_f
= regs
->iaoq
[0];
5114 env
->iaoq_b
= regs
->iaoq
[1];
5116 #elif defined(TARGET_XTENSA)
5119 for (i
= 0; i
< 16; ++i
) {
5120 env
->regs
[i
] = regs
->areg
[i
];
5122 env
->sregs
[WINDOW_START
] = regs
->windowstart
;
5126 #error unsupported target CPU
5129 #if defined(TARGET_ARM) || defined(TARGET_M68K)
5130 ts
->stack_base
= info
->start_stack
;
5131 ts
->heap_base
= info
->brk
;
5132 /* This will be filled in on the first SYS_HEAPINFO call. */
5137 if (gdbserver_start(gdbstub_port
) < 0) {
5138 fprintf(stderr
, "qemu: could not open gdbserver on port %d\n",
5142 gdb_handlesig(cpu
, 0);