2 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
3 * Copyright (C) 2003 - 2008 Paul Mundt
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
12 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
13 ! to be jumped is too far, but it causes illegal slot exception.
16 * entry.S contains the system-call and fault low-level handling routines.
17 * This also contains the timer-interrupt handler, as well as all interrupts
18 * and faults that can result in a task-switch.
20 * NOTE: This code handles signal-recognition, which happens every time
21 * after a timer-interrupt and after each system call.
23 * NOTE: This code uses a convention that instructions in the delay slot
24 * of a transfer-control instruction are indented by an extra space, thus:
26 * jmp @k0 ! control-transfer instruction
27 * ldc k1, ssr ! delay slot
29 * Stack layout in 'ret_from_syscall':
30 * ptrace needs to have all regs on the stack.
31 * if the order here is changed, it needs to be
32 * updated in ptrace.c and ptrace.h
46 #include <asm/dwarf.h>
48 #if defined(CONFIG_PREEMPT)
49 # define preempt_stop() cli ; TRACE_IRQS_OFF
51 # define preempt_stop()
52 # define resume_kernel __restore_all
57 ENTRY(exception_error)
66 1: .long do_exception_error
79 mov.l @(r0,r15), r0 ! get status register
81 shll r0 ! kernel space?
82 get_current_thread_info r8, r0
83 bt resume_kernel ! Yes, it's from kernel, go back soon
91 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
95 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
96 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
100 mov.l @(r0,r15), r0 ! get status register
102 and #(0xf0>>1), r0 ! interrupts off (exception path)?
103 cmp/eq #(0xf0>>1), r0
106 jsr @r0 ! call preempt_schedule_irq
116 1: .long PREEMPT_ACTIVE
118 3: .long preempt_schedule_irq
121 ENTRY(resume_userspace)
122 ! r8: current_thread_info
125 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
126 tst #(_TIF_WORK_MASK & 0xff), r0
128 tst #_TIF_NEED_RESCHED, r0
132 ! r0: current_thread_info->flags
133 ! r8: current_thread_info
134 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
136 tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0
140 mov r12, r5 ! set arg1(save_r0)
153 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
154 tst #(_TIF_WORK_MASK & 0xff), r0
157 tst #_TIF_NEED_RESCHED, r0
161 2: .long do_notify_resume
162 3: .long resume_userspace
166 ! r0: current_thread_info->flags
167 ! r8: current_thread_info
168 tst #(_TIF_WORK_SYSCALL_MASK & 0xff), r0
170 tst #_TIF_NEED_RESCHED, r0
174 mov.l 8f, r0 ! do_syscall_trace_leave
184 mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
185 jsr @r11 ! superior (will chomp R[0-7])
187 mov.l r0, @(OFF_R0,r15) ! Save return value
188 ! Reload R0-R4 from kernel stack, where the
189 ! parent may have modified them using
190 ! ptrace(POKEUSR). (Note that R0-R2 are
191 ! used by the system call handler directly
192 ! from the kernel stack anyway, so don't need
193 ! to be reloaded here.) This allows the parent
194 ! to rewrite system calls and args on the fly.
195 mov.l @(OFF_R4,r15), r4 ! arg0
196 mov.l @(OFF_R5,r15), r5
197 mov.l @(OFF_R6,r15), r6
198 mov.l @(OFF_R7,r15), r7 ! arg3
199 mov.l @(OFF_R3,r15), r3 ! syscall_nr
201 mov.l 2f, r10 ! Number of syscalls
206 mov.l r0, @(OFF_R0,r15) ! Return value
210 mov.l @(r0,r15), r0 ! get status register
230 syscall_badsys: ! Bad syscall number
231 get_current_thread_info r8, r0
234 mov.l r0, @(OFF_R0,r15) ! Return value
237 * The main debug trap handler.
239 * r8=TRA (not the trap number!)
241 * Note: This assumes that the trapa value is left in its original
242 * form (without the shlr2 shift) so the calculation for the jump
243 * call table offset remains a simple in place mask.
258 1: .long debug_trap_table
264 * Arguments #0 to #3: R4--R7
265 * Arguments #4 to #6: R0, R1, R2
266 * TRA: (number of arguments + ABI revision) x 4
268 * This code also handles delegating other traps to the BIOS/gdb stub
274 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
275 * 0x10-0x1f general SH-3/4 syscall ABI.
276 * 0x20-0x2f syscall ABI for SH-2 parts.
277 * 0x30-0x3f debug traps used by the kernel.
278 * 0x40-0xff Not supported by all parts, so left unhandled.
280 * Note: When we're first called, the TRA value must be shifted
281 * right 2 bits in order to get the value that was used as the "trapa"
294 1: .long schedule_tail
297 * The poorly named main trapa decode and dispatch routine, for
298 * system calls and debug traps through their respective jump tables.
302 #if !defined(CONFIG_CPU_SH2)
304 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
309 mov.l r8, @r10 ! set TRA value to tra
312 * Check the trap type
314 mov #((0x20 << 2) - 1), r9
316 bt/s debug_trap ! it's a debug trap..
323 get_current_thread_info r8, r10
324 mov.l @(TI_FLAGS,r8), r8
325 mov #(_TIF_WORK_SYSCALL_MASK & 0xff), r10
326 mov #(_TIF_WORK_SYSCALL_MASK >> 8), r9
329 bf syscall_trace_entry
331 bf syscall_trace_entry
333 mov.l 2f, r8 ! Number of syscalls
339 mov.l 3f, r8 ! Load the address of sys_call_table
342 jsr @r8 ! jump to specific syscall handler
344 mov.l @(OFF_R0,r15), r12 ! save r0
345 mov.l r0, @(OFF_R0,r15) ! save the return value
351 get_current_thread_info r8, r0
352 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
353 tst #(_TIF_ALLWORK_MASK & 0xff), r0
354 mov #(_TIF_ALLWORK_MASK >> 8), r1
362 #if !defined(CONFIG_CPU_SH2)
366 3: .long sys_call_table
367 7: .long do_syscall_trace_enter
368 8: .long do_syscall_trace_leave