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/>.
26 #include <sys/syscall.h>
27 #include <sys/resource.h>
30 #include "qemu-common.h"
31 #include "cache-utils.h"
35 #include "qemu-timer.h"
38 #define DEBUG_LOGFILE "/tmp/qemu.log"
43 unsigned long mmap_min_addr
;
44 #if defined(CONFIG_USE_GUEST_BASE)
45 unsigned long guest_base
;
47 unsigned long reserved_va
;
50 static const char *interp_prefix
= CONFIG_QEMU_INTERP_PREFIX
;
51 const char *qemu_uname_release
= CONFIG_UNAME_RELEASE
;
53 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
54 we allocate a bigger stack. Need a better solution, for example
55 by remapping the process stack directly at the right place */
56 unsigned long guest_stack_size
= 8 * 1024 * 1024UL;
58 void gemu_log(const char *fmt
, ...)
63 vfprintf(stderr
, fmt
, ap
);
67 #if defined(TARGET_I386)
68 int cpu_get_pic_interrupt(CPUState
*env
)
74 /* timers for rdtsc */
78 static uint64_t emu_time
;
80 int64_t cpu_get_real_ticks(void)
87 #if defined(CONFIG_USE_NPTL)
88 /***********************************************************/
89 /* Helper routines for implementing atomic operations. */
91 /* To implement exclusive operations we force all cpus to syncronise.
92 We don't require a full sync, only that no cpus are executing guest code.
93 The alternative is to map target atomic ops onto host equivalents,
94 which requires quite a lot of per host/target work. */
95 static pthread_mutex_t cpu_list_mutex
= PTHREAD_MUTEX_INITIALIZER
;
96 static pthread_mutex_t exclusive_lock
= PTHREAD_MUTEX_INITIALIZER
;
97 static pthread_cond_t exclusive_cond
= PTHREAD_COND_INITIALIZER
;
98 static pthread_cond_t exclusive_resume
= PTHREAD_COND_INITIALIZER
;
99 static int pending_cpus
;
101 /* Make sure everything is in a consistent state for calling fork(). */
102 void fork_start(void)
104 pthread_mutex_lock(&tb_lock
);
105 pthread_mutex_lock(&exclusive_lock
);
109 void fork_end(int child
)
111 mmap_fork_end(child
);
113 /* Child processes created by fork() only have a single thread.
114 Discard information about the parent threads. */
115 first_cpu
= thread_env
;
116 thread_env
->next_cpu
= NULL
;
118 pthread_mutex_init(&exclusive_lock
, NULL
);
119 pthread_mutex_init(&cpu_list_mutex
, NULL
);
120 pthread_cond_init(&exclusive_cond
, NULL
);
121 pthread_cond_init(&exclusive_resume
, NULL
);
122 pthread_mutex_init(&tb_lock
, NULL
);
123 gdbserver_fork(thread_env
);
125 pthread_mutex_unlock(&exclusive_lock
);
126 pthread_mutex_unlock(&tb_lock
);
130 /* Wait for pending exclusive operations to complete. The exclusive lock
132 static inline void exclusive_idle(void)
134 while (pending_cpus
) {
135 pthread_cond_wait(&exclusive_resume
, &exclusive_lock
);
139 /* Start an exclusive operation.
140 Must only be called from outside cpu_arm_exec. */
141 static inline void start_exclusive(void)
144 pthread_mutex_lock(&exclusive_lock
);
148 /* Make all other cpus stop executing. */
149 for (other
= first_cpu
; other
; other
= other
->next_cpu
) {
150 if (other
->running
) {
155 if (pending_cpus
> 1) {
156 pthread_cond_wait(&exclusive_cond
, &exclusive_lock
);
160 /* Finish an exclusive operation. */
161 static inline void end_exclusive(void)
164 pthread_cond_broadcast(&exclusive_resume
);
165 pthread_mutex_unlock(&exclusive_lock
);
168 /* Wait for exclusive ops to finish, and begin cpu execution. */
169 static inline void cpu_exec_start(CPUState
*env
)
171 pthread_mutex_lock(&exclusive_lock
);
174 pthread_mutex_unlock(&exclusive_lock
);
177 /* Mark cpu as not executing, and release pending exclusive ops. */
178 static inline void cpu_exec_end(CPUState
*env
)
180 pthread_mutex_lock(&exclusive_lock
);
182 if (pending_cpus
> 1) {
184 if (pending_cpus
== 1) {
185 pthread_cond_signal(&exclusive_cond
);
189 pthread_mutex_unlock(&exclusive_lock
);
192 void cpu_list_lock(void)
194 pthread_mutex_lock(&cpu_list_mutex
);
197 void cpu_list_unlock(void)
199 pthread_mutex_unlock(&cpu_list_mutex
);
201 #else /* if !CONFIG_USE_NPTL */
202 /* These are no-ops because we are not threadsafe. */
203 static inline void cpu_exec_start(CPUState
*env
)
207 static inline void cpu_exec_end(CPUState
*env
)
211 static inline void start_exclusive(void)
215 static inline void end_exclusive(void)
219 void fork_start(void)
223 void fork_end(int child
)
226 gdbserver_fork(thread_env
);
230 void cpu_list_lock(void)
234 void cpu_list_unlock(void)
241 /***********************************************************/
242 /* CPUX86 core interface */
244 void cpu_smm_update(CPUState
*env
)
248 uint64_t cpu_get_tsc(CPUX86State
*env
)
250 return cpu_get_real_ticks();
253 static void write_dt(void *ptr
, unsigned long addr
, unsigned long limit
,
258 e1
= (addr
<< 16) | (limit
& 0xffff);
259 e2
= ((addr
>> 16) & 0xff) | (addr
& 0xff000000) | (limit
& 0x000f0000);
266 static uint64_t *idt_table
;
268 static void set_gate64(void *ptr
, unsigned int type
, unsigned int dpl
,
269 uint64_t addr
, unsigned int sel
)
272 e1
= (addr
& 0xffff) | (sel
<< 16);
273 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
277 p
[2] = tswap32(addr
>> 32);
280 /* only dpl matters as we do only user space emulation */
281 static void set_idt(int n
, unsigned int dpl
)
283 set_gate64(idt_table
+ n
* 2, 0, dpl
, 0, 0);
286 static void set_gate(void *ptr
, unsigned int type
, unsigned int dpl
,
287 uint32_t addr
, unsigned int sel
)
290 e1
= (addr
& 0xffff) | (sel
<< 16);
291 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
297 /* only dpl matters as we do only user space emulation */
298 static void set_idt(int n
, unsigned int dpl
)
300 set_gate(idt_table
+ n
, 0, dpl
, 0, 0);
304 void cpu_loop(CPUX86State
*env
)
308 target_siginfo_t info
;
311 trapnr
= cpu_x86_exec(env
);
314 /* linux syscall from int $0x80 */
315 env
->regs
[R_EAX
] = do_syscall(env
,
326 /* linux syscall from syscall intruction */
327 env
->regs
[R_EAX
] = do_syscall(env
,
335 env
->eip
= env
->exception_next_eip
;
340 info
.si_signo
= SIGBUS
;
342 info
.si_code
= TARGET_SI_KERNEL
;
343 info
._sifields
._sigfault
._addr
= 0;
344 queue_signal(env
, info
.si_signo
, &info
);
347 /* XXX: potential problem if ABI32 */
348 #ifndef TARGET_X86_64
349 if (env
->eflags
& VM_MASK
) {
350 handle_vm86_fault(env
);
354 info
.si_signo
= SIGSEGV
;
356 info
.si_code
= TARGET_SI_KERNEL
;
357 info
._sifields
._sigfault
._addr
= 0;
358 queue_signal(env
, info
.si_signo
, &info
);
362 info
.si_signo
= SIGSEGV
;
364 if (!(env
->error_code
& 1))
365 info
.si_code
= TARGET_SEGV_MAPERR
;
367 info
.si_code
= TARGET_SEGV_ACCERR
;
368 info
._sifields
._sigfault
._addr
= env
->cr
[2];
369 queue_signal(env
, info
.si_signo
, &info
);
372 #ifndef TARGET_X86_64
373 if (env
->eflags
& VM_MASK
) {
374 handle_vm86_trap(env
, trapnr
);
378 /* division by zero */
379 info
.si_signo
= SIGFPE
;
381 info
.si_code
= TARGET_FPE_INTDIV
;
382 info
._sifields
._sigfault
._addr
= env
->eip
;
383 queue_signal(env
, info
.si_signo
, &info
);
388 #ifndef TARGET_X86_64
389 if (env
->eflags
& VM_MASK
) {
390 handle_vm86_trap(env
, trapnr
);
394 info
.si_signo
= SIGTRAP
;
396 if (trapnr
== EXCP01_DB
) {
397 info
.si_code
= TARGET_TRAP_BRKPT
;
398 info
._sifields
._sigfault
._addr
= env
->eip
;
400 info
.si_code
= TARGET_SI_KERNEL
;
401 info
._sifields
._sigfault
._addr
= 0;
403 queue_signal(env
, info
.si_signo
, &info
);
408 #ifndef TARGET_X86_64
409 if (env
->eflags
& VM_MASK
) {
410 handle_vm86_trap(env
, trapnr
);
414 info
.si_signo
= SIGSEGV
;
416 info
.si_code
= TARGET_SI_KERNEL
;
417 info
._sifields
._sigfault
._addr
= 0;
418 queue_signal(env
, info
.si_signo
, &info
);
422 info
.si_signo
= SIGILL
;
424 info
.si_code
= TARGET_ILL_ILLOPN
;
425 info
._sifields
._sigfault
._addr
= env
->eip
;
426 queue_signal(env
, info
.si_signo
, &info
);
429 /* just indicate that signals should be handled asap */
435 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
440 info
.si_code
= TARGET_TRAP_BRKPT
;
441 queue_signal(env
, info
.si_signo
, &info
);
446 pc
= env
->segs
[R_CS
].base
+ env
->eip
;
447 fprintf(stderr
, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
451 process_pending_signals(env
);
458 static void arm_cache_flush(abi_ulong start
, abi_ulong last
)
460 abi_ulong addr
, last1
;
466 last1
= ((addr
+ TARGET_PAGE_SIZE
) & TARGET_PAGE_MASK
) - 1;
469 tb_invalidate_page_range(addr
, last1
+ 1);
476 /* Handle a jump to the kernel code page. */
478 do_kernel_trap(CPUARMState
*env
)
484 switch (env
->regs
[15]) {
485 case 0xffff0fa0: /* __kernel_memory_barrier */
486 /* ??? No-op. Will need to do better for SMP. */
488 case 0xffff0fc0: /* __kernel_cmpxchg */
489 /* XXX: This only works between threads, not between processes.
490 It's probably possible to implement this with native host
491 operations. However things like ldrex/strex are much harder so
492 there's not much point trying. */
494 cpsr
= cpsr_read(env
);
496 /* FIXME: This should SEGV if the access fails. */
497 if (get_user_u32(val
, addr
))
499 if (val
== env
->regs
[0]) {
501 /* FIXME: Check for segfaults. */
502 put_user_u32(val
, addr
);
509 cpsr_write(env
, cpsr
, CPSR_C
);
512 case 0xffff0fe0: /* __kernel_get_tls */
513 env
->regs
[0] = env
->cp15
.c13_tls2
;
518 /* Jump back to the caller. */
519 addr
= env
->regs
[14];
524 env
->regs
[15] = addr
;
529 static int do_strex(CPUARMState
*env
)
537 addr
= env
->exclusive_addr
;
538 if (addr
!= env
->exclusive_test
) {
541 size
= env
->exclusive_info
& 0xf;
544 segv
= get_user_u8(val
, addr
);
547 segv
= get_user_u16(val
, addr
);
551 segv
= get_user_u32(val
, addr
);
557 env
->cp15
.c6_data
= addr
;
560 if (val
!= env
->exclusive_val
) {
564 segv
= get_user_u32(val
, addr
+ 4);
566 env
->cp15
.c6_data
= addr
+ 4;
569 if (val
!= env
->exclusive_high
) {
573 val
= env
->regs
[(env
->exclusive_info
>> 8) & 0xf];
576 segv
= put_user_u8(val
, addr
);
579 segv
= put_user_u16(val
, addr
);
583 segv
= put_user_u32(val
, addr
);
587 env
->cp15
.c6_data
= addr
;
591 val
= env
->regs
[(env
->exclusive_info
>> 12) & 0xf];
592 segv
= put_user_u32(val
, addr
+ 4);
594 env
->cp15
.c6_data
= addr
+ 4;
601 env
->regs
[(env
->exclusive_info
>> 4) & 0xf] = rc
;
607 void cpu_loop(CPUARMState
*env
)
610 unsigned int n
, insn
;
611 target_siginfo_t info
;
616 trapnr
= cpu_arm_exec(env
);
621 TaskState
*ts
= env
->opaque
;
625 /* we handle the FPU emulation here, as Linux */
626 /* we get the opcode */
627 /* FIXME - what to do if get_user() fails? */
628 get_user_u32(opcode
, env
->regs
[15]);
630 rc
= EmulateAll(opcode
, &ts
->fpa
, env
);
631 if (rc
== 0) { /* illegal instruction */
632 info
.si_signo
= SIGILL
;
634 info
.si_code
= TARGET_ILL_ILLOPN
;
635 info
._sifields
._sigfault
._addr
= env
->regs
[15];
636 queue_signal(env
, info
.si_signo
, &info
);
637 } else if (rc
< 0) { /* FP exception */
640 /* translate softfloat flags to FPSR flags */
641 if (-rc
& float_flag_invalid
)
643 if (-rc
& float_flag_divbyzero
)
645 if (-rc
& float_flag_overflow
)
647 if (-rc
& float_flag_underflow
)
649 if (-rc
& float_flag_inexact
)
652 FPSR fpsr
= ts
->fpa
.fpsr
;
653 //printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe);
655 if (fpsr
& (arm_fpe
<< 16)) { /* exception enabled? */
656 info
.si_signo
= SIGFPE
;
659 /* ordered by priority, least first */
660 if (arm_fpe
& BIT_IXC
) info
.si_code
= TARGET_FPE_FLTRES
;
661 if (arm_fpe
& BIT_UFC
) info
.si_code
= TARGET_FPE_FLTUND
;
662 if (arm_fpe
& BIT_OFC
) info
.si_code
= TARGET_FPE_FLTOVF
;
663 if (arm_fpe
& BIT_DZC
) info
.si_code
= TARGET_FPE_FLTDIV
;
664 if (arm_fpe
& BIT_IOC
) info
.si_code
= TARGET_FPE_FLTINV
;
666 info
._sifields
._sigfault
._addr
= env
->regs
[15];
667 queue_signal(env
, info
.si_signo
, &info
);
672 /* accumulate unenabled exceptions */
673 if ((!(fpsr
& BIT_IXE
)) && (arm_fpe
& BIT_IXC
))
675 if ((!(fpsr
& BIT_UFE
)) && (arm_fpe
& BIT_UFC
))
677 if ((!(fpsr
& BIT_OFE
)) && (arm_fpe
& BIT_OFC
))
679 if ((!(fpsr
& BIT_DZE
)) && (arm_fpe
& BIT_DZC
))
681 if ((!(fpsr
& BIT_IOE
)) && (arm_fpe
& BIT_IOC
))
684 } else { /* everything OK */
695 if (trapnr
== EXCP_BKPT
) {
697 /* FIXME - what to do if get_user() fails? */
698 get_user_u16(insn
, env
->regs
[15]);
702 /* FIXME - what to do if get_user() fails? */
703 get_user_u32(insn
, env
->regs
[15]);
704 n
= (insn
& 0xf) | ((insn
>> 4) & 0xff0);
709 /* FIXME - what to do if get_user() fails? */
710 get_user_u16(insn
, env
->regs
[15] - 2);
713 /* FIXME - what to do if get_user() fails? */
714 get_user_u32(insn
, env
->regs
[15] - 4);
719 if (n
== ARM_NR_cacheflush
) {
720 arm_cache_flush(env
->regs
[0], env
->regs
[1]);
721 } else if (n
== ARM_NR_semihosting
722 || n
== ARM_NR_thumb_semihosting
) {
723 env
->regs
[0] = do_arm_semihosting (env
);
724 } else if (n
== 0 || n
>= ARM_SYSCALL_BASE
725 || (env
->thumb
&& n
== ARM_THUMB_SYSCALL
)) {
727 if (env
->thumb
|| n
== 0) {
730 n
-= ARM_SYSCALL_BASE
;
733 if ( n
> ARM_NR_BASE
) {
735 case ARM_NR_cacheflush
:
736 arm_cache_flush(env
->regs
[0], env
->regs
[1]);
739 cpu_set_tls(env
, env
->regs
[0]);
743 gemu_log("qemu: Unsupported ARM syscall: 0x%x\n",
745 env
->regs
[0] = -TARGET_ENOSYS
;
749 env
->regs
[0] = do_syscall(env
,
764 /* just indicate that signals should be handled asap */
766 case EXCP_PREFETCH_ABORT
:
767 addr
= env
->cp15
.c6_insn
;
769 case EXCP_DATA_ABORT
:
770 addr
= env
->cp15
.c6_data
;
774 info
.si_signo
= SIGSEGV
;
776 /* XXX: check env->error_code */
777 info
.si_code
= TARGET_SEGV_MAPERR
;
778 info
._sifields
._sigfault
._addr
= addr
;
779 queue_signal(env
, info
.si_signo
, &info
);
786 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
791 info
.si_code
= TARGET_TRAP_BRKPT
;
792 queue_signal(env
, info
.si_signo
, &info
);
796 case EXCP_KERNEL_TRAP
:
797 if (do_kernel_trap(env
))
802 addr
= env
->cp15
.c6_data
;
808 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
810 cpu_dump_state(env
, stderr
, fprintf
, 0);
813 process_pending_signals(env
);
819 #ifdef TARGET_UNICORE32
821 void cpu_loop(CPUState
*env
)
824 unsigned int n
, insn
;
825 target_siginfo_t info
;
829 trapnr
= uc32_cpu_exec(env
);
835 get_user_u32(insn
, env
->regs
[31] - 4);
838 if (n
>= UC32_SYSCALL_BASE
) {
840 n
-= UC32_SYSCALL_BASE
;
841 if (n
== UC32_SYSCALL_NR_set_tls
) {
842 cpu_set_tls(env
, env
->regs
[0]);
845 env
->regs
[0] = do_syscall(env
,
860 info
.si_signo
= SIGSEGV
;
862 /* XXX: check env->error_code */
863 info
.si_code
= TARGET_SEGV_MAPERR
;
864 info
._sifields
._sigfault
._addr
= env
->cp0
.c4_faultaddr
;
865 queue_signal(env
, info
.si_signo
, &info
);
868 /* just indicate that signals should be handled asap */
874 sig
= gdb_handlesig(env
, TARGET_SIGTRAP
);
878 info
.si_code
= TARGET_TRAP_BRKPT
;
879 queue_signal(env
, info
.si_signo
, &info
);
886 process_pending_signals(env
);
890 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr
);
891 cpu_dump_state(env
, stderr
, fprintf
, 0);
897 #define SPARC64_STACK_BIAS 2047
901 /* WARNING: dealing with register windows _is_ complicated. More info
902 can be found at http://www.sics.se/~psm/sparcstack.html */
903 static inline int get_reg_index(CPUSPARCState
*env
, int cwp
, int index
)
905 index
= (index
+ cwp
* 16) % (16 * env
->nwindows
);
906 /* wrap handling : if cwp is on the last window, then we use the
907 registers 'after' the end */
908 if (index
< 8 && env
->cwp
== env
->nwindows
- 1)
909 index
+= 16 * env
->nwindows
;
913 /* save the register window 'cwp1' */
914 static inline void save_window_offset(CPUSPARCState
*env
, int cwp1
)
919 sp_ptr
= env
->regbase
[get_reg_index(env
, cwp1
, 6)];
920 #ifdef TARGET_SPARC64
922 sp_ptr
+= SPARC64_STACK_BIAS
;
924 #if defined(DEBUG_WIN)
925 printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx
" save_cwp=%d\n",
928 for(i
= 0; i
< 16; i
++) {
929 /* FIXME - what to do if put_user() fails? */
930 put_user_ual(env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)], sp_ptr
);
931 sp_ptr
+= sizeof(abi_ulong
);
935 static void save_window(CPUSPARCState
*env
)
937 #ifndef TARGET_SPARC64
938 unsigned int new_wim
;
939 new_wim
= ((env
->wim
>> 1) | (env
->wim
<< (env
->nwindows
- 1))) &
940 ((1LL << env
->nwindows
) - 1);
941 save_window_offset(env
, cpu_cwp_dec(env
, env
->cwp
- 2));
944 save_window_offset(env
, cpu_cwp_dec(env
, env
->cwp
- 2));
950 static void restore_window(CPUSPARCState
*env
)
952 #ifndef TARGET_SPARC64
953 unsigned int new_wim
;
955 unsigned int i
, cwp1
;
958 #ifndef TARGET_SPARC64
959 new_wim
= ((env
->wim
<< 1) | (env
->wim
>> (env
->nwindows
- 1))) &
960 ((1LL << env
->nwindows
) - 1);
963 /* restore the invalid window */
964 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ 1);
965 sp_ptr
= env
->regbase
[get_reg_index(env
, cwp1
, 6)];
966 #ifdef TARGET_SPARC64
968 sp_ptr
+= SPARC64_STACK_BIAS
;
970 #if defined(DEBUG_WIN)
971 printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx
" load_cwp=%d\n",
974 for(i
= 0; i
< 16; i
++) {
975 /* FIXME - what to do if get_user() fails? */
976 get_user_ual(env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)], sp_ptr
);
977 sp_ptr
+= sizeof(abi_ulong
);
979 #ifdef TARGET_SPARC64
981 if (env
->cleanwin
< env
->nwindows
- 1)
989 static void flush_windows(CPUSPARCState
*env
)
995 /* if restore would invoke restore_window(), then we can stop */
996 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ offset
);
997 #ifndef TARGET_SPARC64
998 if (env
->wim
& (1 << cwp1
))
1001 if (env
->canrestore
== 0)
1006 save_window_offset(env
, cwp1
);
1009 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ 1);
1010 #ifndef TARGET_SPARC64
1011 /* set wim so that restore will reload the registers */
1012 env
->wim
= 1 << cwp1
;
1014 #if defined(DEBUG_WIN)
1015 printf("flush_windows: nb=%d\n", offset
- 1);
1019 void cpu_loop (CPUSPARCState
*env
)
1023 target_siginfo_t info
;
1026 trapnr
= cpu_sparc_exec (env
);
1029 #ifndef TARGET_SPARC64
1036 ret
= do_syscall (env
, env
->gregs
[1],
1037 env
->regwptr
[0], env
->regwptr
[1],
1038 env
->regwptr
[2], env
->regwptr
[3],
1039 env
->regwptr
[4], env
->regwptr
[5]);
1040 if ((abi_ulong
)ret
>= (abi_ulong
)(-515)) {
1041 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1042 env
->xcc
|= PSR_CARRY
;
1044 env
->psr
|= PSR_CARRY
;
1048 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1049 env
->xcc
&= ~PSR_CARRY
;
1051 env
->psr
&= ~PSR_CARRY
;
1054 env
->regwptr
[0] = ret
;
1055 /* next instruction */
1057 env
->npc
= env
->npc
+ 4;
1059 case 0x83: /* flush windows */
1064 /* next instruction */
1066 env
->npc
= env
->npc
+ 4;
1068 #ifndef TARGET_SPARC64
1069 case TT_WIN_OVF
: /* window overflow */
1072 case TT_WIN_UNF
: /* window underflow */
1073 restore_window(env
);
1078 info
.si_signo
= SIGSEGV
;
1080 /* XXX: check env->error_code */
1081 info
.si_code
= TARGET_SEGV_MAPERR
;
1082 info
._sifields
._sigfault
._addr
= env
->mmuregs
[4];
1083 queue_signal(env
, info
.si_signo
, &info
);
1087 case TT_SPILL
: /* window overflow */
1090 case TT_FILL
: /* window underflow */
1091 restore_window(env
);
1096 info
.si_signo
= SIGSEGV
;
1098 /* XXX: check env->error_code */
1099 info
.si_code
= TARGET_SEGV_MAPERR
;
1100 if (trapnr
== TT_DFAULT
)
1101 info
._sifields
._sigfault
._addr
= env
->dmmuregs
[4];
1103 info
._sifields
._sigfault
._addr
= cpu_tsptr(env
)->tpc
;
1104 queue_signal(env
, info
.si_signo
, &info
);
1107 #ifndef TARGET_ABI32
1110 sparc64_get_context(env
);
1114 sparc64_set_context(env
);
1118 case EXCP_INTERRUPT
:
1119 /* just indicate that signals should be handled asap */
1125 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
1128 info
.si_signo
= sig
;
1130 info
.si_code
= TARGET_TRAP_BRKPT
;
1131 queue_signal(env
, info
.si_signo
, &info
);
1136 printf ("Unhandled trap: 0x%x\n", trapnr
);
1137 cpu_dump_state(env
, stderr
, fprintf
, 0);
1140 process_pending_signals (env
);
1147 static inline uint64_t cpu_ppc_get_tb (CPUState
*env
)
1153 uint64_t cpu_ppc_load_tbl (CPUState
*env
)
1155 return cpu_ppc_get_tb(env
);
1158 uint32_t cpu_ppc_load_tbu (CPUState
*env
)
1160 return cpu_ppc_get_tb(env
) >> 32;
1163 uint64_t cpu_ppc_load_atbl (CPUState
*env
)
1165 return cpu_ppc_get_tb(env
);
1168 uint32_t cpu_ppc_load_atbu (CPUState
*env
)
1170 return cpu_ppc_get_tb(env
) >> 32;
1173 uint32_t cpu_ppc601_load_rtcu (CPUState
*env
)
1174 __attribute__ (( alias ("cpu_ppc_load_tbu") ));
1176 uint32_t cpu_ppc601_load_rtcl (CPUState
*env
)
1178 return cpu_ppc_load_tbl(env
) & 0x3FFFFF80;
1181 /* XXX: to be fixed */
1182 int ppc_dcr_read (ppc_dcr_t
*dcr_env
, int dcrn
, uint32_t *valp
)
1187 int ppc_dcr_write (ppc_dcr_t
*dcr_env
, int dcrn
, uint32_t val
)
1192 #define EXCP_DUMP(env, fmt, ...) \
1194 fprintf(stderr, fmt , ## __VA_ARGS__); \
1195 cpu_dump_state(env, stderr, fprintf, 0); \
1196 qemu_log(fmt, ## __VA_ARGS__); \
1198 log_cpu_state(env, 0); \
1201 static int do_store_exclusive(CPUPPCState
*env
)
1204 target_ulong page_addr
;
1209 addr
= env
->reserve_ea
;
1210 page_addr
= addr
& TARGET_PAGE_MASK
;
1213 flags
= page_get_flags(page_addr
);
1214 if ((flags
& PAGE_READ
) == 0) {
1217 int reg
= env
->reserve_info
& 0x1f;
1218 int size
= (env
->reserve_info
>> 5) & 0xf;
1221 if (addr
== env
->reserve_addr
) {
1223 case 1: segv
= get_user_u8(val
, addr
); break;
1224 case 2: segv
= get_user_u16(val
, addr
); break;
1225 case 4: segv
= get_user_u32(val
, addr
); break;
1226 #if defined(TARGET_PPC64)
1227 case 8: segv
= get_user_u64(val
, addr
); break;
1231 if (!segv
&& val
== env
->reserve_val
) {
1232 val
= env
->gpr
[reg
];
1234 case 1: segv
= put_user_u8(val
, addr
); break;
1235 case 2: segv
= put_user_u16(val
, addr
); break;
1236 case 4: segv
= put_user_u32(val
, addr
); break;
1237 #if defined(TARGET_PPC64)
1238 case 8: segv
= put_user_u64(val
, addr
); break;
1247 env
->crf
[0] = (stored
<< 1) | xer_so
;
1248 env
->reserve_addr
= (target_ulong
)-1;
1258 void cpu_loop(CPUPPCState
*env
)
1260 target_siginfo_t info
;
1265 cpu_exec_start(env
);
1266 trapnr
= cpu_ppc_exec(env
);
1269 case POWERPC_EXCP_NONE
:
1272 case POWERPC_EXCP_CRITICAL
: /* Critical input */
1273 cpu_abort(env
, "Critical interrupt while in user mode. "
1276 case POWERPC_EXCP_MCHECK
: /* Machine check exception */
1277 cpu_abort(env
, "Machine check exception while in user mode. "
1280 case POWERPC_EXCP_DSI
: /* Data storage exception */
1281 EXCP_DUMP(env
, "Invalid data memory access: 0x" TARGET_FMT_lx
"\n",
1283 /* XXX: check this. Seems bugged */
1284 switch (env
->error_code
& 0xFF000000) {
1286 info
.si_signo
= TARGET_SIGSEGV
;
1288 info
.si_code
= TARGET_SEGV_MAPERR
;
1291 info
.si_signo
= TARGET_SIGILL
;
1293 info
.si_code
= TARGET_ILL_ILLADR
;
1296 info
.si_signo
= TARGET_SIGSEGV
;
1298 info
.si_code
= TARGET_SEGV_ACCERR
;
1301 /* Let's send a regular segfault... */
1302 EXCP_DUMP(env
, "Invalid segfault errno (%02x)\n",
1304 info
.si_signo
= TARGET_SIGSEGV
;
1306 info
.si_code
= TARGET_SEGV_MAPERR
;
1309 info
._sifields
._sigfault
._addr
= env
->nip
;
1310 queue_signal(env
, info
.si_signo
, &info
);
1312 case POWERPC_EXCP_ISI
: /* Instruction storage exception */
1313 EXCP_DUMP(env
, "Invalid instruction fetch: 0x\n" TARGET_FMT_lx
1314 "\n", env
->spr
[SPR_SRR0
]);
1315 /* XXX: check this */
1316 switch (env
->error_code
& 0xFF000000) {
1318 info
.si_signo
= TARGET_SIGSEGV
;
1320 info
.si_code
= TARGET_SEGV_MAPERR
;
1324 info
.si_signo
= TARGET_SIGSEGV
;
1326 info
.si_code
= TARGET_SEGV_ACCERR
;
1329 /* Let's send a regular segfault... */
1330 EXCP_DUMP(env
, "Invalid segfault errno (%02x)\n",
1332 info
.si_signo
= TARGET_SIGSEGV
;
1334 info
.si_code
= TARGET_SEGV_MAPERR
;
1337 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1338 queue_signal(env
, info
.si_signo
, &info
);
1340 case POWERPC_EXCP_EXTERNAL
: /* External input */
1341 cpu_abort(env
, "External interrupt while in user mode. "
1344 case POWERPC_EXCP_ALIGN
: /* Alignment exception */
1345 EXCP_DUMP(env
, "Unaligned memory access\n");
1346 /* XXX: check this */
1347 info
.si_signo
= TARGET_SIGBUS
;
1349 info
.si_code
= TARGET_BUS_ADRALN
;
1350 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1351 queue_signal(env
, info
.si_signo
, &info
);
1353 case POWERPC_EXCP_PROGRAM
: /* Program exception */
1354 /* XXX: check this */
1355 switch (env
->error_code
& ~0xF) {
1356 case POWERPC_EXCP_FP
:
1357 EXCP_DUMP(env
, "Floating point program exception\n");
1358 info
.si_signo
= TARGET_SIGFPE
;
1360 switch (env
->error_code
& 0xF) {
1361 case POWERPC_EXCP_FP_OX
:
1362 info
.si_code
= TARGET_FPE_FLTOVF
;
1364 case POWERPC_EXCP_FP_UX
:
1365 info
.si_code
= TARGET_FPE_FLTUND
;
1367 case POWERPC_EXCP_FP_ZX
:
1368 case POWERPC_EXCP_FP_VXZDZ
:
1369 info
.si_code
= TARGET_FPE_FLTDIV
;
1371 case POWERPC_EXCP_FP_XX
:
1372 info
.si_code
= TARGET_FPE_FLTRES
;
1374 case POWERPC_EXCP_FP_VXSOFT
:
1375 info
.si_code
= TARGET_FPE_FLTINV
;
1377 case POWERPC_EXCP_FP_VXSNAN
:
1378 case POWERPC_EXCP_FP_VXISI
:
1379 case POWERPC_EXCP_FP_VXIDI
:
1380 case POWERPC_EXCP_FP_VXIMZ
:
1381 case POWERPC_EXCP_FP_VXVC
:
1382 case POWERPC_EXCP_FP_VXSQRT
:
1383 case POWERPC_EXCP_FP_VXCVI
:
1384 info
.si_code
= TARGET_FPE_FLTSUB
;
1387 EXCP_DUMP(env
, "Unknown floating point exception (%02x)\n",
1392 case POWERPC_EXCP_INVAL
:
1393 EXCP_DUMP(env
, "Invalid instruction\n");
1394 info
.si_signo
= TARGET_SIGILL
;
1396 switch (env
->error_code
& 0xF) {
1397 case POWERPC_EXCP_INVAL_INVAL
:
1398 info
.si_code
= TARGET_ILL_ILLOPC
;
1400 case POWERPC_EXCP_INVAL_LSWX
:
1401 info
.si_code
= TARGET_ILL_ILLOPN
;
1403 case POWERPC_EXCP_INVAL_SPR
:
1404 info
.si_code
= TARGET_ILL_PRVREG
;
1406 case POWERPC_EXCP_INVAL_FP
:
1407 info
.si_code
= TARGET_ILL_COPROC
;
1410 EXCP_DUMP(env
, "Unknown invalid operation (%02x)\n",
1411 env
->error_code
& 0xF);
1412 info
.si_code
= TARGET_ILL_ILLADR
;
1416 case POWERPC_EXCP_PRIV
:
1417 EXCP_DUMP(env
, "Privilege violation\n");
1418 info
.si_signo
= TARGET_SIGILL
;
1420 switch (env
->error_code
& 0xF) {
1421 case POWERPC_EXCP_PRIV_OPC
:
1422 info
.si_code
= TARGET_ILL_PRVOPC
;
1424 case POWERPC_EXCP_PRIV_REG
:
1425 info
.si_code
= TARGET_ILL_PRVREG
;
1428 EXCP_DUMP(env
, "Unknown privilege violation (%02x)\n",
1429 env
->error_code
& 0xF);
1430 info
.si_code
= TARGET_ILL_PRVOPC
;
1434 case POWERPC_EXCP_TRAP
:
1435 cpu_abort(env
, "Tried to call a TRAP\n");
1438 /* Should not happen ! */
1439 cpu_abort(env
, "Unknown program exception (%02x)\n",
1443 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1444 queue_signal(env
, info
.si_signo
, &info
);
1446 case POWERPC_EXCP_FPU
: /* Floating-point unavailable exception */
1447 EXCP_DUMP(env
, "No floating point allowed\n");
1448 info
.si_signo
= TARGET_SIGILL
;
1450 info
.si_code
= TARGET_ILL_COPROC
;
1451 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1452 queue_signal(env
, info
.si_signo
, &info
);
1454 case POWERPC_EXCP_SYSCALL
: /* System call exception */
1455 cpu_abort(env
, "Syscall exception while in user mode. "
1458 case POWERPC_EXCP_APU
: /* Auxiliary processor unavailable */
1459 EXCP_DUMP(env
, "No APU instruction allowed\n");
1460 info
.si_signo
= TARGET_SIGILL
;
1462 info
.si_code
= TARGET_ILL_COPROC
;
1463 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1464 queue_signal(env
, info
.si_signo
, &info
);
1466 case POWERPC_EXCP_DECR
: /* Decrementer exception */
1467 cpu_abort(env
, "Decrementer interrupt while in user mode. "
1470 case POWERPC_EXCP_FIT
: /* Fixed-interval timer interrupt */
1471 cpu_abort(env
, "Fix interval timer interrupt while in user mode. "
1474 case POWERPC_EXCP_WDT
: /* Watchdog timer interrupt */
1475 cpu_abort(env
, "Watchdog timer interrupt while in user mode. "
1478 case POWERPC_EXCP_DTLB
: /* Data TLB error */
1479 cpu_abort(env
, "Data TLB exception while in user mode. "
1482 case POWERPC_EXCP_ITLB
: /* Instruction TLB error */
1483 cpu_abort(env
, "Instruction TLB exception while in user mode. "
1486 case POWERPC_EXCP_SPEU
: /* SPE/embedded floating-point unavail. */
1487 EXCP_DUMP(env
, "No SPE/floating-point instruction allowed\n");
1488 info
.si_signo
= TARGET_SIGILL
;
1490 info
.si_code
= TARGET_ILL_COPROC
;
1491 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1492 queue_signal(env
, info
.si_signo
, &info
);
1494 case POWERPC_EXCP_EFPDI
: /* Embedded floating-point data IRQ */
1495 cpu_abort(env
, "Embedded floating-point data IRQ not handled\n");
1497 case POWERPC_EXCP_EFPRI
: /* Embedded floating-point round IRQ */
1498 cpu_abort(env
, "Embedded floating-point round IRQ not handled\n");
1500 case POWERPC_EXCP_EPERFM
: /* Embedded performance monitor IRQ */
1501 cpu_abort(env
, "Performance monitor exception not handled\n");
1503 case POWERPC_EXCP_DOORI
: /* Embedded doorbell interrupt */
1504 cpu_abort(env
, "Doorbell interrupt while in user mode. "
1507 case POWERPC_EXCP_DOORCI
: /* Embedded doorbell critical interrupt */
1508 cpu_abort(env
, "Doorbell critical interrupt while in user mode. "
1511 case POWERPC_EXCP_RESET
: /* System reset exception */
1512 cpu_abort(env
, "Reset interrupt while in user mode. "
1515 case POWERPC_EXCP_DSEG
: /* Data segment exception */
1516 cpu_abort(env
, "Data segment exception while in user mode. "
1519 case POWERPC_EXCP_ISEG
: /* Instruction segment exception */
1520 cpu_abort(env
, "Instruction segment exception "
1521 "while in user mode. Aborting\n");
1523 /* PowerPC 64 with hypervisor mode support */
1524 case POWERPC_EXCP_HDECR
: /* Hypervisor decrementer exception */
1525 cpu_abort(env
, "Hypervisor decrementer interrupt "
1526 "while in user mode. Aborting\n");
1528 case POWERPC_EXCP_TRACE
: /* Trace exception */
1530 * we use this exception to emulate step-by-step execution mode.
1533 /* PowerPC 64 with hypervisor mode support */
1534 case POWERPC_EXCP_HDSI
: /* Hypervisor data storage exception */
1535 cpu_abort(env
, "Hypervisor data storage exception "
1536 "while in user mode. Aborting\n");
1538 case POWERPC_EXCP_HISI
: /* Hypervisor instruction storage excp */
1539 cpu_abort(env
, "Hypervisor instruction storage exception "
1540 "while in user mode. Aborting\n");
1542 case POWERPC_EXCP_HDSEG
: /* Hypervisor data segment exception */
1543 cpu_abort(env
, "Hypervisor data segment exception "
1544 "while in user mode. Aborting\n");
1546 case POWERPC_EXCP_HISEG
: /* Hypervisor instruction segment excp */
1547 cpu_abort(env
, "Hypervisor instruction segment exception "
1548 "while in user mode. Aborting\n");
1550 case POWERPC_EXCP_VPU
: /* Vector unavailable exception */
1551 EXCP_DUMP(env
, "No Altivec instructions allowed\n");
1552 info
.si_signo
= TARGET_SIGILL
;
1554 info
.si_code
= TARGET_ILL_COPROC
;
1555 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
1556 queue_signal(env
, info
.si_signo
, &info
);
1558 case POWERPC_EXCP_PIT
: /* Programmable interval timer IRQ */
1559 cpu_abort(env
, "Programable interval timer interrupt "
1560 "while in user mode. Aborting\n");
1562 case POWERPC_EXCP_IO
: /* IO error exception */
1563 cpu_abort(env
, "IO error exception while in user mode. "
1566 case POWERPC_EXCP_RUNM
: /* Run mode exception */
1567 cpu_abort(env
, "Run mode exception while in user mode. "
1570 case POWERPC_EXCP_EMUL
: /* Emulation trap exception */
1571 cpu_abort(env
, "Emulation trap exception not handled\n");
1573 case POWERPC_EXCP_IFTLB
: /* Instruction fetch TLB error */
1574 cpu_abort(env
, "Instruction fetch TLB exception "
1575 "while in user-mode. Aborting");
1577 case POWERPC_EXCP_DLTLB
: /* Data load TLB miss */
1578 cpu_abort(env
, "Data load TLB exception while in user-mode. "
1581 case POWERPC_EXCP_DSTLB
: /* Data store TLB miss */
1582 cpu_abort(env
, "Data store TLB exception while in user-mode. "
1585 case POWERPC_EXCP_FPA
: /* Floating-point assist exception */
1586 cpu_abort(env
, "Floating-point assist exception not handled\n");
1588 case POWERPC_EXCP_IABR
: /* Instruction address breakpoint */
1589 cpu_abort(env
, "Instruction address breakpoint exception "
1592 case POWERPC_EXCP_SMI
: /* System management interrupt */
1593 cpu_abort(env
, "System management interrupt while in user mode. "
1596 case POWERPC_EXCP_THERM
: /* Thermal interrupt */
1597 cpu_abort(env
, "Thermal interrupt interrupt while in user mode. "
1600 case POWERPC_EXCP_PERFM
: /* Embedded performance monitor IRQ */
1601 cpu_abort(env
, "Performance monitor exception not handled\n");
1603 case POWERPC_EXCP_VPUA
: /* Vector assist exception */
1604 cpu_abort(env
, "Vector assist exception not handled\n");
1606 case POWERPC_EXCP_SOFTP
: /* Soft patch exception */
1607 cpu_abort(env
, "Soft patch exception not handled\n");
1609 case POWERPC_EXCP_MAINT
: /* Maintenance exception */
1610 cpu_abort(env
, "Maintenance exception while in user mode. "
1613 case POWERPC_EXCP_STOP
: /* stop translation */
1614 /* We did invalidate the instruction cache. Go on */
1616 case POWERPC_EXCP_BRANCH
: /* branch instruction: */
1617 /* We just stopped because of a branch. Go on */
1619 case POWERPC_EXCP_SYSCALL_USER
:
1620 /* system call in user-mode emulation */
1622 * PPC ABI uses overflow flag in cr0 to signal an error
1626 printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env
->gpr
[0],
1627 env
->gpr
[3], env
->gpr
[4], env
->gpr
[5], env
->gpr
[6]);
1629 env
->crf
[0] &= ~0x1;
1630 ret
= do_syscall(env
, env
->gpr
[0], env
->gpr
[3], env
->gpr
[4],
1631 env
->gpr
[5], env
->gpr
[6], env
->gpr
[7],
1633 if (ret
== (uint32_t)(-TARGET_QEMU_ESIGRETURN
)) {
1634 /* Returning from a successful sigreturn syscall.
1635 Avoid corrupting register state. */
1638 if (ret
> (uint32_t)(-515)) {
1644 printf("syscall returned 0x%08x (%d)\n", ret
, ret
);
1647 case POWERPC_EXCP_STCX
:
1648 if (do_store_exclusive(env
)) {
1649 info
.si_signo
= TARGET_SIGSEGV
;
1651 info
.si_code
= TARGET_SEGV_MAPERR
;
1652 info
._sifields
._sigfault
._addr
= env
->nip
;
1653 queue_signal(env
, info
.si_signo
, &info
);
1660 sig
= gdb_handlesig(env
, TARGET_SIGTRAP
);
1662 info
.si_signo
= sig
;
1664 info
.si_code
= TARGET_TRAP_BRKPT
;
1665 queue_signal(env
, info
.si_signo
, &info
);
1669 case EXCP_INTERRUPT
:
1670 /* just indicate that signals should be handled asap */
1673 cpu_abort(env
, "Unknown exception 0x%d. Aborting\n", trapnr
);
1676 process_pending_signals(env
);
1683 #define MIPS_SYS(name, args) args,
1685 static const uint8_t mips_syscall_args
[] = {
1686 MIPS_SYS(sys_syscall
, 0) /* 4000 */
1687 MIPS_SYS(sys_exit
, 1)
1688 MIPS_SYS(sys_fork
, 0)
1689 MIPS_SYS(sys_read
, 3)
1690 MIPS_SYS(sys_write
, 3)
1691 MIPS_SYS(sys_open
, 3) /* 4005 */
1692 MIPS_SYS(sys_close
, 1)
1693 MIPS_SYS(sys_waitpid
, 3)
1694 MIPS_SYS(sys_creat
, 2)
1695 MIPS_SYS(sys_link
, 2)
1696 MIPS_SYS(sys_unlink
, 1) /* 4010 */
1697 MIPS_SYS(sys_execve
, 0)
1698 MIPS_SYS(sys_chdir
, 1)
1699 MIPS_SYS(sys_time
, 1)
1700 MIPS_SYS(sys_mknod
, 3)
1701 MIPS_SYS(sys_chmod
, 2) /* 4015 */
1702 MIPS_SYS(sys_lchown
, 3)
1703 MIPS_SYS(sys_ni_syscall
, 0)
1704 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_stat */
1705 MIPS_SYS(sys_lseek
, 3)
1706 MIPS_SYS(sys_getpid
, 0) /* 4020 */
1707 MIPS_SYS(sys_mount
, 5)
1708 MIPS_SYS(sys_oldumount
, 1)
1709 MIPS_SYS(sys_setuid
, 1)
1710 MIPS_SYS(sys_getuid
, 0)
1711 MIPS_SYS(sys_stime
, 1) /* 4025 */
1712 MIPS_SYS(sys_ptrace
, 4)
1713 MIPS_SYS(sys_alarm
, 1)
1714 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_fstat */
1715 MIPS_SYS(sys_pause
, 0)
1716 MIPS_SYS(sys_utime
, 2) /* 4030 */
1717 MIPS_SYS(sys_ni_syscall
, 0)
1718 MIPS_SYS(sys_ni_syscall
, 0)
1719 MIPS_SYS(sys_access
, 2)
1720 MIPS_SYS(sys_nice
, 1)
1721 MIPS_SYS(sys_ni_syscall
, 0) /* 4035 */
1722 MIPS_SYS(sys_sync
, 0)
1723 MIPS_SYS(sys_kill
, 2)
1724 MIPS_SYS(sys_rename
, 2)
1725 MIPS_SYS(sys_mkdir
, 2)
1726 MIPS_SYS(sys_rmdir
, 1) /* 4040 */
1727 MIPS_SYS(sys_dup
, 1)
1728 MIPS_SYS(sys_pipe
, 0)
1729 MIPS_SYS(sys_times
, 1)
1730 MIPS_SYS(sys_ni_syscall
, 0)
1731 MIPS_SYS(sys_brk
, 1) /* 4045 */
1732 MIPS_SYS(sys_setgid
, 1)
1733 MIPS_SYS(sys_getgid
, 0)
1734 MIPS_SYS(sys_ni_syscall
, 0) /* was signal(2) */
1735 MIPS_SYS(sys_geteuid
, 0)
1736 MIPS_SYS(sys_getegid
, 0) /* 4050 */
1737 MIPS_SYS(sys_acct
, 0)
1738 MIPS_SYS(sys_umount
, 2)
1739 MIPS_SYS(sys_ni_syscall
, 0)
1740 MIPS_SYS(sys_ioctl
, 3)
1741 MIPS_SYS(sys_fcntl
, 3) /* 4055 */
1742 MIPS_SYS(sys_ni_syscall
, 2)
1743 MIPS_SYS(sys_setpgid
, 2)
1744 MIPS_SYS(sys_ni_syscall
, 0)
1745 MIPS_SYS(sys_olduname
, 1)
1746 MIPS_SYS(sys_umask
, 1) /* 4060 */
1747 MIPS_SYS(sys_chroot
, 1)
1748 MIPS_SYS(sys_ustat
, 2)
1749 MIPS_SYS(sys_dup2
, 2)
1750 MIPS_SYS(sys_getppid
, 0)
1751 MIPS_SYS(sys_getpgrp
, 0) /* 4065 */
1752 MIPS_SYS(sys_setsid
, 0)
1753 MIPS_SYS(sys_sigaction
, 3)
1754 MIPS_SYS(sys_sgetmask
, 0)
1755 MIPS_SYS(sys_ssetmask
, 1)
1756 MIPS_SYS(sys_setreuid
, 2) /* 4070 */
1757 MIPS_SYS(sys_setregid
, 2)
1758 MIPS_SYS(sys_sigsuspend
, 0)
1759 MIPS_SYS(sys_sigpending
, 1)
1760 MIPS_SYS(sys_sethostname
, 2)
1761 MIPS_SYS(sys_setrlimit
, 2) /* 4075 */
1762 MIPS_SYS(sys_getrlimit
, 2)
1763 MIPS_SYS(sys_getrusage
, 2)
1764 MIPS_SYS(sys_gettimeofday
, 2)
1765 MIPS_SYS(sys_settimeofday
, 2)
1766 MIPS_SYS(sys_getgroups
, 2) /* 4080 */
1767 MIPS_SYS(sys_setgroups
, 2)
1768 MIPS_SYS(sys_ni_syscall
, 0) /* old_select */
1769 MIPS_SYS(sys_symlink
, 2)
1770 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_lstat */
1771 MIPS_SYS(sys_readlink
, 3) /* 4085 */
1772 MIPS_SYS(sys_uselib
, 1)
1773 MIPS_SYS(sys_swapon
, 2)
1774 MIPS_SYS(sys_reboot
, 3)
1775 MIPS_SYS(old_readdir
, 3)
1776 MIPS_SYS(old_mmap
, 6) /* 4090 */
1777 MIPS_SYS(sys_munmap
, 2)
1778 MIPS_SYS(sys_truncate
, 2)
1779 MIPS_SYS(sys_ftruncate
, 2)
1780 MIPS_SYS(sys_fchmod
, 2)
1781 MIPS_SYS(sys_fchown
, 3) /* 4095 */
1782 MIPS_SYS(sys_getpriority
, 2)
1783 MIPS_SYS(sys_setpriority
, 3)
1784 MIPS_SYS(sys_ni_syscall
, 0)
1785 MIPS_SYS(sys_statfs
, 2)
1786 MIPS_SYS(sys_fstatfs
, 2) /* 4100 */
1787 MIPS_SYS(sys_ni_syscall
, 0) /* was ioperm(2) */
1788 MIPS_SYS(sys_socketcall
, 2)
1789 MIPS_SYS(sys_syslog
, 3)
1790 MIPS_SYS(sys_setitimer
, 3)
1791 MIPS_SYS(sys_getitimer
, 2) /* 4105 */
1792 MIPS_SYS(sys_newstat
, 2)
1793 MIPS_SYS(sys_newlstat
, 2)
1794 MIPS_SYS(sys_newfstat
, 2)
1795 MIPS_SYS(sys_uname
, 1)
1796 MIPS_SYS(sys_ni_syscall
, 0) /* 4110 was iopl(2) */
1797 MIPS_SYS(sys_vhangup
, 0)
1798 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_idle() */
1799 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_vm86 */
1800 MIPS_SYS(sys_wait4
, 4)
1801 MIPS_SYS(sys_swapoff
, 1) /* 4115 */
1802 MIPS_SYS(sys_sysinfo
, 1)
1803 MIPS_SYS(sys_ipc
, 6)
1804 MIPS_SYS(sys_fsync
, 1)
1805 MIPS_SYS(sys_sigreturn
, 0)
1806 MIPS_SYS(sys_clone
, 6) /* 4120 */
1807 MIPS_SYS(sys_setdomainname
, 2)
1808 MIPS_SYS(sys_newuname
, 1)
1809 MIPS_SYS(sys_ni_syscall
, 0) /* sys_modify_ldt */
1810 MIPS_SYS(sys_adjtimex
, 1)
1811 MIPS_SYS(sys_mprotect
, 3) /* 4125 */
1812 MIPS_SYS(sys_sigprocmask
, 3)
1813 MIPS_SYS(sys_ni_syscall
, 0) /* was create_module */
1814 MIPS_SYS(sys_init_module
, 5)
1815 MIPS_SYS(sys_delete_module
, 1)
1816 MIPS_SYS(sys_ni_syscall
, 0) /* 4130 was get_kernel_syms */
1817 MIPS_SYS(sys_quotactl
, 0)
1818 MIPS_SYS(sys_getpgid
, 1)
1819 MIPS_SYS(sys_fchdir
, 1)
1820 MIPS_SYS(sys_bdflush
, 2)
1821 MIPS_SYS(sys_sysfs
, 3) /* 4135 */
1822 MIPS_SYS(sys_personality
, 1)
1823 MIPS_SYS(sys_ni_syscall
, 0) /* for afs_syscall */
1824 MIPS_SYS(sys_setfsuid
, 1)
1825 MIPS_SYS(sys_setfsgid
, 1)
1826 MIPS_SYS(sys_llseek
, 5) /* 4140 */
1827 MIPS_SYS(sys_getdents
, 3)
1828 MIPS_SYS(sys_select
, 5)
1829 MIPS_SYS(sys_flock
, 2)
1830 MIPS_SYS(sys_msync
, 3)
1831 MIPS_SYS(sys_readv
, 3) /* 4145 */
1832 MIPS_SYS(sys_writev
, 3)
1833 MIPS_SYS(sys_cacheflush
, 3)
1834 MIPS_SYS(sys_cachectl
, 3)
1835 MIPS_SYS(sys_sysmips
, 4)
1836 MIPS_SYS(sys_ni_syscall
, 0) /* 4150 */
1837 MIPS_SYS(sys_getsid
, 1)
1838 MIPS_SYS(sys_fdatasync
, 0)
1839 MIPS_SYS(sys_sysctl
, 1)
1840 MIPS_SYS(sys_mlock
, 2)
1841 MIPS_SYS(sys_munlock
, 2) /* 4155 */
1842 MIPS_SYS(sys_mlockall
, 1)
1843 MIPS_SYS(sys_munlockall
, 0)
1844 MIPS_SYS(sys_sched_setparam
, 2)
1845 MIPS_SYS(sys_sched_getparam
, 2)
1846 MIPS_SYS(sys_sched_setscheduler
, 3) /* 4160 */
1847 MIPS_SYS(sys_sched_getscheduler
, 1)
1848 MIPS_SYS(sys_sched_yield
, 0)
1849 MIPS_SYS(sys_sched_get_priority_max
, 1)
1850 MIPS_SYS(sys_sched_get_priority_min
, 1)
1851 MIPS_SYS(sys_sched_rr_get_interval
, 2) /* 4165 */
1852 MIPS_SYS(sys_nanosleep
, 2)
1853 MIPS_SYS(sys_mremap
, 4)
1854 MIPS_SYS(sys_accept
, 3)
1855 MIPS_SYS(sys_bind
, 3)
1856 MIPS_SYS(sys_connect
, 3) /* 4170 */
1857 MIPS_SYS(sys_getpeername
, 3)
1858 MIPS_SYS(sys_getsockname
, 3)
1859 MIPS_SYS(sys_getsockopt
, 5)
1860 MIPS_SYS(sys_listen
, 2)
1861 MIPS_SYS(sys_recv
, 4) /* 4175 */
1862 MIPS_SYS(sys_recvfrom
, 6)
1863 MIPS_SYS(sys_recvmsg
, 3)
1864 MIPS_SYS(sys_send
, 4)
1865 MIPS_SYS(sys_sendmsg
, 3)
1866 MIPS_SYS(sys_sendto
, 6) /* 4180 */
1867 MIPS_SYS(sys_setsockopt
, 5)
1868 MIPS_SYS(sys_shutdown
, 2)
1869 MIPS_SYS(sys_socket
, 3)
1870 MIPS_SYS(sys_socketpair
, 4)
1871 MIPS_SYS(sys_setresuid
, 3) /* 4185 */
1872 MIPS_SYS(sys_getresuid
, 3)
1873 MIPS_SYS(sys_ni_syscall
, 0) /* was sys_query_module */
1874 MIPS_SYS(sys_poll
, 3)
1875 MIPS_SYS(sys_nfsservctl
, 3)
1876 MIPS_SYS(sys_setresgid
, 3) /* 4190 */
1877 MIPS_SYS(sys_getresgid
, 3)
1878 MIPS_SYS(sys_prctl
, 5)
1879 MIPS_SYS(sys_rt_sigreturn
, 0)
1880 MIPS_SYS(sys_rt_sigaction
, 4)
1881 MIPS_SYS(sys_rt_sigprocmask
, 4) /* 4195 */
1882 MIPS_SYS(sys_rt_sigpending
, 2)
1883 MIPS_SYS(sys_rt_sigtimedwait
, 4)
1884 MIPS_SYS(sys_rt_sigqueueinfo
, 3)
1885 MIPS_SYS(sys_rt_sigsuspend
, 0)
1886 MIPS_SYS(sys_pread64
, 6) /* 4200 */
1887 MIPS_SYS(sys_pwrite64
, 6)
1888 MIPS_SYS(sys_chown
, 3)
1889 MIPS_SYS(sys_getcwd
, 2)
1890 MIPS_SYS(sys_capget
, 2)
1891 MIPS_SYS(sys_capset
, 2) /* 4205 */
1892 MIPS_SYS(sys_sigaltstack
, 0)
1893 MIPS_SYS(sys_sendfile
, 4)
1894 MIPS_SYS(sys_ni_syscall
, 0)
1895 MIPS_SYS(sys_ni_syscall
, 0)
1896 MIPS_SYS(sys_mmap2
, 6) /* 4210 */
1897 MIPS_SYS(sys_truncate64
, 4)
1898 MIPS_SYS(sys_ftruncate64
, 4)
1899 MIPS_SYS(sys_stat64
, 2)
1900 MIPS_SYS(sys_lstat64
, 2)
1901 MIPS_SYS(sys_fstat64
, 2) /* 4215 */
1902 MIPS_SYS(sys_pivot_root
, 2)
1903 MIPS_SYS(sys_mincore
, 3)
1904 MIPS_SYS(sys_madvise
, 3)
1905 MIPS_SYS(sys_getdents64
, 3)
1906 MIPS_SYS(sys_fcntl64
, 3) /* 4220 */
1907 MIPS_SYS(sys_ni_syscall
, 0)
1908 MIPS_SYS(sys_gettid
, 0)
1909 MIPS_SYS(sys_readahead
, 5)
1910 MIPS_SYS(sys_setxattr
, 5)
1911 MIPS_SYS(sys_lsetxattr
, 5) /* 4225 */
1912 MIPS_SYS(sys_fsetxattr
, 5)
1913 MIPS_SYS(sys_getxattr
, 4)
1914 MIPS_SYS(sys_lgetxattr
, 4)
1915 MIPS_SYS(sys_fgetxattr
, 4)
1916 MIPS_SYS(sys_listxattr
, 3) /* 4230 */
1917 MIPS_SYS(sys_llistxattr
, 3)
1918 MIPS_SYS(sys_flistxattr
, 3)
1919 MIPS_SYS(sys_removexattr
, 2)
1920 MIPS_SYS(sys_lremovexattr
, 2)
1921 MIPS_SYS(sys_fremovexattr
, 2) /* 4235 */
1922 MIPS_SYS(sys_tkill
, 2)
1923 MIPS_SYS(sys_sendfile64
, 5)
1924 MIPS_SYS(sys_futex
, 2)
1925 MIPS_SYS(sys_sched_setaffinity
, 3)
1926 MIPS_SYS(sys_sched_getaffinity
, 3) /* 4240 */
1927 MIPS_SYS(sys_io_setup
, 2)
1928 MIPS_SYS(sys_io_destroy
, 1)
1929 MIPS_SYS(sys_io_getevents
, 5)
1930 MIPS_SYS(sys_io_submit
, 3)
1931 MIPS_SYS(sys_io_cancel
, 3) /* 4245 */
1932 MIPS_SYS(sys_exit_group
, 1)
1933 MIPS_SYS(sys_lookup_dcookie
, 3)
1934 MIPS_SYS(sys_epoll_create
, 1)
1935 MIPS_SYS(sys_epoll_ctl
, 4)
1936 MIPS_SYS(sys_epoll_wait
, 3) /* 4250 */
1937 MIPS_SYS(sys_remap_file_pages
, 5)
1938 MIPS_SYS(sys_set_tid_address
, 1)
1939 MIPS_SYS(sys_restart_syscall
, 0)
1940 MIPS_SYS(sys_fadvise64_64
, 7)
1941 MIPS_SYS(sys_statfs64
, 3) /* 4255 */
1942 MIPS_SYS(sys_fstatfs64
, 2)
1943 MIPS_SYS(sys_timer_create
, 3)
1944 MIPS_SYS(sys_timer_settime
, 4)
1945 MIPS_SYS(sys_timer_gettime
, 2)
1946 MIPS_SYS(sys_timer_getoverrun
, 1) /* 4260 */
1947 MIPS_SYS(sys_timer_delete
, 1)
1948 MIPS_SYS(sys_clock_settime
, 2)
1949 MIPS_SYS(sys_clock_gettime
, 2)
1950 MIPS_SYS(sys_clock_getres
, 2)
1951 MIPS_SYS(sys_clock_nanosleep
, 4) /* 4265 */
1952 MIPS_SYS(sys_tgkill
, 3)
1953 MIPS_SYS(sys_utimes
, 2)
1954 MIPS_SYS(sys_mbind
, 4)
1955 MIPS_SYS(sys_ni_syscall
, 0) /* sys_get_mempolicy */
1956 MIPS_SYS(sys_ni_syscall
, 0) /* 4270 sys_set_mempolicy */
1957 MIPS_SYS(sys_mq_open
, 4)
1958 MIPS_SYS(sys_mq_unlink
, 1)
1959 MIPS_SYS(sys_mq_timedsend
, 5)
1960 MIPS_SYS(sys_mq_timedreceive
, 5)
1961 MIPS_SYS(sys_mq_notify
, 2) /* 4275 */
1962 MIPS_SYS(sys_mq_getsetattr
, 3)
1963 MIPS_SYS(sys_ni_syscall
, 0) /* sys_vserver */
1964 MIPS_SYS(sys_waitid
, 4)
1965 MIPS_SYS(sys_ni_syscall
, 0) /* available, was setaltroot */
1966 MIPS_SYS(sys_add_key
, 5)
1967 MIPS_SYS(sys_request_key
, 4)
1968 MIPS_SYS(sys_keyctl
, 5)
1969 MIPS_SYS(sys_set_thread_area
, 1)
1970 MIPS_SYS(sys_inotify_init
, 0)
1971 MIPS_SYS(sys_inotify_add_watch
, 3) /* 4285 */
1972 MIPS_SYS(sys_inotify_rm_watch
, 2)
1973 MIPS_SYS(sys_migrate_pages
, 4)
1974 MIPS_SYS(sys_openat
, 4)
1975 MIPS_SYS(sys_mkdirat
, 3)
1976 MIPS_SYS(sys_mknodat
, 4) /* 4290 */
1977 MIPS_SYS(sys_fchownat
, 5)
1978 MIPS_SYS(sys_futimesat
, 3)
1979 MIPS_SYS(sys_fstatat64
, 4)
1980 MIPS_SYS(sys_unlinkat
, 3)
1981 MIPS_SYS(sys_renameat
, 4) /* 4295 */
1982 MIPS_SYS(sys_linkat
, 5)
1983 MIPS_SYS(sys_symlinkat
, 3)
1984 MIPS_SYS(sys_readlinkat
, 4)
1985 MIPS_SYS(sys_fchmodat
, 3)
1986 MIPS_SYS(sys_faccessat
, 3) /* 4300 */
1987 MIPS_SYS(sys_pselect6
, 6)
1988 MIPS_SYS(sys_ppoll
, 5)
1989 MIPS_SYS(sys_unshare
, 1)
1990 MIPS_SYS(sys_splice
, 4)
1991 MIPS_SYS(sys_sync_file_range
, 7) /* 4305 */
1992 MIPS_SYS(sys_tee
, 4)
1993 MIPS_SYS(sys_vmsplice
, 4)
1994 MIPS_SYS(sys_move_pages
, 6)
1995 MIPS_SYS(sys_set_robust_list
, 2)
1996 MIPS_SYS(sys_get_robust_list
, 3) /* 4310 */
1997 MIPS_SYS(sys_kexec_load
, 4)
1998 MIPS_SYS(sys_getcpu
, 3)
1999 MIPS_SYS(sys_epoll_pwait
, 6)
2000 MIPS_SYS(sys_ioprio_set
, 3)
2001 MIPS_SYS(sys_ioprio_get
, 2)
2006 static int do_store_exclusive(CPUMIPSState
*env
)
2009 target_ulong page_addr
;
2017 page_addr
= addr
& TARGET_PAGE_MASK
;
2020 flags
= page_get_flags(page_addr
);
2021 if ((flags
& PAGE_READ
) == 0) {
2024 reg
= env
->llreg
& 0x1f;
2025 d
= (env
->llreg
& 0x20) != 0;
2027 segv
= get_user_s64(val
, addr
);
2029 segv
= get_user_s32(val
, addr
);
2032 if (val
!= env
->llval
) {
2033 env
->active_tc
.gpr
[reg
] = 0;
2036 segv
= put_user_u64(env
->llnewval
, addr
);
2038 segv
= put_user_u32(env
->llnewval
, addr
);
2041 env
->active_tc
.gpr
[reg
] = 1;
2048 env
->active_tc
.PC
+= 4;
2055 void cpu_loop(CPUMIPSState
*env
)
2057 target_siginfo_t info
;
2059 unsigned int syscall_num
;
2062 cpu_exec_start(env
);
2063 trapnr
= cpu_mips_exec(env
);
2067 syscall_num
= env
->active_tc
.gpr
[2] - 4000;
2068 env
->active_tc
.PC
+= 4;
2069 if (syscall_num
>= sizeof(mips_syscall_args
)) {
2074 abi_ulong arg5
= 0, arg6
= 0, arg7
= 0, arg8
= 0;
2076 nb_args
= mips_syscall_args
[syscall_num
];
2077 sp_reg
= env
->active_tc
.gpr
[29];
2079 /* these arguments are taken from the stack */
2080 /* FIXME - what to do if get_user() fails? */
2081 case 8: get_user_ual(arg8
, sp_reg
+ 28);
2082 case 7: get_user_ual(arg7
, sp_reg
+ 24);
2083 case 6: get_user_ual(arg6
, sp_reg
+ 20);
2084 case 5: get_user_ual(arg5
, sp_reg
+ 16);
2088 ret
= do_syscall(env
, env
->active_tc
.gpr
[2],
2089 env
->active_tc
.gpr
[4],
2090 env
->active_tc
.gpr
[5],
2091 env
->active_tc
.gpr
[6],
2092 env
->active_tc
.gpr
[7],
2093 arg5
, arg6
/*, arg7, arg8*/);
2095 if (ret
== -TARGET_QEMU_ESIGRETURN
) {
2096 /* Returning from a successful sigreturn syscall.
2097 Avoid clobbering register state. */
2100 if ((unsigned int)ret
>= (unsigned int)(-1133)) {
2101 env
->active_tc
.gpr
[7] = 1; /* error flag */
2104 env
->active_tc
.gpr
[7] = 0; /* error flag */
2106 env
->active_tc
.gpr
[2] = ret
;
2110 info
.si_signo
= TARGET_SIGSEGV
;
2112 /* XXX: check env->error_code */
2113 info
.si_code
= TARGET_SEGV_MAPERR
;
2114 info
._sifields
._sigfault
._addr
= env
->CP0_BadVAddr
;
2115 queue_signal(env
, info
.si_signo
, &info
);
2119 info
.si_signo
= TARGET_SIGILL
;
2122 queue_signal(env
, info
.si_signo
, &info
);
2124 case EXCP_INTERRUPT
:
2125 /* just indicate that signals should be handled asap */
2131 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
2134 info
.si_signo
= sig
;
2136 info
.si_code
= TARGET_TRAP_BRKPT
;
2137 queue_signal(env
, info
.si_signo
, &info
);
2142 if (do_store_exclusive(env
)) {
2143 info
.si_signo
= TARGET_SIGSEGV
;
2145 info
.si_code
= TARGET_SEGV_MAPERR
;
2146 info
._sifields
._sigfault
._addr
= env
->active_tc
.PC
;
2147 queue_signal(env
, info
.si_signo
, &info
);
2152 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
2154 cpu_dump_state(env
, stderr
, fprintf
, 0);
2157 process_pending_signals(env
);
2163 void cpu_loop (CPUState
*env
)
2166 target_siginfo_t info
;
2169 trapnr
= cpu_sh4_exec (env
);
2174 ret
= do_syscall(env
,
2182 env
->gregs
[0] = ret
;
2184 case EXCP_INTERRUPT
:
2185 /* just indicate that signals should be handled asap */
2191 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
2194 info
.si_signo
= sig
;
2196 info
.si_code
= TARGET_TRAP_BRKPT
;
2197 queue_signal(env
, info
.si_signo
, &info
);
2203 info
.si_signo
= SIGSEGV
;
2205 info
.si_code
= TARGET_SEGV_MAPERR
;
2206 info
._sifields
._sigfault
._addr
= env
->tea
;
2207 queue_signal(env
, info
.si_signo
, &info
);
2211 printf ("Unhandled trap: 0x%x\n", trapnr
);
2212 cpu_dump_state(env
, stderr
, fprintf
, 0);
2215 process_pending_signals (env
);
2221 void cpu_loop (CPUState
*env
)
2224 target_siginfo_t info
;
2227 trapnr
= cpu_cris_exec (env
);
2231 info
.si_signo
= SIGSEGV
;
2233 /* XXX: check env->error_code */
2234 info
.si_code
= TARGET_SEGV_MAPERR
;
2235 info
._sifields
._sigfault
._addr
= env
->pregs
[PR_EDA
];
2236 queue_signal(env
, info
.si_signo
, &info
);
2239 case EXCP_INTERRUPT
:
2240 /* just indicate that signals should be handled asap */
2243 ret
= do_syscall(env
,
2251 env
->regs
[10] = ret
;
2257 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
2260 info
.si_signo
= sig
;
2262 info
.si_code
= TARGET_TRAP_BRKPT
;
2263 queue_signal(env
, info
.si_signo
, &info
);
2268 printf ("Unhandled trap: 0x%x\n", trapnr
);
2269 cpu_dump_state(env
, stderr
, fprintf
, 0);
2272 process_pending_signals (env
);
2277 #ifdef TARGET_MICROBLAZE
2278 void cpu_loop (CPUState
*env
)
2281 target_siginfo_t info
;
2284 trapnr
= cpu_mb_exec (env
);
2288 info
.si_signo
= SIGSEGV
;
2290 /* XXX: check env->error_code */
2291 info
.si_code
= TARGET_SEGV_MAPERR
;
2292 info
._sifields
._sigfault
._addr
= 0;
2293 queue_signal(env
, info
.si_signo
, &info
);
2296 case EXCP_INTERRUPT
:
2297 /* just indicate that signals should be handled asap */
2300 /* Return address is 4 bytes after the call. */
2302 ret
= do_syscall(env
,
2311 env
->sregs
[SR_PC
] = env
->regs
[14];
2314 env
->regs
[17] = env
->sregs
[SR_PC
] + 4;
2315 if (env
->iflags
& D_FLAG
) {
2316 env
->sregs
[SR_ESR
] |= 1 << 12;
2317 env
->sregs
[SR_PC
] -= 4;
2318 /* FIXME: if branch was immed, replay the imm aswell. */
2321 env
->iflags
&= ~(IMM_FLAG
| D_FLAG
);
2323 switch (env
->sregs
[SR_ESR
] & 31) {
2325 info
.si_signo
= SIGFPE
;
2327 if (env
->sregs
[SR_FSR
] & FSR_IO
) {
2328 info
.si_code
= TARGET_FPE_FLTINV
;
2330 if (env
->sregs
[SR_FSR
] & FSR_DZ
) {
2331 info
.si_code
= TARGET_FPE_FLTDIV
;
2333 info
._sifields
._sigfault
._addr
= 0;
2334 queue_signal(env
, info
.si_signo
, &info
);
2337 printf ("Unhandled hw-exception: 0x%x\n",
2338 env
->sregs
[SR_ESR
] & ESR_EC_MASK
);
2339 cpu_dump_state(env
, stderr
, fprintf
, 0);
2348 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
2351 info
.si_signo
= sig
;
2353 info
.si_code
= TARGET_TRAP_BRKPT
;
2354 queue_signal(env
, info
.si_signo
, &info
);
2359 printf ("Unhandled trap: 0x%x\n", trapnr
);
2360 cpu_dump_state(env
, stderr
, fprintf
, 0);
2363 process_pending_signals (env
);
2370 void cpu_loop(CPUM68KState
*env
)
2374 target_siginfo_t info
;
2375 TaskState
*ts
= env
->opaque
;
2378 trapnr
= cpu_m68k_exec(env
);
2382 if (ts
->sim_syscalls
) {
2384 nr
= lduw(env
->pc
+ 2);
2386 do_m68k_simcall(env
, nr
);
2392 case EXCP_HALT_INSN
:
2393 /* Semihosing syscall. */
2395 do_m68k_semihosting(env
, env
->dregs
[0]);
2399 case EXCP_UNSUPPORTED
:
2401 info
.si_signo
= SIGILL
;
2403 info
.si_code
= TARGET_ILL_ILLOPN
;
2404 info
._sifields
._sigfault
._addr
= env
->pc
;
2405 queue_signal(env
, info
.si_signo
, &info
);
2409 ts
->sim_syscalls
= 0;
2412 env
->dregs
[0] = do_syscall(env
,
2422 case EXCP_INTERRUPT
:
2423 /* just indicate that signals should be handled asap */
2427 info
.si_signo
= SIGSEGV
;
2429 /* XXX: check env->error_code */
2430 info
.si_code
= TARGET_SEGV_MAPERR
;
2431 info
._sifields
._sigfault
._addr
= env
->mmu
.ar
;
2432 queue_signal(env
, info
.si_signo
, &info
);
2439 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
2442 info
.si_signo
= sig
;
2444 info
.si_code
= TARGET_TRAP_BRKPT
;
2445 queue_signal(env
, info
.si_signo
, &info
);
2450 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
2452 cpu_dump_state(env
, stderr
, fprintf
, 0);
2455 process_pending_signals(env
);
2458 #endif /* TARGET_M68K */
2461 static void do_store_exclusive(CPUAlphaState
*env
, int reg
, int quad
)
2463 target_ulong addr
, val
, tmp
;
2464 target_siginfo_t info
;
2467 addr
= env
->lock_addr
;
2468 tmp
= env
->lock_st_addr
;
2469 env
->lock_addr
= -1;
2470 env
->lock_st_addr
= 0;
2476 if (quad
? get_user_s64(val
, addr
) : get_user_s32(val
, addr
)) {
2480 if (val
== env
->lock_value
) {
2482 if (quad
? put_user_u64(tmp
, addr
) : put_user_u32(tmp
, addr
)) {
2499 info
.si_signo
= TARGET_SIGSEGV
;
2501 info
.si_code
= TARGET_SEGV_MAPERR
;
2502 info
._sifields
._sigfault
._addr
= addr
;
2503 queue_signal(env
, TARGET_SIGSEGV
, &info
);
2506 void cpu_loop (CPUState
*env
)
2509 target_siginfo_t info
;
2513 trapnr
= cpu_alpha_exec (env
);
2515 /* All of the traps imply a transition through PALcode, which
2516 implies an REI instruction has been executed. Which means
2517 that the intr_flag should be cleared. */
2522 fprintf(stderr
, "Reset requested. Exit\n");
2526 fprintf(stderr
, "Machine check exception. Exit\n");
2530 env
->lock_addr
= -1;
2531 info
.si_signo
= TARGET_SIGFPE
;
2533 info
.si_code
= TARGET_FPE_FLTINV
;
2534 info
._sifields
._sigfault
._addr
= env
->pc
;
2535 queue_signal(env
, info
.si_signo
, &info
);
2537 case EXCP_HW_INTERRUPT
:
2538 fprintf(stderr
, "External interrupt. Exit\n");
2542 env
->lock_addr
= -1;
2543 info
.si_signo
= TARGET_SIGSEGV
;
2545 info
.si_code
= (page_get_flags(env
->ipr
[IPR_EXC_ADDR
]) & PAGE_VALID
2546 ? TARGET_SEGV_ACCERR
: TARGET_SEGV_MAPERR
);
2547 info
._sifields
._sigfault
._addr
= env
->ipr
[IPR_EXC_ADDR
];
2548 queue_signal(env
, info
.si_signo
, &info
);
2550 case EXCP_DTB_MISS_PAL
:
2551 fprintf(stderr
, "MMU data TLB miss in PALcode\n");
2555 fprintf(stderr
, "MMU instruction TLB miss\n");
2559 fprintf(stderr
, "MMU instruction access violation\n");
2562 case EXCP_DTB_MISS_NATIVE
:
2563 fprintf(stderr
, "MMU data TLB miss\n");
2567 env
->lock_addr
= -1;
2568 info
.si_signo
= TARGET_SIGBUS
;
2570 info
.si_code
= TARGET_BUS_ADRALN
;
2571 info
._sifields
._sigfault
._addr
= env
->ipr
[IPR_EXC_ADDR
];
2572 queue_signal(env
, info
.si_signo
, &info
);
2576 env
->lock_addr
= -1;
2577 info
.si_signo
= TARGET_SIGILL
;
2579 info
.si_code
= TARGET_ILL_ILLOPC
;
2580 info
._sifields
._sigfault
._addr
= env
->pc
;
2581 queue_signal(env
, info
.si_signo
, &info
);
2584 /* No-op. Linux simply re-enables the FPU. */
2586 case EXCP_CALL_PAL
... (EXCP_CALL_PALP
- 1):
2587 env
->lock_addr
= -1;
2588 switch ((trapnr
>> 6) | 0x80) {
2591 info
.si_signo
= TARGET_SIGTRAP
;
2593 info
.si_code
= TARGET_TRAP_BRKPT
;
2594 info
._sifields
._sigfault
._addr
= env
->pc
;
2595 queue_signal(env
, info
.si_signo
, &info
);
2599 info
.si_signo
= TARGET_SIGTRAP
;
2602 info
._sifields
._sigfault
._addr
= env
->pc
;
2603 queue_signal(env
, info
.si_signo
, &info
);
2607 trapnr
= env
->ir
[IR_V0
];
2608 sysret
= do_syscall(env
, trapnr
,
2609 env
->ir
[IR_A0
], env
->ir
[IR_A1
],
2610 env
->ir
[IR_A2
], env
->ir
[IR_A3
],
2611 env
->ir
[IR_A4
], env
->ir
[IR_A5
]);
2612 if (trapnr
== TARGET_NR_sigreturn
2613 || trapnr
== TARGET_NR_rt_sigreturn
) {
2616 /* Syscall writes 0 to V0 to bypass error check, similar
2617 to how this is handled internal to Linux kernel. */
2618 if (env
->ir
[IR_V0
] == 0) {
2619 env
->ir
[IR_V0
] = sysret
;
2621 env
->ir
[IR_V0
] = (sysret
< 0 ? -sysret
: sysret
);
2622 env
->ir
[IR_A3
] = (sysret
< 0);
2627 /* ??? We can probably elide the code using page_unprotect
2628 that is checking for self-modifying code. Instead we
2629 could simply call tb_flush here. Until we work out the
2630 changes required to turn off the extra write protection,
2631 this can be a no-op. */
2635 /* Handled in the translator for usermode. */
2639 /* Handled in the translator for usermode. */
2643 info
.si_signo
= TARGET_SIGFPE
;
2644 switch (env
->ir
[IR_A0
]) {
2645 case TARGET_GEN_INTOVF
:
2646 info
.si_code
= TARGET_FPE_INTOVF
;
2648 case TARGET_GEN_INTDIV
:
2649 info
.si_code
= TARGET_FPE_INTDIV
;
2651 case TARGET_GEN_FLTOVF
:
2652 info
.si_code
= TARGET_FPE_FLTOVF
;
2654 case TARGET_GEN_FLTUND
:
2655 info
.si_code
= TARGET_FPE_FLTUND
;
2657 case TARGET_GEN_FLTINV
:
2658 info
.si_code
= TARGET_FPE_FLTINV
;
2660 case TARGET_GEN_FLTINE
:
2661 info
.si_code
= TARGET_FPE_FLTRES
;
2663 case TARGET_GEN_ROPRAND
:
2667 info
.si_signo
= TARGET_SIGTRAP
;
2672 info
._sifields
._sigfault
._addr
= env
->pc
;
2673 queue_signal(env
, info
.si_signo
, &info
);
2679 case EXCP_CALL_PALP
... (EXCP_CALL_PALE
- 1):
2682 info
.si_signo
= gdb_handlesig (env
, TARGET_SIGTRAP
);
2683 if (info
.si_signo
) {
2684 env
->lock_addr
= -1;
2686 info
.si_code
= TARGET_TRAP_BRKPT
;
2687 queue_signal(env
, info
.si_signo
, &info
);
2692 do_store_exclusive(env
, env
->error_code
, trapnr
- EXCP_STL_C
);
2695 printf ("Unhandled trap: 0x%x\n", trapnr
);
2696 cpu_dump_state(env
, stderr
, fprintf
, 0);
2699 process_pending_signals (env
);
2702 #endif /* TARGET_ALPHA */
2704 static void version(void)
2706 printf("qemu-" TARGET_ARCH
" version " QEMU_VERSION QEMU_PKGVERSION
2707 ", Copyright (c) 2003-2008 Fabrice Bellard\n");
2710 static void usage(void)
2713 printf("usage: qemu-" TARGET_ARCH
" [options] program [arguments...]\n"
2714 "Linux CPU emulator (compiled for %s emulation)\n"
2716 "Standard options:\n"
2717 "-h print this help\n"
2718 "-version display version information and exit\n"
2719 "-g port wait gdb connection to port\n"
2720 "-L path set the elf interpreter prefix (default=%s)\n"
2721 "-s size set the stack size in bytes (default=%ld)\n"
2722 "-cpu model select CPU (-cpu ? for list)\n"
2723 "-drop-ld-preload drop LD_PRELOAD for target process\n"
2724 "-E var=value sets/modifies targets environment variable(s)\n"
2725 "-U var unsets targets environment variable(s)\n"
2726 "-0 argv0 forces target process argv[0] to be argv0\n"
2727 #if defined(CONFIG_USE_GUEST_BASE)
2728 "-B address set guest_base address to address\n"
2729 "-R size reserve size bytes for guest virtual address space\n"
2733 "-d options activate log (logfile=%s)\n"
2734 "-p pagesize set the host page size to 'pagesize'\n"
2735 "-singlestep always run in singlestep mode\n"
2736 "-strace log system calls\n"
2738 "Environment variables:\n"
2739 "QEMU_STRACE Print system calls and arguments similar to the\n"
2740 " 'strace' program. Enable by setting to any value.\n"
2741 "You can use -E and -U options to set/unset environment variables\n"
2742 "for target process. It is possible to provide several variables\n"
2743 "by repeating the option. For example:\n"
2744 " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n"
2745 "Note that if you provide several changes to single variable\n"
2746 "last change will stay in effect.\n"
2755 THREAD CPUState
*thread_env
;
2757 void task_settid(TaskState
*ts
)
2759 if (ts
->ts_tid
== 0) {
2760 #ifdef CONFIG_USE_NPTL
2761 ts
->ts_tid
= (pid_t
)syscall(SYS_gettid
);
2763 /* when no threads are used, tid becomes pid */
2764 ts
->ts_tid
= getpid();
2769 void stop_all_tasks(void)
2772 * We trust that when using NPTL, start_exclusive()
2773 * handles thread stopping correctly.
2778 /* Assumes contents are already zeroed. */
2779 void init_task_state(TaskState
*ts
)
2784 ts
->first_free
= ts
->sigqueue_table
;
2785 for (i
= 0; i
< MAX_SIGQUEUE_SIZE
- 1; i
++) {
2786 ts
->sigqueue_table
[i
].next
= &ts
->sigqueue_table
[i
+ 1];
2788 ts
->sigqueue_table
[i
].next
= NULL
;
2791 int main(int argc
, char **argv
, char **envp
)
2793 const char *filename
;
2794 const char *cpu_model
;
2795 struct target_pt_regs regs1
, *regs
= ®s1
;
2796 struct image_info info1
, *info
= &info1
;
2797 struct linux_binprm bprm
;
2802 int gdbstub_port
= 0;
2803 char **target_environ
, **wrk
;
2806 envlist_t
*envlist
= NULL
;
2807 const char *argv0
= NULL
;
2814 qemu_cache_utils_init(envp
);
2817 cpu_set_log_filename(DEBUG_LOGFILE
);
2819 if ((envlist
= envlist_create()) == NULL
) {
2820 (void) fprintf(stderr
, "Unable to allocate envlist\n");
2824 /* add current environment into the list */
2825 for (wrk
= environ
; *wrk
!= NULL
; wrk
++) {
2826 (void) envlist_setenv(envlist
, *wrk
);
2829 /* Read the stack limit from the kernel. If it's "unlimited",
2830 then we can do little else besides use the default. */
2833 if (getrlimit(RLIMIT_STACK
, &lim
) == 0
2834 && lim
.rlim_cur
!= RLIM_INFINITY
2835 && lim
.rlim_cur
== (target_long
)lim
.rlim_cur
) {
2836 guest_stack_size
= lim
.rlim_cur
;
2841 #if defined(cpudef_setup)
2842 cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
2854 if (!strcmp(r
, "-")) {
2856 } else if (!strcmp(r
, "d")) {
2858 const CPULogItem
*item
;
2864 mask
= cpu_str_to_log_mask(r
);
2866 printf("Log items (comma separated):\n");
2867 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
2868 printf("%-10s %s\n", item
->name
, item
->help
);
2873 } else if (!strcmp(r
, "E")) {
2875 if (envlist_setenv(envlist
, r
) != 0)
2877 } else if (!strcmp(r
, "ignore-environment")) {
2878 envlist_free(envlist
);
2879 if ((envlist
= envlist_create()) == NULL
) {
2880 (void) fprintf(stderr
, "Unable to allocate envlist\n");
2883 } else if (!strcmp(r
, "U")) {
2885 if (envlist_unsetenv(envlist
, r
) != 0)
2887 } else if (!strcmp(r
, "0")) {
2890 } else if (!strcmp(r
, "s")) {
2894 guest_stack_size
= strtoul(r
, (char **)&r
, 0);
2895 if (guest_stack_size
== 0)
2898 guest_stack_size
*= 1024 * 1024;
2899 else if (*r
== 'k' || *r
== 'K')
2900 guest_stack_size
*= 1024;
2901 } else if (!strcmp(r
, "L")) {
2902 interp_prefix
= argv
[optind
++];
2903 } else if (!strcmp(r
, "p")) {
2906 qemu_host_page_size
= atoi(argv
[optind
++]);
2907 if (qemu_host_page_size
== 0 ||
2908 (qemu_host_page_size
& (qemu_host_page_size
- 1)) != 0) {
2909 fprintf(stderr
, "page size must be a power of two\n");
2912 } else if (!strcmp(r
, "g")) {
2915 gdbstub_port
= atoi(argv
[optind
++]);
2916 } else if (!strcmp(r
, "r")) {
2917 qemu_uname_release
= argv
[optind
++];
2918 } else if (!strcmp(r
, "cpu")) {
2919 cpu_model
= argv
[optind
++];
2920 if (cpu_model
== NULL
|| strcmp(cpu_model
, "?") == 0) {
2921 /* XXX: implement xxx_cpu_list for targets that still miss it */
2922 #if defined(cpu_list_id)
2923 cpu_list_id(stdout
, &fprintf
, "");
2924 #elif defined(cpu_list)
2925 cpu_list(stdout
, &fprintf
); /* deprecated */
2929 #if defined(CONFIG_USE_GUEST_BASE)
2930 } else if (!strcmp(r
, "B")) {
2931 guest_base
= strtol(argv
[optind
++], NULL
, 0);
2932 have_guest_base
= 1;
2933 } else if (!strcmp(r
, "R")) {
2936 reserved_va
= strtoul(argv
[optind
++], &p
, 0);
2950 unsigned long unshifted
= reserved_va
;
2952 reserved_va
<<= shift
;
2953 if (((reserved_va
>> shift
) != unshifted
)
2954 #if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
2955 || (reserved_va
> (1ul << TARGET_VIRT_ADDR_SPACE_BITS
))
2958 fprintf(stderr
, "Reserved virtual address too big\n");
2963 fprintf(stderr
, "Unrecognised -R size suffix '%s'\n", p
);
2967 } else if (!strcmp(r
, "drop-ld-preload")) {
2968 (void) envlist_unsetenv(envlist
, "LD_PRELOAD");
2969 } else if (!strcmp(r
, "singlestep")) {
2971 } else if (!strcmp(r
, "strace")) {
2973 } else if (!strcmp(r
, "version")) {
2982 filename
= argv
[optind
];
2983 exec_path
= argv
[optind
];
2986 memset(regs
, 0, sizeof(struct target_pt_regs
));
2988 /* Zero out image_info */
2989 memset(info
, 0, sizeof(struct image_info
));
2991 memset(&bprm
, 0, sizeof (bprm
));
2993 /* Scan interp_prefix dir for replacement files. */
2994 init_paths(interp_prefix
);
2996 if (cpu_model
== NULL
) {
2997 #if defined(TARGET_I386)
2998 #ifdef TARGET_X86_64
2999 cpu_model
= "qemu64";
3001 cpu_model
= "qemu32";
3003 #elif defined(TARGET_ARM)
3005 #elif defined(TARGET_UNICORE32)
3007 #elif defined(TARGET_M68K)
3009 #elif defined(TARGET_SPARC)
3010 #ifdef TARGET_SPARC64
3011 cpu_model
= "TI UltraSparc II";
3013 cpu_model
= "Fujitsu MB86904";
3015 #elif defined(TARGET_MIPS)
3016 #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
3021 #elif defined(TARGET_PPC)
3023 cpu_model
= "970fx";
3031 cpu_exec_init_all(0);
3032 /* NOTE: we need to init the CPU at this stage to get
3033 qemu_host_page_size */
3034 env
= cpu_init(cpu_model
);
3036 fprintf(stderr
, "Unable to find CPU definition\n");
3039 #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
3045 if (getenv("QEMU_STRACE")) {
3049 target_environ
= envlist_to_environ(envlist
, NULL
);
3050 envlist_free(envlist
);
3052 #if defined(CONFIG_USE_GUEST_BASE)
3054 * Now that page sizes are configured in cpu_init() we can do
3055 * proper page alignment for guest_base.
3057 guest_base
= HOST_PAGE_ALIGN(guest_base
);
3063 flags
= MAP_ANONYMOUS
| MAP_PRIVATE
| MAP_NORESERVE
;
3064 if (have_guest_base
) {
3067 p
= mmap((void *)guest_base
, reserved_va
, PROT_NONE
, flags
, -1, 0);
3068 if (p
== MAP_FAILED
) {
3069 fprintf(stderr
, "Unable to reserve guest address space\n");
3072 guest_base
= (unsigned long)p
;
3073 /* Make sure the address is properly aligned. */
3074 if (guest_base
& ~qemu_host_page_mask
) {
3075 munmap(p
, reserved_va
);
3076 p
= mmap((void *)guest_base
, reserved_va
+ qemu_host_page_size
,
3077 PROT_NONE
, flags
, -1, 0);
3078 if (p
== MAP_FAILED
) {
3079 fprintf(stderr
, "Unable to reserve guest address space\n");
3082 guest_base
= HOST_PAGE_ALIGN((unsigned long)p
);
3084 qemu_log("Reserved 0x%lx bytes of guest address space\n", reserved_va
);
3086 #endif /* CONFIG_USE_GUEST_BASE */
3089 * Read in mmap_min_addr kernel parameter. This value is used
3090 * When loading the ELF image to determine whether guest_base
3091 * is needed. It is also used in mmap_find_vma.
3096 if ((fp
= fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL
) {
3098 if (fscanf(fp
, "%lu", &tmp
) == 1) {
3099 mmap_min_addr
= tmp
;
3100 qemu_log("host mmap_min_addr=0x%lx\n", mmap_min_addr
);
3107 * Prepare copy of argv vector for target.
3109 target_argc
= argc
- optind
;
3110 target_argv
= calloc(target_argc
+ 1, sizeof (char *));
3111 if (target_argv
== NULL
) {
3112 (void) fprintf(stderr
, "Unable to allocate memory for target_argv\n");
3117 * If argv0 is specified (using '-0' switch) we replace
3118 * argv[0] pointer with the given one.
3121 if (argv0
!= NULL
) {
3122 target_argv
[i
++] = strdup(argv0
);
3124 for (; i
< target_argc
; i
++) {
3125 target_argv
[i
] = strdup(argv
[optind
+ i
]);
3127 target_argv
[target_argc
] = NULL
;
3129 ts
= qemu_mallocz (sizeof(TaskState
));
3130 init_task_state(ts
);
3131 /* build Task State */
3137 ret
= loader_exec(filename
, target_argv
, target_environ
, regs
,
3140 printf("Error %d while loading %s\n", ret
, filename
);
3144 for (i
= 0; i
< target_argc
; i
++) {
3145 free(target_argv
[i
]);
3149 for (wrk
= target_environ
; *wrk
; wrk
++) {
3153 free(target_environ
);
3155 if (qemu_log_enabled()) {
3156 #if defined(CONFIG_USE_GUEST_BASE)
3157 qemu_log("guest_base 0x%lx\n", guest_base
);
3161 qemu_log("start_brk 0x" TARGET_ABI_FMT_lx
"\n", info
->start_brk
);
3162 qemu_log("end_code 0x" TARGET_ABI_FMT_lx
"\n", info
->end_code
);
3163 qemu_log("start_code 0x" TARGET_ABI_FMT_lx
"\n",
3165 qemu_log("start_data 0x" TARGET_ABI_FMT_lx
"\n",
3167 qemu_log("end_data 0x" TARGET_ABI_FMT_lx
"\n", info
->end_data
);
3168 qemu_log("start_stack 0x" TARGET_ABI_FMT_lx
"\n",
3170 qemu_log("brk 0x" TARGET_ABI_FMT_lx
"\n", info
->brk
);
3171 qemu_log("entry 0x" TARGET_ABI_FMT_lx
"\n", info
->entry
);
3174 target_set_brk(info
->brk
);
3178 #if defined(CONFIG_USE_GUEST_BASE)
3179 /* Now that we've loaded the binary, GUEST_BASE is fixed. Delay
3180 generating the prologue until now so that the prologue can take
3181 the real value of GUEST_BASE into account. */
3182 tcg_prologue_init(&tcg_ctx
);
3185 #if defined(TARGET_I386)
3186 cpu_x86_set_cpl(env
, 3);
3188 env
->cr
[0] = CR0_PG_MASK
| CR0_WP_MASK
| CR0_PE_MASK
;
3189 env
->hflags
|= HF_PE_MASK
;
3190 if (env
->cpuid_features
& CPUID_SSE
) {
3191 env
->cr
[4] |= CR4_OSFXSR_MASK
;
3192 env
->hflags
|= HF_OSFXSR_MASK
;
3194 #ifndef TARGET_ABI32
3195 /* enable 64 bit mode if possible */
3196 if (!(env
->cpuid_ext2_features
& CPUID_EXT2_LM
)) {
3197 fprintf(stderr
, "The selected x86 CPU does not support 64 bit mode\n");
3200 env
->cr
[4] |= CR4_PAE_MASK
;
3201 env
->efer
|= MSR_EFER_LMA
| MSR_EFER_LME
;
3202 env
->hflags
|= HF_LMA_MASK
;
3205 /* flags setup : we activate the IRQs by default as in user mode */
3206 env
->eflags
|= IF_MASK
;
3208 /* linux register setup */
3209 #ifndef TARGET_ABI32
3210 env
->regs
[R_EAX
] = regs
->rax
;
3211 env
->regs
[R_EBX
] = regs
->rbx
;
3212 env
->regs
[R_ECX
] = regs
->rcx
;
3213 env
->regs
[R_EDX
] = regs
->rdx
;
3214 env
->regs
[R_ESI
] = regs
->rsi
;
3215 env
->regs
[R_EDI
] = regs
->rdi
;
3216 env
->regs
[R_EBP
] = regs
->rbp
;
3217 env
->regs
[R_ESP
] = regs
->rsp
;
3218 env
->eip
= regs
->rip
;
3220 env
->regs
[R_EAX
] = regs
->eax
;
3221 env
->regs
[R_EBX
] = regs
->ebx
;
3222 env
->regs
[R_ECX
] = regs
->ecx
;
3223 env
->regs
[R_EDX
] = regs
->edx
;
3224 env
->regs
[R_ESI
] = regs
->esi
;
3225 env
->regs
[R_EDI
] = regs
->edi
;
3226 env
->regs
[R_EBP
] = regs
->ebp
;
3227 env
->regs
[R_ESP
] = regs
->esp
;
3228 env
->eip
= regs
->eip
;
3231 /* linux interrupt setup */
3232 #ifndef TARGET_ABI32
3233 env
->idt
.limit
= 511;
3235 env
->idt
.limit
= 255;
3237 env
->idt
.base
= target_mmap(0, sizeof(uint64_t) * (env
->idt
.limit
+ 1),
3238 PROT_READ
|PROT_WRITE
,
3239 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3240 idt_table
= g2h(env
->idt
.base
);
3263 /* linux segment setup */
3265 uint64_t *gdt_table
;
3266 env
->gdt
.base
= target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES
,
3267 PROT_READ
|PROT_WRITE
,
3268 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3269 env
->gdt
.limit
= sizeof(uint64_t) * TARGET_GDT_ENTRIES
- 1;
3270 gdt_table
= g2h(env
->gdt
.base
);
3272 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
3273 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
3274 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
3276 /* 64 bit code segment */
3277 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
3278 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
3280 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
3282 write_dt(&gdt_table
[__USER_DS
>> 3], 0, 0xfffff,
3283 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
3284 (3 << DESC_DPL_SHIFT
) | (0x2 << DESC_TYPE_SHIFT
));
3286 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
3287 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
3289 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
3290 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
3291 cpu_x86_load_seg(env
, R_FS
, __USER_DS
);
3292 cpu_x86_load_seg(env
, R_GS
, __USER_DS
);
3293 /* This hack makes Wine work... */
3294 env
->segs
[R_FS
].selector
= 0;
3296 cpu_x86_load_seg(env
, R_DS
, 0);
3297 cpu_x86_load_seg(env
, R_ES
, 0);
3298 cpu_x86_load_seg(env
, R_FS
, 0);
3299 cpu_x86_load_seg(env
, R_GS
, 0);
3301 #elif defined(TARGET_ARM)
3304 cpsr_write(env
, regs
->uregs
[16], 0xffffffff);
3305 for(i
= 0; i
< 16; i
++) {
3306 env
->regs
[i
] = regs
->uregs
[i
];
3309 #elif defined(TARGET_UNICORE32)
3312 cpu_asr_write(env
, regs
->uregs
[32], 0xffffffff);
3313 for (i
= 0; i
< 32; i
++) {
3314 env
->regs
[i
] = regs
->uregs
[i
];
3317 #elif defined(TARGET_SPARC)
3321 env
->npc
= regs
->npc
;
3323 for(i
= 0; i
< 8; i
++)
3324 env
->gregs
[i
] = regs
->u_regs
[i
];
3325 for(i
= 0; i
< 8; i
++)
3326 env
->regwptr
[i
] = regs
->u_regs
[i
+ 8];
3328 #elif defined(TARGET_PPC)
3332 #if defined(TARGET_PPC64)
3333 #if defined(TARGET_ABI32)
3334 env
->msr
&= ~((target_ulong
)1 << MSR_SF
);
3336 env
->msr
|= (target_ulong
)1 << MSR_SF
;
3339 env
->nip
= regs
->nip
;
3340 for(i
= 0; i
< 32; i
++) {
3341 env
->gpr
[i
] = regs
->gpr
[i
];
3344 #elif defined(TARGET_M68K)
3347 env
->dregs
[0] = regs
->d0
;
3348 env
->dregs
[1] = regs
->d1
;
3349 env
->dregs
[2] = regs
->d2
;
3350 env
->dregs
[3] = regs
->d3
;
3351 env
->dregs
[4] = regs
->d4
;
3352 env
->dregs
[5] = regs
->d5
;
3353 env
->dregs
[6] = regs
->d6
;
3354 env
->dregs
[7] = regs
->d7
;
3355 env
->aregs
[0] = regs
->a0
;
3356 env
->aregs
[1] = regs
->a1
;
3357 env
->aregs
[2] = regs
->a2
;
3358 env
->aregs
[3] = regs
->a3
;
3359 env
->aregs
[4] = regs
->a4
;
3360 env
->aregs
[5] = regs
->a5
;
3361 env
->aregs
[6] = regs
->a6
;
3362 env
->aregs
[7] = regs
->usp
;
3364 ts
->sim_syscalls
= 1;
3366 #elif defined(TARGET_MICROBLAZE)
3368 env
->regs
[0] = regs
->r0
;
3369 env
->regs
[1] = regs
->r1
;
3370 env
->regs
[2] = regs
->r2
;
3371 env
->regs
[3] = regs
->r3
;
3372 env
->regs
[4] = regs
->r4
;
3373 env
->regs
[5] = regs
->r5
;
3374 env
->regs
[6] = regs
->r6
;
3375 env
->regs
[7] = regs
->r7
;
3376 env
->regs
[8] = regs
->r8
;
3377 env
->regs
[9] = regs
->r9
;
3378 env
->regs
[10] = regs
->r10
;
3379 env
->regs
[11] = regs
->r11
;
3380 env
->regs
[12] = regs
->r12
;
3381 env
->regs
[13] = regs
->r13
;
3382 env
->regs
[14] = regs
->r14
;
3383 env
->regs
[15] = regs
->r15
;
3384 env
->regs
[16] = regs
->r16
;
3385 env
->regs
[17] = regs
->r17
;
3386 env
->regs
[18] = regs
->r18
;
3387 env
->regs
[19] = regs
->r19
;
3388 env
->regs
[20] = regs
->r20
;
3389 env
->regs
[21] = regs
->r21
;
3390 env
->regs
[22] = regs
->r22
;
3391 env
->regs
[23] = regs
->r23
;
3392 env
->regs
[24] = regs
->r24
;
3393 env
->regs
[25] = regs
->r25
;
3394 env
->regs
[26] = regs
->r26
;
3395 env
->regs
[27] = regs
->r27
;
3396 env
->regs
[28] = regs
->r28
;
3397 env
->regs
[29] = regs
->r29
;
3398 env
->regs
[30] = regs
->r30
;
3399 env
->regs
[31] = regs
->r31
;
3400 env
->sregs
[SR_PC
] = regs
->pc
;
3402 #elif defined(TARGET_MIPS)
3406 for(i
= 0; i
< 32; i
++) {
3407 env
->active_tc
.gpr
[i
] = regs
->regs
[i
];
3409 env
->active_tc
.PC
= regs
->cp0_epc
& ~(target_ulong
)1;
3410 if (regs
->cp0_epc
& 1) {
3411 env
->hflags
|= MIPS_HFLAG_M16
;
3414 #elif defined(TARGET_SH4)
3418 for(i
= 0; i
< 16; i
++) {
3419 env
->gregs
[i
] = regs
->regs
[i
];
3423 #elif defined(TARGET_ALPHA)
3427 for(i
= 0; i
< 28; i
++) {
3428 env
->ir
[i
] = ((abi_ulong
*)regs
)[i
];
3430 env
->ir
[IR_SP
] = regs
->usp
;
3433 #elif defined(TARGET_CRIS)
3435 env
->regs
[0] = regs
->r0
;
3436 env
->regs
[1] = regs
->r1
;
3437 env
->regs
[2] = regs
->r2
;
3438 env
->regs
[3] = regs
->r3
;
3439 env
->regs
[4] = regs
->r4
;
3440 env
->regs
[5] = regs
->r5
;
3441 env
->regs
[6] = regs
->r6
;
3442 env
->regs
[7] = regs
->r7
;
3443 env
->regs
[8] = regs
->r8
;
3444 env
->regs
[9] = regs
->r9
;
3445 env
->regs
[10] = regs
->r10
;
3446 env
->regs
[11] = regs
->r11
;
3447 env
->regs
[12] = regs
->r12
;
3448 env
->regs
[13] = regs
->r13
;
3449 env
->regs
[14] = info
->start_stack
;
3450 env
->regs
[15] = regs
->acr
;
3451 env
->pc
= regs
->erp
;
3454 #error unsupported target CPU
3457 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
3458 ts
->stack_base
= info
->start_stack
;
3459 ts
->heap_base
= info
->brk
;
3460 /* This will be filled in on the first SYS_HEAPINFO call. */
3465 gdbserver_start (gdbstub_port
);
3466 gdb_handlesig(env
, 0);