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
|
2006-12-04 17:17:28 +08:00
|
|
|
mov.l 3f, 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
|
|
|
|
1: .long PREEMPT_ACTIVE
|
|
|
|
2: .long schedule
|
2008-09-05 13:42:16 +08:00
|
|
|
3: .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
|
2009-10-14 15:05:42 +08:00
|
|
|
tst #_TIF_SIGPENDING, 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
|
|
|
|
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
|
|
|
|
! used by the system call handler directly
|
|
|
|
! from the kernel stack anyway, so don't need
|
|
|
|
! to be reloaded here.) This allows the parent
|
|
|
|
! to rewrite system calls and args on the fly.
|
|
|
|
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
|
|
|
|
bra __restore_all
|
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
|
2006-12-13 16:40:05 +08:00
|
|
|
* TRA: (number of arguments + ABI revision) x 4
|
2006-11-05 15:15:19 +08:00
|
|
|
*
|
|
|
|
* This code also handles delegating other traps to the BIOS/gdb stub
|
|
|
|
* according to:
|
|
|
|
*
|
|
|
|
* Trap number
|
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.
|
|
|
|
* 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.
|
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
|
|
|
|
.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
|
2006-11-05 15:15:19 +08:00
|
|
|
jsr @r8 ! jump to specific syscall handler
|
|
|
|
nop
|
|
|
|
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
|