linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arch/sh: provide unified syscall trap compatible with all SH models
@ 2015-08-25  3:03 Rich Felker
  2015-08-25  7:18 ` Geert Uytterhoeven
  2015-08-25 21:23 ` [PATCH v2] " Rich Felker
  0 siblings, 2 replies; 8+ messages in thread
From: Rich Felker @ 2015-08-25  3:03 UTC (permalink / raw)
  To: linux-sh; +Cc: linux-kernel, shumpei.kawasaki, ysato, jeff

From: Rich Felker <dalias@libc.org>

Historically SH-2 Linux (and originally uClinux) used a syscall
calling convention incompatible with the established SH-3/4 Linux ABI.
This choice was made because the trap range used by the existing ABI,
0x10-0x17, overlaps with the hardware exception/interrupt trap range
reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
division-overflow exceptions.

Despite the documented syscall convention using the low bits of the
trap number to signal the number of arguments the kernel should
expect, no version of the kernel has ever used this information, nor
is it useful; all of the registers need to be saved anyway. Therefore,
it is possible to pick a new trap number, 0x1f, that is both supported
by all existing SH-3/4 kernels and unassigned as a hardware trap in
the SH-2 range. This makes it possible to produce SH-2 application
binaries that are forwards-compatible with running on SH-3/4 kernels
and to treat SH as a unified platform with varying ISA support levels
rather than multiple gratuitously-incompatible platforms.

This patch adjusts the range checking SH-2 and SH-2A kernels make for
the syscall trap to accept the range 0x1f-0x2f rather than just
0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
models.

Signed-off-by: Rich Felker <dalias@libc.org>

---

The original proposal for using 0x1f as a unified syscall trap was
reviewed by Jeff Dionne, Yoshinori Sato, and Shumpei Kawasaki for
conflicts with existing trap number assignments, and none were found.
I introduced this proposal as a way to add SH-2 support to musl libc
in a forwards-compatible way, treating SH as a unified architecture,
with the particular intent of supporting the Open Processor
Foundation's J2 Core (SH-2 ISA plus some extensions) and providing a
smooth upgrade path to the future J4 Core (SH-4 equivalent) and other
full-fledged SH platforms with MMU.

There is also some interest in having glibc's SH port support SH-2/J2,
which is more practical with a common syscall ABI; whether this will
actually happen remains uncertain.

Rich



diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S ./arch/sh/kernel/cpu/sh2/entry.S
--- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S	2015-08-09 19:54:30.000000000 +0000
+++ ./arch/sh/kernel/cpu/sh2/entry.S	2015-08-24 03:23:34.159387924 +0000
@@ -144,9 +144,9 @@ ENTRY(exception_handler)
 	mov	#64,r8
 	cmp/hs	r8,r9
 	bt	interrupt_entry	! vec >= 64 is interrupt
-	mov	#32,r8
+	mov	#31,r8
 	cmp/hs	r8,r9
-	bt	trap_entry	! 64 > vec >= 32  is trap
+	bt	trap_entry	! 64 > vec >= 31  is trap
 
 	mov.l	4f,r8
 	mov	r9,r4
@@ -178,9 +178,9 @@ interrupt_entry:
 
 trap_entry:
 	mov	#0x30,r8
-	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
+	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
 	bt	1f
-	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
+	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
 1:	
 	shll2	r9			! TRA
 	bra	system_call	! jump common systemcall entry
diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S ./arch/sh/kernel/cpu/sh2a/entry.S
--- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S	2015-08-09 19:54:30.000000000 +0000
+++ ./arch/sh/kernel/cpu/sh2a/entry.S	2015-08-24 03:23:58.849386418 +0000
@@ -109,9 +109,9 @@ ENTRY(exception_handler)
 	mov	#64,r8
 	cmp/hs	r8,r9
 	bt	interrupt_entry	! vec >= 64 is interrupt
-	mov	#32,r8
+	mov	#31,r8
 	cmp/hs	r8,r9
-	bt	trap_entry	! 64 > vec >= 32  is trap
+	bt	trap_entry	! 64 > vec >= 31  is trap
 
 	mov.l	4f,r8
 	mov	r9,r4
@@ -143,9 +143,9 @@ interrupt_entry:
 
 trap_entry:
 	mov	#0x30,r8
-	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
+	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
 	bt	1f
-	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
+	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
 1:	
 	shll2	r9			! TRA
 	bra	system_call	! jump common systemcall entry
diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S ./arch/sh/kernel/entry-common.S
--- ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S	2015-08-09 19:54:30.000000000 +0000
+++ ./arch/sh/kernel/entry-common.S	2015-08-24 03:33:50.062683702 +0000
@@ -268,19 +268,20 @@ debug_trap:
  *	Syscall #: R3
  *	Arguments #0 to #3: R4--R7
  *	Arguments #4 to #6: R0, R1, R2
- *	TRA: (number of arguments + ABI revision) x 4
+ *	TRA>>2: 0x1f, or one of a model-specific set of legacy values:
  *
- * This code also handles delegating other traps to the BIOS/gdb stub
- * according to:
- *
- * Trap number
  * (TRA>>2)	Purpose
  * --------	-------
  * 0x00-0x0f	original SH-3/4 syscall ABI (not in general use).
  * 0x10-0x1f	general SH-3/4 syscall ABI.
- * 0x20-0x2f	syscall ABI for SH-2 parts.
- * 0x30-0x3f	debug traps used by the kernel.
- * 0x40-0xff	Not supported by all parts, so left unhandled.
+ * 0x20-0x2f	original SH-2 syscall ABI.
+ *
+ * SH-2 originally used a separate trap range because several hardware
+ * exceptions fell in the range used for the SH-3/4 syscall ABI. These
+ * are still supported, but trap 0x1f is preferred because it is
+ * compatible with all models.
+ *
+ * This code also handles delegating other traps to the BIOS/gdb stub.
  *
  * Note: When we're first called, the TRA value must be shifted
  * right 2 bits in order to get the value that was used as the "trapa"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] arch/sh: provide unified syscall trap compatible with all SH models
  2015-08-25  3:03 [PATCH] arch/sh: provide unified syscall trap compatible with all SH models Rich Felker
@ 2015-08-25  7:18 ` Geert Uytterhoeven
  2015-08-25  7:22   ` Rich Felker
  2015-08-25 21:23 ` [PATCH v2] " Rich Felker
  1 sibling, 1 reply; 8+ messages in thread
From: Geert Uytterhoeven @ 2015-08-25  7:18 UTC (permalink / raw)
  To: Rich Felker
  Cc: Linux-sh list, linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff

Hi Rich,

On Tue, Aug 25, 2015 at 5:03 AM, Rich Felker <dalias@libc.org> wrote:
> From: Rich Felker <dalias@libc.org>
>
> Historically SH-2 Linux (and originally uClinux) used a syscall
> calling convention incompatible with the established SH-3/4 Linux ABI.
> This choice was made because the trap range used by the existing ABI,
> 0x10-0x17, overlaps with the hardware exception/interrupt trap range
> reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
> division-overflow exceptions.
>
> Despite the documented syscall convention using the low bits of the
> trap number to signal the number of arguments the kernel should
> expect, no version of the kernel has ever used this information, nor
> is it useful; all of the registers need to be saved anyway. Therefore,
> it is possible to pick a new trap number, 0x1f, that is both supported
> by all existing SH-3/4 kernels and unassigned as a hardware trap in
> the SH-2 range. This makes it possible to produce SH-2 application
> binaries that are forwards-compatible with running on SH-3/4 kernels
> and to treat SH as a unified platform with varying ISA support levels
> rather than multiple gratuitously-incompatible platforms.
>
> This patch adjusts the range checking SH-2 and SH-2A kernels make for
> the syscall trap to accept the range 0x1f-0x2f rather than just
> 0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
> models.
>
> Signed-off-by: Rich Felker <dalias@libc.org>

> --- ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S 2015-08-09 19:54:30.000000000 +0000
> +++ ./arch/sh/kernel/entry-common.S     2015-08-24 03:33:50.062683702 +0000
> @@ -268,19 +268,20 @@ debug_trap:
>   *     Syscall #: R3
>   *     Arguments #0 to #3: R4--R7
>   *     Arguments #4 to #6: R0, R1, R2
> - *     TRA: (number of arguments + ABI revision) x 4
> + *     TRA>>2: 0x1f, or one of a model-specific set of legacy values:
>   *
> - * This code also handles delegating other traps to the BIOS/gdb stub
> - * according to:
> - *
> - * Trap number
>   * (TRA>>2)    Purpose
>   * --------    -------
>   * 0x00-0x0f   original SH-3/4 syscall ABI (not in general use).
>   * 0x10-0x1f   general SH-3/4 syscall ABI.
> - * 0x20-0x2f   syscall ABI for SH-2 parts.
> - * 0x30-0x3f   debug traps used by the kernel.
> - * 0x40-0xff   Not supported by all parts, so left unhandled.

Why did you remoe the two lines of documentation above?

> + * 0x20-0x2f   original SH-2 syscall ABI.
> + *
> + * SH-2 originally used a separate trap range because several hardware
> + * exceptions fell in the range used for the SH-3/4 syscall ABI. These
> + * are still supported, but trap 0x1f is preferred because it is
> + * compatible with all models.
> + *
> + * This code also handles delegating other traps to the BIOS/gdb stub.
>   *
>   * Note: When we're first called, the TRA value must be shifted
>   * right 2 bits in order to get the value that was used as the "trapa"
Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] arch/sh: provide unified syscall trap compatible with all SH models
  2015-08-25  7:18 ` Geert Uytterhoeven
@ 2015-08-25  7:22   ` Rich Felker
  0 siblings, 0 replies; 8+ messages in thread
From: Rich Felker @ 2015-08-25  7:22 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Linux-sh list, linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff

On Tue, Aug 25, 2015 at 09:18:44AM +0200, Geert Uytterhoeven wrote:
> Hi Rich,
> 
> On Tue, Aug 25, 2015 at 5:03 AM, Rich Felker <dalias@libc.org> wrote:
> > From: Rich Felker <dalias@libc.org>
> >
> > Historically SH-2 Linux (and originally uClinux) used a syscall
> > calling convention incompatible with the established SH-3/4 Linux ABI.
> > This choice was made because the trap range used by the existing ABI,
> > 0x10-0x17, overlaps with the hardware exception/interrupt trap range
> > reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
> > division-overflow exceptions.
> >
> > Despite the documented syscall convention using the low bits of the
> > trap number to signal the number of arguments the kernel should
> > expect, no version of the kernel has ever used this information, nor
> > is it useful; all of the registers need to be saved anyway. Therefore,
> > it is possible to pick a new trap number, 0x1f, that is both supported
> > by all existing SH-3/4 kernels and unassigned as a hardware trap in
> > the SH-2 range. This makes it possible to produce SH-2 application
> > binaries that are forwards-compatible with running on SH-3/4 kernels
> > and to treat SH as a unified platform with varying ISA support levels
> > rather than multiple gratuitously-incompatible platforms.
> >
> > This patch adjusts the range checking SH-2 and SH-2A kernels make for
> > the syscall trap to accept the range 0x1f-0x2f rather than just
> > 0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
> > models.
> >
> > Signed-off-by: Rich Felker <dalias@libc.org>
> 
> > --- ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S 2015-08-09 19:54:30.000000000 +0000
> > +++ ./arch/sh/kernel/entry-common.S     2015-08-24 03:33:50.062683702 +0000
> > @@ -268,19 +268,20 @@ debug_trap:
> >   *     Syscall #: R3
> >   *     Arguments #0 to #3: R4--R7
> >   *     Arguments #4 to #6: R0, R1, R2
> > - *     TRA: (number of arguments + ABI revision) x 4
> > + *     TRA>>2: 0x1f, or one of a model-specific set of legacy values:
> >   *
> > - * This code also handles delegating other traps to the BIOS/gdb stub
> > - * according to:
> > - *
> > - * Trap number
> >   * (TRA>>2)    Purpose
> >   * --------    -------
> >   * 0x00-0x0f   original SH-3/4 syscall ABI (not in general use).
> >   * 0x10-0x1f   general SH-3/4 syscall ABI.
> > - * 0x20-0x2f   syscall ABI for SH-2 parts.
> > - * 0x30-0x3f   debug traps used by the kernel.
> > - * 0x40-0xff   Not supported by all parts, so left unhandled.
> 
> Why did you remoe the two lines of documentation above?

It was an unintended side-effect of restructuring the table to be a
list of legacy values. While the actual functional work of this patch
was done months ago, I just noticed that the comments should be
changed yesterday while preparing the patch for submission. I can
rework them to avoid dropping the useful information.

Thanks for the quick initial review!

Rich

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] arch/sh: provide unified syscall trap compatible with all SH models
  2015-08-25  3:03 [PATCH] arch/sh: provide unified syscall trap compatible with all SH models Rich Felker
  2015-08-25  7:18 ` Geert Uytterhoeven
@ 2015-08-25 21:23 ` Rich Felker
  2015-09-15  3:17   ` Rob Landley
  2015-09-15  4:11   ` Rich Felker
  1 sibling, 2 replies; 8+ messages in thread
From: Rich Felker @ 2015-08-25 21:23 UTC (permalink / raw)
  To: linux-sh
  Cc: linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff, Geert Uytterhoeven

From: Rich Felker <dalias@libc.org>

Historically SH-2 Linux (and originally uClinux) used a syscall
calling convention incompatible with the established SH-3/4 Linux ABI.
This choice was made because the trap range used by the existing ABI,
0x10-0x17, overlaps with the hardware exception/interrupt trap range
reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
division-overflow exceptions.

Despite the documented syscall convention using the low bits of the
trap number to signal the number of arguments the kernel should
expect, no version of the kernel has ever used this information, nor
is it useful; all of the registers need to be saved anyway. Therefore,
it is possible to pick a new trap number, 0x1f, that is both supported
by all existing SH-3/4 kernels and unassigned as a hardware trap in
the SH-2 range. This makes it possible to produce SH-2 application
binaries that are forwards-compatible with running on SH-3/4 kernels
and to treat SH as a unified platform with varying ISA support levels
rather than multiple gratuitously-incompatible platforms.

This patch adjusts the range checking SH-2 and SH-2A kernels make for
the syscall trap to accept the range 0x1f-0x2f rather than just
0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
models.

Signed-off-by: Rich Felker <dalias@libc.org>

---

The original proposal for using 0x1f as a unified syscall trap was
reviewed by Jeff Dionne, Yoshinori Sato, and Shumpei Kawasaki for
conflicts with existing trap number assignments, and none were found.
I introduced this proposal as a way to add SH-2 support to musl libc
in a forwards-compatible way, treating SH as a unified architecture,
with the particular intent of supporting the Open Processor
Foundation's J2 Core (SH-2 ISA plus some extensions) and providing a
smooth upgrade path to the future J4 Core (SH-4 equivalent) and other
full-fledged SH platforms with MMU.

There is also some interest in having glibc's SH port support SH-2/J2,
which is more practical with a common syscall ABI; whether this will
actually happen remains uncertain.

Version 2 of the patch addresses issues raised by Geert Uytterhoeven
with the changes to comments in entry-common.S.

Rich



diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S ./arch/sh/kernel/cpu/sh2/entry.S
--- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S	2015-08-09 19:54:30.000000000 +0000
+++ ./arch/sh/kernel/cpu/sh2/entry.S	2015-08-24 03:23:34.159387924 +0000
@@ -144,9 +144,9 @@ ENTRY(exception_handler)
 	mov	#64,r8
 	cmp/hs	r8,r9
 	bt	interrupt_entry	! vec >= 64 is interrupt
-	mov	#32,r8
+	mov	#31,r8
 	cmp/hs	r8,r9
-	bt	trap_entry	! 64 > vec >= 32  is trap
+	bt	trap_entry	! 64 > vec >= 31  is trap
 
 	mov.l	4f,r8
 	mov	r9,r4
@@ -178,9 +178,9 @@ interrupt_entry:
 
 trap_entry:
 	mov	#0x30,r8
-	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
+	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
 	bt	1f
-	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
+	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
 1:	
 	shll2	r9			! TRA
 	bra	system_call	! jump common systemcall entry
diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S ./arch/sh/kernel/cpu/sh2a/entry.S
--- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S	2015-08-09 19:54:30.000000000 +0000
+++ ./arch/sh/kernel/cpu/sh2a/entry.S	2015-08-24 03:23:58.849386418 +0000
@@ -109,9 +109,9 @@ ENTRY(exception_handler)
 	mov	#64,r8
 	cmp/hs	r8,r9
 	bt	interrupt_entry	! vec >= 64 is interrupt
-	mov	#32,r8
+	mov	#31,r8
 	cmp/hs	r8,r9
-	bt	trap_entry	! 64 > vec >= 32  is trap
+	bt	trap_entry	! 64 > vec >= 31  is trap
 
 	mov.l	4f,r8
 	mov	r9,r4
@@ -143,9 +143,9 @@ interrupt_entry:
 
 trap_entry:
 	mov	#0x30,r8
-	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
+	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
 	bt	1f
-	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
+	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
 1:	
 	shll2	r9			! TRA
 	bra	system_call	! jump common systemcall entry
diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S ./arch/sh/kernel/entry-common.S
--- ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S	2015-08-09 19:54:30.000000000 +0000
+++ ./arch/sh/kernel/entry-common.S	2015-08-25 21:08:15.835463227 +0000
@@ -268,20 +268,29 @@ debug_trap:
  *	Syscall #: R3
  *	Arguments #0 to #3: R4--R7
  *	Arguments #4 to #6: R0, R1, R2
- *	TRA: (number of arguments + ABI revision) x 4
+ *	TRA: See following table.
  *
- * This code also handles delegating other traps to the BIOS/gdb stub
- * according to:
- *
- * Trap number
  * (TRA>>2)	Purpose
  * --------	-------
  * 0x00-0x0f	original SH-3/4 syscall ABI (not in general use).
  * 0x10-0x1f	general SH-3/4 syscall ABI.
- * 0x20-0x2f	syscall ABI for SH-2 parts.
+ *      0x1f	unified SH-2/3/4 syscall ABI (preferred).
+ * 0x20-0x2f	original SH-2 syscall ABI.
  * 0x30-0x3f	debug traps used by the kernel.
  * 0x40-0xff	Not supported by all parts, so left unhandled.
  *
+ * For making system calls, any trap number in the range for the
+ * given cpu model may be used, but the unified trap number 0x1f is
+ * preferred for compatibility with all models.
+ *
+ * The low bits of the trap number were once documented as matching
+ * the number of arguments, but they were never actually used as such
+ * by the kernel. SH-2 originally used its own separate trap range
+ * because several hardware exceptions fell in the range used for the
+ * SH-3/4 syscall ABI.
+ *
+ * This code also handles delegating other traps to the BIOS/gdb stub.
+ *
  * Note: When we're first called, the TRA value must be shifted
  * right 2 bits in order to get the value that was used as the "trapa"
  * argument.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arch/sh: provide unified syscall trap compatible with all SH models
  2015-08-25 21:23 ` [PATCH v2] " Rich Felker
@ 2015-09-15  3:17   ` Rob Landley
  2015-09-15  4:28     ` Rich Felker
  2015-09-15  4:11   ` Rich Felker
  1 sibling, 1 reply; 8+ messages in thread
From: Rob Landley @ 2015-09-15  3:17 UTC (permalink / raw)
  To: Rich Felker, linux-sh
  Cc: linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff, Geert Uytterhoeven

On 08/25/2015 04:23 PM, Rich Felker wrote:
> From: Rich Felker <dalias@libc.org>
> 
> Historically SH-2 Linux (and originally uClinux) used a syscall
> calling convention incompatible with the established SH-3/4 Linux ABI.
> This choice was made because the trap range used by the existing ABI,
> 0x10-0x17, overlaps with the hardware exception/interrupt trap range
> reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
> division-overflow exceptions.
> 
> Despite the documented syscall convention using the low bits of the
> trap number to signal the number of arguments the kernel should
> expect, no version of the kernel has ever used this information, nor
> is it useful; all of the registers need to be saved anyway. Therefore,
> it is possible to pick a new trap number, 0x1f, that is both supported
> by all existing SH-3/4 kernels and unassigned as a hardware trap in
> the SH-2 range. This makes it possible to produce SH-2 application
> binaries that are forwards-compatible with running on SH-3/4 kernels
> and to treat SH as a unified platform with varying ISA support levels
> rather than multiple gratuitously-incompatible platforms.
> 
> This patch adjusts the range checking SH-2 and SH-2A kernels make for
> the syscall trap to accept the range 0x1f-0x2f rather than just
> 0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
> models.

Except that sh2 is a nommu platform, requiring different binary formats.
You can't run a standard ELF binary on sh2, and sh3/4 usually don't have
fdpic or elf loaders configured in.

Even if you could, basic system calls like fork() don't work on a nommu
system. The workarounds for fork() not working (re-exec yourself
signaling that this is the second instance, then have main() detect the
signal and call a different entry point) are intrusive and cumbersome
enough that you generally don't want them in programs that _don't_ need
them. Therefore you historically always distinguish at build time
whether to include nommu codepaths or not. This is why uClibc doesn't
include those in nommu builds of the library, so you can easily
comple-time probe for it even when cross compiling.

(Speaking of which, I would very much like to be able to pass a NULL
exec to signal "re-exec this same program" without relying on /proc to
be mounted for /proc/self/exe, but alas the kernel can't do that.)

I agree it doesn't hurt anything (other than new binaries built to use
it not running on old kernels, but that's pretty much the case for fdpic
anyway), but what is the actual _advantage_ of this patch?

Rob

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arch/sh: provide unified syscall trap compatible with all SH models
  2015-08-25 21:23 ` [PATCH v2] " Rich Felker
  2015-09-15  3:17   ` Rob Landley
@ 2015-09-15  4:11   ` Rich Felker
  2015-10-01 22:27     ` Rich Felker
  1 sibling, 1 reply; 8+ messages in thread
From: Rich Felker @ 2015-09-15  4:11 UTC (permalink / raw)
  To: linux-sh
  Cc: linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff, Geert Uytterhoeven

Ping?

On Tue, Aug 25, 2015 at 05:23:11PM -0400, Rich Felker wrote:
> From: Rich Felker <dalias@libc.org>
> 
> Historically SH-2 Linux (and originally uClinux) used a syscall
> calling convention incompatible with the established SH-3/4 Linux ABI.
> This choice was made because the trap range used by the existing ABI,
> 0x10-0x17, overlaps with the hardware exception/interrupt trap range
> reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
> division-overflow exceptions.
> 
> Despite the documented syscall convention using the low bits of the
> trap number to signal the number of arguments the kernel should
> expect, no version of the kernel has ever used this information, nor
> is it useful; all of the registers need to be saved anyway. Therefore,
> it is possible to pick a new trap number, 0x1f, that is both supported
> by all existing SH-3/4 kernels and unassigned as a hardware trap in
> the SH-2 range. This makes it possible to produce SH-2 application
> binaries that are forwards-compatible with running on SH-3/4 kernels
> and to treat SH as a unified platform with varying ISA support levels
> rather than multiple gratuitously-incompatible platforms.
> 
> This patch adjusts the range checking SH-2 and SH-2A kernels make for
> the syscall trap to accept the range 0x1f-0x2f rather than just
> 0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
> models.
> 
> Signed-off-by: Rich Felker <dalias@libc.org>
> 
> ---
> 
> The original proposal for using 0x1f as a unified syscall trap was
> reviewed by Jeff Dionne, Yoshinori Sato, and Shumpei Kawasaki for
> conflicts with existing trap number assignments, and none were found.
> I introduced this proposal as a way to add SH-2 support to musl libc
> in a forwards-compatible way, treating SH as a unified architecture,
> with the particular intent of supporting the Open Processor
> Foundation's J2 Core (SH-2 ISA plus some extensions) and providing a
> smooth upgrade path to the future J4 Core (SH-4 equivalent) and other
> full-fledged SH platforms with MMU.
> 
> There is also some interest in having glibc's SH port support SH-2/J2,
> which is more practical with a common syscall ABI; whether this will
> actually happen remains uncertain.
> 
> Version 2 of the patch addresses issues raised by Geert Uytterhoeven
> with the changes to comments in entry-common.S.
> 
> Rich
> 
> 
> 
> diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S ./arch/sh/kernel/cpu/sh2/entry.S
> --- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S	2015-08-09 19:54:30.000000000 +0000
> +++ ./arch/sh/kernel/cpu/sh2/entry.S	2015-08-24 03:23:34.159387924 +0000
> @@ -144,9 +144,9 @@ ENTRY(exception_handler)
>  	mov	#64,r8
>  	cmp/hs	r8,r9
>  	bt	interrupt_entry	! vec >= 64 is interrupt
> -	mov	#32,r8
> +	mov	#31,r8
>  	cmp/hs	r8,r9
> -	bt	trap_entry	! 64 > vec >= 32  is trap
> +	bt	trap_entry	! 64 > vec >= 31  is trap
>  
>  	mov.l	4f,r8
>  	mov	r9,r4
> @@ -178,9 +178,9 @@ interrupt_entry:
>  
>  trap_entry:
>  	mov	#0x30,r8
> -	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
> +	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
>  	bt	1f
> -	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
> +	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
>  1:	
>  	shll2	r9			! TRA
>  	bra	system_call	! jump common systemcall entry
> diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S ./arch/sh/kernel/cpu/sh2a/entry.S
> --- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S	2015-08-09 19:54:30.000000000 +0000
> +++ ./arch/sh/kernel/cpu/sh2a/entry.S	2015-08-24 03:23:58.849386418 +0000
> @@ -109,9 +109,9 @@ ENTRY(exception_handler)
>  	mov	#64,r8
>  	cmp/hs	r8,r9
>  	bt	interrupt_entry	! vec >= 64 is interrupt
> -	mov	#32,r8
> +	mov	#31,r8
>  	cmp/hs	r8,r9
> -	bt	trap_entry	! 64 > vec >= 32  is trap
> +	bt	trap_entry	! 64 > vec >= 31  is trap
>  
>  	mov.l	4f,r8
>  	mov	r9,r4
> @@ -143,9 +143,9 @@ interrupt_entry:
>  
>  trap_entry:
>  	mov	#0x30,r8
> -	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
> +	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
>  	bt	1f
> -	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
> +	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
>  1:	
>  	shll2	r9			! TRA
>  	bra	system_call	! jump common systemcall entry
> diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S ./arch/sh/kernel/entry-common.S
> --- ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S	2015-08-09 19:54:30.000000000 +0000
> +++ ./arch/sh/kernel/entry-common.S	2015-08-25 21:08:15.835463227 +0000
> @@ -268,20 +268,29 @@ debug_trap:
>   *	Syscall #: R3
>   *	Arguments #0 to #3: R4--R7
>   *	Arguments #4 to #6: R0, R1, R2
> - *	TRA: (number of arguments + ABI revision) x 4
> + *	TRA: See following table.
>   *
> - * This code also handles delegating other traps to the BIOS/gdb stub
> - * according to:
> - *
> - * Trap number
>   * (TRA>>2)	Purpose
>   * --------	-------
>   * 0x00-0x0f	original SH-3/4 syscall ABI (not in general use).
>   * 0x10-0x1f	general SH-3/4 syscall ABI.
> - * 0x20-0x2f	syscall ABI for SH-2 parts.
> + *      0x1f	unified SH-2/3/4 syscall ABI (preferred).
> + * 0x20-0x2f	original SH-2 syscall ABI.
>   * 0x30-0x3f	debug traps used by the kernel.
>   * 0x40-0xff	Not supported by all parts, so left unhandled.
>   *
> + * For making system calls, any trap number in the range for the
> + * given cpu model may be used, but the unified trap number 0x1f is
> + * preferred for compatibility with all models.
> + *
> + * The low bits of the trap number were once documented as matching
> + * the number of arguments, but they were never actually used as such
> + * by the kernel. SH-2 originally used its own separate trap range
> + * because several hardware exceptions fell in the range used for the
> + * SH-3/4 syscall ABI.
> + *
> + * This code also handles delegating other traps to the BIOS/gdb stub.
> + *
>   * Note: When we're first called, the TRA value must be shifted
>   * right 2 bits in order to get the value that was used as the "trapa"
>   * argument.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arch/sh: provide unified syscall trap compatible with all SH models
  2015-09-15  3:17   ` Rob Landley
@ 2015-09-15  4:28     ` Rich Felker
  0 siblings, 0 replies; 8+ messages in thread
From: Rich Felker @ 2015-09-15  4:28 UTC (permalink / raw)
  To: Rob Landley
  Cc: linux-sh, linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff,
	Geert Uytterhoeven

On Mon, Sep 14, 2015 at 10:17:50PM -0500, Rob Landley wrote:
> On 08/25/2015 04:23 PM, Rich Felker wrote:
> > From: Rich Felker <dalias@libc.org>
> > 
> > Historically SH-2 Linux (and originally uClinux) used a syscall
> > calling convention incompatible with the established SH-3/4 Linux ABI.
> > This choice was made because the trap range used by the existing ABI,
> > 0x10-0x17, overlaps with the hardware exception/interrupt trap range
> > reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
> > division-overflow exceptions.
> > 
> > Despite the documented syscall convention using the low bits of the
> > trap number to signal the number of arguments the kernel should
> > expect, no version of the kernel has ever used this information, nor
> > is it useful; all of the registers need to be saved anyway. Therefore,
> > it is possible to pick a new trap number, 0x1f, that is both supported
> > by all existing SH-3/4 kernels and unassigned as a hardware trap in
> > the SH-2 range. This makes it possible to produce SH-2 application
> > binaries that are forwards-compatible with running on SH-3/4 kernels
> > and to treat SH as a unified platform with varying ISA support levels
> > rather than multiple gratuitously-incompatible platforms.
> > 
> > This patch adjusts the range checking SH-2 and SH-2A kernels make for
> > the syscall trap to accept the range 0x1f-0x2f rather than just
> > 0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
> > models.
> 
> Except that sh2 is a nommu platform, requiring different binary formats.
> You can't run a standard ELF binary on sh2,

You can. It's a near-trivial patch to make it work now, though I want
to polish it more before sending it upstream.

> and sh3/4 usually don't have
> fdpic or elf loaders configured in.

The normal ELF loader loads FDPIC just fine; it just doesn't float the
data segment separately. At first it didn't work for me due to
limitations in my entry-point code, but now even qemu-sh4eb runs my
FDPIC binaries fine. Of course it would be really _nice_ to have
separately floating text/data even on systems with MMU. In theory the
code in binfmt_elf_fdpic.c supports this, but it's just not enabled in
kconfig.

> Even if you could, basic system calls like fork() don't work on a nommu
> system.

Obviously programs that need fork will not work. But the vast majority
of software does not need fork -- or if it does need it, is using it
gratuitously, and should be using posix_spawn which would give you
both major performance boosts and NOMMU support.

And of course the other direction, which is the interesting one, of
course works perfectly fine -- software that does not expect fork to
be available because it was built for NOMMU certainly does not care if
fork is available on the system it actually runs on.

> I agree it doesn't hurt anything (other than new binaries built to use
> it not running on old kernels, but that's pretty much the case for fdpic
> anyway), but what is the actual _advantage_ of this patch?

I've been over this many times, but I can summarize again. The big
points are:

- Ability to run & debug the exact same binaries you're going to
  deploy to NOMMU hardware on a much nicer system with memory
  protection, dev tools, etc. (or qemu-sh4eb).

- Establishing SH as a mature, serious platform with ISA levels and
  only minimal hard ABI splits (like endianness, hard/soft float,
  etc.) rather than having each ISA level be its own completely
  separate and incompatible platform.

Do these seem unreasonable?

Rich

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arch/sh: provide unified syscall trap compatible with all SH models
  2015-09-15  4:11   ` Rich Felker
@ 2015-10-01 22:27     ` Rich Felker
  0 siblings, 0 replies; 8+ messages in thread
From: Rich Felker @ 2015-10-01 22:27 UTC (permalink / raw)
  To: linux-sh
  Cc: linux-kernel, shumpei.kawasaki, Yoshinori Sato, jeff, Geert Uytterhoeven

Ping.

On Tue, Sep 15, 2015 at 12:11:24AM -0400, Rich Felker wrote:
> Ping?
> 
> On Tue, Aug 25, 2015 at 05:23:11PM -0400, Rich Felker wrote:
> > From: Rich Felker <dalias@libc.org>
> > 
> > Historically SH-2 Linux (and originally uClinux) used a syscall
> > calling convention incompatible with the established SH-3/4 Linux ABI.
> > This choice was made because the trap range used by the existing ABI,
> > 0x10-0x17, overlaps with the hardware exception/interrupt trap range
> > reserved by SH-2, and in particular, with the SH-2A divide-by-zero and
> > division-overflow exceptions.
> > 
> > Despite the documented syscall convention using the low bits of the
> > trap number to signal the number of arguments the kernel should
> > expect, no version of the kernel has ever used this information, nor
> > is it useful; all of the registers need to be saved anyway. Therefore,
> > it is possible to pick a new trap number, 0x1f, that is both supported
> > by all existing SH-3/4 kernels and unassigned as a hardware trap in
> > the SH-2 range. This makes it possible to produce SH-2 application
> > binaries that are forwards-compatible with running on SH-3/4 kernels
> > and to treat SH as a unified platform with varying ISA support levels
> > rather than multiple gratuitously-incompatible platforms.
> > 
> > This patch adjusts the range checking SH-2 and SH-2A kernels make for
> > the syscall trap to accept the range 0x1f-0x2f rather than just
> > 0x20-0x2f. As a result, trap 0x1f now acts as a syscall for all SH
> > models.
> > 
> > Signed-off-by: Rich Felker <dalias@libc.org>
> > 
> > ---
> > 
> > The original proposal for using 0x1f as a unified syscall trap was
> > reviewed by Jeff Dionne, Yoshinori Sato, and Shumpei Kawasaki for
> > conflicts with existing trap number assignments, and none were found.
> > I introduced this proposal as a way to add SH-2 support to musl libc
> > in a forwards-compatible way, treating SH as a unified architecture,
> > with the particular intent of supporting the Open Processor
> > Foundation's J2 Core (SH-2 ISA plus some extensions) and providing a
> > smooth upgrade path to the future J4 Core (SH-4 equivalent) and other
> > full-fledged SH platforms with MMU.
> > 
> > There is also some interest in having glibc's SH port support SH-2/J2,
> > which is more practical with a common syscall ABI; whether this will
> > actually happen remains uncertain.
> > 
> > Version 2 of the patch addresses issues raised by Geert Uytterhoeven
> > with the changes to comments in entry-common.S.
> > 
> > Rich
> > 
> > 
> > 
> > diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S ./arch/sh/kernel/cpu/sh2/entry.S
> > --- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2/entry.S	2015-08-09 19:54:30.000000000 +0000
> > +++ ./arch/sh/kernel/cpu/sh2/entry.S	2015-08-24 03:23:34.159387924 +0000
> > @@ -144,9 +144,9 @@ ENTRY(exception_handler)
> >  	mov	#64,r8
> >  	cmp/hs	r8,r9
> >  	bt	interrupt_entry	! vec >= 64 is interrupt
> > -	mov	#32,r8
> > +	mov	#31,r8
> >  	cmp/hs	r8,r9
> > -	bt	trap_entry	! 64 > vec >= 32  is trap
> > +	bt	trap_entry	! 64 > vec >= 31  is trap
> >  
> >  	mov.l	4f,r8
> >  	mov	r9,r4
> > @@ -178,9 +178,9 @@ interrupt_entry:
> >  
> >  trap_entry:
> >  	mov	#0x30,r8
> > -	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
> > +	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
> >  	bt	1f
> > -	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
> > +	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
> >  1:	
> >  	shll2	r9			! TRA
> >  	bra	system_call	! jump common systemcall entry
> > diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S ./arch/sh/kernel/cpu/sh2a/entry.S
> > --- ../linux-4.2-rc6.orig/arch/sh/kernel/cpu/sh2a/entry.S	2015-08-09 19:54:30.000000000 +0000
> > +++ ./arch/sh/kernel/cpu/sh2a/entry.S	2015-08-24 03:23:58.849386418 +0000
> > @@ -109,9 +109,9 @@ ENTRY(exception_handler)
> >  	mov	#64,r8
> >  	cmp/hs	r8,r9
> >  	bt	interrupt_entry	! vec >= 64 is interrupt
> > -	mov	#32,r8
> > +	mov	#31,r8
> >  	cmp/hs	r8,r9
> > -	bt	trap_entry	! 64 > vec >= 32  is trap
> > +	bt	trap_entry	! 64 > vec >= 31  is trap
> >  
> >  	mov.l	4f,r8
> >  	mov	r9,r4
> > @@ -143,9 +143,9 @@ interrupt_entry:
> >  
> >  trap_entry:
> >  	mov	#0x30,r8
> > -	cmp/ge	r8,r9		! vector 0x20-0x2f is systemcall
> > +	cmp/ge	r8,r9		! vector 0x1f-0x2f is systemcall
> >  	bt	1f
> > -	add	#-0x10,r9	! convert SH2 to SH3/4 ABI
> > +	mov     #0x1f,r9	! convert to unified SH2/3/4 trap number
> >  1:	
> >  	shll2	r9			! TRA
> >  	bra	system_call	! jump common systemcall entry
> > diff -urp ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S ./arch/sh/kernel/entry-common.S
> > --- ../linux-4.2-rc6.orig/arch/sh/kernel/entry-common.S	2015-08-09 19:54:30.000000000 +0000
> > +++ ./arch/sh/kernel/entry-common.S	2015-08-25 21:08:15.835463227 +0000
> > @@ -268,20 +268,29 @@ debug_trap:
> >   *	Syscall #: R3
> >   *	Arguments #0 to #3: R4--R7
> >   *	Arguments #4 to #6: R0, R1, R2
> > - *	TRA: (number of arguments + ABI revision) x 4
> > + *	TRA: See following table.
> >   *
> > - * This code also handles delegating other traps to the BIOS/gdb stub
> > - * according to:
> > - *
> > - * Trap number
> >   * (TRA>>2)	Purpose
> >   * --------	-------
> >   * 0x00-0x0f	original SH-3/4 syscall ABI (not in general use).
> >   * 0x10-0x1f	general SH-3/4 syscall ABI.
> > - * 0x20-0x2f	syscall ABI for SH-2 parts.
> > + *      0x1f	unified SH-2/3/4 syscall ABI (preferred).
> > + * 0x20-0x2f	original SH-2 syscall ABI.
> >   * 0x30-0x3f	debug traps used by the kernel.
> >   * 0x40-0xff	Not supported by all parts, so left unhandled.
> >   *
> > + * For making system calls, any trap number in the range for the
> > + * given cpu model may be used, but the unified trap number 0x1f is
> > + * preferred for compatibility with all models.
> > + *
> > + * The low bits of the trap number were once documented as matching
> > + * the number of arguments, but they were never actually used as such
> > + * by the kernel. SH-2 originally used its own separate trap range
> > + * because several hardware exceptions fell in the range used for the
> > + * SH-3/4 syscall ABI.
> > + *
> > + * This code also handles delegating other traps to the BIOS/gdb stub.
> > + *
> >   * Note: When we're first called, the TRA value must be shifted
> >   * right 2 bits in order to get the value that was used as the "trapa"
> >   * argument.
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-10-01 22:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-25  3:03 [PATCH] arch/sh: provide unified syscall trap compatible with all SH models Rich Felker
2015-08-25  7:18 ` Geert Uytterhoeven
2015-08-25  7:22   ` Rich Felker
2015-08-25 21:23 ` [PATCH v2] " Rich Felker
2015-09-15  3:17   ` Rob Landley
2015-09-15  4:28     ` Rich Felker
2015-09-15  4:11   ` Rich Felker
2015-10-01 22:27     ` Rich Felker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).