]>
git.proxmox.com Git - mirror_qemu.git/blob - linux-user/main.c
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 __init_array_start
[0];
43 long __init_array_end
[0];
44 long __fini_array_start
[0];
45 long __fini_array_end
[0];
48 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
49 we allocate a bigger stack. Need a better solution, for example
50 by remapping the process stack directly at the right place */
51 unsigned long x86_stack_size
= 512 * 1024;
53 void gemu_log(const char *fmt
, ...)
58 vfprintf(stderr
, fmt
, ap
);
62 void cpu_outb(CPUState
*env
, int addr
, int val
)
64 fprintf(stderr
, "outb: port=0x%04x, data=%02x\n", addr
, val
);
67 void cpu_outw(CPUState
*env
, int addr
, int val
)
69 fprintf(stderr
, "outw: port=0x%04x, data=%04x\n", addr
, val
);
72 void cpu_outl(CPUState
*env
, int addr
, int val
)
74 fprintf(stderr
, "outl: port=0x%04x, data=%08x\n", addr
, val
);
77 int cpu_inb(CPUState
*env
, int addr
)
79 fprintf(stderr
, "inb: port=0x%04x\n", addr
);
83 int cpu_inw(CPUState
*env
, int addr
)
85 fprintf(stderr
, "inw: port=0x%04x\n", addr
);
89 int cpu_inl(CPUState
*env
, int addr
)
91 fprintf(stderr
, "inl: port=0x%04x\n", addr
);
96 /***********************************************************/
97 /* CPUX86 core interface */
99 int cpu_x86_get_pic_interrupt(CPUState
*env
)
104 static void write_dt(void *ptr
, unsigned long addr
, unsigned long limit
,
108 e1
= (addr
<< 16) | (limit
& 0xffff);
109 e2
= ((addr
>> 16) & 0xff) | (addr
& 0xff000000) | (limit
& 0x000f0000);
111 stl((uint8_t *)ptr
, e1
);
112 stl((uint8_t *)ptr
+ 4, e2
);
115 static void set_gate(void *ptr
, unsigned int type
, unsigned int dpl
,
116 unsigned long addr
, unsigned int sel
)
119 e1
= (addr
& 0xffff) | (sel
<< 16);
120 e2
= (addr
& 0xffff0000) | 0x8000 | (dpl
<< 13) | (type
<< 8);
121 stl((uint8_t *)ptr
, e1
);
122 stl((uint8_t *)ptr
+ 4, e2
);
125 uint64_t gdt_table
[6];
126 uint64_t idt_table
[256];
128 /* only dpl matters as we do only user space emulation */
129 static void set_idt(int n
, unsigned int dpl
)
131 set_gate(idt_table
+ n
, 0, dpl
, 0, 0);
134 void cpu_loop(CPUX86State
*env
)
138 target_siginfo_t info
;
141 trapnr
= cpu_x86_exec(env
);
145 env
->regs
[R_EAX
] = do_syscall(env
,
156 info
.si_signo
= SIGBUS
;
158 info
.si_code
= TARGET_SI_KERNEL
;
159 info
._sifields
._sigfault
._addr
= 0;
160 queue_signal(info
.si_signo
, &info
);
163 if (env
->eflags
& VM_MASK
) {
164 handle_vm86_fault(env
);
166 info
.si_signo
= SIGSEGV
;
168 info
.si_code
= TARGET_SI_KERNEL
;
169 info
._sifields
._sigfault
._addr
= 0;
170 queue_signal(info
.si_signo
, &info
);
174 info
.si_signo
= SIGSEGV
;
176 if (!(env
->error_code
& 1))
177 info
.si_code
= TARGET_SEGV_MAPERR
;
179 info
.si_code
= TARGET_SEGV_ACCERR
;
180 info
._sifields
._sigfault
._addr
= env
->cr
[2];
181 queue_signal(info
.si_signo
, &info
);
184 if (env
->eflags
& VM_MASK
) {
185 handle_vm86_trap(env
, trapnr
);
187 /* division by zero */
188 info
.si_signo
= SIGFPE
;
190 info
.si_code
= TARGET_FPE_INTDIV
;
191 info
._sifields
._sigfault
._addr
= env
->eip
;
192 queue_signal(info
.si_signo
, &info
);
197 if (env
->eflags
& VM_MASK
) {
198 handle_vm86_trap(env
, trapnr
);
200 info
.si_signo
= SIGTRAP
;
202 if (trapnr
== EXCP01_SSTP
) {
203 info
.si_code
= TARGET_TRAP_BRKPT
;
204 info
._sifields
._sigfault
._addr
= env
->eip
;
206 info
.si_code
= TARGET_SI_KERNEL
;
207 info
._sifields
._sigfault
._addr
= 0;
209 queue_signal(info
.si_signo
, &info
);
214 if (env
->eflags
& VM_MASK
) {
215 handle_vm86_trap(env
, trapnr
);
217 info
.si_signo
= SIGSEGV
;
219 info
.si_code
= TARGET_SI_KERNEL
;
220 info
._sifields
._sigfault
._addr
= 0;
221 queue_signal(info
.si_signo
, &info
);
225 info
.si_signo
= SIGILL
;
227 info
.si_code
= TARGET_ILL_ILLOPN
;
228 info
._sifields
._sigfault
._addr
= env
->eip
;
229 queue_signal(info
.si_signo
, &info
);
232 /* just indicate that signals should be handled asap */
235 pc
= env
->segs
[R_CS
].base
+ env
->eip
;
236 fprintf(stderr
, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
240 process_pending_signals(env
);
247 void cpu_loop(CPUARMState
*env
)
250 unsigned int n
, insn
;
251 target_siginfo_t info
;
254 trapnr
= cpu_arm_exec(env
);
257 info
.si_signo
= SIGILL
;
259 info
.si_code
= TARGET_ILL_ILLOPN
;
260 info
._sifields
._sigfault
._addr
= env
->regs
[15];
261 queue_signal(info
.si_signo
, &info
);
266 insn
= ldl((void *)(env
->regs
[15] - 4));
268 if (n
>= ARM_SYSCALL_BASE
) {
270 n
-= ARM_SYSCALL_BASE
;
271 env
->regs
[0] = do_syscall(env
,
285 /* just indicate that signals should be handled asap */
289 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
291 cpu_arm_dump_state(env
, stderr
, 0);
294 process_pending_signals(env
);
304 /* WARNING: dealing with register windows _is_ complicated */
305 static inline int get_reg_index(CPUSPARCState
*env
, int cwp
, int index
)
307 index
= (index
+ cwp
* 16) & (16 * NWINDOWS
- 1);
308 /* wrap handling : if cwp is on the last window, then we use the
309 registers 'after' the end */
310 if (index
< 8 && env
->cwp
== (NWINDOWS
- 1))
311 index
+= (16 * NWINDOWS
);
315 static inline void save_window_offset(CPUSPARCState
*env
, int offset
)
317 unsigned int new_wim
, i
, cwp1
;
320 new_wim
= ((env
->wim
>> 1) | (env
->wim
<< (NWINDOWS
- 1))) &
321 ((1LL << NWINDOWS
) - 1);
322 /* save the window */
323 cwp1
= (env
->cwp
+ offset
) & (NWINDOWS
- 1);
324 sp_ptr
= (uint32_t *)(env
->regbase
[get_reg_index(env
, cwp1
, 6)]);
325 #if defined(DEBUG_WIN)
326 printf("win_overflow: sp_ptr=0x%x save_cwp=%d\n",
329 for(i
= 0; i
< 16; i
++)
330 stl_raw(sp_ptr
+ i
, env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)]);
334 static void save_window(CPUSPARCState
*env
)
336 save_window_offset(env
, 2);
339 static void restore_window(CPUSPARCState
*env
)
341 unsigned int new_wim
, i
, cwp1
;
344 new_wim
= ((env
->wim
<< 1) | (env
->wim
>> (NWINDOWS
- 1))) &
345 ((1LL << NWINDOWS
) - 1);
347 /* restore the invalid window */
348 cwp1
= (env
->cwp
+ 1) & (NWINDOWS
- 1);
349 sp_ptr
= (uint32_t *)(env
->regbase
[get_reg_index(env
, cwp1
, 6)]);
350 #if defined(DEBUG_WIN)
351 printf("win_underflow: sp_ptr=0x%x load_cwp=%d\n",
354 for(i
= 0; i
< 16; i
++)
355 env
->regbase
[get_reg_index(env
, cwp1
, 8 + i
)] = ldl_raw(sp_ptr
+ i
);
359 static void flush_windows(CPUSPARCState
*env
)
362 #if defined(DEBUG_WIN)
363 printf("flush_windows:\n");
367 /* if restore would invoke restore_window(), then we can stop */
368 cwp1
= (env
->cwp
+ 1) & (NWINDOWS
- 1);
369 if (env
->wim
& (1 << cwp1
))
371 #if defined(DEBUG_WIN)
372 printf("offset=%d: ", offset
);
374 save_window_offset(env
, offset
);
379 void cpu_loop (CPUSPARCState
*env
)
384 trapnr
= cpu_sparc_exec (env
);
389 ret
= do_syscall (env
, env
->gregs
[1],
390 env
->regwptr
[0], env
->regwptr
[1],
391 env
->regwptr
[2], env
->regwptr
[3],
392 env
->regwptr
[4], env
->regwptr
[5]);
393 if ((unsigned int)ret
>= (unsigned int)(-515)) {
394 env
->psr
|= PSR_CARRY
;
397 env
->psr
&= ~PSR_CARRY
;
399 env
->regwptr
[0] = ret
;
400 /* next instruction */
402 env
->npc
= env
->npc
+ 4;
404 case 0x83: /* flush windows */
405 // flush_windows(env);
406 /* next instruction */
408 env
->npc
= env
->npc
+ 4;
410 case TT_WIN_OVF
: /* window overflow */
413 case TT_WIN_UNF
: /* window underflow */
417 printf ("Unhandled trap: 0x%x\n", trapnr
);
418 cpu_sparc_dump_state(env
, stderr
, 0);
421 process_pending_signals (env
);
429 void cpu_loop(CPUPPCState
*env
)
431 target_siginfo_t info
;
436 trapnr
= cpu_ppc_exec(env
);
437 if (trapnr
!= EXCP_SYSCALL_USER
&& trapnr
!= EXCP_BRANCH
&&
438 trapnr
!= EXCP_TRACE
) {
440 cpu_ppc_dump_state(env
, logfile
, 0);
446 case EXCP_SYSCALL_USER
:
449 * PPC ABI uses overflow flag in cr0 to signal an error
453 printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env
->gpr
[0],
454 env
->gpr
[3], env
->gpr
[4], env
->gpr
[5], env
->gpr
[6]);
457 ret
= do_syscall(env
, env
->gpr
[0], env
->gpr
[3], env
->gpr
[4],
458 env
->gpr
[5], env
->gpr
[6], env
->gpr
[7],
460 if (ret
> (uint32_t)(-515)) {
466 printf("syscall returned 0x%08x (%d)\n", ret
, ret
);
470 /* Should not happen ! */
471 fprintf(stderr
, "RESET asked... Stop emulation\n");
473 fprintf(logfile
, "RESET asked... Stop emulation\n");
475 case EXCP_MACHINE_CHECK
:
476 fprintf(stderr
, "Machine check exeption... Stop emulation\n");
478 fprintf(logfile
, "RESET asked... Stop emulation\n");
479 info
.si_signo
= TARGET_SIGBUS
;
481 info
.si_code
= TARGET_BUS_OBJERR
;
482 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
483 queue_signal(info
.si_signo
, &info
);
485 fprintf(stderr
, "Invalid data memory access: 0x%08x\n", env
->spr
[DAR
]);
487 fprintf(logfile
, "Invalid data memory access: 0x%08x\n",
490 switch (env
->error_code
& 0xF) {
491 case EXCP_DSI_TRANSLATE
:
492 info
.si_signo
= TARGET_SIGSEGV
;
494 info
.si_code
= TARGET_SEGV_MAPERR
;
496 case EXCP_DSI_NOTSUP
:
497 case EXCP_DSI_EXTERNAL
:
498 info
.si_signo
= TARGET_SIGILL
;
500 info
.si_code
= TARGET_ILL_ILLADR
;
503 info
.si_signo
= TARGET_SIGSEGV
;
505 info
.si_code
= TARGET_SEGV_ACCERR
;
508 info
.si_signo
= TARGET_SIGTRAP
;
510 info
.si_code
= TARGET_TRAP_BRKPT
;
513 /* Let's send a regular segfault... */
514 fprintf(stderr
, "Invalid segfault errno (%02x)\n",
517 fprintf(logfile
, "Invalid segfault errno (%02x)\n",
520 info
.si_signo
= TARGET_SIGSEGV
;
522 info
.si_code
= TARGET_SEGV_MAPERR
;
525 info
._sifields
._sigfault
._addr
= env
->nip
;
526 queue_signal(info
.si_signo
, &info
);
529 fprintf(stderr
, "Invalid instruction fetch\n");
531 fprintf(logfile
, "Invalid instruction fetch\n");
532 switch (env
->error_code
) {
533 case EXCP_ISI_TRANSLATE
:
534 info
.si_signo
= TARGET_SIGSEGV
;
536 info
.si_code
= TARGET_SEGV_MAPERR
;
539 info
.si_signo
= TARGET_SIGILL
;
541 info
.si_code
= TARGET_ILL_ILLADR
;
543 case EXCP_ISI_NOEXEC
:
545 info
.si_signo
= TARGET_SIGSEGV
;
547 info
.si_code
= TARGET_SEGV_ACCERR
;
550 /* Let's send a regular segfault... */
551 fprintf(stderr
, "Invalid segfault errno (%02x)\n",
554 fprintf(logfile
, "Invalid segfault errno (%02x)\n",
557 info
.si_signo
= TARGET_SIGSEGV
;
559 info
.si_code
= TARGET_SEGV_MAPERR
;
562 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
563 queue_signal(info
.si_signo
, &info
);
566 /* Should not happen ! */
567 fprintf(stderr
, "External interruption... Stop emulation\n");
569 fprintf(logfile
, "External interruption... Stop emulation\n");
572 fprintf(stderr
, "Invalid unaligned memory access\n");
574 fprintf(logfile
, "Invalid unaligned memory access\n");
575 info
.si_signo
= TARGET_SIGBUS
;
577 info
.si_code
= TARGET_BUS_ADRALN
;
578 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
579 queue_signal(info
.si_signo
, &info
);
582 switch (env
->error_code
& ~0xF) {
584 fprintf(stderr
, "Program exception\n");
586 fprintf(logfile
, "Program exception\n");
588 env
->fpscr
[7] |= 0x8;
589 /* Finally, update FEX */
590 if ((((env
->fpscr
[7] & 0x3) << 3) | (env
->fpscr
[6] >> 1)) &
591 ((env
->fpscr
[1] << 1) | (env
->fpscr
[0] >> 3)))
592 env
->fpscr
[7] |= 0x4;
593 info
.si_signo
= TARGET_SIGFPE
;
595 switch (env
->error_code
& 0xF) {
597 info
.si_code
= TARGET_FPE_FLTOVF
;
600 info
.si_code
= TARGET_FPE_FLTUND
;
604 info
.si_code
= TARGET_FPE_FLTDIV
;
607 info
.si_code
= TARGET_FPE_FLTRES
;
610 info
.si_code
= TARGET_FPE_FLTINV
;
619 info
.si_code
= TARGET_FPE_FLTSUB
;
622 fprintf(stderr
, "Unknown floating point exception "
623 "(%02x)\n", env
->error_code
);
625 fprintf(logfile
, "Unknown floating point exception "
626 "(%02x)\n", env
->error_code
& 0xF);
631 fprintf(stderr
, "Invalid instruction\n");
633 fprintf(logfile
, "Invalid instruction\n");
634 info
.si_signo
= TARGET_SIGILL
;
636 switch (env
->error_code
& 0xF) {
637 case EXCP_INVAL_INVAL
:
638 info
.si_code
= TARGET_ILL_ILLOPC
;
640 case EXCP_INVAL_LSWX
:
641 info
.si_code
= TARGET_ILL_ILLOPN
;
644 info
.si_code
= TARGET_ILL_PRVREG
;
647 info
.si_code
= TARGET_ILL_COPROC
;
650 fprintf(stderr
, "Unknown invalid operation (%02x)\n",
651 env
->error_code
& 0xF);
653 fprintf(logfile
, "Unknown invalid operation (%02x)\n",
654 env
->error_code
& 0xF);
656 info
.si_code
= TARGET_ILL_ILLADR
;
661 fprintf(stderr
, "Privilege violation\n");
663 fprintf(logfile
, "Privilege violation\n");
664 info
.si_signo
= TARGET_SIGILL
;
666 switch (env
->error_code
& 0xF) {
668 info
.si_code
= TARGET_ILL_PRVOPC
;
671 info
.si_code
= TARGET_ILL_PRVREG
;
674 fprintf(stderr
, "Unknown privilege violation (%02x)\n",
675 env
->error_code
& 0xF);
676 info
.si_code
= TARGET_ILL_PRVOPC
;
681 fprintf(stderr
, "Tried to call a TRAP\n");
683 fprintf(logfile
, "Tried to call a TRAP\n");
686 /* Should not happen ! */
687 fprintf(stderr
, "Unknown program exception (%02x)\n",
690 fprintf(logfile
, "Unknwon program exception (%02x)\n",
695 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
696 queue_signal(info
.si_signo
, &info
);
699 fprintf(stderr
, "No floating point allowed\n");
701 fprintf(logfile
, "No floating point allowed\n");
702 info
.si_signo
= TARGET_SIGILL
;
704 info
.si_code
= TARGET_ILL_COPROC
;
705 info
._sifields
._sigfault
._addr
= env
->nip
- 4;
706 queue_signal(info
.si_signo
, &info
);
709 /* Should not happen ! */
710 fprintf(stderr
, "Decrementer exception\n");
712 fprintf(logfile
, "Decrementer exception\n");
714 case EXCP_RESA
: /* Implementation specific */
715 /* Should not happen ! */
716 fprintf(stderr
, "RESA exception should never happen !\n");
718 fprintf(logfile
, "RESA exception should never happen !\n");
720 case EXCP_RESB
: /* Implementation specific */
721 /* Should not happen ! */
722 fprintf(stderr
, "RESB exception should never happen !\n");
724 fprintf(logfile
, "RESB exception should never happen !\n");
727 /* Do nothing: we use this to trace execution */
730 /* Should not happen ! */
731 fprintf(stderr
, "Floating point assist exception\n");
733 fprintf(logfile
, "Floating point assist exception\n");
736 /* We reloaded the msr, just go on */
738 fprintf(stderr
, "Tried to go into supervisor mode !\n");
740 fprintf(logfile
, "Tried to go into supervisor mode !\n");
745 /* We stopped because of a jump... */
748 /* Should not occur: we always are in user mode */
749 fprintf(stderr
, "Return from interrupt ?\n");
751 fprintf(logfile
, "Return from interrupt ?\n");
754 /* Don't know why this should ever happen... */
757 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
760 fprintf(logfile
, "qemu: unhandled CPU exception 0x%02x - "
761 "0x%02x - aborting\n", trapnr
, env
->error_code
);
765 if (trapnr
< EXCP_PPC_MAX
)
766 env
->exceptions
&= ~(1 << trapnr
);
767 process_pending_signals(env
);
768 if (env
->exceptions
!= 0) {
769 check_exception_state(env
);
777 printf("qemu-" TARGET_ARCH
" version " QEMU_VERSION
", Copyright (c) 2003 Fabrice Bellard\n"
778 "usage: qemu-" TARGET_ARCH
" [-h] [-d] [-L path] [-s size] program [arguments...]\n"
779 "Linux CPU emulator (compiled for %s emulation)\n"
781 "-h print this help\n"
782 "-L path set the elf interpreter prefix (default=%s)\n"
783 "-s size set the stack size in bytes (default=%ld)\n"
786 "-d activate log (logfile=%s)\n"
787 "-p pagesize set the host page size to 'pagesize'\n",
795 /* XXX: currently only used for async signals (see signal.c) */
796 CPUState
*global_env
;
797 /* used only if single thread */
798 CPUState
*cpu_single_env
= NULL
;
800 /* used to free thread contexts */
801 TaskState
*first_task_state
;
803 int main(int argc
, char **argv
)
805 const char *filename
;
806 struct target_pt_regs regs1
, *regs
= ®s1
;
807 struct image_info info1
, *info
= &info1
;
808 TaskState ts1
, *ts
= &ts1
;
817 cpu_set_log_filename(DEBUG_LOGFILE
);
828 if (!strcmp(r
, "-")) {
830 } else if (!strcmp(r
, "d")) {
831 cpu_set_log(CPU_LOG_ALL
);
832 } else if (!strcmp(r
, "s")) {
834 x86_stack_size
= strtol(r
, (char **)&r
, 0);
835 if (x86_stack_size
<= 0)
838 x86_stack_size
*= 1024 * 1024;
839 else if (*r
== 'k' || *r
== 'K')
840 x86_stack_size
*= 1024;
841 } else if (!strcmp(r
, "L")) {
842 interp_prefix
= argv
[optind
++];
843 } else if (!strcmp(r
, "p")) {
844 host_page_size
= atoi(argv
[optind
++]);
845 if (host_page_size
== 0 ||
846 (host_page_size
& (host_page_size
- 1)) != 0) {
847 fprintf(stderr
, "page size must be a power of two\n");
856 filename
= argv
[optind
];
859 memset(regs
, 0, sizeof(struct target_pt_regs
));
861 /* Zero out image_info */
862 memset(info
, 0, sizeof(struct image_info
));
864 /* Scan interp_prefix dir for replacement files. */
865 init_paths(interp_prefix
);
867 /* NOTE: we need to init the CPU at this stage to get the
871 if (elf_exec(filename
, argv
+optind
, environ
, regs
, info
) != 0) {
872 printf("Error loading %s\n", filename
);
879 fprintf(logfile
, "start_brk 0x%08lx\n" , info
->start_brk
);
880 fprintf(logfile
, "end_code 0x%08lx\n" , info
->end_code
);
881 fprintf(logfile
, "start_code 0x%08lx\n" , info
->start_code
);
882 fprintf(logfile
, "end_data 0x%08lx\n" , info
->end_data
);
883 fprintf(logfile
, "start_stack 0x%08lx\n" , info
->start_stack
);
884 fprintf(logfile
, "brk 0x%08lx\n" , info
->brk
);
885 fprintf(logfile
, "entry 0x%08lx\n" , info
->entry
);
888 target_set_brk((char *)info
->brk
);
894 /* build Task State */
895 memset(ts
, 0, sizeof(TaskState
));
898 env
->user_mode_only
= 1;
900 #if defined(TARGET_I386)
901 cpu_x86_set_cpl(env
, 3);
903 env
->cr
[0] = CR0_PG_MASK
| CR0_WP_MASK
| CR0_PE_MASK
;
904 env
->hflags
|= HF_PE_MASK
;
906 /* flags setup : we activate the IRQs by default as in user mode */
907 env
->eflags
|= IF_MASK
;
909 /* linux register setup */
910 env
->regs
[R_EAX
] = regs
->eax
;
911 env
->regs
[R_EBX
] = regs
->ebx
;
912 env
->regs
[R_ECX
] = regs
->ecx
;
913 env
->regs
[R_EDX
] = regs
->edx
;
914 env
->regs
[R_ESI
] = regs
->esi
;
915 env
->regs
[R_EDI
] = regs
->edi
;
916 env
->regs
[R_EBP
] = regs
->ebp
;
917 env
->regs
[R_ESP
] = regs
->esp
;
918 env
->eip
= regs
->eip
;
920 /* linux interrupt setup */
921 env
->idt
.base
= (void *)idt_table
;
922 env
->idt
.limit
= sizeof(idt_table
) - 1;
945 /* linux segment setup */
946 env
->gdt
.base
= (void *)gdt_table
;
947 env
->gdt
.limit
= sizeof(gdt_table
) - 1;
948 write_dt(&gdt_table
[__USER_CS
>> 3], 0, 0xfffff,
949 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
950 (3 << DESC_DPL_SHIFT
) | (0xa << DESC_TYPE_SHIFT
));
951 write_dt(&gdt_table
[__USER_DS
>> 3], 0, 0xfffff,
952 DESC_G_MASK
| DESC_B_MASK
| DESC_P_MASK
| DESC_S_MASK
|
953 (3 << DESC_DPL_SHIFT
) | (0x2 << DESC_TYPE_SHIFT
));
954 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
955 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
956 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
957 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
958 cpu_x86_load_seg(env
, R_FS
, __USER_DS
);
959 cpu_x86_load_seg(env
, R_GS
, __USER_DS
);
961 #elif defined(TARGET_ARM)
964 for(i
= 0; i
< 16; i
++) {
965 env
->regs
[i
] = regs
->uregs
[i
];
967 env
->cpsr
= regs
->uregs
[16];
969 #elif defined(TARGET_SPARC)
973 env
->npc
= regs
->npc
;
975 for(i
= 0; i
< 8; i
++)
976 env
->gregs
[i
] = regs
->u_regs
[i
];
977 for(i
= 0; i
< 8; i
++)
978 env
->regwptr
[i
] = regs
->u_regs
[i
+ 8];
980 #elif defined(TARGET_PPC)
983 for (i
= 0; i
< 32; i
++) {
984 if (i
!= 12 && i
!= 6)
985 env
->msr
[i
] = (regs
->msr
>> i
) & 1;
987 env
->nip
= regs
->nip
;
988 for(i
= 0; i
< 32; i
++) {
989 env
->gpr
[i
] = regs
->gpr
[i
];
993 #error unsupported target CPU