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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 #include <machine/trap.h>
28 #include <sys/types.h>
32 #include "qemu-common.h"
36 #define DEBUG_LOGFILE "/tmp/qemu.log"
40 static const char *interp_prefix
= CONFIG_QEMU_PREFIX
;
41 const char *qemu_uname_release
= CONFIG_UNAME_RELEASE
;
42 extern char **environ
;
44 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
45 we allocate a bigger stack. Need a better solution, for example
46 by remapping the process stack directly at the right place */
47 unsigned long x86_stack_size
= 512 * 1024;
49 void gemu_log(const char *fmt
, ...)
54 vfprintf(stderr
, fmt
, ap
);
58 #if defined(TARGET_I386)
59 int cpu_get_pic_interrupt(CPUState
*env
)
65 /* These are no-ops because we are not threadsafe. */
66 static inline void cpu_exec_start(CPUState
*env
)
70 static inline void cpu_exec_end(CPUState
*env
)
74 static inline void start_exclusive(void)
78 static inline void end_exclusive(void)
86 void fork_end(int child
)
89 gdbserver_fork(thread_env
);
93 void cpu_list_lock(void)
97 void cpu_list_unlock(void)
102 /***********************************************************/
103 /* CPUX86 core interface */
105 void cpu_smm_update(CPUState
*env
)
109 uint64_t cpu_get_tsc(CPUX86State
*env
)
111 return cpu_get_real_ticks();
114 static void write_dt(void *ptr
, unsigned long addr
, unsigned long limit
,
119 e1
= (addr
<< 16) | (limit
& 0xffff);
120 e2
= ((addr
>> 16) & 0xff) | (addr
& 0xff000000) | (limit
& 0x000f0000);
127 static uint64_t *idt_table
;
129 static void set_gate64(void *ptr
, unsigned int type
, unsigned int dpl
,
130 uint64_t addr
, unsigned int sel
)
133 e1
= (addr
& 0xffff) | (sel
<< 16);
134 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
138 p
[2] = tswap32(addr
>> 32);
141 /* only dpl matters as we do only user space emulation */
142 static void set_idt(int n
, unsigned int dpl
)
144 set_gate64(idt_table
+ n
* 2, 0, dpl
, 0, 0);
147 static void set_gate(void *ptr
, unsigned int type
, unsigned int dpl
,
148 uint32_t addr
, unsigned int sel
)
151 e1
= (addr
& 0xffff) | (sel
<< 16);
152 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
158 /* only dpl matters as we do only user space emulation */
159 static void set_idt(int n
, unsigned int dpl
)
161 set_gate(idt_table
+ n
, 0, dpl
, 0, 0);
165 void cpu_loop(CPUX86State
*env
, enum BSDType bsd_type
)
169 //target_siginfo_t info;
172 trapnr
= cpu_x86_exec(env
);
175 /* syscall from int $0x80 */
176 env
->regs
[R_EAX
] = do_openbsd_syscall(env
,
187 /* linux syscall from syscall intruction */
188 env
->regs
[R_EAX
] = do_openbsd_syscall(env
,
196 env
->eip
= env
->exception_next_eip
;
202 info
.si_signo
= SIGBUS
;
204 info
.si_code
= TARGET_SI_KERNEL
;
205 info
._sifields
._sigfault
._addr
= 0;
206 queue_signal(env
, info
.si_signo
, &info
);
209 /* XXX: potential problem if ABI32 */
210 #ifndef TARGET_X86_64
211 if (env
->eflags
& VM_MASK
) {
212 handle_vm86_fault(env
);
216 info
.si_signo
= SIGSEGV
;
218 info
.si_code
= TARGET_SI_KERNEL
;
219 info
._sifields
._sigfault
._addr
= 0;
220 queue_signal(env
, info
.si_signo
, &info
);
224 info
.si_signo
= SIGSEGV
;
226 if (!(env
->error_code
& 1))
227 info
.si_code
= TARGET_SEGV_MAPERR
;
229 info
.si_code
= TARGET_SEGV_ACCERR
;
230 info
._sifields
._sigfault
._addr
= env
->cr
[2];
231 queue_signal(env
, info
.si_signo
, &info
);
234 #ifndef TARGET_X86_64
235 if (env
->eflags
& VM_MASK
) {
236 handle_vm86_trap(env
, trapnr
);
240 /* division by zero */
241 info
.si_signo
= SIGFPE
;
243 info
.si_code
= TARGET_FPE_INTDIV
;
244 info
._sifields
._sigfault
._addr
= env
->eip
;
245 queue_signal(env
, info
.si_signo
, &info
);
250 #ifndef TARGET_X86_64
251 if (env
->eflags
& VM_MASK
) {
252 handle_vm86_trap(env
, trapnr
);
256 info
.si_signo
= SIGTRAP
;
258 if (trapnr
== EXCP01_DB
) {
259 info
.si_code
= TARGET_TRAP_BRKPT
;
260 info
._sifields
._sigfault
._addr
= env
->eip
;
262 info
.si_code
= TARGET_SI_KERNEL
;
263 info
._sifields
._sigfault
._addr
= 0;
265 queue_signal(env
, info
.si_signo
, &info
);
270 #ifndef TARGET_X86_64
271 if (env
->eflags
& VM_MASK
) {
272 handle_vm86_trap(env
, trapnr
);
276 info
.si_signo
= SIGSEGV
;
278 info
.si_code
= TARGET_SI_KERNEL
;
279 info
._sifields
._sigfault
._addr
= 0;
280 queue_signal(env
, info
.si_signo
, &info
);
284 info
.si_signo
= SIGILL
;
286 info
.si_code
= TARGET_ILL_ILLOPN
;
287 info
._sifields
._sigfault
._addr
= env
->eip
;
288 queue_signal(env
, info
.si_signo
, &info
);
292 /* just indicate that signals should be handled asap */
299 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
304 info
.si_code
= TARGET_TRAP_BRKPT
;
305 queue_signal(env
, info
.si_signo
, &info
);
311 pc
= env
->segs
[R_CS
].base
+ env
->eip
;
312 fprintf(stderr
, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
316 process_pending_signals(env
);
322 #define SPARC64_STACK_BIAS 2047
325 /* WARNING: dealing with register windows _is_ complicated. More info
326 can be found at http://www.sics.se/~psm/sparcstack.html */
327 static inline int get_reg_index(CPUSPARCState
*env
, int cwp
, int index
)
329 index
= (index
+ cwp
* 16) % (16 * env
->nwindows
);
330 /* wrap handling : if cwp is on the last window, then we use the
331 registers 'after' the end */
332 if (index
< 8 && env
->cwp
== env
->nwindows
- 1)
333 index
+= 16 * env
->nwindows
;
337 /* save the register window 'cwp1' */
338 static inline void save_window_offset(CPUSPARCState
*env
, int cwp1
)
343 sp_ptr
= env
->regbase
[get_reg_index(env
, cwp1
, 6)];
344 #ifdef TARGET_SPARC64
346 sp_ptr
+= SPARC64_STACK_BIAS
;
348 #if defined(DEBUG_WIN)
349 printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx
" save_cwp=%d\n",
352 for(i
= 0; i
< 16; i
++) {
353 /* FIXME - what to do if put_user() fails? */
354 put_user_ual(env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)], sp_ptr
);
355 sp_ptr
+= sizeof(abi_ulong
);
359 static void save_window(CPUSPARCState
*env
)
361 #ifndef TARGET_SPARC64
362 unsigned int new_wim
;
363 new_wim
= ((env
->wim
>> 1) | (env
->wim
<< (env
->nwindows
- 1))) &
364 ((1LL << env
->nwindows
) - 1);
365 save_window_offset(env
, cpu_cwp_dec(env
, env
->cwp
- 2));
368 save_window_offset(env
, cpu_cwp_dec(env
, env
->cwp
- 2));
374 static void restore_window(CPUSPARCState
*env
)
376 #ifndef TARGET_SPARC64
377 unsigned int new_wim
;
379 unsigned int i
, cwp1
;
382 #ifndef TARGET_SPARC64
383 new_wim
= ((env
->wim
<< 1) | (env
->wim
>> (env
->nwindows
- 1))) &
384 ((1LL << env
->nwindows
) - 1);
387 /* restore the invalid window */
388 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ 1);
389 sp_ptr
= env
->regbase
[get_reg_index(env
, cwp1
, 6)];
390 #ifdef TARGET_SPARC64
392 sp_ptr
+= SPARC64_STACK_BIAS
;
394 #if defined(DEBUG_WIN)
395 printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx
" load_cwp=%d\n",
398 for(i
= 0; i
< 16; i
++) {
399 /* FIXME - what to do if get_user() fails? */
400 get_user_ual(env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)], sp_ptr
);
401 sp_ptr
+= sizeof(abi_ulong
);
403 #ifdef TARGET_SPARC64
405 if (env
->cleanwin
< env
->nwindows
- 1)
413 static void flush_windows(CPUSPARCState
*env
)
419 /* if restore would invoke restore_window(), then we can stop */
420 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ offset
);
421 #ifndef TARGET_SPARC64
422 if (env
->wim
& (1 << cwp1
))
425 if (env
->canrestore
== 0)
430 save_window_offset(env
, cwp1
);
433 cwp1
= cpu_cwp_inc(env
, env
->cwp
+ 1);
434 #ifndef TARGET_SPARC64
435 /* set wim so that restore will reload the registers */
436 env
->wim
= 1 << cwp1
;
438 #if defined(DEBUG_WIN)
439 printf("flush_windows: nb=%d\n", offset
- 1);
443 void cpu_loop(CPUSPARCState
*env
, enum BSDType bsd_type
)
445 int trapnr
, ret
, syscall_nr
;
446 //target_siginfo_t info;
449 trapnr
= cpu_sparc_exec (env
);
452 #ifndef TARGET_SPARC64
457 syscall_nr
= env
->gregs
[1];
458 if (bsd_type
== target_freebsd
)
459 ret
= do_freebsd_syscall(env
, syscall_nr
,
460 env
->regwptr
[0], env
->regwptr
[1],
461 env
->regwptr
[2], env
->regwptr
[3],
462 env
->regwptr
[4], env
->regwptr
[5]);
463 else if (bsd_type
== target_netbsd
)
464 ret
= do_netbsd_syscall(env
, syscall_nr
,
465 env
->regwptr
[0], env
->regwptr
[1],
466 env
->regwptr
[2], env
->regwptr
[3],
467 env
->regwptr
[4], env
->regwptr
[5]);
468 else { //if (bsd_type == target_openbsd)
469 #if defined(TARGET_SPARC64)
470 syscall_nr
&= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG
|
471 TARGET_OPENBSD_SYSCALL_G2RFLAG
);
473 ret
= do_openbsd_syscall(env
, syscall_nr
,
474 env
->regwptr
[0], env
->regwptr
[1],
475 env
->regwptr
[2], env
->regwptr
[3],
476 env
->regwptr
[4], env
->regwptr
[5]);
478 if ((unsigned int)ret
>= (unsigned int)(-515)) {
479 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
480 env
->xcc
|= PSR_CARRY
;
482 env
->psr
|= PSR_CARRY
;
485 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
486 env
->xcc
&= ~PSR_CARRY
;
488 env
->psr
&= ~PSR_CARRY
;
491 env
->regwptr
[0] = ret
;
492 /* next instruction */
493 #if defined(TARGET_SPARC64)
494 if (bsd_type
== target_openbsd
&&
495 env
->gregs
[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG
) {
496 env
->pc
= env
->gregs
[2];
497 env
->npc
= env
->pc
+ 4;
498 } else if (bsd_type
== target_openbsd
&&
499 env
->gregs
[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG
) {
500 env
->pc
= env
->gregs
[7];
501 env
->npc
= env
->pc
+ 4;
504 env
->npc
= env
->npc
+ 4;
508 env
->npc
= env
->npc
+ 4;
511 case 0x83: /* flush windows */
516 /* next instruction */
518 env
->npc
= env
->npc
+ 4;
520 #ifndef TARGET_SPARC64
521 case TT_WIN_OVF
: /* window overflow */
524 case TT_WIN_UNF
: /* window underflow */
531 info
.si_signo
= SIGSEGV
;
533 /* XXX: check env->error_code */
534 info
.si_code
= TARGET_SEGV_MAPERR
;
535 info
._sifields
._sigfault
._addr
= env
->mmuregs
[4];
536 queue_signal(env
, info
.si_signo
, &info
);
541 case TT_SPILL
: /* window overflow */
544 case TT_FILL
: /* window underflow */
551 info
.si_signo
= SIGSEGV
;
553 /* XXX: check env->error_code */
554 info
.si_code
= TARGET_SEGV_MAPERR
;
555 if (trapnr
== TT_DFAULT
)
556 info
._sifields
._sigfault
._addr
= env
->dmmuregs
[4];
558 info
._sifields
._sigfault
._addr
= env
->tsptr
->tpc
;
559 //queue_signal(env, info.si_signo, &info);
565 /* just indicate that signals should be handled asap */
571 sig
= gdb_handlesig (env
, TARGET_SIGTRAP
);
577 info
.si_code
= TARGET_TRAP_BRKPT
;
578 //queue_signal(env, info.si_signo, &info);
584 printf ("Unhandled trap: 0x%x\n", trapnr
);
585 cpu_dump_state(env
, stderr
, fprintf
, 0);
588 process_pending_signals (env
);
594 static void usage(void)
596 printf("qemu-" TARGET_ARCH
" version " QEMU_VERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n"
597 "usage: qemu-" TARGET_ARCH
" [options] program [arguments...]\n"
598 "BSD CPU emulator (compiled for %s emulation)\n"
600 "Standard options:\n"
601 "-h print this help\n"
602 "-g port wait gdb connection to port\n"
603 "-L path set the elf interpreter prefix (default=%s)\n"
604 "-s size set the stack size in bytes (default=%ld)\n"
605 "-cpu model select CPU (-cpu ? for list)\n"
606 "-drop-ld-preload drop LD_PRELOAD for target process\n"
607 "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n"
610 "-d options activate log (logfile=%s)\n"
611 "-p pagesize set the host page size to 'pagesize'\n"
612 "-singlestep always run in singlestep mode\n"
613 "-strace log system calls\n"
615 "Environment variables:\n"
616 "QEMU_STRACE Print system calls and arguments similar to the\n"
617 " 'strace' program. Enable by setting to any value.\n"
626 THREAD CPUState
*thread_env
;
628 /* Assumes contents are already zeroed. */
629 void init_task_state(TaskState
*ts
)
634 ts
->first_free
= ts
->sigqueue_table
;
635 for (i
= 0; i
< MAX_SIGQUEUE_SIZE
- 1; i
++) {
636 ts
->sigqueue_table
[i
].next
= &ts
->sigqueue_table
[i
+ 1];
638 ts
->sigqueue_table
[i
].next
= NULL
;
641 int main(int argc
, char **argv
)
643 const char *filename
;
644 const char *cpu_model
;
645 struct target_pt_regs regs1
, *regs
= ®s1
;
646 struct image_info info1
, *info
= &info1
;
647 TaskState ts1
, *ts
= &ts1
;
651 int gdbstub_port
= 0;
652 int drop_ld_preload
= 0, environ_count
= 0;
653 char **target_environ
, **wrk
, **dst
;
654 enum BSDType bsd_type
= target_openbsd
;
660 cpu_set_log_filename(DEBUG_LOGFILE
);
672 if (!strcmp(r
, "-")) {
674 } else if (!strcmp(r
, "d")) {
676 const CPULogItem
*item
;
682 mask
= cpu_str_to_log_mask(r
);
684 printf("Log items (comma separated):\n");
685 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
686 printf("%-10s %s\n", item
->name
, item
->help
);
691 } else if (!strcmp(r
, "s")) {
693 x86_stack_size
= strtol(r
, (char **)&r
, 0);
694 if (x86_stack_size
<= 0)
697 x86_stack_size
*= 1024 * 1024;
698 else if (*r
== 'k' || *r
== 'K')
699 x86_stack_size
*= 1024;
700 } else if (!strcmp(r
, "L")) {
701 interp_prefix
= argv
[optind
++];
702 } else if (!strcmp(r
, "p")) {
703 qemu_host_page_size
= atoi(argv
[optind
++]);
704 if (qemu_host_page_size
== 0 ||
705 (qemu_host_page_size
& (qemu_host_page_size
- 1)) != 0) {
706 fprintf(stderr
, "page size must be a power of two\n");
709 } else if (!strcmp(r
, "g")) {
710 gdbstub_port
= atoi(argv
[optind
++]);
711 } else if (!strcmp(r
, "r")) {
712 qemu_uname_release
= argv
[optind
++];
713 } else if (!strcmp(r
, "cpu")) {
714 cpu_model
= argv
[optind
++];
715 if (strcmp(cpu_model
, "?") == 0) {
716 /* XXX: implement xxx_cpu_list for targets that still miss it */
717 #if defined(cpu_list)
718 cpu_list(stdout
, &fprintf
);
722 } else if (!strcmp(r
, "drop-ld-preload")) {
724 } else if (!strcmp(r
, "bsd")) {
725 if (!strcasecmp(argv
[optind
], "freebsd")) {
726 bsd_type
= target_freebsd
;
727 } else if (!strcasecmp(argv
[optind
], "netbsd")) {
728 bsd_type
= target_netbsd
;
729 } else if (!strcasecmp(argv
[optind
], "openbsd")) {
730 bsd_type
= target_openbsd
;
735 } else if (!strcmp(r
, "singlestep")) {
737 } else if (!strcmp(r
, "strace")) {
746 filename
= argv
[optind
];
749 memset(regs
, 0, sizeof(struct target_pt_regs
));
751 /* Zero out image_info */
752 memset(info
, 0, sizeof(struct image_info
));
754 /* Scan interp_prefix dir for replacement files. */
755 init_paths(interp_prefix
);
757 if (cpu_model
== NULL
) {
758 #if defined(TARGET_I386)
760 cpu_model
= "qemu64";
762 cpu_model
= "qemu32";
764 #elif defined(TARGET_SPARC)
765 #ifdef TARGET_SPARC64
766 cpu_model
= "TI UltraSparc II";
768 cpu_model
= "Fujitsu MB86904";
774 cpu_exec_init_all(0);
775 /* NOTE: we need to init the CPU at this stage to get
776 qemu_host_page_size */
777 env
= cpu_init(cpu_model
);
779 fprintf(stderr
, "Unable to find CPU definition\n");
784 if (getenv("QEMU_STRACE")) {
792 target_environ
= malloc((environ_count
+ 1) * sizeof(char *));
795 for (wrk
= environ
, dst
= target_environ
; *wrk
; wrk
++) {
796 if (drop_ld_preload
&& !strncmp(*wrk
, "LD_PRELOAD=", 11))
798 *(dst
++) = strdup(*wrk
);
800 *dst
= NULL
; /* NULL terminate target_environ */
802 if (loader_exec(filename
, argv
+optind
, target_environ
, regs
, info
) != 0) {
803 printf("Error loading %s\n", filename
);
807 for (wrk
= target_environ
; *wrk
; wrk
++) {
811 free(target_environ
);
813 if (qemu_log_enabled()) {
816 qemu_log("start_brk 0x" TARGET_ABI_FMT_lx
"\n", info
->start_brk
);
817 qemu_log("end_code 0x" TARGET_ABI_FMT_lx
"\n", info
->end_code
);
818 qemu_log("start_code 0x" TARGET_ABI_FMT_lx
"\n",
820 qemu_log("start_data 0x" TARGET_ABI_FMT_lx
"\n",
822 qemu_log("end_data 0x" TARGET_ABI_FMT_lx
"\n", info
->end_data
);
823 qemu_log("start_stack 0x" TARGET_ABI_FMT_lx
"\n",
825 qemu_log("brk 0x" TARGET_ABI_FMT_lx
"\n", info
->brk
);
826 qemu_log("entry 0x" TARGET_ABI_FMT_lx
"\n", info
->entry
);
829 target_set_brk(info
->brk
);
833 /* build Task State */
834 memset(ts
, 0, sizeof(TaskState
));
839 #if defined(TARGET_I386)
840 cpu_x86_set_cpl(env
, 3);
842 env
->cr
[0] = CR0_PG_MASK
| CR0_WP_MASK
| CR0_PE_MASK
;
843 env
->hflags
|= HF_PE_MASK
;
844 if (env
->cpuid_features
& CPUID_SSE
) {
845 env
->cr
[4] |= CR4_OSFXSR_MASK
;
846 env
->hflags
|= HF_OSFXSR_MASK
;
849 /* enable 64 bit mode if possible */
850 if (!(env
->cpuid_ext2_features
& CPUID_EXT2_LM
)) {
851 fprintf(stderr
, "The selected x86 CPU does not support 64 bit mode\n");
854 env
->cr
[4] |= CR4_PAE_MASK
;
855 env
->efer
|= MSR_EFER_LMA
| MSR_EFER_LME
;
856 env
->hflags
|= HF_LMA_MASK
;
859 /* flags setup : we activate the IRQs by default as in user mode */
860 env
->eflags
|= IF_MASK
;
862 /* linux register setup */
864 env
->regs
[R_EAX
] = regs
->rax
;
865 env
->regs
[R_EBX
] = regs
->rbx
;
866 env
->regs
[R_ECX
] = regs
->rcx
;
867 env
->regs
[R_EDX
] = regs
->rdx
;
868 env
->regs
[R_ESI
] = regs
->rsi
;
869 env
->regs
[R_EDI
] = regs
->rdi
;
870 env
->regs
[R_EBP
] = regs
->rbp
;
871 env
->regs
[R_ESP
] = regs
->rsp
;
872 env
->eip
= regs
->rip
;
874 env
->regs
[R_EAX
] = regs
->eax
;
875 env
->regs
[R_EBX
] = regs
->ebx
;
876 env
->regs
[R_ECX
] = regs
->ecx
;
877 env
->regs
[R_EDX
] = regs
->edx
;
878 env
->regs
[R_ESI
] = regs
->esi
;
879 env
->regs
[R_EDI
] = regs
->edi
;
880 env
->regs
[R_EBP
] = regs
->ebp
;
881 env
->regs
[R_ESP
] = regs
->esp
;
882 env
->eip
= regs
->eip
;
885 /* linux interrupt setup */
887 env
->idt
.limit
= 511;
889 env
->idt
.limit
= 255;
891 env
->idt
.base
= target_mmap(0, sizeof(uint64_t) * (env
->idt
.limit
+ 1),
892 PROT_READ
|PROT_WRITE
,
893 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
894 idt_table
= g2h(env
->idt
.base
);
917 /* linux segment setup */
920 env
->gdt
.base
= target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES
,
921 PROT_READ
|PROT_WRITE
,
922 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
923 env
->gdt
.limit
= sizeof(uint64_t) * TARGET_GDT_ENTRIES
- 1;
924 gdt_table
= g2h(env
->gdt
.base
);
926 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
927 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
928 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
930 /* 64 bit code segment */
931 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
932 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
934 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
936 write_dt(&gdt_table
[__USER_DS
>> 3], 0, 0xfffff,
937 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
938 (3 << DESC_DPL_SHIFT
) | (0x2 << DESC_TYPE_SHIFT
));
941 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
942 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
944 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
945 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
946 cpu_x86_load_seg(env
, R_FS
, __USER_DS
);
947 cpu_x86_load_seg(env
, R_GS
, __USER_DS
);
948 /* This hack makes Wine work... */
949 env
->segs
[R_FS
].selector
= 0;
951 cpu_x86_load_seg(env
, R_DS
, 0);
952 cpu_x86_load_seg(env
, R_ES
, 0);
953 cpu_x86_load_seg(env
, R_FS
, 0);
954 cpu_x86_load_seg(env
, R_GS
, 0);
956 #elif defined(TARGET_SPARC)
960 env
->npc
= regs
->npc
;
962 for(i
= 0; i
< 8; i
++)
963 env
->gregs
[i
] = regs
->u_regs
[i
];
964 for(i
= 0; i
< 8; i
++)
965 env
->regwptr
[i
] = regs
->u_regs
[i
+ 8];
968 #error unsupported target CPU
972 gdbserver_start (gdbstub_port
);
973 gdb_handlesig(env
, 0);
975 cpu_loop(env
, bsd_type
);