Skip to contentSkip to conversation

Support NPTL support for ColdFire and related fixes

PATCH In review Maxim Kuvyrkov 2 participants 9 messages Mar 1, 2010 – Jul 15, 2010

lore
Share & tools
lore
#0 lore raw

cover Support NPTL support for ColdFire and related fixes

The following series of 4 patches adds NPTL support for ColdFire user-mode emulation and fixes several related issues, mainly in signal handling.

0001-Add-NPTL-support-for-ColdFire.patch
Implement new kernel syscalls to support TLS storage and synchronization (merged to 2.6.34 kernel)

0002-Handle-SIGKILL-and-SIGCHLD.patch
Target-independent improvement to add SIGKILL and SIGCHLD to the list of handled signals.

0003-Fix-signal-handling-for-ColdFire.patch Fix and improve signal handling support for ColdFire.

0004-Define-MMAP_SHIFT-for-ColdFire.patch
Follow kernel behavior.

The patches were tested on GCC and GLIBC testsuites. All signal handling and frame unwinding GCC tests pass. GLIBC testsuite now has more tests passing with no regressions.

Any comments?

Thanks,

Signature · 4 lines
Maxim Kuvyrkov
CodeSourcery
[email protected]
(650) 331-3385 x724
#1 lore raw

PATCH 1/4 Add NPTL support for ColdFire

Quoted 1 line

From 1e505c8434d42f9b4fb1cc60934f856ffc06b476 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Mon, 1 Mar 2010 02:35:53 -0800
Subject: [PATCH 1/4] Add NPTL support for ColdFire

Add emulation of new m68k syscalls that provide kernel support for NPTL.

---
 configure                    |    1 +
 linux-user/m68k/syscall_nr.h |    5 +++++
 linux-user/main.c            |   21 +++++++++++++++++++++
 linux-user/strace.list       |    6 ++++++
 linux-user/syscall.c         |   20 ++++++++++++++++++++
 target-m68k/cpu.h            |   21 ++++++++++++++++++++-
 6 files changed, 73 insertions(+), 1 deletions(-)
configure +1 -0
index 8eb5f5b..0c03640 100755
@@ -2375,6 +2375,7 @@ case "$target_arch2" in
   ;;
   m68k)
     bflt="yes"
+    target_nptl="yes"
     gdb_xml_files="cf-core.xml cf-fp.xml"
     target_phys_bits=32
   ;;
linux-user/m68k/syscall_nr.h +5 -0
index 1c0ba07..00d4966 100644
@@ -328,3 +328,8 @@
 #define TARGET_NR_dup3			326
 #define TARGET_NR_pipe2		327
 #define TARGET_NR_inotify_init1	328
+
+#define TARGET_NR_get_thread_area	333
+#define TARGET_NR_set_thread_area	334
+#define TARGET_NR_atomic_cmpxchg_32	335
+#define TARGET_NR_atomic_barrier	336
linux-user/main.c +21 -0
index eeae22e..70e39fc 100644
@@ -2256,6 +2256,27 @@ void cpu_loop (CPUState *env)
 
 #ifdef TARGET_M68K
 
+uint32_t do_cmpxchg_32 (uint32_t addr, uint32_t oldval, uint32_t newval)
+{
+    uint32_t val;
+
+    /* XXX: This only works between threads, not between processes.
+       It's probably possible to implement this with native host
+       operations. However things like ldrex/strex are much harder so
+       there's not much point trying.  */
+    start_exclusive();
+
+    /* FIXME: This should SEGV if the access fails.  */
+    get_user_u32(val, addr);
+    if (val == oldval)
+        /* FIXME: Check for segfaults.  */
+        put_user_u32(newval, addr);
+
+    end_exclusive();
+
+    return val;
+}
+
 void cpu_loop(CPUM68KState *env)
 {
     int trapnr;
linux-user/strace.list +6 -0
index 97b7f76..c8c79cc 100644
@@ -33,6 +33,12 @@
 #ifdef TARGET_NR_arm_fadvise64_64
 { TARGET_NR_arm_fadvise64_64, "arm_fadvise64_64" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_atomic_barrier
+{ TARGET_NR_atomic_barrier, "atomic_barrier" , NULL, NULL, NULL },
+#endif
+#ifdef TARGET_NR_atomic_cmpxchg_32
+{ TARGET_NR_atomic_cmpxchg_32, "atomic_cmpxchg_32" , NULL, NULL, NULL },
+#endif
 #ifdef TARGET_NR_bdflush
 { TARGET_NR_bdflush, "bdflush" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +20 -0
index 38eb35f..364f671 100644
@@ -5756,6 +5756,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
 #elif defined(TARGET_CRIS)
         ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg4, arg5));
+#elif defined(TARGET_M68K)
+	ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
 #else
         ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
 #endif
@@ -6943,6 +6945,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
       ret = do_set_thread_area(cpu_env, arg1);
       break;
+#elif defined(TARGET_M68K)
+      cpu_set_tls (cpu_env, arg1);
+      ret = 0;
+      break;
 #else
       goto unimplemented_nowarn;
 #endif
@@ -6951,6 +6957,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_get_thread_area:
 #if defined(TARGET_I386) && defined(TARGET_ABI32)
         ret = do_get_thread_area(cpu_env, arg1);
+	break;
+#elif defined(TARGET_M68K)
+	ret = cpu_get_tls (cpu_env);
+	break;
 #else
         goto unimplemented_nowarn;
 #endif
@@ -7197,6 +7207,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
         break;
 #endif
+#ifdef TARGET_NR_atomic_cmpxchg_32
+	case TARGET_NR_atomic_cmpxchg_32:
+	ret = do_cmpxchg_32 (arg6, arg2, arg1);
+	break;
+#endif
+#ifdef TARGET_NR_atomic_barrier
+	case TARGET_NR_atomic_barrier:
+	ret = 0;
+	break;
+#endif
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
target-m68k/cpu.h +20 -1
index 68a7e41..6bafc40 100644
@@ -109,6 +109,9 @@ typedef struct CPUM68KState {
 
     uint32_t qregs[MAX_QREGS];
 
+    /* For usermode emulation */
+    target_ulong tls_value;
+
     CPU_COMMON
 
     uint32_t features;
@@ -126,6 +129,8 @@ int cpu_m68k_signal_handler(int host_signum, void *pinfo,
                            void *puc);
 void cpu_m68k_flush_flags(CPUM68KState *, int);
 
+uint32_t do_cmpxchg_32 (uint32_t, uint32_t, uint32_t);
+
 enum {
     CC_OP_DYNAMIC, /* Use env->cc_op  */
     CC_OP_FLAGS, /* CC_DEST = CVZN, CC_SRC = unused */
@@ -236,7 +241,21 @@ static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
         env->aregs[7] = newsp;
     env->dregs[0] = 0;
 }
-#endif
+
+static inline target_ulong cpu_get_tls(CPUState *env)
+{
+    return env->tls_value;
+}
+
+static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
+{
+    env->tls_value = newtls;
+}
+
+static inline void cpu_clear_exclusive(void)
+{
+}
+#endif /* CONFIG_USER_ONLY */
 
 #include "cpu-all.h"
 #include "exec-all.h"
Signature · 1 line
1.6.2.4
#2 lore raw

PATCH 2/4 Handle SIGKILL and SIGCHLD

In reply to Maxim Kuvyrkov
Quoted 1 line

From a659ff77804712826c1c1fe739339f1b1a172ed6 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Mon, 1 Mar 2010 02:39:48 -0800
Subject: [PATCH 2/4] Handle SIGKILL and SIGCHLD

Handle SIGKILL and SIGCHLD in linux user-space emulation.

---
 linux-user/signal.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
linux-user/signal.c +21 -0
index a560a5c..8f9da80 100644
@@ -213,6 +213,15 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
         /* should never come here, but who knows. The information for
            the target is irrelevant */
         tinfo->_sifields._sigfault._addr = 0;
+    } else if (sig == SIGKILL || sig == SIGCHLD) {
+        tinfo->_sifields._kill._pid = info->si_pid;
+        tinfo->_sifields._kill._uid = info->si_uid;
+
+        if (sig == SIGCHLD) {
+            tinfo->_sifields._sigchld._status = info->si_status;
+            tinfo->_sifields._sigchld._utime = info->si_utime;
+            tinfo->_sifields._sigchld._stime = info->si_stime;
+        }
     } else if (sig == SIGIO) {
 	tinfo->_sifields._sigpoll._fd = info->si_fd;
     } else if (sig >= TARGET_SIGRTMIN) {
@@ -236,6 +245,18 @@ static void tswap_siginfo(target_siginfo_t *tinfo,
         sig == SIGBUS || sig == SIGTRAP) {
         tinfo->_sifields._sigfault._addr =
             tswapl(info->_sifields._sigfault._addr);
+    } else if (sig == SIGKILL || sig == SIGCHLD) {
+        tinfo->_sifields._kill._pid = tswap32(info->_sifields._kill._pid);
+        tinfo->_sifields._kill._uid = tswap32(info->_sifields._kill._uid);
+
+        if (sig == SIGCHLD) {
+            tinfo->_sifields._sigchld._status
+                = tswap32(info->_sifields._sigchld._status);
+            tinfo->_sifields._sigchld._utime
+                = tswap32(info->_sifields._sigchld._utime);
+            tinfo->_sifields._sigchld._stime
+                = tswap32(info->_sifields._sigchld._stime);
+        }
     } else if (sig == SIGIO) {
 	tinfo->_sifields._sigpoll._fd = tswap32(info->_sifields._sigpoll._fd);
     } else if (sig >= TARGET_SIGRTMIN) {
Signature · 1 line
1.6.2.4
#3 lore raw

PATCH 3/4 Fix signal handling for ColdFire

In reply to Maxim Kuvyrkov
Quoted 1 line

From 1450a09c513a3051e3cf44d948983fe48ef368e0 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Mon, 1 Mar 2010 02:48:31 -0800
Subject: [PATCH 3/4] Fix signal handling for ColdFire

Handle FPU registers.
Pack structures that contain 16-bit fields. This avoid problems due to differences between host and target structure alignment requirements. Use ColdFire version of rt_sigreturn trampoline.

---
 linux-user/signal.c |   60 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 10 deletions(-)
linux-user/signal.c +50 -10
index 8f9da80..dc6f957 100644
@@ -4058,9 +4058,17 @@ struct target_sigcontext {
     abi_ulong  sc_d1;
     abi_ulong  sc_a0;
     abi_ulong  sc_a1;
-    unsigned short sc_sr;
+    uint16_t sc_sr;
+    /* M68K Linux ABI allows int32_t to be aligned at 2 bytes,
+       as most host architectures align int32's at 4 bytes,
+       we need to pack target_sigcontext so that sc_pc will be at
+       the correct offset.  */
     abi_ulong  sc_pc;
-};
+    uint16_t	sc_formatvec;
+    float64	sc_fpregs[2];	/* room for two fp registers */
+    uint32_t	sc_fpcntl[3];
+    unsigned char sc_fpstate[216];
+} __attribute__((__packed__));
 
 struct target_sigframe
 {
@@ -4078,8 +4086,8 @@ typedef int target_greg_t;
 typedef target_greg_t target_gregset_t[TARGET_NGREG];
 
 typedef struct target_fpregset {
-    int f_fpcntl[3];
-    int f_fpregs[8*3];
+    uint32_t	f_fpcntl[3];
+    float64	f_fpregs[8];
 } target_fpregset_t;
 
 struct target_mcontext {
@@ -4106,7 +4114,7 @@ struct target_rt_sigframe
     abi_ulong pinfo;
     abi_ulong puc;
     char retcode[8];
-    struct target_siginfo info;
+    target_siginfo_t info;
     struct target_ucontext uc;
 };
 
@@ -4123,6 +4131,12 @@ setup_sigcontext(struct target_sigcontext *sc, CPUState *env, abi_ulong mask)
     err |= __put_user(env->aregs[1], &sc->sc_a1);
     err |= __put_user(env->sr, &sc->sc_sr);
     err |= __put_user(env->pc, &sc->sc_pc);
+    err |= __put_user(env->fregs[0],	&sc->sc_fpregs[0]);
+    err |= __put_user(env->fregs[1],	&sc->sc_fpregs[1]);
+    err |= __put_user(env->fpcr,	&sc->sc_fpcntl[0]);
+    err |= __put_user(env->fpsr,	&sc->sc_fpcntl[1]);
+    err |= __put_user(0,		&sc->sc_fpcntl[2]);
+    err |= __put_user(0,		(uint32_t *) &sc->sc_fpstate[0]);
 
     return err;
 }
@@ -4140,6 +4154,10 @@ restore_sigcontext(CPUState *env, struct target_sigcontext *sc, int *pd0)
     err |= __get_user(env->pc, &sc->sc_pc);
     err |= __get_user(temp, &sc->sc_sr);
     env->sr = (env->sr & 0xff00) | (temp & 0xff);
+    err |= __get_user(env->fregs[0],	&sc->sc_fpregs[0]);
+    err |= __get_user(env->fregs[1],	&sc->sc_fpregs[1]);
+    err |= __get_user(env->fpcr,	&sc->sc_fpcntl[0]);
+    err |= __get_user(env->fpsr,	&sc->sc_fpcntl[1]);
 
     *pd0 = tswapl(sc->sc_d0);
 
@@ -4222,6 +4240,7 @@ static inline int target_rt_setup_ucontext(struct target_ucontext *uc,
                                            CPUState *env)
 {
     target_greg_t *gregs = uc->uc_mcontext.gregs;
+    target_fpregset_t *fpregs = &uc->uc_mcontext.fpregs;
     int err;
 
     err = __put_user(TARGET_MCONTEXT_VERSION, &uc->uc_mcontext.version);
@@ -4243,6 +4262,17 @@ static inline int target_rt_setup_ucontext(struct target_ucontext *uc,
     err |= __put_user(env->aregs[7], &gregs[15]);
     err |= __put_user(env->pc, &gregs[16]);
     err |= __put_user(env->sr, &gregs[17]);
+    err |= __put_user(env->fpcr,	&fpregs->f_fpcntl[0]);
+    err |= __put_user(env->fpsr,	&fpregs->f_fpcntl[1]);
+    err |= __put_user(0,		&fpregs->f_fpcntl[2]);
+    err |= __put_user(env->fregs[0],	&fpregs->f_fpregs[0]);
+    err |= __put_user(env->fregs[1],	&fpregs->f_fpregs[1]);
+    err |= __put_user(env->fregs[2],	&fpregs->f_fpregs[2]);
+    err |= __put_user(env->fregs[3],	&fpregs->f_fpregs[3]);
+    err |= __put_user(env->fregs[4],	&fpregs->f_fpregs[4]);
+    err |= __put_user(env->fregs[5],	&fpregs->f_fpregs[5]);
+    err |= __put_user(env->fregs[6],	&fpregs->f_fpregs[6]);
+    err |= __put_user(env->fregs[7],	&fpregs->f_fpregs[7]);
 
     return err;
 }
@@ -4254,6 +4284,7 @@ static inline int target_rt_restore_ucontext(CPUState *env,
     int temp;
     int err;
     target_greg_t *gregs = uc->uc_mcontext.gregs;
+    target_fpregset_t *fpregs = &uc->uc_mcontext.fpregs;
     
     err = __get_user(temp, &uc->uc_mcontext.version);
     if (temp != TARGET_MCONTEXT_VERSION)
@@ -4279,6 +4310,16 @@ static inline int target_rt_restore_ucontext(CPUState *env,
     err |= __get_user(env->pc, &gregs[16]);
     err |= __get_user(temp, &gregs[17]);
     env->sr = (env->sr & 0xff00) | (temp & 0xff);
+    err |= __get_user(env->fpcr,	&fpregs->f_fpcntl[0]);
+    err |= __get_user(env->fpsr,	&fpregs->f_fpcntl[1]);
+    err |= __get_user(env->fregs[0],	&fpregs->f_fpregs[0]);
+    err |= __get_user(env->fregs[1],	&fpregs->f_fpregs[1]);
+    err |= __get_user(env->fregs[2],	&fpregs->f_fpregs[2]);
+    err |= __get_user(env->fregs[3],	&fpregs->f_fpregs[3]);
+    err |= __get_user(env->fregs[4],	&fpregs->f_fpregs[4]);
+    err |= __get_user(env->fregs[5],	&fpregs->f_fpregs[5]);
+    err |= __get_user(env->fregs[6],	&fpregs->f_fpregs[6]);
+    err |= __get_user(env->fregs[7],	&fpregs->f_fpregs[7]);
 
     *pd0 = env->dregs[0];
     return err;
@@ -4338,11 +4379,10 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
     retcode_addr = frame_addr + offsetof(struct target_sigframe, retcode);
     err |= __put_user(retcode_addr, &frame->pretcode);
 
-    /* moveq #,d0; notb d0; trap #0 */
-
-    err |= __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn ^ 0xff) << 16),
-                      (long *)(frame->retcode + 0));
-    err |= __put_user(0x4e40, (short *)(frame->retcode + 4));
+    /* movel #__NR_rt_sigreturn,d0; trap #0 */
+    err |= __put_user(0x203c0000, (long *)(frame->retcode + 0));
+    err |= __put_user(0x00004e40 + (TARGET_NR_rt_sigreturn << 16),
+		      (long *)(frame->retcode + 4));
 
     if (err)
         goto give_sigsegv;
Signature · 1 line
1.6.2.4
#4 lore raw

Re: [Qemu-devel] [PATCH 3/4] Fix signal handling for ColdFire

Quoted 1 line

+ float64 sc_fpregs[2]; /* room for two fp registers */

...

linux-user/signal.c typedef int target_greg_t; · line 4090

Quoted 4 lines
linux-user/signal.c +2 -2
-    int f_fpcntl[3];
-    int f_fpregs[8*3];
+    uint32_t	f_fpcntl[3];
+    float64	f_fpregs[8];

Surely these float64 uses are incorrect. The kernel uses 3*int at both of these places, which matches up with the 96-bit values in the regular m68k fpu.

r~

#5 lore raw

Re: [Qemu-devel] [PATCH 3/4] Fix signal handling for ColdFire

Quoted 10 lines · Richard Henderson
Quoted 1 line

+ float64 sc_fpregs[2]; /* room for two fp registers */

...

Quoted 4 lines

- int f_fpcntl[3];
- int f_fpregs[8*3];
+ uint32_t f_fpcntl[3];
+ float64 f_fpregs[8];

Surely these float64 uses are incorrect. The kernel uses 3*int at both of these places, which matches up with the 96-bit values in the regular m68k fpu.

ColdFire FPU registers are 64-bit wide, this is one of the difference between ColdFire and classic m68k.

The kernel patch to sigcontext.h to support ColdFire was merged several days ago at http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/m68k/include/asm/sigcontext.h;h=1320eaa4cc2aab4b531a565c57ab62afb30bd0ec;hb=HEAD .

And thanks to your comment I noticed that an old version of the sigcontext patch was merged into the kernel in the above commit. Will need to fix it.

Regards,

Signature · 4 lines
Maxim Kuvyrkov
CodeSourcery
[email protected]
(650) 331-3385 x724
#6 lore raw

PATCH 4/4 Define MMAP_SHIFT for ColdFire

In reply to Maxim Kuvyrkov
Quoted 1 line

From c65168b123032ef2ab10c90254e4ac8bc6cb0120 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Mon, 1 Mar 2010 02:51:10 -0800
Subject: [PATCH 4/4] Define MMAP_SHIFT for ColdFire

ColdFire has MMAP_SHIFT equal to TARGET_PAGE_BITS.

---
 target-m68k/cpu.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
target-m68k/cpu.h +1 -0
index 6bafc40..6f652c5 100644
@@ -210,6 +210,7 @@ void register_m68k_insns (CPUM68KState *env);
 #ifdef CONFIG_USER_ONLY
 /* Linux uses 8k pages.  */
 #define TARGET_PAGE_BITS 13
+#define MMAP_SHIFT TARGET_PAGE_BITS
 #else
 /* Smallest TLB entry size is 1k.  */
 #define TARGET_PAGE_BITS 10
Signature · 1 line
1.6.2.4
#7 lore raw

[Qemu-devel] {PING}[PATCH 0/4] Support NPTL support for ColdFire and related fixes

In reply to Maxim Kuvyrkov
Quoted 15 lines · Maxim Kuvyrkov

The following series of 4 patches adds NPTL support for ColdFire user-mode emulation and fixes several related issues, mainly in signal handling.

0001-Add-NPTL-support-for-ColdFire.patch
Implement new kernel syscalls to support TLS storage and synchronization (merged to 2.6.34 kernel)

0002-Handle-SIGKILL-and-SIGCHLD.patch
Target-independent improvement to add SIGKILL and SIGCHLD to the list of handled signals.

0003-Fix-signal-handling-for-ColdFire.patch Fix and improve signal handling support for ColdFire.

Quoted 6 lines

0004-Define-MMAP_SHIFT-for-ColdFire.patch
Follow kernel behavior.

The patches were tested on GCC and GLIBC testsuites. All signal handling and frame unwinding GCC tests pass. GLIBC testsuite now has more tests passing with no regressions.

Ping.

These patches implement NPTL support for m68k/ColdFire and improve signal handling for linux user-mode emulation.

Signature · 4 lines
Maxim Kuvyrkov
CodeSourcery
[email protected]
(650) 331-3385 x724
#8 lore raw

[Qemu-devel] {PING^2} [PATCH 0/4] Support NPTL support for ColdFire and related fixes

In reply to Maxim Kuvyrkov
Quoted 18 lines · Maxim Kuvyrkov

The following series of 4 patches adds NPTL support for ColdFire user-mode emulation and fixes several related issues, mainly in signal handling.

0001-Add-NPTL-support-for-ColdFire.patch
Implement new kernel syscalls to support TLS storage and synchronization (merged to 2.6.34 kernel)

0002-Handle-SIGKILL-and-SIGCHLD.patch
Target-independent improvement to add SIGKILL and SIGCHLD to the list of handled signals.

0003-Fix-signal-handling-for-ColdFire.patch Fix and improve signal handling support for ColdFire.

0004-Define-MMAP_SHIFT-for-ColdFire.patch
Follow kernel behavior.

Quoted 8 lines

The patches were tested on GCC and GLIBC testsuites. All signal handling and frame unwinding GCC tests pass. GLIBC testsuite now has more tests passing with no regressions.

Any comments?

Thanks,

Ping^2.

These patches implement NPTL support for m68k/ColdFire and improve signal handling for linux user-mode emulation.

Thanks,

Signature · 4 lines
Maxim Kuvyrkov
CodeSourcery
[email protected]
(650) 331-3385 x724