2 * Common Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
3 * (included from entry-<isa>.S
5 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
6 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 /*------------------------------------------------------------------
15 *------------------------------------------------------------------
18 * Caller Saved Registers r0 - r12
19 * Callee Saved Registers r13- r25
20 * Global Pointer (gp) r26
21 * Frame Pointer (fp) r27
22 * Stack Pointer (sp) r28
23 * Branch link register (blink) r31
24 *------------------------------------------------------------------
27 ;################### Special Sys Call Wrappers ##########################
29 ENTRY(sys_clone_wrapper)
30 SAVE_CALLEE_SAVED_USER
32 DISCARD_CALLEE_SAVED_USER
34 GET_CURR_THR_INFO_FLAGS r10
35 btst r10, TIF_SYSCALL_TRACE
38 b ret_from_system_call
39 END(sys_clone_wrapper)
42 ; when the forked child comes here from the __switch_to function
43 ; r0 has the last task pointer.
44 ; put last task in scheduler queue
47 ld r9, [sp, PT_status32]
50 jl.d [r14] ; kernel thread entry point
51 mov r0, r13 ; (see PF_KTHREAD block in copy_thread)
54 ; Return to user space
55 ; 1. Any forked task (Reach here via BRne above)
56 ; 2. First ever init task (Reach here via return from JL above)
57 ; This is the historic "kernel_execve" use-case, to return to init
58 ; user mode, in a round about way since that is always done from
59 ; a kernel thread which is executed via JL above but always returns
60 ; out whenever kernel_execve (now inline do_fork()) is involved
64 #ifdef CONFIG_ARC_DW2_UNWIND
65 ; Workaround for bug 94179 (STAR ):
66 ; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
67 ; section (.debug_frame) as loadable. So we force it here.
68 ; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
69 ; would not work after a clean build due to kernel build system dependencies.
70 .section .debug_frame, "wa",@progbits
72 ; Reset to .text as this file is included in entry-<isa>.S
73 .section .text, "ax",@progbits
76 ;################### Non TLB Exception Handling #############################
78 ; ---------------------------------------------
79 ; Instruction Error Exception Handler
80 ; ---------------------------------------------
91 bl do_insterror_or_kprobe
95 ; ---------------------------------------------
96 ; Memory Error Exception Handler
97 ; ---------------------------------------------
112 ; ---------------------------------------------
113 ; Machine Check Exception Handler
114 ; ---------------------------------------------
116 ENTRY(EV_MachineCheck)
126 brne r3, ECR_C_MCHK_DUP_TLB, 1f
128 bl do_tlb_overlap_fault
132 ; DEAD END: can't do much, display Regs and HALT
133 SAVE_CALLEE_SAVED_USER
135 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
136 st sp, [r10, THREAD_CALLEE_REG]
138 j do_machine_check_fault
142 ; ---------------------------------------------
143 ; Privilege Violation Exception Handler
144 ; ---------------------------------------------
154 bl do_privilege_fault
158 ; ---------------------------------------------
159 ; Extension Instruction Exception Handler
160 ; ---------------------------------------------
170 bl do_extension_fault
174 ;################ Trap Handling (Syscall, Breakpoint) ##################
176 ; ---------------------------------------------
178 ; ---------------------------------------------
180 ; save EFA in case tracer wants the PC of traced task
181 ; using ERET won't work since next-PC has already committed
183 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
184 st r12, [r11, THREAD_FAULT_ADDR] ; thread.fault_address
186 ; PRE Sys Call Ptrace hook
187 mov r0, sp ; pt_regs needed
188 bl @syscall_trace_entry
190 ; Tracing code now returns the syscall num (orig or modif)
193 ; Do the Sys Call as we normally would.
194 ; Validate the Sys Call number
199 ; Restore the sys-call args. Mere invocation of the hook abv could have
200 ; clobbered them (since they are in scratch regs). The tracer could also
201 ; have deliberately changed the syscall args: r0-r7
210 ld.as r9, [sys_call_table, r8]
211 jl [r9] ; Entry into Sys Call Handler
214 st r0, [sp, PT_r0] ; sys call return value in pt_regs
216 ;POST Sys Call Ptrace Hook
217 bl @syscall_trace_exit
218 b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
219 ; we'd done before calling post hook above
221 ; ---------------------------------------------
223 ; ---------------------------------------------
226 ; stop_pc info by gdb needs this info
230 ; Now that we have read EFA, it is safe to do "fake" rtie
231 ; and get out of CPU exception mode
234 ; Save callee regs in case gdb wants to have a look
235 ; SP will grow up by size of CALLEE Reg-File
237 SAVE_CALLEE_SAVED_USER
239 ; save location of saved Callee Regs @ thread_struct->pc
240 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
241 st sp, [r10, THREAD_CALLEE_REG]
243 ; Call the trap handler
246 ; unwind stack to discard Callee saved Regs
247 DISCARD_CALLEE_SAVED_USER
251 ; ---------------------------------------------
253 ; ABI: (r0-r7) upto 8 args, (r8) syscall number
254 ; ---------------------------------------------
260 ;============ TRAP 1 :breakpoints
261 ; Check ECR for trap with arg (PROLOGUE ensures r9 has ECR)
265 ;============ TRAP (no param): syscall top level
267 ; First return from Exception to pure K mode (Exception/IRQs renabled)
270 ; If syscall tracing ongoing, invoke pre-post-hooks
271 GET_CURR_THR_INFO_FLAGS r10
272 btst r10, TIF_SYSCALL_TRACE
273 bnz tracesys ; this never comes back
275 ;============ Normal syscall case
277 ; syscall num shd not exceed the total system calls avail
280 bhi ret_from_system_call
282 ; Offset into the syscall_table and call handler
283 ld.as r9,[sys_call_table, r8]
284 jl [r9] ; Entry into Sys Call Handler
286 ; fall through to ret_from_system_call
289 ENTRY(ret_from_system_call)
291 st r0, [sp, PT_r0] ; sys call return value in pt_regs
293 ; fall through yet again to ret_from_exception
295 ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
297 ; If ret to user mode do we need to handle signals, schedule() et al.
299 ENTRY(ret_from_exception)
301 ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
302 ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
304 bbit0 r8, STATUS_U_BIT, resume_kernel_mode
306 ; Before returning to User mode check-for-and-complete any pending work
307 ; such as rescheduling/signal-delivery etc.
308 resume_user_mode_begin:
310 ; Disable IRQs to ensures that chk for pending work itself is atomic
311 ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
315 ; Fast Path return to user mode if no pending work
316 GET_CURR_THR_INFO_FLAGS r9
317 and.f 0, r9, _TIF_WORK_MASK
320 ; --- (Slow Path #1) task preemption ---
321 bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
322 mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
323 b @schedule ; BTST+Bnz causes relo error in link
328 ; --- (Slow Path #2) pending signal ---
329 mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
331 GET_CURR_THR_INFO_FLAGS r9
332 bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
334 ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
335 ; in pt_reg since the "C" ABI (kernel code) will automatically
336 ; save/restore callee-saved regs.
338 ; However, here we need to explicitly save callee regs because
339 ; (i) If this signal causes coredump - full regfile needed
340 ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
341 ; tracer might call PEEKUSR(CALLEE reg)
343 ; NOTE: SP will grow up by size of CALLEE Reg-File
344 SAVE_CALLEE_SAVED_USER ; clobbers r12
346 ; save location of saved Callee Regs @ thread_struct->callee
347 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
348 st sp, [r10, THREAD_CALLEE_REG]
352 ; Ideally we want to discard the Callee reg above, however if this was
353 ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
354 RESTORE_CALLEE_SAVED_USER
356 b resume_user_mode_begin ; loop back to start of U mode ret
358 ; --- (Slow Path #3) notify_resume ---
360 btst r9, TIF_NOTIFY_RESUME
361 blnz @do_notify_resume
362 b resume_user_mode_begin ; unconditionally back to U mode ret chks
363 ; for single exit point from this block
367 ; Disable Interrupts from this point on
368 ; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
369 ; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
372 #ifdef CONFIG_PREEMPT
374 ; Can't preempt if preemption disabled
375 GET_CURR_THR_INFO_FROM_SP r10
376 ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
377 brne r8, 0, .Lrestore_regs
379 ; check if this task's NEED_RESCHED flag set
380 ld r9, [r10, THREAD_INFO_FLAGS]
381 bbit0 r9, TIF_NEED_RESCHED, .Lrestore_regs
384 bl preempt_schedule_irq
386 ; preempt_schedule_irq() always returns with IRQ disabled
391 ##### DONT ADD CODE HERE - .Lrestore_regs actually follows in entry-<isa>.S