1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Common Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
4 * (included from entry-<isa>.S
6 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
7 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
10 /*------------------------------------------------------------------
12 *------------------------------------------------------------------
15 * Caller Saved Registers r0 - r12
16 * Callee Saved Registers r13- r25
17 * Global Pointer (gp) r26
18 * Frame Pointer (fp) r27
19 * Stack Pointer (sp) r28
20 * Branch link register (blink) r31
21 *------------------------------------------------------------------
24 ;################### Special Sys Call Wrappers ##########################
26 ENTRY(sys_clone_wrapper)
27 SAVE_CALLEE_SAVED_USER
29 DISCARD_CALLEE_SAVED_USER
31 GET_CURR_THR_INFO_FLAGS r10
32 and.f 0, r10, _TIF_SYSCALL_WORK
35 b .Lret_from_system_call
36 END(sys_clone_wrapper)
38 ENTRY(sys_clone3_wrapper)
39 SAVE_CALLEE_SAVED_USER
41 DISCARD_CALLEE_SAVED_USER
43 GET_CURR_THR_INFO_FLAGS r10
44 and.f 0, r10, _TIF_SYSCALL_WORK
47 b .Lret_from_system_call
48 END(sys_clone3_wrapper)
51 ; when the forked child comes here from the __switch_to function
52 ; r0 has the last task pointer.
53 ; put last task in scheduler queue
56 ld r9, [sp, PT_status32]
59 jl.d [r14] ; kernel thread entry point
60 mov r0, r13 ; (see PF_KTHREAD block in copy_thread)
63 ; Return to user space
64 ; 1. Any forked task (Reach here via BRne above)
65 ; 2. First ever init task (Reach here via return from JL above)
66 ; This is the historic "kernel_execve" use-case, to return to init
67 ; user mode, in a round about way since that is always done from
68 ; a kernel thread which is executed via JL above but always returns
69 ; out whenever kernel_execve (now inline do_fork()) is involved
73 ;################### Non TLB Exception Handling #############################
75 ; ---------------------------------------------
76 ; Instruction Error Exception Handler
77 ; ---------------------------------------------
88 bl do_insterror_or_kprobe
92 ; ---------------------------------------------
93 ; Machine Check Exception Handler
94 ; ---------------------------------------------
96 ENTRY(EV_MachineCheck)
104 ; MC excpetions disable MMU
109 brne r3, ECR_C_MCHK_DUP_TLB, 1f
111 bl do_tlb_overlap_fault
115 ; DEAD END: can't do much, display Regs and HALT
116 SAVE_CALLEE_SAVED_USER
118 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
119 st sp, [r10, THREAD_CALLEE_REG]
121 j do_machine_check_fault
125 ; ---------------------------------------------
126 ; Privilege Violation Exception Handler
127 ; ---------------------------------------------
137 bl do_privilege_fault
141 ; ---------------------------------------------
142 ; Extension Instruction Exception Handler
143 ; ---------------------------------------------
153 bl do_extension_fault
157 ;################ Trap Handling (Syscall, Breakpoint) ##################
159 ; ---------------------------------------------
161 ; ---------------------------------------------
163 ; save EFA in case tracer wants the PC of traced task
164 ; using ERET won't work since next-PC has already committed
165 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
166 st r12, [r11, THREAD_FAULT_ADDR] ; thread.fault_address
168 ; PRE Sys Call Ptrace hook
169 mov r0, sp ; pt_regs needed
170 bl @syscall_trace_entry
172 ; Tracing code now returns the syscall num (orig or modif)
175 ; Do the Sys Call as we normally would.
176 ; Validate the Sys Call number
177 cmp r8, NR_syscalls - 1
181 ; Restore the sys-call args. Mere invocation of the hook abv could have
182 ; clobbered them (since they are in scratch regs). The tracer could also
183 ; have deliberately changed the syscall args: r0-r7
192 ld.as r9, [sys_call_table, r8]
193 jl [r9] ; Entry into Sys Call Handler
196 st r0, [sp, PT_r0] ; sys call return value in pt_regs
198 ;POST Sys Call Ptrace Hook
199 mov r0, sp ; pt_regs needed
200 bl @syscall_trace_exit
201 b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
202 ; we'd done before calling post hook above
204 ; ---------------------------------------------
206 ; ---------------------------------------------
208 mov r0, r12 ; EFA in case ptracer/gdb wants stop_pc
211 ; Save callee regs in case gdb wants to have a look
212 ; SP will grow up by size of CALLEE Reg-File
214 SAVE_CALLEE_SAVED_USER
216 ; save location of saved Callee Regs @ thread_struct->pc
217 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
218 st sp, [r10, THREAD_CALLEE_REG]
220 ; Call the trap handler
223 ; unwind stack to discard Callee saved Regs
224 DISCARD_CALLEE_SAVED_USER
228 ; ---------------------------------------------
230 ; ABI: (r0-r7) upto 8 args, (r8) syscall number
231 ; ---------------------------------------------
241 ;============ TRAP 1 :breakpoints
242 ; Check ECR for trap with arg (PROLOGUE ensures r10 has ECR)
246 ;============ TRAP (no param): syscall top level
248 ; If syscall tracing ongoing, invoke pre-post-hooks
249 GET_CURR_THR_INFO_FLAGS r10
250 and.f 0, r10, _TIF_SYSCALL_WORK
251 bnz tracesys ; this never comes back
253 ;============ Normal syscall case
255 ; syscall num shd not exceed the total system calls avail
256 cmp r8, NR_syscalls - 1
258 bhi .Lret_from_system_call
260 ; Offset into the syscall_table and call handler
261 ld.as r9,[sys_call_table, r8]
262 jl [r9] ; Entry into Sys Call Handler
264 .Lret_from_system_call:
266 st r0, [sp, PT_r0] ; sys call return value in pt_regs
268 ; fall through to ret_from_exception
271 ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
273 ; If ret to user mode do we need to handle signals, schedule() et al.
275 ENTRY(ret_from_exception)
277 ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
278 ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
280 bbit0 r8, STATUS_U_BIT, resume_kernel_mode
282 ; Before returning to User mode check-for-and-complete any pending work
283 ; such as rescheduling/signal-delivery etc.
284 resume_user_mode_begin:
286 ; Disable IRQs to ensures that chk for pending work itself is atomic
287 ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
291 ; Fast Path return to user mode if no pending work
292 GET_CURR_THR_INFO_FLAGS r9
293 and.f 0, r9, _TIF_WORK_MASK
296 ; --- (Slow Path #1) task preemption ---
297 bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
298 mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
299 j @schedule ; BTST+Bnz causes relo error in link
304 ; --- (Slow Path #2) pending signal ---
305 mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
307 GET_CURR_THR_INFO_FLAGS r9
308 and.f 0, r9, _TIF_SIGPENDING|_TIF_NOTIFY_SIGNAL
309 bz .Lchk_notify_resume
311 ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
312 ; in pt_reg since the "C" ABI (kernel code) will automatically
313 ; save/restore callee-saved regs.
315 ; However, here we need to explicitly save callee regs because
316 ; (i) If this signal causes coredump - full regfile needed
317 ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
318 ; tracer might call PEEKUSR(CALLEE reg)
320 ; NOTE: SP will grow up by size of CALLEE Reg-File
321 SAVE_CALLEE_SAVED_USER ; clobbers r12
323 ; save location of saved Callee Regs @ thread_struct->callee
324 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
325 st sp, [r10, THREAD_CALLEE_REG]
329 ; Ideally we want to discard the Callee reg above, however if this was
330 ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
331 RESTORE_CALLEE_SAVED_USER
333 b resume_user_mode_begin ; loop back to start of U mode ret
335 ; --- (Slow Path #3) notify_resume ---
337 btst r9, TIF_NOTIFY_RESUME
338 blnz @do_notify_resume
339 b resume_user_mode_begin ; unconditionally back to U mode ret chks
340 ; for single exit point from this block
344 ; Disable Interrupts from this point on
345 ; CONFIG_PREEMPTION: This is a must for preempt_schedule_irq()
346 ; !CONFIG_PREEMPTION: To ensure restore_regs is intr safe
349 #ifdef CONFIG_PREEMPTION
351 ; Can't preempt if preemption disabled
352 GET_CURR_THR_INFO_FROM_SP r10
353 ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
354 brne r8, 0, .Lrestore_regs
356 ; check if this task's NEED_RESCHED flag set
357 ld r9, [r10, THREAD_INFO_FLAGS]
358 bbit0 r9, TIF_NEED_RESCHED, .Lrestore_regs
361 jl preempt_schedule_irq
363 ; preempt_schedule_irq() always returns with IRQ disabled
368 ##### DONT ADD CODE HERE - .Lrestore_regs actually follows in entry-<isa>.S