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
47 #if defined(CONFIG_PREEMPT)
48 # define preempt_stop() cli
50 # define preempt_stop()
51 # define resume_kernel __restore_all
56 ENTRY(exception_error)
58 #ifdef CONFIG_TRACE_IRQFLAGS
69 1: .long do_exception_error
70 #ifdef CONFIG_TRACE_IRQFLAGS
71 2: .long trace_hardirqs_on
77 #ifdef CONFIG_TRACE_IRQFLAGS
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
95 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
99 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
100 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
104 mov.l @(r0,r15), r0 ! get status register
105 and #0xf0, r0 ! interrupts off (exception path)?
110 mov.l r0, @(TI_PRE_COUNT,r8)
112 #ifdef CONFIG_TRACE_IRQFLAGS
122 mov.l r0, @(TI_PRE_COUNT,r8)
124 #ifdef CONFIG_TRACE_IRQFLAGS
138 1: .long PREEMPT_ACTIVE
140 #ifdef CONFIG_TRACE_IRQFLAGS
141 3: .long trace_hardirqs_on
142 4: .long trace_hardirqs_off
146 ENTRY(resume_userspace)
147 ! r8: current_thread_info
149 #ifdef CONFIG_TRACE_IRQFLAGS
154 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
155 tst #_TIF_WORK_MASK, r0
157 tst #_TIF_NEED_RESCHED, r0
161 ! r0: current_thread_info->flags
162 ! r8: current_thread_info
163 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
165 tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0
169 mov r12, r5 ! set arg1(save_r0)
180 #ifdef CONFIG_TRACE_IRQFLAGS
186 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
187 tst #_TIF_WORK_MASK, r0
190 tst #_TIF_NEED_RESCHED, r0
194 2: .long do_notify_resume
196 #ifdef CONFIG_TRACE_IRQFLAGS
197 4: .long trace_hardirqs_on
198 5: .long trace_hardirqs_off
203 ! r0: current_thread_info->flags
204 ! r8: current_thread_info
205 tst #_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | _TIF_SYSCALL_AUDIT, r0
207 tst #_TIF_NEED_RESCHED, r0
208 #ifdef CONFIG_TRACE_IRQFLAGS
214 ! XXX setup arguments...
217 mov.l 4f, r0 ! do_syscall_trace
226 ! XXX setup arguments...
229 mov.l 4f, r11 ! Call do_syscall_trace which notifies
230 jsr @r11 ! superior (will chomp R[0-7])
232 ! Reload R0-R4 from kernel stack, where the
233 ! parent may have modified them using
234 ! ptrace(POKEUSR). (Note that R0-R2 are
235 ! used by the system call handler directly
236 ! from the kernel stack anyway, so don't need
237 ! to be reloaded here.) This allows the parent
238 ! to rewrite system calls and args on the fly.
239 mov.l @(OFF_R4,r15), r4 ! arg0
240 mov.l @(OFF_R5,r15), r5
241 mov.l @(OFF_R6,r15), r6
242 mov.l @(OFF_R7,r15), r7 ! arg3
243 mov.l @(OFF_R3,r15), r3 ! syscall_nr
245 mov.l 2f, r10 ! Number of syscalls
250 mov.l r0, @(OFF_R0,r15) ! Return value
261 syscall_badsys: ! Bad syscall number
262 get_current_thread_info r8, r0
265 mov.l r0, @(OFF_R0,r15) ! Return value
268 * The main debug trap handler.
270 * r8=TRA (not the trap number!)
272 * Note: This assumes that the trapa value is left in its original
273 * form (without the shlr2 shift) so the calculation for the jump
274 * call table offset remains a simple in place mask.
288 1: .long debug_trap_table
294 * Arguments #0 to #3: R4--R7
295 * Arguments #4 to #6: R0, R1, R2
296 * TRA: (number of arguments + ABI revision) x 4
298 * This code also handles delegating other traps to the BIOS/gdb stub
304 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
305 * 0x10-0x1f general SH-3/4 syscall ABI.
306 * 0x20-0x2f syscall ABI for SH-2 parts.
307 * 0x30-0x3f debug traps used by the kernel.
308 * 0x40-0xff Not supported by all parts, so left unhandled.
310 * Note: When we're first called, the TRA value must be shifted
311 * right 2 bits in order to get the value that was used as the "trapa"
324 1: .long schedule_tail
327 * The poorly named main trapa decode and dispatch routine, for
328 * system calls and debug traps through their respective jump tables.
331 #if !defined(CONFIG_CPU_SH2)
333 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
336 * Check the trap type
338 mov #((0x20 << 2) - 1), r9
340 bt/s debug_trap ! it's a debug trap..
343 mov.l r8, @r9 ! set TRA value to tra
344 #ifdef CONFIG_TRACE_IRQFLAGS
352 get_current_thread_info r8, r10
353 mov.l @(TI_FLAGS,r8), r8
354 mov #(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT), r10
356 bf syscall_trace_entry
358 mov.l 2f, r8 ! Number of syscalls
364 mov.l 3f, r8 ! Load the address of sys_call_table
367 jsr @r8 ! jump to specific syscall handler
369 mov.l @(OFF_R0,r15), r12 ! save r0
370 mov.l r0, @(OFF_R0,r15) ! save the return value
374 #ifdef CONFIG_TRACE_IRQFLAGS
380 get_current_thread_info r8, r0
381 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
382 tst #_TIF_ALLWORK_MASK, r0
387 #if !defined(CONFIG_CPU_SH2)
391 3: .long sys_call_table
392 4: .long do_syscall_trace
393 #ifdef CONFIG_TRACE_IRQFLAGS
394 5: .long trace_hardirqs_on
395 6: .long trace_hardirqs_off