2008-05-19 18:39:33 +08:00
|
|
|
/*
|
2006-11-05 15:15:19 +08:00
|
|
|
* Copyright (C) 1999, 2000, 2002 Niibe Yutaka
|
2008-05-19 18:39:33 +08:00
|
|
|
* Copyright (C) 2003 - 2008 Paul Mundt
|
2006-11-05 15:15:19 +08:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
! NOTE:
|
|
|
|
! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
|
|
|
|
! to be jumped is too far, but it causes illegal slot exception.
|
|
|
|
|
|
|
|
/*
|
|
|
|
* entry.S contains the system-call and fault low-level handling routines.
|
|
|
|
* This also contains the timer-interrupt handler, as well as all interrupts
|
|
|
|
* and faults that can result in a task-switch.
|
|
|
|
*
|
|
|
|
* NOTE: This code handles signal-recognition, which happens every time
|
|
|
|
* after a timer-interrupt and after each system call.
|
|
|
|
*
|
|
|
|
* NOTE: This code uses a convention that instructions in the delay slot
|
|
|
|
* of a transfer-control instruction are indented by an extra space, thus:
|
|
|
|
*
|
|
|
|
* jmp @k0 ! control-transfer instruction
|
|
|
|
* ldc k1, ssr ! delay slot
|
|
|
|
*
|
|
|
|
* Stack layout in 'ret_from_syscall':
|
|
|
|
* ptrace needs to have all regs on the stack.
|
|
|
|
* if the order here is changed, it needs to be
|
|
|
|
* updated in ptrace.c and ptrace.h
|
|
|
|
*
|
|
|
|
* r0
|
|
|
|
* ...
|
|
|
|
* r15 = stack pointer
|
|
|
|
* spc
|
|
|
|
* pr
|
|
|
|
* ssr
|
|
|
|
* gbr
|
|
|
|
* mach
|
|
|
|
* macl
|
|
|
|
* syscall #
|
|
|
|
*
|
|
|
|
*/
|
2009-08-03 05:40:11 +08:00
|
|
|
#include <asm/dwarf.h>
|
2006-11-05 15:15:19 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_PREEMPT)
|
2009-07-29 22:01:24 +08:00
|
|
|
# define preempt_stop() cli ; TRACE_IRQS_OFF
|
2006-11-05 15:15:19 +08:00
|
|
|
#else
|
|
|
|
# define preempt_stop()
|
|
|
|
# define resume_kernel __restore_all
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
.align 2
|
|
|
|
ENTRY(exception_error)
|
|
|
|
!
|
2009-07-29 22:01:24 +08:00
|
|
|
TRACE_IRQS_ON
|
2006-11-05 15:15:19 +08:00
|
|
|
sti
|
2006-12-13 16:40:05 +08:00
|
|
|
mov.l 1f, r0
|
2006-11-05 15:15:19 +08:00
|
|
|
jmp @r0
|
|
|
|
nop
|
|
|
|
|
|
|
|
.align 2
|
2006-12-13 16:40:05 +08:00
|
|
|
1: .long do_exception_error
|
2006-11-05 15:15:19 +08:00
|
|
|
|
|
|
|
.align 2
|
|
|
|
ret_from_exception:
|
2009-08-03 05:40:11 +08:00
|
|
|
CFI_STARTPROC simple
|
|
|
|
CFI_DEF_CFA r14, 0
|
|
|
|
CFI_REL_OFFSET 17, 64
|
2010-01-28 04:05:20 +08:00
|
|
|
CFI_REL_OFFSET 15, 60
|
2009-08-03 05:40:11 +08:00
|
|
|
CFI_REL_OFFSET 14, 56
|
2010-01-28 04:05:20 +08:00
|
|
|
CFI_REL_OFFSET 13, 52
|
|
|
|
CFI_REL_OFFSET 12, 48
|
|
|
|
CFI_REL_OFFSET 11, 44
|
|
|
|
CFI_REL_OFFSET 10, 40
|
|
|
|
CFI_REL_OFFSET 9, 36
|
|
|
|
CFI_REL_OFFSET 8, 32
|
2006-11-05 15:15:19 +08:00
|
|
|
preempt_stop()
|
|
|
|
ENTRY(ret_from_irq)
|
|
|
|
!
|
|
|
|
mov #OFF_SR, r0
|
|
|
|
mov.l @(r0,r15), r0 ! get status register
|
|
|
|
shll r0
|
|
|
|
shll r0 ! kernel space?
|
|
|
|
get_current_thread_info r8, r0
|
|
|
|
bt resume_kernel ! Yes, it's from kernel, go back soon
|
|
|
|
|
|
|
|
#ifdef CONFIG_PREEMPT
|
|
|
|
bra resume_userspace
|
|
|
|
nop
|
|
|
|
ENTRY(resume_kernel)
|
2008-09-05 13:42:16 +08:00
|
|
|
cli
|
2009-08-18 10:35:09 +08:00
|
|
|
TRACE_IRQS_OFF
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
|
|
|
|
tst r0, r0
|
|
|
|
bf noresched
|
|
|
|
need_resched:
|
|
|
|
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
|
|
|
|
tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
|
|
|
|
bt noresched
|
|
|
|
|
|
|
|
mov #OFF_SR, r0
|
|
|
|
mov.l @(r0,r15), r0 ! get status register
|
2009-08-24 16:09:53 +08:00
|
|
|
shlr r0
|
|
|
|
and #(0xf0>>1), r0 ! interrupts off (exception path)?
|
|
|
|
cmp/eq #(0xf0>>1), r0
|
2006-11-05 15:15:19 +08:00
|
|
|
bt noresched
|
2013-09-18 02:53:09 +08:00
|
|
|
mov.l 1f, r0
|
2008-09-05 13:42:16 +08:00
|
|
|
jsr @r0 ! call preempt_schedule_irq
|
2006-12-04 17:17:28 +08:00
|
|
|
nop
|
2006-11-05 15:15:19 +08:00
|
|
|
bra need_resched
|
|
|
|
nop
|
2006-12-04 17:17:28 +08:00
|
|
|
|
2006-11-05 15:15:19 +08:00
|
|
|
noresched:
|
|
|
|
bra __restore_all
|
|
|
|
nop
|
|
|
|
|
|
|
|
.align 2
|
2013-09-18 02:53:09 +08:00
|
|
|
1: .long preempt_schedule_irq
|
2006-11-05 15:15:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ENTRY(resume_userspace)
|
|
|
|
! r8: current_thread_info
|
|
|
|
cli
|
2009-10-14 14:50:28 +08:00
|
|
|
TRACE_IRQS_OFF
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
|
2009-07-06 19:16:33 +08:00
|
|
|
tst #(_TIF_WORK_MASK & 0xff), r0
|
2006-11-05 15:15:19 +08:00
|
|
|
bt/s __restore_all
|
|
|
|
tst #_TIF_NEED_RESCHED, r0
|
|
|
|
|
|
|
|
.align 2
|
|
|
|
work_pending:
|
|
|
|
! r0: current_thread_info->flags
|
|
|
|
! r8: current_thread_info
|
|
|
|
! t: result of "tst #_TIF_NEED_RESCHED, r0"
|
|
|
|
bf/s work_resched
|
2012-09-18 16:04:37 +08:00
|
|
|
tst #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME), r0
|
2006-11-05 15:15:19 +08:00
|
|
|
work_notifysig:
|
|
|
|
bt/s __restore_all
|
|
|
|
mov r15, r4
|
|
|
|
mov r12, r5 ! set arg1(save_r0)
|
|
|
|
mov r0, r6
|
2012-01-10 15:30:37 +08:00
|
|
|
sti
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l 2f, r1
|
|
|
|
mov.l 3f, r0
|
|
|
|
jmp @r1
|
|
|
|
lds r0, pr
|
|
|
|
work_resched:
|
|
|
|
mov.l 1f, r1
|
|
|
|
jsr @r1 ! schedule
|
|
|
|
nop
|
|
|
|
cli
|
2009-07-29 22:01:24 +08:00
|
|
|
TRACE_IRQS_OFF
|
2006-11-05 15:15:19 +08:00
|
|
|
!
|
|
|
|
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
|
2009-07-06 19:16:33 +08:00
|
|
|
tst #(_TIF_WORK_MASK & 0xff), r0
|
2006-11-05 15:15:19 +08:00
|
|
|
bt __restore_all
|
|
|
|
bra work_pending
|
|
|
|
tst #_TIF_NEED_RESCHED, r0
|
|
|
|
|
|
|
|
.align 2
|
|
|
|
1: .long schedule
|
|
|
|
2: .long do_notify_resume
|
2008-07-17 20:08:40 +08:00
|
|
|
3: .long resume_userspace
|
2006-11-05 15:15:19 +08:00
|
|
|
|
|
|
|
.align 2
|
|
|
|
syscall_exit_work:
|
|
|
|
! r0: current_thread_info->flags
|
|
|
|
! r8: current_thread_info
|
2009-07-06 19:16:33 +08:00
|
|
|
tst #(_TIF_WORK_SYSCALL_MASK & 0xff), r0
|
2006-11-05 15:15:19 +08:00
|
|
|
bt/s work_pending
|
|
|
|
tst #_TIF_NEED_RESCHED, r0
|
2009-07-29 22:01:24 +08:00
|
|
|
TRACE_IRQS_ON
|
2006-11-05 15:15:19 +08:00
|
|
|
sti
|
2007-11-10 18:21:34 +08:00
|
|
|
mov r15, r4
|
2008-07-30 18:55:30 +08:00
|
|
|
mov.l 8f, r0 ! do_syscall_trace_leave
|
2006-11-05 15:15:19 +08:00
|
|
|
jsr @r0
|
|
|
|
nop
|
|
|
|
bra resume_userspace
|
|
|
|
nop
|
|
|
|
|
|
|
|
.align 2
|
|
|
|
syscall_trace_entry:
|
|
|
|
! Yes it is traced.
|
2007-11-10 18:21:34 +08:00
|
|
|
mov r15, r4
|
2008-07-30 18:55:30 +08:00
|
|
|
mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
|
2006-11-05 15:15:19 +08:00
|
|
|
jsr @r11 ! superior (will chomp R[0-7])
|
|
|
|
nop
|
2008-07-30 18:55:30 +08:00
|
|
|
mov.l r0, @(OFF_R0,r15) ! Save return value
|
2006-11-05 15:15:19 +08:00
|
|
|
! Reload R0-R4 from kernel stack, where the
|
|
|
|
! parent may have modified them using
|
|
|
|
! ptrace(POKEUSR). (Note that R0-R2 are
|
sh: push extra copy of r0-r2 for syscall parameters
When invoking syscall handlers on sh32, the saved userspace registers
are at the top of the stack. This seems to have been intentional, as it
is an easy way to pass r0, r1, ... to the handler as parameters 5, 6,
...
It causes problems, however, because the compiler is allowed to generate
code for a function which clobbers that function's own parameters. For
example, gcc generates the following code for clone:
<SyS_clone>:
mov.l 8c020714 <SyS_clone+0xc>,r1 ! 8c020540 <do_fork>
mov.l r7,@r15
mov r6,r7
jmp @r1
mov #0,r6
nop
.word 0x0540
.word 0x8c02
The `mov.l r7,@r15` clobbers the saved value of r0 passed from
userspace. For most system calls, this might not be a problem, because
we'll be overwriting r0 with the return value anyway. But in the case
of clone, copy_thread will need the original value of r0 if the
CLONE_SETTLS flag was specified.
The first patch in this series fixes this issue for system calls by
pushing to the stack and extra copy of r0-r2 before invoking the
handler. We discard this copy before restoring the userspace registers,
so it is not a problem if they are clobbered.
Exception handlers also receive the userspace register values in a
similar manner, and may hit the same problem. The second patch removes
the do_fpu_error handler, which looks susceptible to this problem and
which, as far as I can tell, has not been used in some time. The third
patch addresses other exception handlers.
This patch (of 3):
The userspace registers are stored at the top of the stack when the
syscall handler is invoked, which allows r0-r2 to act as parameters 5-7.
Parameters passed on the stack may be clobbered by the syscall handler.
The solution is to push an extra copy of the registers which might be
used as syscall parameters to the stack, so that the authoritative set
of saved register values does not get clobbered.
A few system call handlers are also updated to get the userspace
registers using current_pt_regs() instead of from the stack.
Signed-off-by: Bobby Bingham <koorogi@koorogi.info>
Cc: Paul Mundt <paul.mundt@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-04 05:46:39 +08:00
|
|
|
! reloaded from the kernel stack by syscall_call
|
|
|
|
! below, so don't need to be reloaded here.)
|
|
|
|
! This allows the parent to rewrite system calls
|
|
|
|
! and args on the fly.
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l @(OFF_R4,r15), r4 ! arg0
|
|
|
|
mov.l @(OFF_R5,r15), r5
|
|
|
|
mov.l @(OFF_R6,r15), r6
|
|
|
|
mov.l @(OFF_R7,r15), r7 ! arg3
|
|
|
|
mov.l @(OFF_R3,r15), r3 ! syscall_nr
|
2006-11-24 12:01:36 +08:00
|
|
|
!
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l 2f, r10 ! Number of syscalls
|
|
|
|
cmp/hs r10, r3
|
|
|
|
bf syscall_call
|
|
|
|
mov #-ENOSYS, r0
|
|
|
|
bra syscall_exit
|
|
|
|
mov.l r0, @(OFF_R0,r15) ! Return value
|
|
|
|
|
|
|
|
__restore_all:
|
2009-08-18 10:35:09 +08:00
|
|
|
mov #OFF_SR, r0
|
|
|
|
mov.l @(r0,r15), r0 ! get status register
|
|
|
|
|
|
|
|
shlr2 r0
|
|
|
|
and #0x3c, r0
|
|
|
|
cmp/eq #0x3c, r0
|
|
|
|
bt 1f
|
|
|
|
TRACE_IRQS_ON
|
|
|
|
bra 2f
|
|
|
|
nop
|
|
|
|
1:
|
|
|
|
TRACE_IRQS_OFF
|
|
|
|
2:
|
|
|
|
mov.l 3f, r0
|
2006-11-05 15:15:19 +08:00
|
|
|
jmp @r0
|
|
|
|
nop
|
|
|
|
|
|
|
|
.align 2
|
2009-08-18 10:35:09 +08:00
|
|
|
3: .long restore_all
|
2006-11-05 15:15:19 +08:00
|
|
|
|
2006-11-24 12:01:36 +08:00
|
|
|
.align 2
|
|
|
|
syscall_badsys: ! Bad syscall number
|
2008-05-15 12:30:05 +08:00
|
|
|
get_current_thread_info r8, r0
|
2006-11-24 12:01:36 +08:00
|
|
|
mov #-ENOSYS, r0
|
|
|
|
bra resume_userspace
|
|
|
|
mov.l r0, @(OFF_R0,r15) ! Return value
|
2006-12-13 16:40:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The main debug trap handler.
|
|
|
|
*
|
|
|
|
* r8=TRA (not the trap number!)
|
|
|
|
*
|
|
|
|
* Note: This assumes that the trapa value is left in its original
|
|
|
|
* form (without the shlr2 shift) so the calculation for the jump
|
|
|
|
* call table offset remains a simple in place mask.
|
|
|
|
*/
|
|
|
|
debug_trap:
|
|
|
|
mov r8, r0
|
|
|
|
and #(0xf << 2), r0
|
|
|
|
mov.l 1f, r8
|
|
|
|
add r0, r8
|
|
|
|
mov.l @r8, r8
|
2008-05-19 18:39:33 +08:00
|
|
|
jsr @r8
|
|
|
|
nop
|
2018-03-16 08:01:36 +08:00
|
|
|
bra ret_from_exception
|
2006-12-13 16:40:05 +08:00
|
|
|
nop
|
2009-08-03 05:40:11 +08:00
|
|
|
CFI_ENDPROC
|
2006-12-13 16:40:05 +08:00
|
|
|
|
|
|
|
.align 2
|
|
|
|
1: .long debug_trap_table
|
2006-11-24 12:01:36 +08:00
|
|
|
|
2006-11-05 15:15:19 +08:00
|
|
|
/*
|
|
|
|
* Syscall interface:
|
|
|
|
*
|
|
|
|
* Syscall #: R3
|
|
|
|
* Arguments #0 to #3: R4--R7
|
|
|
|
* Arguments #4 to #6: R0, R1, R2
|
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>
2015-12-17 09:04:25 +08:00
|
|
|
* TRA: See following table.
|
2006-11-05 15:15:19 +08:00
|
|
|
*
|
2006-12-13 16:40:05 +08:00
|
|
|
* (TRA>>2) Purpose
|
|
|
|
* -------- -------
|
|
|
|
* 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
|
|
|
|
* 0x10-0x1f general SH-3/4 syscall ABI.
|
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>
2015-12-17 09:04:25 +08:00
|
|
|
* 0x1f unified SH-2/3/4 syscall ABI (preferred).
|
|
|
|
* 0x20-0x2f original SH-2 syscall ABI.
|
2006-12-13 16:40:05 +08:00
|
|
|
* 0x30-0x3f debug traps used by the kernel.
|
|
|
|
* 0x40-0xff Not supported by all parts, so left unhandled.
|
2006-11-05 15:15:19 +08:00
|
|
|
*
|
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>
2015-12-17 09:04:25 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2006-11-05 15:15:19 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
.align 2
|
|
|
|
.globl ret_from_fork
|
|
|
|
ret_from_fork:
|
|
|
|
mov.l 1f, r8
|
|
|
|
jsr @r8
|
|
|
|
mov r0, r4
|
|
|
|
bra syscall_exit
|
|
|
|
nop
|
2012-10-14 13:41:42 +08:00
|
|
|
|
|
|
|
.align 2
|
|
|
|
.globl ret_from_kernel_thread
|
|
|
|
ret_from_kernel_thread:
|
|
|
|
mov.l 1f, r8
|
|
|
|
jsr @r8
|
|
|
|
mov r0, r4
|
|
|
|
mov.l @(OFF_R5,r15), r5 ! fn
|
|
|
|
jsr @r5
|
|
|
|
mov.l @(OFF_R4,r15), r4 ! arg
|
|
|
|
bra syscall_exit
|
|
|
|
nop
|
|
|
|
|
2006-11-05 15:15:19 +08:00
|
|
|
.align 2
|
|
|
|
1: .long schedule_tail
|
2006-12-13 16:40:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The poorly named main trapa decode and dispatch routine, for
|
|
|
|
* system calls and debug traps through their respective jump tables.
|
|
|
|
*/
|
2006-11-05 15:15:19 +08:00
|
|
|
ENTRY(system_call)
|
2009-08-03 05:33:26 +08:00
|
|
|
setup_frame_reg
|
2006-11-05 15:15:19 +08:00
|
|
|
#if !defined(CONFIG_CPU_SH2)
|
|
|
|
mov.l 1f, r9
|
|
|
|
mov.l @r9, r8 ! Read from TRA (Trap Address) Register
|
|
|
|
#endif
|
2008-12-11 17:46:46 +08:00
|
|
|
|
|
|
|
mov #OFF_TRA, r10
|
|
|
|
add r15, r10
|
|
|
|
mov.l r8, @r10 ! set TRA value to tra
|
|
|
|
|
2006-12-13 16:40:05 +08:00
|
|
|
/*
|
|
|
|
* Check the trap type
|
|
|
|
*/
|
|
|
|
mov #((0x20 << 2) - 1), r9
|
2006-11-05 15:15:19 +08:00
|
|
|
cmp/hi r9, r8
|
2006-12-13 16:40:05 +08:00
|
|
|
bt/s debug_trap ! it's a debug trap..
|
2008-12-11 17:46:46 +08:00
|
|
|
nop
|
|
|
|
|
2009-07-29 22:01:24 +08:00
|
|
|
TRACE_IRQS_ON
|
2006-11-05 15:15:19 +08:00
|
|
|
sti
|
2006-12-04 17:17:28 +08:00
|
|
|
|
2006-11-05 15:15:19 +08:00
|
|
|
!
|
2006-11-24 12:01:36 +08:00
|
|
|
get_current_thread_info r8, r10
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l @(TI_FLAGS,r8), r8
|
2009-07-06 19:16:33 +08:00
|
|
|
mov #(_TIF_WORK_SYSCALL_MASK & 0xff), r10
|
|
|
|
mov #(_TIF_WORK_SYSCALL_MASK >> 8), r9
|
2006-11-05 15:15:19 +08:00
|
|
|
tst r10, r8
|
2009-07-06 19:16:33 +08:00
|
|
|
shll8 r9
|
|
|
|
bf syscall_trace_entry
|
|
|
|
tst r9, r8
|
2006-11-05 15:15:19 +08:00
|
|
|
bf syscall_trace_entry
|
|
|
|
!
|
2006-11-24 12:01:36 +08:00
|
|
|
mov.l 2f, r8 ! Number of syscalls
|
|
|
|
cmp/hs r8, r3
|
|
|
|
bt syscall_badsys
|
|
|
|
!
|
2006-11-05 15:15:19 +08:00
|
|
|
syscall_call:
|
2006-11-24 12:01:36 +08:00
|
|
|
shll2 r3 ! x4
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l 3f, r8 ! Load the address of sys_call_table
|
2006-11-24 12:01:36 +08:00
|
|
|
add r8, r3
|
|
|
|
mov.l @r3, r8
|
sh: push extra copy of r0-r2 for syscall parameters
When invoking syscall handlers on sh32, the saved userspace registers
are at the top of the stack. This seems to have been intentional, as it
is an easy way to pass r0, r1, ... to the handler as parameters 5, 6,
...
It causes problems, however, because the compiler is allowed to generate
code for a function which clobbers that function's own parameters. For
example, gcc generates the following code for clone:
<SyS_clone>:
mov.l 8c020714 <SyS_clone+0xc>,r1 ! 8c020540 <do_fork>
mov.l r7,@r15
mov r6,r7
jmp @r1
mov #0,r6
nop
.word 0x0540
.word 0x8c02
The `mov.l r7,@r15` clobbers the saved value of r0 passed from
userspace. For most system calls, this might not be a problem, because
we'll be overwriting r0 with the return value anyway. But in the case
of clone, copy_thread will need the original value of r0 if the
CLONE_SETTLS flag was specified.
The first patch in this series fixes this issue for system calls by
pushing to the stack and extra copy of r0-r2 before invoking the
handler. We discard this copy before restoring the userspace registers,
so it is not a problem if they are clobbered.
Exception handlers also receive the userspace register values in a
similar manner, and may hit the same problem. The second patch removes
the do_fpu_error handler, which looks susceptible to this problem and
which, as far as I can tell, has not been used in some time. The third
patch addresses other exception handlers.
This patch (of 3):
The userspace registers are stored at the top of the stack when the
syscall handler is invoked, which allows r0-r2 to act as parameters 5-7.
Parameters passed on the stack may be clobbered by the syscall handler.
The solution is to push an extra copy of the registers which might be
used as syscall parameters to the stack, so that the authoritative set
of saved register values does not get clobbered.
A few system call handlers are also updated to get the userspace
registers using current_pt_regs() instead of from the stack.
Signed-off-by: Bobby Bingham <koorogi@koorogi.info>
Cc: Paul Mundt <paul.mundt@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-04 05:46:39 +08:00
|
|
|
mov.l @(OFF_R2,r15), r2
|
|
|
|
mov.l @(OFF_R1,r15), r1
|
|
|
|
mov.l @(OFF_R0,r15), r0
|
|
|
|
mov.l r2, @-r15
|
|
|
|
mov.l r1, @-r15
|
|
|
|
mov.l r0, @-r15
|
2006-11-05 15:15:19 +08:00
|
|
|
jsr @r8 ! jump to specific syscall handler
|
|
|
|
nop
|
sh: push extra copy of r0-r2 for syscall parameters
When invoking syscall handlers on sh32, the saved userspace registers
are at the top of the stack. This seems to have been intentional, as it
is an easy way to pass r0, r1, ... to the handler as parameters 5, 6,
...
It causes problems, however, because the compiler is allowed to generate
code for a function which clobbers that function's own parameters. For
example, gcc generates the following code for clone:
<SyS_clone>:
mov.l 8c020714 <SyS_clone+0xc>,r1 ! 8c020540 <do_fork>
mov.l r7,@r15
mov r6,r7
jmp @r1
mov #0,r6
nop
.word 0x0540
.word 0x8c02
The `mov.l r7,@r15` clobbers the saved value of r0 passed from
userspace. For most system calls, this might not be a problem, because
we'll be overwriting r0 with the return value anyway. But in the case
of clone, copy_thread will need the original value of r0 if the
CLONE_SETTLS flag was specified.
The first patch in this series fixes this issue for system calls by
pushing to the stack and extra copy of r0-r2 before invoking the
handler. We discard this copy before restoring the userspace registers,
so it is not a problem if they are clobbered.
Exception handlers also receive the userspace register values in a
similar manner, and may hit the same problem. The second patch removes
the do_fpu_error handler, which looks susceptible to this problem and
which, as far as I can tell, has not been used in some time. The third
patch addresses other exception handlers.
This patch (of 3):
The userspace registers are stored at the top of the stack when the
syscall handler is invoked, which allows r0-r2 to act as parameters 5-7.
Parameters passed on the stack may be clobbered by the syscall handler.
The solution is to push an extra copy of the registers which might be
used as syscall parameters to the stack, so that the authoritative set
of saved register values does not get clobbered.
A few system call handlers are also updated to get the userspace
registers using current_pt_regs() instead of from the stack.
Signed-off-by: Bobby Bingham <koorogi@koorogi.info>
Cc: Paul Mundt <paul.mundt@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-04 05:46:39 +08:00
|
|
|
add #12, r15
|
2006-11-05 15:15:19 +08:00
|
|
|
mov.l @(OFF_R0,r15), r12 ! save r0
|
|
|
|
mov.l r0, @(OFF_R0,r15) ! save the return value
|
|
|
|
!
|
|
|
|
syscall_exit:
|
|
|
|
cli
|
2009-07-29 22:01:24 +08:00
|
|
|
TRACE_IRQS_OFF
|
2006-11-05 15:15:19 +08:00
|
|
|
!
|
|
|
|
get_current_thread_info r8, r0
|
|
|
|
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
|
2009-07-06 19:16:33 +08:00
|
|
|
tst #(_TIF_ALLWORK_MASK & 0xff), r0
|
|
|
|
mov #(_TIF_ALLWORK_MASK >> 8), r1
|
|
|
|
bf syscall_exit_work
|
|
|
|
shlr8 r0
|
|
|
|
tst r0, r1
|
2006-11-05 15:15:19 +08:00
|
|
|
bf syscall_exit_work
|
|
|
|
bra __restore_all
|
|
|
|
nop
|
|
|
|
.align 2
|
|
|
|
#if !defined(CONFIG_CPU_SH2)
|
|
|
|
1: .long TRA
|
|
|
|
#endif
|
|
|
|
2: .long NR_syscalls
|
|
|
|
3: .long sys_call_table
|
2008-07-30 18:55:30 +08:00
|
|
|
7: .long do_syscall_trace_enter
|
|
|
|
8: .long do_syscall_trace_leave
|