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
85 mov.l @(r0,r15), r0 ! get status register
87 shll r0 ! kernel space?
88 get_current_thread_info r8, r0
89 bt resume_kernel ! Yes, it's from kernel, go back soon
97 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
101 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
102 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
106 mov.l @(r0,r15), r0 ! get status register
108 and #(0xf0>>1), r0 ! interrupts off (exception path)?
109 cmp/eq #(0xf0>>1), r0
112 jsr @r0 ! call preempt_schedule_irq
122 1: .long preempt_schedule_irq
125 ENTRY(resume_userspace)
126 ! r8: current_thread_info
129 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
130 tst #(_TIF_WORK_MASK & 0xff), r0
132 tst #_TIF_NEED_RESCHED, r0
136 ! r0: current_thread_info->flags
137 ! r8: current_thread_info
138 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
140 tst #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME), r0
144 mov r12, r5 ! set arg1(save_r0)
158 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
159 tst #(_TIF_WORK_MASK & 0xff), r0
162 tst #_TIF_NEED_RESCHED, r0
166 2: .long do_notify_resume
167 3: .long resume_userspace
171 ! r0: current_thread_info->flags
172 ! r8: current_thread_info
173 tst #(_TIF_WORK_SYSCALL_MASK & 0xff), r0
175 tst #_TIF_NEED_RESCHED, r0
179 mov.l 8f, r0 ! do_syscall_trace_leave
189 mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
190 jsr @r11 ! superior (will chomp R[0-7])
192 mov.l r0, @(OFF_R0,r15) ! Save return value
193 ! Reload R0-R4 from kernel stack, where the
194 ! parent may have modified them using
195 ! ptrace(POKEUSR). (Note that R0-R2 are
196 ! reloaded from the kernel stack by syscall_call
197 ! below, so don't need to be reloaded here.)
198 ! This allows the parent to rewrite system calls
199 ! and args on the fly.
200 mov.l @(OFF_R4,r15), r4 ! arg0
201 mov.l @(OFF_R5,r15), r5
202 mov.l @(OFF_R6,r15), r6
203 mov.l @(OFF_R7,r15), r7 ! arg3
204 mov.l @(OFF_R3,r15), r3 ! syscall_nr
206 mov.l 2f, r10 ! Number of syscalls
211 mov.l r0, @(OFF_R0,r15) ! Return value
215 mov.l @(r0,r15), r0 ! get status register
235 syscall_badsys: ! Bad syscall number
236 get_current_thread_info r8, r0
239 mov.l r0, @(OFF_R0,r15) ! Return value
242 * The main debug trap handler.
244 * r8=TRA (not the trap number!)
246 * Note: This assumes that the trapa value is left in its original
247 * form (without the shlr2 shift) so the calculation for the jump
248 * call table offset remains a simple in place mask.
263 1: .long debug_trap_table
269 * Arguments #0 to #3: R4--R7
270 * Arguments #4 to #6: R0, R1, R2
271 * TRA: See following table.
275 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
276 * 0x10-0x1f general SH-3/4 syscall ABI.
277 * 0x1f unified SH-2/3/4 syscall ABI (preferred).
278 * 0x20-0x2f original SH-2 syscall ABI.
279 * 0x30-0x3f debug traps used by the kernel.
280 * 0x40-0xff Not supported by all parts, so left unhandled.
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.
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.
292 * This code also handles delegating other traps to the BIOS/gdb stub.
294 * Note: When we're first called, the TRA value must be shifted
295 * right 2 bits in order to get the value that was used as the "trapa"
309 .globl ret_from_kernel_thread
310 ret_from_kernel_thread:
314 mov.l @(OFF_R5,r15), r5 ! fn
316 mov.l @(OFF_R4,r15), r4 ! arg
321 1: .long schedule_tail
324 * The poorly named main trapa decode and dispatch routine, for
325 * system calls and debug traps through their respective jump tables.
329 #if !defined(CONFIG_CPU_SH2)
331 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
336 mov.l r8, @r10 ! set TRA value to tra
339 * Check the trap type
341 mov #((0x20 << 2) - 1), r9
343 bt/s debug_trap ! it's a debug trap..
350 get_current_thread_info r8, r10
351 mov.l @(TI_FLAGS,r8), r8
352 mov #(_TIF_WORK_SYSCALL_MASK & 0xff), r10
353 mov #(_TIF_WORK_SYSCALL_MASK >> 8), r9
356 bf syscall_trace_entry
358 bf syscall_trace_entry
360 mov.l 2f, r8 ! Number of syscalls
366 mov.l 3f, r8 ! Load the address of sys_call_table
369 mov.l @(OFF_R2,r15), r2
370 mov.l @(OFF_R1,r15), r1
371 mov.l @(OFF_R0,r15), r0
375 jsr @r8 ! jump to specific syscall handler
378 mov.l @(OFF_R0,r15), r12 ! save r0
379 mov.l r0, @(OFF_R0,r15) ! save the return value
385 get_current_thread_info r8, r0
386 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
387 tst #(_TIF_ALLWORK_MASK & 0xff), r0
388 mov #(_TIF_ALLWORK_MASK >> 8), r1
396 #if !defined(CONFIG_CPU_SH2)
400 3: .long sys_call_table
401 7: .long do_syscall_trace_enter
402 8: .long do_syscall_trace_leave