1 /* $Id: entry.S,v 1.37 2004/06/11 13:02:46 doyu Exp $
3 * linux/arch/sh/entry.S
5 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
6 * Copyright (C) 2003 Paul Mundt
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
15 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
16 ! to be jumped is too far, but it causes illegal slot exception.
19 * entry.S contains the system-call and fault low-level handling routines.
20 * This also contains the timer-interrupt handler, as well as all interrupts
21 * and faults that can result in a task-switch.
23 * NOTE: This code handles signal-recognition, which happens every time
24 * after a timer-interrupt and after each system call.
26 * NOTE: This code uses a convention that instructions in the delay slot
27 * of a transfer-control instruction are indented by an extra space, thus:
29 * jmp @k0 ! control-transfer instruction
30 * ldc k1, ssr ! delay slot
32 * Stack layout in 'ret_from_syscall':
33 * ptrace needs to have all regs on the stack.
34 * if the order here is changed, it needs to be
35 * updated in ptrace.c and ptrace.h
50 #if defined(CONFIG_PREEMPT)
51 # define preempt_stop() cli
53 # define preempt_stop()
54 # define resume_kernel __restore_all
59 ENTRY(exception_error)
61 #ifdef CONFIG_TRACE_IRQFLAGS
72 1: .long do_exception_error
73 #ifdef CONFIG_TRACE_IRQFLAGS
74 2: .long trace_hardirqs_on
80 #ifdef CONFIG_TRACE_IRQFLAGS
88 mov.l @(r0,r15), r0 ! get status register
90 shll r0 ! kernel space?
91 get_current_thread_info r8, r0
92 bt resume_kernel ! Yes, it's from kernel, go back soon
98 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
102 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
103 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
107 mov.l @(r0,r15), r0 ! get status register
108 and #0xf0, r0 ! interrupts off (exception path)?
113 mov.l r0, @(TI_PRE_COUNT,r8)
115 #ifdef CONFIG_TRACE_IRQFLAGS
125 mov.l r0, @(TI_PRE_COUNT,r8)
127 #ifdef CONFIG_TRACE_IRQFLAGS
141 1: .long PREEMPT_ACTIVE
143 #ifdef CONFIG_TRACE_IRQFLAGS
144 3: .long trace_hardirqs_on
145 4: .long trace_hardirqs_off
149 ENTRY(resume_userspace)
150 ! r8: current_thread_info
152 #ifdef CONFIG_TRACE_IRQFLAGS
157 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
158 tst #_TIF_WORK_MASK, r0
160 tst #_TIF_NEED_RESCHED, r0
164 ! r0: current_thread_info->flags
165 ! r8: current_thread_info
166 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
168 tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0
172 mov r12, r5 ! set arg1(save_r0)
179 #if defined(CONFIG_GUSA) && !defined(CONFIG_PREEMPT)
181 mov.l @(OFF_SP,r15), r0 ! get user space stack pointer
188 ! SP >= 0xc0000000 : gUSA mark
189 mov.l @(r0,r15), r2 ! get user space PC (program counter)
190 mov.l @(OFF_R0,r15), r3 ! end point
191 cmp/hs r3, r2 ! r2 >= r3?
193 add r3, r1 ! rewind point #2
194 mov.l r1, @(r0,r15) ! reset PC to rewind point #2
202 #ifdef CONFIG_TRACE_IRQFLAGS
208 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
209 tst #_TIF_WORK_MASK, r0
212 tst #_TIF_NEED_RESCHED, r0
216 2: .long do_notify_resume
218 #ifdef CONFIG_TRACE_IRQFLAGS
219 4: .long trace_hardirqs_on
220 5: .long trace_hardirqs_off
225 ! r0: current_thread_info->flags
226 ! r8: current_thread_info
227 tst #_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | _TIF_SYSCALL_AUDIT, r0
229 tst #_TIF_NEED_RESCHED, r0
230 #ifdef CONFIG_TRACE_IRQFLAGS
236 ! XXX setup arguments...
239 mov.l 4f, r0 ! do_syscall_trace
248 ! XXX setup arguments...
251 mov.l 4f, r11 ! Call do_syscall_trace which notifies
252 jsr @r11 ! superior (will chomp R[0-7])
254 ! Reload R0-R4 from kernel stack, where the
255 ! parent may have modified them using
256 ! ptrace(POKEUSR). (Note that R0-R2 are
257 ! used by the system call handler directly
258 ! from the kernel stack anyway, so don't need
259 ! to be reloaded here.) This allows the parent
260 ! to rewrite system calls and args on the fly.
261 mov.l @(OFF_R4,r15), r4 ! arg0
262 mov.l @(OFF_R5,r15), r5
263 mov.l @(OFF_R6,r15), r6
264 mov.l @(OFF_R7,r15), r7 ! arg3
265 mov.l @(OFF_R3,r15), r3 ! syscall_nr
267 mov.l 2f, r10 ! Number of syscalls
272 mov.l r0, @(OFF_R0,r15) ! Return value
283 syscall_badsys: ! Bad syscall number
286 mov.l r0, @(OFF_R0,r15) ! Return value
289 * The main debug trap handler.
291 * r8=TRA (not the trap number!)
293 * Note: This assumes that the trapa value is left in its original
294 * form (without the shlr2 shift) so the calculation for the jump
295 * call table offset remains a simple in place mask.
307 1: .long debug_trap_table
313 * Arguments #0 to #3: R4--R7
314 * Arguments #4 to #6: R0, R1, R2
315 * TRA: (number of arguments + ABI revision) x 4
317 * This code also handles delegating other traps to the BIOS/gdb stub
323 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
324 * 0x10-0x1f general SH-3/4 syscall ABI.
325 * 0x20-0x2f syscall ABI for SH-2 parts.
326 * 0x30-0x3f debug traps used by the kernel.
327 * 0x40-0xff Not supported by all parts, so left unhandled.
329 * Note: When we're first called, the TRA value must be shifted
330 * right 2 bits in order to get the value that was used as the "trapa"
343 1: .long schedule_tail
346 * The poorly named main trapa decode and dispatch routine, for
347 * system calls and debug traps through their respective jump tables.
350 #if !defined(CONFIG_CPU_SH2)
352 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
355 * Check the trap type
357 mov #((0x20 << 2) - 1), r9
359 bt/s debug_trap ! it's a debug trap..
362 mov.l r8, @r9 ! set TRA value to tra
363 #ifdef CONFIG_TRACE_IRQFLAGS
371 get_current_thread_info r8, r10
372 mov.l @(TI_FLAGS,r8), r8
373 mov #(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT), r10
375 bf syscall_trace_entry
377 mov.l 2f, r8 ! Number of syscalls
383 mov.l 3f, r8 ! Load the address of sys_call_table
386 jsr @r8 ! jump to specific syscall handler
388 mov.l @(OFF_R0,r15), r12 ! save r0
389 mov.l r0, @(OFF_R0,r15) ! save the return value
393 #ifdef CONFIG_TRACE_IRQFLAGS
399 get_current_thread_info r8, r0
400 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
401 tst #_TIF_ALLWORK_MASK, r0
406 #if !defined(CONFIG_CPU_SH2)
410 3: .long sys_call_table
411 4: .long do_syscall_trace
412 #ifdef CONFIG_TRACE_IRQFLAGS
413 5: .long trace_hardirqs_on
414 6: .long trace_hardirqs_off