4 * Copyright (c) 2003 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., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define DEBUG_LOGFILE "/tmp/qemu.log"
31 static const char *interp_prefix = CONFIG_QEMU_PREFIX;
33 #if defined(__i386__) && !defined(CONFIG_STATIC)
34 /* Force usage of an ELF interpreter even if it is an ELF shared
36 const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
39 /* for recent libc, we add these dummy symbols which are not declared
40 when generating a linked object (bug in ld ?) */
41 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
42 long __preinit_array_start[0];
43 long __preinit_array_end[0];
44 long __init_array_start[0];
45 long __init_array_end[0];
46 long __fini_array_start[0];
47 long __fini_array_end[0];
50 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
51 we allocate a bigger stack. Need a better solution, for example
52 by remapping the process stack directly at the right place */
53 unsigned long x86_stack_size = 512 * 1024;
55 void gemu_log(const char *fmt, ...)
60 vfprintf(stderr, fmt, ap);
64 void cpu_outb(CPUState *env, int addr, int val)
66 fprintf(stderr, "outb: port=0x%04x, data=%02x\n", addr, val);
69 void cpu_outw(CPUState *env, int addr, int val)
71 fprintf(stderr, "outw: port=0x%04x, data=%04x\n", addr, val);
74 void cpu_outl(CPUState *env, int addr, int val)
76 fprintf(stderr, "outl: port=0x%04x, data=%08x\n", addr, val);
79 int cpu_inb(CPUState *env, int addr)
81 fprintf(stderr, "inb: port=0x%04x\n", addr);
85 int cpu_inw(CPUState *env, int addr)
87 fprintf(stderr, "inw: port=0x%04x\n", addr);
91 int cpu_inl(CPUState *env, int addr)
93 fprintf(stderr, "inl: port=0x%04x\n", addr);
98 /***********************************************************/
99 /* CPUX86 core interface */
101 int cpu_x86_get_pic_interrupt(CPUState *env)
106 static void write_dt(void *ptr, unsigned long addr, unsigned long limit,
110 e1 = (addr << 16) | (limit & 0xffff);
111 e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
113 stl((uint8_t *)ptr, e1);
114 stl((uint8_t *)ptr + 4, e2);
117 static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
118 unsigned long addr, unsigned int sel)
121 e1 = (addr & 0xffff) | (sel << 16);
122 e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
123 stl((uint8_t *)ptr, e1);
124 stl((uint8_t *)ptr + 4, e2);
127 uint64_t gdt_table[6];
128 uint64_t idt_table[256];
130 /* only dpl matters as we do only user space emulation */
131 static void set_idt(int n, unsigned int dpl)
133 set_gate(idt_table + n, 0, dpl, 0, 0);
136 void cpu_loop(CPUX86State *env)
140 target_siginfo_t info;
143 trapnr = cpu_x86_exec(env);
147 env->regs[R_EAX] = do_syscall(env,
158 info.si_signo = SIGBUS;
160 info.si_code = TARGET_SI_KERNEL;
161 info._sifields._sigfault._addr = 0;
162 queue_signal(info.si_signo, &info);
165 if (env->eflags & VM_MASK) {
166 handle_vm86_fault(env);
168 info.si_signo = SIGSEGV;
170 info.si_code = TARGET_SI_KERNEL;
171 info._sifields._sigfault._addr = 0;
172 queue_signal(info.si_signo, &info);
176 info.si_signo = SIGSEGV;
178 if (!(env->error_code & 1))
179 info.si_code = TARGET_SEGV_MAPERR;
181 info.si_code = TARGET_SEGV_ACCERR;
182 info._sifields._sigfault._addr = env->cr[2];
183 queue_signal(info.si_signo, &info);
186 if (env->eflags & VM_MASK) {
187 handle_vm86_trap(env, trapnr);
189 /* division by zero */
190 info.si_signo = SIGFPE;
192 info.si_code = TARGET_FPE_INTDIV;
193 info._sifields._sigfault._addr = env->eip;
194 queue_signal(info.si_signo, &info);
199 if (env->eflags & VM_MASK) {
200 handle_vm86_trap(env, trapnr);
202 info.si_signo = SIGTRAP;
204 if (trapnr == EXCP01_SSTP) {
205 info.si_code = TARGET_TRAP_BRKPT;
206 info._sifields._sigfault._addr = env->eip;
208 info.si_code = TARGET_SI_KERNEL;
209 info._sifields._sigfault._addr = 0;
211 queue_signal(info.si_signo, &info);
216 if (env->eflags & VM_MASK) {
217 handle_vm86_trap(env, trapnr);
219 info.si_signo = SIGSEGV;
221 info.si_code = TARGET_SI_KERNEL;
222 info._sifields._sigfault._addr = 0;
223 queue_signal(info.si_signo, &info);
227 info.si_signo = SIGILL;
229 info.si_code = TARGET_ILL_ILLOPN;
230 info._sifields._sigfault._addr = env->eip;
231 queue_signal(info.si_signo, &info);
234 /* just indicate that signals should be handled asap */
237 pc = env->segs[R_CS].base + env->eip;
238 fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
242 process_pending_signals(env);
249 void cpu_loop(CPUARMState *env)
252 unsigned int n, insn;
253 target_siginfo_t info;
256 trapnr = cpu_arm_exec(env);
260 TaskState *ts = env->opaque;
263 /* we handle the FPU emulation here, as Linux */
264 /* we get the opcode */
265 opcode = ldl_raw((uint8_t *)env->regs[15]);
267 if (EmulateAll(opcode, &ts->fpa, env->regs) == 0) {
268 info.si_signo = SIGILL;
270 info.si_code = TARGET_ILL_ILLOPN;
271 info._sifields._sigfault._addr = env->regs[15];
272 queue_signal(info.si_signo, &info);
282 insn = ldl((void *)(env->regs[15] - 4));
284 if (n >= ARM_SYSCALL_BASE) {
286 n -= ARM_SYSCALL_BASE;
287 env->regs[0] = do_syscall(env,
301 /* just indicate that signals should be handled asap */
305 fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
307 cpu_arm_dump_state(env, stderr, 0);
310 process_pending_signals(env);
320 /* WARNING: dealing with register windows _is_ complicated */
321 static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
323 index = (index + cwp * 16) & (16 * NWINDOWS - 1);
324 /* wrap handling : if cwp is on the last window, then we use the
325 registers 'after' the end */
326 if (index < 8 && env->cwp == (NWINDOWS - 1))
327 index += (16 * NWINDOWS);
331 static inline void save_window_offset(CPUSPARCState *env, int offset)
333 unsigned int new_wim, i, cwp1;
336 new_wim = ((env->wim >> 1) | (env->wim << (NWINDOWS - 1))) &
337 ((1LL << NWINDOWS) - 1);
338 /* save the window */
339 cwp1 = (env->cwp + offset) & (NWINDOWS - 1);
340 sp_ptr = (uint32_t *)(env->regbase[get_reg_index(env, cwp1, 6)]);
341 #if defined(DEBUG_WIN)
342 printf("win_overflow: sp_ptr=0x%x save_cwp=%d\n",
345 for(i = 0; i < 16; i++)
346 stl_raw(sp_ptr + i, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
350 static void save_window(CPUSPARCState *env)
352 save_window_offset(env, 2);
355 static void restore_window(CPUSPARCState *env)
357 unsigned int new_wim, i, cwp1;
360 new_wim = ((env->wim << 1) | (env->wim >> (NWINDOWS - 1))) &
361 ((1LL << NWINDOWS) - 1);
363 /* restore the invalid window */
364 cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
365 sp_ptr = (uint32_t *)(env->regbase[get_reg_index(env, cwp1, 6)]);
366 #if defined(DEBUG_WIN)
367 printf("win_underflow: sp_ptr=0x%x load_cwp=%d\n",
370 for(i = 0; i < 16; i++)
371 env->regbase[get_reg_index(env, cwp1, 8 + i)] = ldl_raw(sp_ptr + i);
375 static void flush_windows(CPUSPARCState *env)
378 #if defined(DEBUG_WIN)
379 printf("flush_windows:\n");
383 /* if restore would invoke restore_window(), then we can stop */
384 cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
385 if (env->wim & (1 << cwp1))
387 #if defined(DEBUG_WIN)
388 printf("offset=%d: ", offset);
390 save_window_offset(env, offset);
395 void cpu_loop (CPUSPARCState *env)
400 trapnr = cpu_sparc_exec (env);
405 ret = do_syscall (env, env->gregs[1],
406 env->regwptr[0], env->regwptr[1],
407 env->regwptr[2], env->regwptr[3],
408 env->regwptr[4], env->regwptr[5]);
409 if ((unsigned int)ret >= (unsigned int)(-515)) {
410 env->psr |= PSR_CARRY;
413 env->psr &= ~PSR_CARRY;
415 env->regwptr[0] = ret;
416 /* next instruction */
418 env->npc = env->npc + 4;
420 case 0x83: /* flush windows */
421 // flush_windows(env);
422 /* next instruction */
424 env->npc = env->npc + 4;
426 case TT_WIN_OVF: /* window overflow */
429 case TT_WIN_UNF: /* window underflow */
433 printf ("Unhandled trap: 0x%x\n", trapnr);
434 cpu_sparc_dump_state(env, stderr, 0);
437 process_pending_signals (env);
445 void cpu_loop(CPUPPCState *env)
447 target_siginfo_t info;
452 trapnr = cpu_ppc_exec(env);
453 if (trapnr != EXCP_SYSCALL_USER && trapnr != EXCP_BRANCH &&
454 trapnr != EXCP_TRACE) {
456 cpu_ppc_dump_state(env, logfile, 0);
462 case EXCP_SYSCALL_USER:
465 * PPC ABI uses overflow flag in cr0 to signal an error
469 printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env->gpr[0],
470 env->gpr[3], env->gpr[4], env->gpr[5], env->gpr[6]);
473 ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4],
474 env->gpr[5], env->gpr[6], env->gpr[7],
476 if (ret > (uint32_t)(-515)) {
482 printf("syscall returned 0x%08x (%d)\n", ret, ret);
486 /* Should not happen ! */
487 fprintf(stderr, "RESET asked... Stop emulation\n");
489 fprintf(logfile, "RESET asked... Stop emulation\n");
491 case EXCP_MACHINE_CHECK:
492 fprintf(stderr, "Machine check exeption... Stop emulation\n");
494 fprintf(logfile, "RESET asked... Stop emulation\n");
495 info.si_signo = TARGET_SIGBUS;
497 info.si_code = TARGET_BUS_OBJERR;
498 info._sifields._sigfault._addr = env->nip - 4;
499 queue_signal(info.si_signo, &info);
501 fprintf(stderr, "Invalid data memory access: 0x%08x\n", env->spr[DAR]);
503 fprintf(logfile, "Invalid data memory access: 0x%08x\n",
506 switch (env->error_code & 0xF) {
507 case EXCP_DSI_TRANSLATE:
508 info.si_signo = TARGET_SIGSEGV;
510 info.si_code = TARGET_SEGV_MAPERR;
512 case EXCP_DSI_NOTSUP:
513 case EXCP_DSI_EXTERNAL:
514 info.si_signo = TARGET_SIGILL;
516 info.si_code = TARGET_ILL_ILLADR;
519 info.si_signo = TARGET_SIGSEGV;
521 info.si_code = TARGET_SEGV_ACCERR;
524 info.si_signo = TARGET_SIGTRAP;
526 info.si_code = TARGET_TRAP_BRKPT;
529 /* Let's send a regular segfault... */
530 fprintf(stderr, "Invalid segfault errno (%02x)\n",
533 fprintf(logfile, "Invalid segfault errno (%02x)\n",
536 info.si_signo = TARGET_SIGSEGV;
538 info.si_code = TARGET_SEGV_MAPERR;
541 info._sifields._sigfault._addr = env->nip;
542 queue_signal(info.si_signo, &info);
545 fprintf(stderr, "Invalid instruction fetch\n");
547 fprintf(logfile, "Invalid instruction fetch\n");
548 switch (env->error_code) {
549 case EXCP_ISI_TRANSLATE:
550 info.si_signo = TARGET_SIGSEGV;
552 info.si_code = TARGET_SEGV_MAPERR;
555 info.si_signo = TARGET_SIGILL;
557 info.si_code = TARGET_ILL_ILLADR;
559 case EXCP_ISI_NOEXEC:
561 info.si_signo = TARGET_SIGSEGV;
563 info.si_code = TARGET_SEGV_ACCERR;
566 /* Let's send a regular segfault... */
567 fprintf(stderr, "Invalid segfault errno (%02x)\n",
570 fprintf(logfile, "Invalid segfault errno (%02x)\n",
573 info.si_signo = TARGET_SIGSEGV;
575 info.si_code = TARGET_SEGV_MAPERR;
578 info._sifields._sigfault._addr = env->nip - 4;
579 queue_signal(info.si_signo, &info);
582 /* Should not happen ! */
583 fprintf(stderr, "External interruption... Stop emulation\n");
585 fprintf(logfile, "External interruption... Stop emulation\n");
588 fprintf(stderr, "Invalid unaligned memory access\n");
590 fprintf(logfile, "Invalid unaligned memory access\n");
591 info.si_signo = TARGET_SIGBUS;
593 info.si_code = TARGET_BUS_ADRALN;
594 info._sifields._sigfault._addr = env->nip - 4;
595 queue_signal(info.si_signo, &info);
598 switch (env->error_code & ~0xF) {
600 fprintf(stderr, "Program exception\n");
602 fprintf(logfile, "Program exception\n");
604 env->fpscr[7] |= 0x8;
605 /* Finally, update FEX */
606 if ((((env->fpscr[7] & 0x3) << 3) | (env->fpscr[6] >> 1)) &
607 ((env->fpscr[1] << 1) | (env->fpscr[0] >> 3)))
608 env->fpscr[7] |= 0x4;
609 info.si_signo = TARGET_SIGFPE;
611 switch (env->error_code & 0xF) {
613 info.si_code = TARGET_FPE_FLTOVF;
616 info.si_code = TARGET_FPE_FLTUND;
620 info.si_code = TARGET_FPE_FLTDIV;
623 info.si_code = TARGET_FPE_FLTRES;
626 info.si_code = TARGET_FPE_FLTINV;
635 info.si_code = TARGET_FPE_FLTSUB;
638 fprintf(stderr, "Unknown floating point exception "
639 "(%02x)\n", env->error_code);
641 fprintf(logfile, "Unknown floating point exception "
642 "(%02x)\n", env->error_code & 0xF);
647 fprintf(stderr, "Invalid instruction\n");
649 fprintf(logfile, "Invalid instruction\n");
650 info.si_signo = TARGET_SIGILL;
652 switch (env->error_code & 0xF) {
653 case EXCP_INVAL_INVAL:
654 info.si_code = TARGET_ILL_ILLOPC;
656 case EXCP_INVAL_LSWX:
657 info.si_code = TARGET_ILL_ILLOPN;
660 info.si_code = TARGET_ILL_PRVREG;
663 info.si_code = TARGET_ILL_COPROC;
666 fprintf(stderr, "Unknown invalid operation (%02x)\n",
667 env->error_code & 0xF);
669 fprintf(logfile, "Unknown invalid operation (%02x)\n",
670 env->error_code & 0xF);
672 info.si_code = TARGET_ILL_ILLADR;
677 fprintf(stderr, "Privilege violation\n");
679 fprintf(logfile, "Privilege violation\n");
680 info.si_signo = TARGET_SIGILL;
682 switch (env->error_code & 0xF) {
684 info.si_code = TARGET_ILL_PRVOPC;
687 info.si_code = TARGET_ILL_PRVREG;
690 fprintf(stderr, "Unknown privilege violation (%02x)\n",
691 env->error_code & 0xF);
692 info.si_code = TARGET_ILL_PRVOPC;
697 fprintf(stderr, "Tried to call a TRAP\n");
699 fprintf(logfile, "Tried to call a TRAP\n");
702 /* Should not happen ! */
703 fprintf(stderr, "Unknown program exception (%02x)\n",
706 fprintf(logfile, "Unknwon program exception (%02x)\n",
711 info._sifields._sigfault._addr = env->nip - 4;
712 queue_signal(info.si_signo, &info);
715 fprintf(stderr, "No floating point allowed\n");
717 fprintf(logfile, "No floating point allowed\n");
718 info.si_signo = TARGET_SIGILL;
720 info.si_code = TARGET_ILL_COPROC;
721 info._sifields._sigfault._addr = env->nip - 4;
722 queue_signal(info.si_signo, &info);
725 /* Should not happen ! */
726 fprintf(stderr, "Decrementer exception\n");
728 fprintf(logfile, "Decrementer exception\n");
730 case EXCP_RESA: /* Implementation specific */
731 /* Should not happen ! */
732 fprintf(stderr, "RESA exception should never happen !\n");
734 fprintf(logfile, "RESA exception should never happen !\n");
736 case EXCP_RESB: /* Implementation specific */
737 /* Should not happen ! */
738 fprintf(stderr, "RESB exception should never happen !\n");
740 fprintf(logfile, "RESB exception should never happen !\n");
743 /* Do nothing: we use this to trace execution */
746 /* Should not happen ! */
747 fprintf(stderr, "Floating point assist exception\n");
749 fprintf(logfile, "Floating point assist exception\n");
752 /* We reloaded the msr, just go on */
754 fprintf(stderr, "Tried to go into supervisor mode !\n");
756 fprintf(logfile, "Tried to go into supervisor mode !\n");
761 /* We stopped because of a jump... */
764 /* Should not occur: we always are in user mode */
765 fprintf(stderr, "Return from interrupt ?\n");
767 fprintf(logfile, "Return from interrupt ?\n");
770 /* Don't know why this should ever happen... */
773 fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
776 fprintf(logfile, "qemu: unhandled CPU exception 0x%02x - "
777 "0x%02x - aborting\n", trapnr, env->error_code);
781 if (trapnr < EXCP_PPC_MAX)
782 env->exceptions &= ~(1 << trapnr);
783 process_pending_signals(env);
784 if (env->exceptions != 0) {
785 check_exception_state(env);
793 printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003 Fabrice Bellard\n"
794 "usage: qemu-" TARGET_ARCH " [-h] [-d] [-L path] [-s size] program [arguments...]\n"
795 "Linux CPU emulator (compiled for %s emulation)\n"
797 "-h print this help\n"
798 "-L path set the elf interpreter prefix (default=%s)\n"
799 "-s size set the stack size in bytes (default=%ld)\n"
803 "-no-code-copy disable code copy acceleration\n"
805 "-d activate log (logfile=%s)\n"
806 "-p pagesize set the host page size to 'pagesize'\n",
814 /* XXX: currently only used for async signals (see signal.c) */
815 CPUState *global_env;
816 /* used only if single thread */
817 CPUState *cpu_single_env = NULL;
819 /* used to free thread contexts */
820 TaskState *first_task_state;
822 int main(int argc, char **argv)
824 const char *filename;
825 struct target_pt_regs regs1, *regs = ®s1;
826 struct image_info info1, *info = &info1;
827 TaskState ts1, *ts = &ts1;
836 cpu_set_log_filename(DEBUG_LOGFILE);
847 if (!strcmp(r, "-")) {
849 } else if (!strcmp(r, "d")) {
853 mask = cpu_str_to_log_mask(optarg);
855 printf("Log items (comma separated):\n");
856 for(item = cpu_log_items; item->mask != 0; item++) {
857 printf("%-10s %s\n", item->name, item->help);
862 } else if (!strcmp(r, "s")) {
864 x86_stack_size = strtol(r, (char **)&r, 0);
865 if (x86_stack_size <= 0)
868 x86_stack_size *= 1024 * 1024;
869 else if (*r == 'k' || *r == 'K')
870 x86_stack_size *= 1024;
871 } else if (!strcmp(r, "L")) {
872 interp_prefix = argv[optind++];
873 } else if (!strcmp(r, "p")) {
874 host_page_size = atoi(argv[optind++]);
875 if (host_page_size == 0 ||
876 (host_page_size & (host_page_size - 1)) != 0) {
877 fprintf(stderr, "page size must be a power of two\n");
882 if (!strcmp(r, "no-code-copy")) {
883 code_copy_enabled = 0;
892 filename = argv[optind];
895 memset(regs, 0, sizeof(struct target_pt_regs));
897 /* Zero out image_info */
898 memset(info, 0, sizeof(struct image_info));
900 /* Scan interp_prefix dir for replacement files. */
901 init_paths(interp_prefix);
903 /* NOTE: we need to init the CPU at this stage to get the
907 if (elf_exec(filename, argv+optind, environ, regs, info) != 0) {
908 printf("Error loading %s\n", filename);
915 fprintf(logfile, "start_brk 0x%08lx\n" , info->start_brk);
916 fprintf(logfile, "end_code 0x%08lx\n" , info->end_code);
917 fprintf(logfile, "start_code 0x%08lx\n" , info->start_code);
918 fprintf(logfile, "end_data 0x%08lx\n" , info->end_data);
919 fprintf(logfile, "start_stack 0x%08lx\n" , info->start_stack);
920 fprintf(logfile, "brk 0x%08lx\n" , info->brk);
921 fprintf(logfile, "entry 0x%08lx\n" , info->entry);
924 target_set_brk((char *)info->brk);
930 /* build Task State */
931 memset(ts, 0, sizeof(TaskState));
934 env->user_mode_only = 1;
936 #if defined(TARGET_I386)
937 cpu_x86_set_cpl(env, 3);
939 env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
940 env->hflags |= HF_PE_MASK;
942 /* flags setup : we activate the IRQs by default as in user mode */
943 env->eflags |= IF_MASK;
945 /* linux register setup */
946 env->regs[R_EAX] = regs->eax;
947 env->regs[R_EBX] = regs->ebx;
948 env->regs[R_ECX] = regs->ecx;
949 env->regs[R_EDX] = regs->edx;
950 env->regs[R_ESI] = regs->esi;
951 env->regs[R_EDI] = regs->edi;
952 env->regs[R_EBP] = regs->ebp;
953 env->regs[R_ESP] = regs->esp;
954 env->eip = regs->eip;
956 /* linux interrupt setup */
957 env->idt.base = (void *)idt_table;
958 env->idt.limit = sizeof(idt_table) - 1;
981 /* linux segment setup */
982 env->gdt.base = (void *)gdt_table;
983 env->gdt.limit = sizeof(gdt_table) - 1;
984 write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
985 DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
986 (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT));
987 write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff,
988 DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
989 (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT));
990 cpu_x86_load_seg(env, R_CS, __USER_CS);
991 cpu_x86_load_seg(env, R_DS, __USER_DS);
992 cpu_x86_load_seg(env, R_ES, __USER_DS);
993 cpu_x86_load_seg(env, R_SS, __USER_DS);
994 cpu_x86_load_seg(env, R_FS, __USER_DS);
995 cpu_x86_load_seg(env, R_GS, __USER_DS);
997 #elif defined(TARGET_ARM)
1000 for(i = 0; i < 16; i++) {
1001 env->regs[i] = regs->uregs[i];
1003 env->cpsr = regs->uregs[16];
1005 #elif defined(TARGET_SPARC)
1009 env->npc = regs->npc;
1011 for(i = 0; i < 8; i++)
1012 env->gregs[i] = regs->u_regs[i];
1013 for(i = 0; i < 8; i++)
1014 env->regwptr[i] = regs->u_regs[i + 8];
1016 #elif defined(TARGET_PPC)
1019 for (i = 0; i < 32; i++) {
1020 if (i != 12 && i != 6)
1021 env->msr[i] = (regs->msr >> i) & 1;
1023 env->nip = regs->nip;
1024 for(i = 0; i < 32; i++) {
1025 env->gpr[i] = regs->gpr[i];
1029 #error unsupported target CPU