1 /* SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
4 * Copyright (C) 2003 - 2008 Paul Mundt
8 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
9 ! to be jumped is too far, but it causes illegal slot exception.
12 * entry.S contains the system-call and fault low-level handling routines.
13 * This also contains the timer-interrupt handler, as well as all interrupts
14 * and faults that can result in a task-switch.
16 * NOTE: This code handles signal-recognition, which happens every time
17 * after a timer-interrupt and after each system call.
19 * NOTE: This code uses a convention that instructions in the delay slot
20 * of a transfer-control instruction are indented by an extra space, thus:
22 * jmp @k0 ! control-transfer instruction
23 * ldc k1, ssr ! delay slot
25 * Stack layout in 'ret_from_syscall':
26 * ptrace needs to have all regs on the stack.
27 * if the order here is changed, it needs to be
28 * updated in ptrace.c and ptrace.h
42 #include <asm/dwarf.h>
44 #if defined(CONFIG_PREEMPTION)
45 # define preempt_stop() cli ; TRACE_IRQS_OFF
47 # define preempt_stop()
48 # define resume_kernel __restore_all
53 ENTRY(exception_error)
62 1: .long do_exception_error
81 mov.l @(r0,r15), r0 ! get status register
83 shll r0 ! kernel space?
84 get_current_thread_info r8, r0
85 bt resume_kernel ! Yes, it's from kernel, go back soon
87 #ifdef CONFIG_PREEMPTION
93 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
97 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
98 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
102 mov.l @(r0,r15), r0 ! get status register
104 and #(0xf0>>1), r0 ! interrupts off (exception path)?
105 cmp/eq #(0xf0>>1), r0
108 jsr @r0 ! call preempt_schedule_irq
118 1: .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_NOTIFY_RESUME), r0
140 mov r12, r5 ! set arg1(save_r0)
154 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
155 tst #(_TIF_WORK_MASK & 0xff), r0
158 tst #_TIF_NEED_RESCHED, r0
162 2: .long do_notify_resume
163 3: .long resume_userspace
167 ! r0: current_thread_info->flags
168 ! r8: current_thread_info
169 tst #(_TIF_WORK_SYSCALL_MASK & 0xff), r0
171 tst #_TIF_NEED_RESCHED, r0
175 mov.l 8f, r0 ! do_syscall_trace_leave
183 mov.l @(r0,r15), r0 ! get status register
203 syscall_badsys: ! Bad syscall number
204 get_current_thread_info r8, r0
207 mov.l r0, @(OFF_R0,r15) ! Return value
210 * The main debug trap handler.
212 * r8=TRA (not the trap number!)
214 * Note: This assumes that the trapa value is left in its original
215 * form (without the shlr2 shift) so the calculation for the jump
216 * call table offset remains a simple in place mask.
226 bra ret_from_exception
231 1: .long debug_trap_table
237 * Arguments #0 to #3: R4--R7
238 * Arguments #4 to #6: R0, R1, R2
239 * TRA: See following table.
243 * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
244 * 0x10-0x1f general SH-3/4 syscall ABI.
245 * 0x1f unified SH-2/3/4 syscall ABI (preferred).
246 * 0x20-0x2f original SH-2 syscall ABI.
247 * 0x30-0x3f debug traps used by the kernel.
248 * 0x40-0xff Not supported by all parts, so left unhandled.
250 * For making system calls, any trap number in the range for the
251 * given cpu model may be used, but the unified trap number 0x1f is
252 * preferred for compatibility with all models.
254 * The low bits of the trap number were once documented as matching
255 * the number of arguments, but they were never actually used as such
256 * by the kernel. SH-2 originally used its own separate trap range
257 * because several hardware exceptions fell in the range used for the
258 * SH-3/4 syscall ABI.
260 * This code also handles delegating other traps to the BIOS/gdb stub.
262 * Note: When we're first called, the TRA value must be shifted
263 * right 2 bits in order to get the value that was used as the "trapa"
277 .globl ret_from_kernel_thread
278 ret_from_kernel_thread:
282 mov.l @(OFF_R5,r15), r5 ! fn
284 mov.l @(OFF_R4,r15), r4 ! arg
289 1: .long schedule_tail
292 * The poorly named main trapa decode and dispatch routine, for
293 * system calls and debug traps through their respective jump tables.
297 #if !defined(CONFIG_CPU_SH2)
299 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
304 mov.l r8, @r10 ! set TRA value to tra
307 * Check the trap type
309 mov #((0x20 << 2) - 1), r9
311 bt/s debug_trap ! it's a debug trap..
318 get_current_thread_info r8, r10
319 mov.l @(TI_FLAGS,r8), r8
320 mov #(_TIF_WORK_SYSCALL_MASK & 0xff), r10
321 mov #(_TIF_WORK_SYSCALL_MASK >> 8), r9
324 bf syscall_trace_entry
326 bf syscall_trace_entry
328 mov.l 6f, r8 ! Number of syscalls
334 mov.l 3f, r8 ! Load the address of sys_call_table
337 mov.l @(OFF_R2,r15), r2
338 mov.l @(OFF_R1,r15), r1
339 mov.l @(OFF_R0,r15), r0
343 jsr @r8 ! jump to specific syscall handler
346 mov.l @(OFF_R0,r15), r12 ! save r0
347 mov.l r0, @(OFF_R0,r15) ! save the return value
353 get_current_thread_info r8, r0
354 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
355 tst #(_TIF_ALLWORK_MASK & 0xff), r0
356 mov #(_TIF_ALLWORK_MASK >> 8), r1
368 mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
369 jsr @r11 ! superior (will chomp R[0-7])
373 ! Reload R0-R4 from kernel stack, where the
374 ! parent may have modified them using
375 ! ptrace(POKEUSR). (Note that R0-R2 are
376 ! reloaded from the kernel stack by syscall_call
377 ! below, so don't need to be reloaded here.)
378 ! This allows the parent to rewrite system calls
379 ! and args on the fly.
380 mov.l @(OFF_R4,r15), r4 ! arg0
381 mov.l @(OFF_R5,r15), r5
382 mov.l @(OFF_R6,r15), r6
383 mov.l @(OFF_R7,r15), r7 ! arg3
384 mov.l @(OFF_R3,r15), r3 ! syscall_nr
386 mov.l 6f, r10 ! Number of syscalls
391 mov.l r0, @(OFF_R0,r15) ! Return value
394 #if !defined(CONFIG_CPU_SH2)
398 3: .long sys_call_table
399 7: .long do_syscall_trace_enter
400 8: .long do_syscall_trace_leave