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 void cpu_outb(CPUState *env, int addr, int val)
60 fprintf(stderr, "outb: port=0x%04x, data=%02x\n", addr, val);
63 void cpu_outw(CPUState *env, int addr, int val)
65 fprintf(stderr, "outw: port=0x%04x, data=%04x\n", addr, val);
68 void cpu_outl(CPUState *env, int addr, int val)
70 fprintf(stderr, "outl: port=0x%04x, data=%08x\n", addr, val);
73 int cpu_inb(CPUState *env, int addr)
75 fprintf(stderr, "inb: port=0x%04x\n", addr);
79 int cpu_inw(CPUState *env, int addr)
81 fprintf(stderr, "inw: port=0x%04x\n", addr);
85 int cpu_inl(CPUState *env, int addr)
87 fprintf(stderr, "inl: port=0x%04x\n", addr);
91 #if defined(TARGET_I386)
92 int cpu_get_pic_interrupt(CPUState *env)
98 /* These are no-ops because we are not threadsafe. */
99 static inline void cpu_exec_start(CPUState *env)
103 static inline void cpu_exec_end(CPUState *env)
107 static inline void start_exclusive(void)
111 static inline void end_exclusive(void)
115 void fork_start(void)
119 void fork_end(int child)
122 gdbserver_fork(thread_env);
126 void cpu_list_lock(void)
130 void cpu_list_unlock(void)
135 /***********************************************************/
136 /* CPUX86 core interface */
138 void cpu_smm_update(CPUState *env)
142 uint64_t cpu_get_tsc(CPUX86State *env)
144 return cpu_get_real_ticks();
147 static void write_dt(void *ptr, unsigned long addr, unsigned long limit,
152 e1 = (addr << 16) | (limit & 0xffff);
153 e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
160 static uint64_t *idt_table;
162 static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
163 uint64_t addr, unsigned int sel)
166 e1 = (addr & 0xffff) | (sel << 16);
167 e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
171 p[2] = tswap32(addr >> 32);
174 /* only dpl matters as we do only user space emulation */
175 static void set_idt(int n, unsigned int dpl)
177 set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
180 static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
181 uint32_t addr, unsigned int sel)
184 e1 = (addr & 0xffff) | (sel << 16);
185 e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
191 /* only dpl matters as we do only user space emulation */
192 static void set_idt(int n, unsigned int dpl)
194 set_gate(idt_table + n, 0, dpl, 0, 0);
198 void cpu_loop(CPUX86State *env, enum BSDType bsd_type)
202 //target_siginfo_t info;
205 trapnr = cpu_x86_exec(env);
208 /* syscall from int $0x80 */
209 env->regs[R_EAX] = do_openbsd_syscall(env,
220 /* linux syscall from syscall intruction */
221 env->regs[R_EAX] = do_openbsd_syscall(env,
229 env->eip = env->exception_next_eip;
235 info.si_signo = SIGBUS;
237 info.si_code = TARGET_SI_KERNEL;
238 info._sifields._sigfault._addr = 0;
239 queue_signal(env, info.si_signo, &info);
242 /* XXX: potential problem if ABI32 */
243 #ifndef TARGET_X86_64
244 if (env->eflags & VM_MASK) {
245 handle_vm86_fault(env);
249 info.si_signo = SIGSEGV;
251 info.si_code = TARGET_SI_KERNEL;
252 info._sifields._sigfault._addr = 0;
253 queue_signal(env, info.si_signo, &info);
257 info.si_signo = SIGSEGV;
259 if (!(env->error_code & 1))
260 info.si_code = TARGET_SEGV_MAPERR;
262 info.si_code = TARGET_SEGV_ACCERR;
263 info._sifields._sigfault._addr = env->cr[2];
264 queue_signal(env, info.si_signo, &info);
267 #ifndef TARGET_X86_64
268 if (env->eflags & VM_MASK) {
269 handle_vm86_trap(env, trapnr);
273 /* division by zero */
274 info.si_signo = SIGFPE;
276 info.si_code = TARGET_FPE_INTDIV;
277 info._sifields._sigfault._addr = env->eip;
278 queue_signal(env, info.si_signo, &info);
283 #ifndef TARGET_X86_64
284 if (env->eflags & VM_MASK) {
285 handle_vm86_trap(env, trapnr);
289 info.si_signo = SIGTRAP;
291 if (trapnr == EXCP01_DB) {
292 info.si_code = TARGET_TRAP_BRKPT;
293 info._sifields._sigfault._addr = env->eip;
295 info.si_code = TARGET_SI_KERNEL;
296 info._sifields._sigfault._addr = 0;
298 queue_signal(env, info.si_signo, &info);
303 #ifndef TARGET_X86_64
304 if (env->eflags & VM_MASK) {
305 handle_vm86_trap(env, trapnr);
309 info.si_signo = SIGSEGV;
311 info.si_code = TARGET_SI_KERNEL;
312 info._sifields._sigfault._addr = 0;
313 queue_signal(env, info.si_signo, &info);
317 info.si_signo = SIGILL;
319 info.si_code = TARGET_ILL_ILLOPN;
320 info._sifields._sigfault._addr = env->eip;
321 queue_signal(env, info.si_signo, &info);
325 /* just indicate that signals should be handled asap */
332 sig = gdb_handlesig (env, TARGET_SIGTRAP);
337 info.si_code = TARGET_TRAP_BRKPT;
338 queue_signal(env, info.si_signo, &info);
344 pc = env->segs[R_CS].base + env->eip;
345 fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
349 process_pending_signals(env);
355 #define SPARC64_STACK_BIAS 2047
358 /* WARNING: dealing with register windows _is_ complicated. More info
359 can be found at http://www.sics.se/~psm/sparcstack.html */
360 static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
362 index = (index + cwp * 16) % (16 * env->nwindows);
363 /* wrap handling : if cwp is on the last window, then we use the
364 registers 'after' the end */
365 if (index < 8 && env->cwp == env->nwindows - 1)
366 index += 16 * env->nwindows;
370 /* save the register window 'cwp1' */
371 static inline void save_window_offset(CPUSPARCState *env, int cwp1)
376 sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
377 #ifdef TARGET_SPARC64
379 sp_ptr += SPARC64_STACK_BIAS;
381 #if defined(DEBUG_WIN)
382 printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
385 for(i = 0; i < 16; i++) {
386 /* FIXME - what to do if put_user() fails? */
387 put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
388 sp_ptr += sizeof(abi_ulong);
392 static void save_window(CPUSPARCState *env)
394 #ifndef TARGET_SPARC64
395 unsigned int new_wim;
396 new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) &
397 ((1LL << env->nwindows) - 1);
398 save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
401 save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
407 static void restore_window(CPUSPARCState *env)
409 #ifndef TARGET_SPARC64
410 unsigned int new_wim;
412 unsigned int i, cwp1;
415 #ifndef TARGET_SPARC64
416 new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) &
417 ((1LL << env->nwindows) - 1);
420 /* restore the invalid window */
421 cwp1 = cpu_cwp_inc(env, env->cwp + 1);
422 sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
423 #ifdef TARGET_SPARC64
425 sp_ptr += SPARC64_STACK_BIAS;
427 #if defined(DEBUG_WIN)
428 printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
431 for(i = 0; i < 16; i++) {
432 /* FIXME - what to do if get_user() fails? */
433 get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
434 sp_ptr += sizeof(abi_ulong);
436 #ifdef TARGET_SPARC64
438 if (env->cleanwin < env->nwindows - 1)
446 static void flush_windows(CPUSPARCState *env)
452 /* if restore would invoke restore_window(), then we can stop */
453 cwp1 = cpu_cwp_inc(env, env->cwp + offset);
454 #ifndef TARGET_SPARC64
455 if (env->wim & (1 << cwp1))
458 if (env->canrestore == 0)
463 save_window_offset(env, cwp1);
466 cwp1 = cpu_cwp_inc(env, env->cwp + 1);
467 #ifndef TARGET_SPARC64
468 /* set wim so that restore will reload the registers */
469 env->wim = 1 << cwp1;
471 #if defined(DEBUG_WIN)
472 printf("flush_windows: nb=%d\n", offset - 1);
476 void cpu_loop(CPUSPARCState *env, enum BSDType bsd_type)
478 int trapnr, ret, syscall_nr;
479 //target_siginfo_t info;
482 trapnr = cpu_sparc_exec (env);
485 #ifndef TARGET_SPARC64
490 syscall_nr = env->gregs[1];
491 if (bsd_type == target_freebsd)
492 ret = do_freebsd_syscall(env, syscall_nr,
493 env->regwptr[0], env->regwptr[1],
494 env->regwptr[2], env->regwptr[3],
495 env->regwptr[4], env->regwptr[5]);
496 else if (bsd_type == target_netbsd)
497 ret = do_netbsd_syscall(env, syscall_nr,
498 env->regwptr[0], env->regwptr[1],
499 env->regwptr[2], env->regwptr[3],
500 env->regwptr[4], env->regwptr[5]);
501 else { //if (bsd_type == target_openbsd)
502 #if defined(TARGET_SPARC64)
503 syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
504 TARGET_OPENBSD_SYSCALL_G2RFLAG);
506 ret = do_openbsd_syscall(env, syscall_nr,
507 env->regwptr[0], env->regwptr[1],
508 env->regwptr[2], env->regwptr[3],
509 env->regwptr[4], env->regwptr[5]);
511 if ((unsigned int)ret >= (unsigned int)(-515)) {
512 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
513 env->xcc |= PSR_CARRY;
515 env->psr |= PSR_CARRY;
518 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
519 env->xcc &= ~PSR_CARRY;
521 env->psr &= ~PSR_CARRY;
524 env->regwptr[0] = ret;
525 /* next instruction */
526 #if defined(TARGET_SPARC64)
527 if (bsd_type == target_openbsd &&
528 env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) {
529 env->pc = env->gregs[2];
530 env->npc = env->pc + 4;
531 } else if (bsd_type == target_openbsd &&
532 env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) {
533 env->pc = env->gregs[7];
534 env->npc = env->pc + 4;
537 env->npc = env->npc + 4;
541 env->npc = env->npc + 4;
544 case 0x83: /* flush windows */
549 /* next instruction */
551 env->npc = env->npc + 4;
553 #ifndef TARGET_SPARC64
554 case TT_WIN_OVF: /* window overflow */
557 case TT_WIN_UNF: /* window underflow */
564 info.si_signo = SIGSEGV;
566 /* XXX: check env->error_code */
567 info.si_code = TARGET_SEGV_MAPERR;
568 info._sifields._sigfault._addr = env->mmuregs[4];
569 queue_signal(env, info.si_signo, &info);
574 case TT_SPILL: /* window overflow */
577 case TT_FILL: /* window underflow */
584 info.si_signo = SIGSEGV;
586 /* XXX: check env->error_code */
587 info.si_code = TARGET_SEGV_MAPERR;
588 if (trapnr == TT_DFAULT)
589 info._sifields._sigfault._addr = env->dmmuregs[4];
591 info._sifields._sigfault._addr = env->tsptr->tpc;
592 //queue_signal(env, info.si_signo, &info);
598 /* just indicate that signals should be handled asap */
604 sig = gdb_handlesig (env, TARGET_SIGTRAP);
610 info.si_code = TARGET_TRAP_BRKPT;
611 //queue_signal(env, info.si_signo, &info);
617 printf ("Unhandled trap: 0x%x\n", trapnr);
618 cpu_dump_state(env, stderr, fprintf, 0);
621 process_pending_signals (env);
627 static void usage(void)
629 printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"
630 "usage: qemu-" TARGET_ARCH " [options] program [arguments...]\n"
631 "BSD CPU emulator (compiled for %s emulation)\n"
633 "Standard options:\n"
634 "-h print this help\n"
635 "-g port wait gdb connection to port\n"
636 "-L path set the elf interpreter prefix (default=%s)\n"
637 "-s size set the stack size in bytes (default=%ld)\n"
638 "-cpu model select CPU (-cpu ? for list)\n"
639 "-drop-ld-preload drop LD_PRELOAD for target process\n"
640 "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n"
643 "-d options activate log (logfile=%s)\n"
644 "-p pagesize set the host page size to 'pagesize'\n"
645 "-singlestep always run in singlestep mode\n"
646 "-strace log system calls\n"
648 "Environment variables:\n"
649 "QEMU_STRACE Print system calls and arguments similar to the\n"
650 " 'strace' program. Enable by setting to any value.\n"
659 THREAD CPUState *thread_env;
661 /* Assumes contents are already zeroed. */
662 void init_task_state(TaskState *ts)
667 ts->first_free = ts->sigqueue_table;
668 for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) {
669 ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1];
671 ts->sigqueue_table[i].next = NULL;
674 int main(int argc, char **argv)
676 const char *filename;
677 const char *cpu_model;
678 struct target_pt_regs regs1, *regs = ®s1;
679 struct image_info info1, *info = &info1;
680 TaskState ts1, *ts = &ts1;
684 int gdbstub_port = 0;
685 int drop_ld_preload = 0, environ_count = 0;
686 char **target_environ, **wrk, **dst;
687 enum BSDType bsd_type = target_openbsd;
693 cpu_set_log_filename(DEBUG_LOGFILE);
705 if (!strcmp(r, "-")) {
707 } else if (!strcmp(r, "d")) {
709 const CPULogItem *item;
715 mask = cpu_str_to_log_mask(r);
717 printf("Log items (comma separated):\n");
718 for(item = cpu_log_items; item->mask != 0; item++) {
719 printf("%-10s %s\n", item->name, item->help);
724 } else if (!strcmp(r, "s")) {
726 x86_stack_size = strtol(r, (char **)&r, 0);
727 if (x86_stack_size <= 0)
730 x86_stack_size *= 1024 * 1024;
731 else if (*r == 'k' || *r == 'K')
732 x86_stack_size *= 1024;
733 } else if (!strcmp(r, "L")) {
734 interp_prefix = argv[optind++];
735 } else if (!strcmp(r, "p")) {
736 qemu_host_page_size = atoi(argv[optind++]);
737 if (qemu_host_page_size == 0 ||
738 (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
739 fprintf(stderr, "page size must be a power of two\n");
742 } else if (!strcmp(r, "g")) {
743 gdbstub_port = atoi(argv[optind++]);
744 } else if (!strcmp(r, "r")) {
745 qemu_uname_release = argv[optind++];
746 } else if (!strcmp(r, "cpu")) {
747 cpu_model = argv[optind++];
748 if (strcmp(cpu_model, "?") == 0) {
749 /* XXX: implement xxx_cpu_list for targets that still miss it */
750 #if defined(cpu_list)
751 cpu_list(stdout, &fprintf);
755 } else if (!strcmp(r, "drop-ld-preload")) {
757 } else if (!strcmp(r, "bsd")) {
758 if (!strcasecmp(argv[optind], "freebsd")) {
759 bsd_type = target_freebsd;
760 } else if (!strcasecmp(argv[optind], "netbsd")) {
761 bsd_type = target_netbsd;
762 } else if (!strcasecmp(argv[optind], "openbsd")) {
763 bsd_type = target_openbsd;
768 } else if (!strcmp(r, "singlestep")) {
770 } else if (!strcmp(r, "strace")) {
779 filename = argv[optind];
782 memset(regs, 0, sizeof(struct target_pt_regs));
784 /* Zero out image_info */
785 memset(info, 0, sizeof(struct image_info));
787 /* Scan interp_prefix dir for replacement files. */
788 init_paths(interp_prefix);
790 if (cpu_model == NULL) {
791 #if defined(TARGET_I386)
793 cpu_model = "qemu64";
795 cpu_model = "qemu32";
797 #elif defined(TARGET_SPARC)
798 #ifdef TARGET_SPARC64
799 cpu_model = "TI UltraSparc II";
801 cpu_model = "Fujitsu MB86904";
807 cpu_exec_init_all(0);
808 /* NOTE: we need to init the CPU at this stage to get
809 qemu_host_page_size */
810 env = cpu_init(cpu_model);
812 fprintf(stderr, "Unable to find CPU definition\n");
817 if (getenv("QEMU_STRACE")) {
825 target_environ = malloc((environ_count + 1) * sizeof(char *));
828 for (wrk = environ, dst = target_environ; *wrk; wrk++) {
829 if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
831 *(dst++) = strdup(*wrk);
833 *dst = NULL; /* NULL terminate target_environ */
835 if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
836 printf("Error loading %s\n", filename);
840 for (wrk = target_environ; *wrk; wrk++) {
844 free(target_environ);
846 if (qemu_log_enabled()) {
849 qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk);
850 qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code);
851 qemu_log("start_code 0x" TARGET_ABI_FMT_lx "\n",
853 qemu_log("start_data 0x" TARGET_ABI_FMT_lx "\n",
855 qemu_log("end_data 0x" TARGET_ABI_FMT_lx "\n", info->end_data);
856 qemu_log("start_stack 0x" TARGET_ABI_FMT_lx "\n",
858 qemu_log("brk 0x" TARGET_ABI_FMT_lx "\n", info->brk);
859 qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry);
862 target_set_brk(info->brk);
866 /* build Task State */
867 memset(ts, 0, sizeof(TaskState));
872 #if defined(TARGET_I386)
873 cpu_x86_set_cpl(env, 3);
875 env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
876 env->hflags |= HF_PE_MASK;
877 if (env->cpuid_features & CPUID_SSE) {
878 env->cr[4] |= CR4_OSFXSR_MASK;
879 env->hflags |= HF_OSFXSR_MASK;
882 /* enable 64 bit mode if possible */
883 if (!(env->cpuid_ext2_features & CPUID_EXT2_LM)) {
884 fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n");
887 env->cr[4] |= CR4_PAE_MASK;
888 env->efer |= MSR_EFER_LMA | MSR_EFER_LME;
889 env->hflags |= HF_LMA_MASK;
892 /* flags setup : we activate the IRQs by default as in user mode */
893 env->eflags |= IF_MASK;
895 /* linux register setup */
897 env->regs[R_EAX] = regs->rax;
898 env->regs[R_EBX] = regs->rbx;
899 env->regs[R_ECX] = regs->rcx;
900 env->regs[R_EDX] = regs->rdx;
901 env->regs[R_ESI] = regs->rsi;
902 env->regs[R_EDI] = regs->rdi;
903 env->regs[R_EBP] = regs->rbp;
904 env->regs[R_ESP] = regs->rsp;
905 env->eip = regs->rip;
907 env->regs[R_EAX] = regs->eax;
908 env->regs[R_EBX] = regs->ebx;
909 env->regs[R_ECX] = regs->ecx;
910 env->regs[R_EDX] = regs->edx;
911 env->regs[R_ESI] = regs->esi;
912 env->regs[R_EDI] = regs->edi;
913 env->regs[R_EBP] = regs->ebp;
914 env->regs[R_ESP] = regs->esp;
915 env->eip = regs->eip;
918 /* linux interrupt setup */
920 env->idt.limit = 511;
922 env->idt.limit = 255;
924 env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1),
925 PROT_READ|PROT_WRITE,
926 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
927 idt_table = g2h(env->idt.base);
950 /* linux segment setup */
953 env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES,
954 PROT_READ|PROT_WRITE,
955 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
956 env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
957 gdt_table = g2h(env->gdt.base);
959 write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
960 DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
961 (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT));
963 /* 64 bit code segment */
964 write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
965 DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
967 (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT));
969 write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff,
970 DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
971 (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT));
974 cpu_x86_load_seg(env, R_CS, __USER_CS);
975 cpu_x86_load_seg(env, R_SS, __USER_DS);
977 cpu_x86_load_seg(env, R_DS, __USER_DS);
978 cpu_x86_load_seg(env, R_ES, __USER_DS);
979 cpu_x86_load_seg(env, R_FS, __USER_DS);
980 cpu_x86_load_seg(env, R_GS, __USER_DS);
981 /* This hack makes Wine work... */
982 env->segs[R_FS].selector = 0;
984 cpu_x86_load_seg(env, R_DS, 0);
985 cpu_x86_load_seg(env, R_ES, 0);
986 cpu_x86_load_seg(env, R_FS, 0);
987 cpu_x86_load_seg(env, R_GS, 0);
989 #elif defined(TARGET_SPARC)
993 env->npc = regs->npc;
995 for(i = 0; i < 8; i++)
996 env->gregs[i] = regs->u_regs[i];
997 for(i = 0; i < 8; i++)
998 env->regwptr[i] = regs->u_regs[i + 8];
1001 #error unsupported target CPU
1005 gdbserver_start (gdbstub_port);
1006 gdb_handlesig(env, 0);
1008 cpu_loop(env, bsd_type);