Move clone() register setup to target specific code. Handle fork-like clone.
authorpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
Fri, 30 May 2008 17:22:15 +0000 (17:22 +0000)
committerpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
Fri, 30 May 2008 17:22:15 +0000 (17:22 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4623 c046a42c-6fe2-441c-8c8c-71466251a162

linux-user/syscall.c
target-alpha/cpu.h
target-arm/cpu.h
target-cris/cpu.h
target-i386/cpu.h
target-m68k/cpu.h
target-mips/cpu.h
target-ppc/cpu.h
target-sh4/cpu.h
target-sparc/cpu.h

index 0c5f0a2ae97907251d1f66cc838cd916cacb3fb2..3c39e9f82cd0001dacf614e287cebaee10abf1a9 100644 (file)
@@ -2744,64 +2744,8 @@ int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp)
         first_task_state = ts;
         /* we create a new CPU instance. */
         new_env = cpu_copy(env);
-#if defined(TARGET_I386)
-        if (!newsp)
-            newsp = env->regs[R_ESP];
-        new_env->regs[R_ESP] = newsp;
-        new_env->regs[R_EAX] = 0;
-#elif defined(TARGET_ARM)
-        if (!newsp)
-            newsp = env->regs[13];
-        new_env->regs[13] = newsp;
-        new_env->regs[0] = 0;
-#elif defined(TARGET_SPARC)
-        if (!newsp)
-            newsp = env->regwptr[22];
-        new_env->regwptr[22] = newsp;
-        new_env->regwptr[0] = 0;
-       /* XXXXX */
-        printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
-#elif defined(TARGET_M68K)
-        if (!newsp)
-            newsp = env->aregs[7];
-        new_env->aregs[7] = newsp;
-        new_env->dregs[0] = 0;
-        /* ??? is this sufficient?  */
-#elif defined(TARGET_MIPS)
-        if (!newsp)
-            newsp = env->gpr[env->current_tc][29];
-        new_env->gpr[env->current_tc][29] = newsp;
-#elif defined(TARGET_PPC)
-        if (!newsp)
-            newsp = env->gpr[1];
-        new_env->gpr[1] = newsp;
-        {
-            int i;
-            for (i = 7; i < 32; i++)
-                new_env->gpr[i] = 0;
-        }
-#elif defined(TARGET_SH4)
-       if (!newsp)
-         newsp = env->gregs[15];
-       new_env->gregs[15] = newsp;
-       /* XXXXX */
-#elif defined(TARGET_ALPHA)
-       if (!newsp)
-         newsp = env->ir[30];
-       new_env->ir[30] = newsp;
-        /* ? */
-        {
-            int i;
-            for (i = 7; i < 30; i++)
-                new_env->ir[i] = 0;
-        }
-#elif defined(TARGET_CRIS)
-       if (!newsp)
-         newsp = env->regs[14];
-       new_env->regs[14] = newsp;
-#else
-#error unsupported target CPU
-#endif
+        /* Init regs that differ from the parent.  */
+        cpu_clone_regs(new_env, newsp);
         new_env->opaque = ts;
 #ifdef __ia64__
         ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
@@ -2813,6 +2757,9 @@ int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp)
         if ((flags & ~CSIGNAL) != 0)
             return -EINVAL;
         ret = fork();
+        if (ret == 0) {
+            cpu_clone_regs(env, newsp);
+        }
     }
     return ret;
 }
index c955997fcee6bd1cd262b199c189b0227b87810e..0c1b580f97b81c4d037861e88d234253d4bee841 100644 (file)
@@ -311,6 +311,15 @@ static inline int cpu_mmu_index (CPUState *env)
     return (env->ps >> 3) & 3;
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->ir[30] = newsp;
+    /* FIXME: Zero syscall return value.  */
+}
+#endif
+
 #include "cpu-all.h"
 
 enum {
index 10428086659398363fbbf360b90924d23bfd0a63..1c51d2df400b0ab3d029ddd36ffc06c8dfad0dda 100644 (file)
@@ -408,6 +408,15 @@ static inline int cpu_mmu_index (CPUState *env)
     return (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR ? 1 : 0;
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->regs[13] = newsp;
+    env->regs[0] = 0;
+}
+#endif
+
 #include "cpu-all.h"
 
 #endif
index 14b09d8cb666bf580e7a7a3f320f25d7c255b6fd..ea86bf902426934d707c93cb0ff37b8fe01defd0 100644 (file)
@@ -218,6 +218,15 @@ static inline int cpu_mmu_index (CPUState *env)
        return !!(env->pregs[PR_CCS] & U_FLAG);
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->regs[14] = newsp;
+    env->regs[10] = 0;
+}
+#endif
+
 /* Support function regs.  */
 #define SFR_RW_GC_CFG      0][0
 #define SFR_RW_MM_CFG      env->pregs[PR_SRS]][0
index eb0052786cee3d6360453afdbc11051d66bddfdc..7d4551e76550f372d5153fbcdc2821b5d57855ec 100644 (file)
@@ -734,6 +734,15 @@ typedef struct CCTable {
 
 extern CCTable cc_table[];
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->regs[R_ESP] = newsp;
+    env->regs[R_EAX] = 0;
+}
+#endif
+
 #include "cpu-all.h"
 
 #include "svm.h"
index d5c5a10556fd95614f296b09489285a56cc8a594..76914525f6e52863a9e5a20dd5536435e9263531 100644 (file)
@@ -226,6 +226,15 @@ static inline int cpu_mmu_index (CPUState *env)
     return (env->sr & SR_S) == 0 ? 1 : 0;
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->aregs[7] = newsp;
+    env->dregs[0] = 0;
+}
+#endif
+
 #include "cpu-all.h"
 
 #endif
index 9295b531d6faaf093aefc9761b112545ea389a33..f9fcafbb1f9948bc017a7ed939ef2ed2f12bb5fd 100644 (file)
@@ -500,6 +500,16 @@ static inline int cpu_mmu_index (CPUState *env)
     return env->hflags & MIPS_HFLAG_KSU;
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->gpr[env->current_tc][29] = newsp;
+    env->gpr[env->current_tc][7] = 0;
+    env->gpr[env->current_tc][2] = 0;
+}
+#endif
+
 #include "cpu-all.h"
 
 /* Memory access type :
index a884fd63335b4b30eb0a81e312546404092982af..06dc083909a822eefad66d2ca91956316c790ad6 100644 (file)
@@ -822,6 +822,17 @@ static inline int cpu_mmu_index (CPUState *env)
     return env->mmu_idx;
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    int i;
+    if (!newsp)
+        env->gpr[1] = newsp;
+    for (i = 7; i < 32; i++)
+        env->gpr[i] = 0;
+}
+#endif
+
 #include "cpu-all.h"
 
 /*****************************************************************************/
index c03cdb188cce7de739ac99f863ac351f4f79599e..9294b94e3f5738e867a9a911b64978e89ca975ae 100644 (file)
@@ -143,6 +143,15 @@ static inline int cpu_mmu_index (CPUState *env)
     return (env->sr & SR_MD) == 0 ? 1 : 0;
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->gregs[15] = newsp;
+    env->gregs[0] = 0;
+}
+#endif
+
 #include "cpu-all.h"
 
 /* Memory access type */
index 539fd2d2648b59e8aece2003b9eee6b4603ae8e6..54807fb02152309fd6a83b25ee74d30b527cff18 100644 (file)
@@ -403,6 +403,18 @@ static inline int cpu_fpu_enabled(CPUState *env1)
 #endif
 }
 
+#if defined(CONFIG_USER_ONLY)
+static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
+{
+    if (!newsp)
+        env->regwptr[22] = newsp;
+    env->regwptr[0] = 0;
+    /* FIXME: Do we also need to clear CF?  */
+    /* XXXXX */
+    printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
+}
+#endif
+
 #include "cpu-all.h"
 
 #endif