added utime syscall - fixed nanosleep exact behaviour
[qemu] / linux-user / main.c
index a8ae9c7..811b8bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  qemu main
+ *  qemu user main
  * 
  *  Copyright (c) 2003 Fabrice Bellard
  *
@@ -26,8 +26,6 @@
 
 #include "qemu.h"
 
-#include "cpu-i386.h"
-
 #define DEBUG_LOGFILE "/tmp/qemu.log"
 
 FILE *logfile = NULL;
@@ -40,7 +38,7 @@ static const char *interp_prefix = CONFIG_QEMU_PREFIX;
 const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
 #endif
 
-/* for recent libc, we add these dummies symbol which are not declared
+/* for recent libc, we add these dummy symbols which are not declared
    when generating a linked object (bug in ld ?) */
 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
 long __init_array_start[0];
@@ -248,8 +246,6 @@ void cpu_loop(CPUX86State *env)
 
 #ifdef TARGET_ARM
 
-#define ARM_SYSCALL_BASE       0x900000
-
 void cpu_loop(CPUARMState *env)
 {
     int trapnr;
@@ -287,6 +283,9 @@ void cpu_loop(CPUARMState *env)
                 }
             }
             break;
+        case EXCP_INTERRUPT:
+            /* just indicate that signals should be handled asap */
+            break;
         default:
         error:
             fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n", 
@@ -300,10 +299,37 @@ void cpu_loop(CPUARMState *env)
 
 #endif
 
+#ifdef TARGET_SPARC
+
+void cpu_loop (CPUSPARCState *env)
+{
+       int trapnr;
+
+       while (1) {
+               trapnr = cpu_sparc_exec (env);
+
+               switch (trapnr) {
+                 case 0x8: case 0x10:
+                       env->regwptr[0] = do_syscall (env, env->gregs[1],
+                               env->regwptr[0], env->regwptr[1], env->regwptr[2],
+                               env->regwptr[3], env->regwptr[4], env->regwptr[13]);
+                       if (env->regwptr[0] >= 0xffffffe0)
+                               env->psr |= PSR_CARRY;
+                       break;
+                 default:
+                       printf ("Invalid trap: %d\n", trapnr);
+                       exit (1);
+               }
+               process_pending_signals (env);
+       }
+}
+
+#endif
+
 void usage(void)
 {
-    printf("qemu version " QEMU_VERSION ", Copyright (c) 2003 Fabrice Bellard\n"
-           "usage: qemu [-h] [-d] [-L path] [-s size] program [arguments...]\n"
+    printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003 Fabrice Bellard\n"
+           "usage: qemu-" TARGET_ARCH " [-h] [-d] [-L path] [-s size] program [arguments...]\n"
            "Linux CPU emulator (compiled for %s emulation)\n"
            "\n"
            "-h           print this help\n"
@@ -322,6 +348,9 @@ void usage(void)
 
 /* XXX: currently only used for async signals (see signal.c) */
 CPUState *global_env;
+/* used only if single thread */
+CPUState *cpu_single_env = NULL;
+
 /* used to free thread contexts */
 TaskState *first_task_state;
 
@@ -428,8 +457,13 @@ int main(int argc, char **argv)
     memset(ts, 0, sizeof(TaskState));
     env->opaque = ts;
     ts->used = 1;
+    env->user_mode_only = 1;
     
 #if defined(TARGET_I386)
+    cpu_x86_set_cpl(env, 3);
+
+    env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
+
     /* linux register setup */
     env->regs[R_EAX] = regs->eax;
     env->regs[R_EBX] = regs->ebx;
@@ -481,7 +515,6 @@ int main(int argc, char **argv)
     cpu_x86_load_seg(env, R_SS, __USER_DS);
     cpu_x86_load_seg(env, R_FS, __USER_DS);
     cpu_x86_load_seg(env, R_GS, __USER_DS);
-    env->user_mode_only = 1;
 
 #elif defined(TARGET_ARM)
     {
@@ -491,6 +524,9 @@ int main(int argc, char **argv)
         }
         env->cpsr = regs->uregs[16];
     }
+#elif defined(TARGET_SPARC)
+       env->pc = regs->u_regs[0];
+       env->regwptr[6] = regs->u_regs[1]-0x40;
 #else
 #error unsupported target CPU
 #endif