Skip to contentSkip to conversation

Define sigcontext ABI of ColdFire

PATCH In review Maxim Kuvyrkov 2 participants 5 messages Sep 18, 2009 – Feb 10, 2010 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Define sigcontext ABI of ColdFire

The following patch define sigcontext ABI of ColdFire.

Once these changes are reviewed, I'll follow up with patches to GLIBC and GCC's linux-unwind.h.

Thanks,

--
Maxim K.
CodeSourcery

Quoted 1 line

From 998f3f07de69f51aa6d810800c8e8a685a4dec77 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Fri, 18 Sep 2009 14:09:03 +0400
Subject: [PATCH] Define sigcontext ABI of ColdFire

The following patch defines sigcontext ABI of ColdFire. Due to ISA restrictions ColdFire needs different rt_sigreturn trampoline.

And due to ColdFire FP registers being 8-bytes instead of 12-bytes on m68k, sigcontext and fpregset structures should be updated.

Regarding the sc_fpstate[16+6*8] field, it would've been enough 16 bytes to store ColdFire's FP state. To accomodate GLIBC's libSegFault it would'be been enough 6*8 bytes (room for the 6 non-call-clobbered FP registers). I set it to 16+6*8 to provide some extra space for any future changes in the ColdFire FPU.

---
 arch/m68k/include/asm/sigcontext.h |    6 ++++++
 arch/m68k/include/asm/ucontext.h   |    4 ++++
 arch/m68k/kernel/signal.c          |    6 ++++++
 3 files changed, 16 insertions(+), 0 deletions(-)
arch/m68k/include/asm/sigcontext.h +6 -0
index 523db2a..1320eaa 100644
@@ -15,9 +15,15 @@ struct sigcontext {
 	unsigned long  sc_pc;
 	unsigned short sc_formatvec;
 #ifndef __uClinux__
+# ifdef __mcoldfire__
+	unsigned long  sc_fpregs[2][2];	/* room for two fp registers */
+	unsigned long  sc_fpcntl[3];
+	unsigned char  sc_fpstate[16+6*8];
+# else
 	unsigned long  sc_fpregs[2*3];  /* room for two fp registers */
 	unsigned long  sc_fpcntl[3];
 	unsigned char  sc_fpstate[216];
+# endif
 #endif
 };
 
arch/m68k/include/asm/ucontext.h +4 -0
index e4e2266..00dcc51 100644
@@ -7,7 +7,11 @@ typedef greg_t gregset_t[NGREG];
 
 typedef struct fpregset {
 	int f_fpcntl[3];
+#ifdef __mcoldfire__
+	int f_fpregs[8][2];
+#else
 	int f_fpregs[8*3];
+#endif
 } fpregset_t;
 
 struct mcontext {
arch/m68k/kernel/signal.c +6 -0
index de2d05d..9913c2b 100644
@@ -897,9 +897,15 @@ static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
 
 	/* Set up to return from userspace.  */
 	err |= __put_user(frame->retcode, &frame->pretcode);
+#ifdef __mcoldfire__
+	/* move.w #,d0; trap #0 */
+	err |= __put_user(0x303c0000 + __NR_rt_sigreturn,
+			  (long __user *)(frame->retcode + 0));
+#else
 	/* moveq #,d0; notb d0; trap #0 */
 	err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
 			  (long __user *)(frame->retcode + 0));
+#endif
 	err |= __put_user(0x4e40, (short __user *)(frame->retcode + 4));
 
 	if (err)
Signature · 1 line
1.6.4
#1 lore raw
Quoted 1 line · Maxim Kuvyrkov

The following patch define sigcontext ABI of ColdFire.

...

Quoted 8 lines
arch/m68k/kernel/signal.c +2 -0
@@ -897,9 +897,15 @@ static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
 
 	/* Set up to return from userspace.  */
 	err |= __put_user(frame->retcode, &frame->pretcode);
+#ifdef __mcoldfire__
+	/* move.w #,d0; trap #0 */

arch/m68k/kernel/signal.c static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info, · line 911

Quoted 10 lines
arch/m68k/kernel/signal.c +4 -0
+	err |= __put_user(0x303c0000 + __NR_rt_sigreturn,
+			  (long __user *)(frame->retcode + 0));
+#else
 	/* moveq #,d0; notb d0; trap #0 */
 	err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
 			  (long __user *)(frame->retcode + 0));
+#endif
 	err |= __put_user(0x4e40, (short __user *)(frame->retcode + 4));
 
 	if (err)

This turned out to be buggy: move.w will only set the lower 16 bits of %d0 so if the signal handler leaves something in the high-order bits, then the trampoline will trap into a non-existent syscall. The attached patch fixes this; nothing else in it has changed since the initial revision.

I was lured into thinking that the above sequence is OK by m68knommu's version of the trampoline. Arch/m68knommu/kernel/entry.S uses "move #__NR_rt_sigreturn,%d0" which assembles into "move.w". This is too is buggy and I'm also attaching the fix for the nommu version.

Regards,

--
Maxim K.
CodeSourcery

Quoted 1 line

From bafb4e11ac13ea3095d9e8510f9a58c4cdc0481d Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Wed, 23 Sep 2009 01:22:43 +0400
Subject: [PATCH 1/2] Define sigcontext ABI of ColdFire

The following patch defines sigcontext ABI of ColdFire. Due to ISA restrictions ColdFire needs different rt_sigreturn trampoline.

And due to ColdFire FP registers being 8-bytes instead of 12-bytes on m68k, sigcontext and fpregset structures should be updated.

Regarding the sc_fpstate[16+6*8] field, it would've been enough 16 bytes to store ColdFire's FP state. To accomodate GLIBC's libSegFault it would'be been enough 6*8 bytes (room for the 6 non-call-clobbered FP registers). I set it to 16+6*8 to provide some extra space for any future changes in the ColdFire FPU.

---
 arch/m68k/include/asm/sigcontext.h |    6 ++++++
 arch/m68k/include/asm/ucontext.h   |    4 ++++
 arch/m68k/kernel/signal.c          |    7 +++++++
 3 files changed, 17 insertions(+), 0 deletions(-)
arch/m68k/include/asm/sigcontext.h +6 -0
index 523db2a..1320eaa 100644
@@ -15,9 +15,15 @@ struct sigcontext {
 	unsigned long  sc_pc;
 	unsigned short sc_formatvec;
 #ifndef __uClinux__
+# ifdef __mcoldfire__
+	unsigned long  sc_fpregs[2][2];	/* room for two fp registers */
+	unsigned long  sc_fpcntl[3];
+	unsigned char  sc_fpstate[16+6*8];
+# else
 	unsigned long  sc_fpregs[2*3];  /* room for two fp registers */
 	unsigned long  sc_fpcntl[3];
 	unsigned char  sc_fpstate[216];
+# endif
 #endif
 };
 
arch/m68k/include/asm/ucontext.h +4 -0
index e4e2266..00dcc51 100644
@@ -7,7 +7,11 @@ typedef greg_t gregset_t[NGREG];
 
 typedef struct fpregset {
 	int f_fpcntl[3];
+#ifdef __mcoldfire__
+	int f_fpregs[8][2];
+#else
 	int f_fpregs[8*3];
+#endif
 } fpregset_t;
 
 struct mcontext {
arch/m68k/kernel/signal.c +7 -0
index de2d05d..4b38753 100644
@@ -897,10 +897,17 @@ static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
 
 	/* Set up to return from userspace.  */
 	err |= __put_user(frame->retcode, &frame->pretcode);
+#ifdef __mcoldfire__
+	/* movel #__NR_rt_sigreturn,d0; trap #0 */
+	err |= __put_user(0x203c0000, (long __user *)(frame->retcode + 0));
+	err |= __put_user(0x00004e40 + (__NR_rt_sigreturn << 16),
+			  (long __user *)(frame->retcode + 4));
+#else
 	/* moveq #,d0; notb d0; trap #0 */
 	err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
 			  (long __user *)(frame->retcode + 0));
 	err |= __put_user(0x4e40, (short __user *)(frame->retcode + 4));
+#endif
 
 	if (err)
 		goto give_sigsegv;
Signature · 1 line
1.6.4
Quoted 1 line

From ac003b05af17bb48e6acffd454cae6fdf6e80737 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Wed, 23 Sep 2009 01:25:44 +0400
Subject: [PATCH 2/2] Fix m68k-uclinux's rt_sigreturn trampoline

---
 arch/m68knommu/kernel/entry.S |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/m68knommu/kernel/entry.S +1 -1
index f56faa5..2717605 100644
@@ -145,6 +145,6 @@ ENTRY(ret_from_user_signal)
 	trap #0
 
 ENTRY(ret_from_user_rt_signal)
-	move #__NR_rt_sigreturn,%d0
+	movel #__NR_rt_sigreturn,%d0
 	trap #0
 
Signature · 1 line
1.6.4
#2 lore raw
Quoted 2 lines · Maxim Kuvyrkov
Quoted 1 line · Maxim Kuvyrkov

The following patch define sigcontext ABI of ColdFire.

Ping.

The lack of defined ABI is blocking submission of the other pieces of NPTL support for m68k.

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

Re: [PATCH] Define sigcontext ABI for ColdFire

In reply to Maxim Kuvyrkov
Quoted 2 lines · Maxim Kuvyrkov
Quoted 1 line · Maxim Kuvyrkov

The following patch define sigcontext ABI of ColdFire.

...

Quoted 4 lines

I was lured into thinking that the above sequence is OK by m68knommu's version of the trampoline. Arch/m68knommu/kernel/entry.S uses "move #__NR_rt_sigreturn,%d0" which assembles into "move.w". This is too is buggy and I'm also attaching the fix for the nommu version.

I have cleaned up the sigcontext patch for ColdFire to only touch the necessary fields in the sigcontext structure. Attached are the cleaned up sigcontext patch and the rt_sigreturn fix for m68knommu.

I hope these patches will find their way into m68k/for-2.6.34 branch.

Regards,

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

From 1630ef86e8a1239c1d4ec6f8a6566ab57771f615 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Tue, 9 Feb 2010 14:03:16 +0300
Subject: [PATCH 1/2] Define sigcontext ABI for ColdFire

The following patch defines sigcontext ABI of ColdFire. Due to ISA restrictions ColdFire needs different rt_sigreturn trampoline. And due to ColdFire FPU registers being 8-bytes instead of 12-bytes, sigcontext and fpregset structures need to be updated.

---
 arch/m68k/include/asm/sigcontext.h |    4 ++++
 arch/m68k/include/asm/ucontext.h   |    4 ++++
 arch/m68k/kernel/signal.c          |    7 +++++++
 3 files changed, 15 insertions(+), 0 deletions(-)
arch/m68k/include/asm/sigcontext.h +4 -0
index 523db2a..68d8881 100644
@@ -15,7 +15,11 @@ struct sigcontext {
 	unsigned long  sc_pc;
 	unsigned short sc_formatvec;
 #ifndef __uClinux__
+# ifndef __mcoldfire__
 	unsigned long  sc_fpregs[2*3];  /* room for two fp registers */
+# else
+	unsigned long  sc_fpregs[2][2];	/* room for two fp registers */
+# endif
 	unsigned long  sc_fpcntl[3];
 	unsigned char  sc_fpstate[216];
 #endif
arch/m68k/include/asm/ucontext.h +4 -0
index e4e2266..465062b 100644
@@ -7,7 +7,11 @@ typedef greg_t gregset_t[NGREG];
 
 typedef struct fpregset {
 	int f_fpcntl[3];
+#ifndef __mcoldfire__
 	int f_fpregs[8*3];
+#else
+	int f_fpregs[8][2];
+#endif
 } fpregset_t;
 
 struct mcontext {
arch/m68k/kernel/signal.c +7 -0
index de2d05d..3be91e1 100644
@@ -897,10 +897,17 @@ static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
 
 	/* Set up to return from userspace.  */
 	err |= __put_user(frame->retcode, &frame->pretcode);
+#ifndef __mcoldfire__
 	/* moveq #,d0; notb d0; trap #0 */
 	err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
 			  (long __user *)(frame->retcode + 0));
 	err |= __put_user(0x4e40, (short __user *)(frame->retcode + 4));
+#else
+	/* movel #__NR_rt_sigreturn,d0; trap #0 */
+	err |= __put_user(0x203c0000, (long __user *)(frame->retcode + 0));
+	err |= __put_user(0x00004e40 + (__NR_rt_sigreturn << 16),
+			  (long __user *)(frame->retcode + 4));
+#endif
 
 	if (err)
 		goto give_sigsegv;
Signature · 1 line
1.6.6.1
Quoted 1 line

From 68c601c6f0135ca7cede22d4b1d4f59ef545f965 Mon Sep 17 00:00:00 2001

From: Maxim Kuvyrkov <[email protected]>
Date: Wed, 23 Sep 2009 01:25:44 +0400
Subject: [PATCH 2/2] Fix m68k-uclinux's rt_sigreturn trampoline

---
 arch/m68knommu/kernel/entry.S |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/m68knommu/kernel/entry.S +1 -1
index 56043ad..aff6f57 100644
@@ -145,6 +145,6 @@ ENTRY(ret_from_user_signal)
 	trap #0
 
 ENTRY(ret_from_user_rt_signal)
-	move #__NR_rt_sigreturn,%d0
+	movel #__NR_rt_sigreturn,%d0
 	trap #0
 
Signature · 1 line
1.6.6.1
#4 lore raw

Re: [PATCH] Define sigcontext ABI for ColdFire

Hi Maxim,

Quoted 4 lines · Maxim Kuvyrkov
Quoted 2 lines · Maxim Kuvyrkov
Quoted 1 line · Maxim Kuvyrkov

The following patch define sigcontext ABI of ColdFire.

...

Quoted 8 lines
Quoted 4 lines

I was lured into thinking that the above sequence is OK by m68knommu's version of the trampoline. Arch/m68knommu/kernel/entry.S uses "move #__NR_rt_sigreturn,%d0" which assembles into "move.w". This is too is buggy and I'm also attaching the fix for the nommu version.

I have cleaned up the sigcontext patch for ColdFire to only touch the necessary fields in the sigcontext structure. Attached are the cleaned up sigcontext patch and the rt_sigreturn fix for m68knommu.

I hope these patches will find their way into m68k/for-2.6.34 branch.

I'll take 0002-Fix-m68k-uclinux-s-rt_sigreturn-trampoline.patch and apply to the m68knommu git tree.

Thanks
Greg

------------------------------------------------------------------------

Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected]
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com