aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRich Felker <dalias@libc.org>2015-12-16 20:04:25 -0500
committerRich Felker <dalias@libc.org>2016-03-17 15:46:06 -0400
commit3623d138213aedf0e2c89720f6a3cd0e164cb310 (patch)
tree09dfa5d4a2610f5b1b9b20e964a0ae82e2f64b61
parent940d4113f3306e07a1f86541489b686d1a979d54 (diff)
sh: provide unified syscall trap compatible with all SH models
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>
-rw-r--r--arch/sh/kernel/cpu/sh2/entry.S8
-rw-r--r--arch/sh/kernel/cpu/sh2a/entry.S8
-rw-r--r--arch/sh/kernel/entry-common.S21
3 files changed, 23 insertions, 14 deletions
diff --git a/arch/sh/kernel/cpu/sh2/entry.S b/arch/sh/kernel/cpu/sh2/entry.S
index c8a4331d9b8d..a1505956ef28 100644
--- a/arch/sh/kernel/cpu/sh2/entry.S
+++ b/arch/sh/kernel/cpu/sh2/entry.S
@@ -144,9 +144,9 @@ ENTRY(exception_handler)
144 mov #64,r8 144 mov #64,r8
145 cmp/hs r8,r9 145 cmp/hs r8,r9
146 bt interrupt_entry ! vec >= 64 is interrupt 146 bt interrupt_entry ! vec >= 64 is interrupt
147 mov #32,r8 147 mov #31,r8
148 cmp/hs r8,r9 148 cmp/hs r8,r9
149 bt trap_entry ! 64 > vec >= 32 is trap 149 bt trap_entry ! 64 > vec >= 31 is trap
150 150
151 mov.l 4f,r8 151 mov.l 4f,r8
152 mov r9,r4 152 mov r9,r4
@@ -178,9 +178,9 @@ interrupt_entry:
178 178
179trap_entry: 179trap_entry:
180 mov #0x30,r8 180 mov #0x30,r8
181 cmp/ge r8,r9 ! vector 0x20-0x2f is systemcall 181 cmp/ge r8,r9 ! vector 0x1f-0x2f is systemcall
182 bt 1f 182 bt 1f
183 add #-0x10,r9 ! convert SH2 to SH3/4 ABI 183 mov #0x1f,r9 ! convert to unified SH2/3/4 trap number
1841: 1841:
185 shll2 r9 ! TRA 185 shll2 r9 ! TRA
186 bra system_call ! jump common systemcall entry 186 bra system_call ! jump common systemcall entry
diff --git a/arch/sh/kernel/cpu/sh2a/entry.S b/arch/sh/kernel/cpu/sh2a/entry.S
index 222742ddc0d6..da77a8ef4696 100644
--- a/arch/sh/kernel/cpu/sh2a/entry.S
+++ b/arch/sh/kernel/cpu/sh2a/entry.S
@@ -109,9 +109,9 @@ ENTRY(exception_handler)
109 mov #64,r8 109 mov #64,r8
110 cmp/hs r8,r9 110 cmp/hs r8,r9
111 bt interrupt_entry ! vec >= 64 is interrupt 111 bt interrupt_entry ! vec >= 64 is interrupt
112 mov #32,r8 112 mov #31,r8
113 cmp/hs r8,r9 113 cmp/hs r8,r9
114 bt trap_entry ! 64 > vec >= 32 is trap 114 bt trap_entry ! 64 > vec >= 31 is trap
115 115
116 mov.l 4f,r8 116 mov.l 4f,r8
117 mov r9,r4 117 mov r9,r4
@@ -143,9 +143,9 @@ interrupt_entry:
143 143
144trap_entry: 144trap_entry:
145 mov #0x30,r8 145 mov #0x30,r8
146 cmp/ge r8,r9 ! vector 0x20-0x2f is systemcall 146 cmp/ge r8,r9 ! vector 0x1f-0x2f is systemcall
147 bt 1f 147 bt 1f
148 add #-0x10,r9 ! convert SH2 to SH3/4 ABI 148 mov #0x1f,r9 ! convert to unified SH2/3/4 trap number
1491: 1491:
150 shll2 r9 ! TRA 150 shll2 r9 ! TRA
151 bra system_call ! jump common systemcall entry 151 bra system_call ! jump common systemcall entry
diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S
index 13047a4facd2..c001f782c5f1 100644
--- a/arch/sh/kernel/entry-common.S
+++ b/arch/sh/kernel/entry-common.S
@@ -268,20 +268,29 @@ debug_trap:
268 * Syscall #: R3 268 * Syscall #: R3
269 * Arguments #0 to #3: R4--R7 269 * Arguments #0 to #3: R4--R7
270 * Arguments #4 to #6: R0, R1, R2 270 * Arguments #4 to #6: R0, R1, R2
271 * TRA: (number of arguments + ABI revision) x 4 271 * TRA: See following table.
272 * 272 *
273 * This code also handles delegating other traps to the BIOS/gdb stub
274 * according to:
275 *
276 * Trap number
277 * (TRA>>2) Purpose 273 * (TRA>>2) Purpose
278 * -------- ------- 274 * -------- -------
279 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use). 275 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
280 * 0x10-0x1f general SH-3/4 syscall ABI. 276 * 0x10-0x1f general SH-3/4 syscall ABI.
281 * 0x20-0x2f syscall ABI for SH-2 parts. 277 * 0x1f unified SH-2/3/4 syscall ABI (preferred).
278 * 0x20-0x2f original SH-2 syscall ABI.
282 * 0x30-0x3f debug traps used by the kernel. 279 * 0x30-0x3f debug traps used by the kernel.
283 * 0x40-0xff Not supported by all parts, so left unhandled. 280 * 0x40-0xff Not supported by all parts, so left unhandled.
284 * 281 *
282 * For making system calls, any trap number in the range for the
283 * given cpu model may be used, but the unified trap number 0x1f is
284 * preferred for compatibility with all models.
285 *
286 * The low bits of the trap number were once documented as matching
287 * the number of arguments, but they were never actually used as such
288 * by the kernel. SH-2 originally used its own separate trap range
289 * because several hardware exceptions fell in the range used for the
290 * SH-3/4 syscall ABI.
291 *
292 * This code also handles delegating other traps to the BIOS/gdb stub.
293 *
285 * Note: When we're first called, the TRA value must be shifted 294 * Note: When we're first called, the TRA value must be shifted
286 * right 2 bits in order to get the value that was used as the "trapa" 295 * right 2 bits in order to get the value that was used as the "trapa"
287 * argument. 296 * argument.