]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arc/kernel/entry.S
ARC: entry.S: split into ARCompact ISA specific, common bits
[karo-tx-linux.git] / arch / arc / kernel / entry.S
1 /*
2  * Common Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
3  * (included from entry-<isa>.S
4  *
5  * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
6  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
7  *
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.
11  */
12
13 /*------------------------------------------------------------------
14  *    Function                            ABI
15  *------------------------------------------------------------------
16  *
17  *  Arguments                           r0 - r7
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  *------------------------------------------------------------------
25  */
26
27 ;################### Non TLB Exception Handling #############################
28
29 ; ---------------------------------------------
30 ; Instruction Error Exception Handler
31 ; ---------------------------------------------
32
33 ENTRY(instr_service)
34
35         EXCEPTION_PROLOGUE
36
37         lr  r0, [efa]
38         mov r1, sp
39
40         FAKE_RET_FROM_EXCPN
41
42         bl  do_insterror_or_kprobe
43         b   ret_from_exception
44 END(instr_service)
45
46 ; ---------------------------------------------
47 ; Memory Error Exception Handler
48 ; ---------------------------------------------
49
50 ENTRY(mem_service)
51
52         EXCEPTION_PROLOGUE
53
54         lr  r0, [efa]
55         mov r1, sp
56
57         FAKE_RET_FROM_EXCPN
58
59         bl  do_memory_error
60         b   ret_from_exception
61 END(mem_service)
62
63 ; ---------------------------------------------
64 ; Machine Check Exception Handler
65 ; ---------------------------------------------
66
67 ENTRY(EV_MachineCheck)
68
69         EXCEPTION_PROLOGUE
70
71         lr  r2, [ecr]
72         lr  r0, [efa]
73         mov r1, sp
74
75         lsr     r3, r2, 8
76         bmsk    r3, r3, 7
77         brne    r3, ECR_C_MCHK_DUP_TLB, 1f
78
79         bl      do_tlb_overlap_fault
80         b       ret_from_exception
81
82 1:
83         ; DEAD END: can't do much, display Regs and HALT
84         SAVE_CALLEE_SAVED_USER
85
86         GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
87         st  sp, [r10, THREAD_CALLEE_REG]
88
89         j  do_machine_check_fault
90
91 END(EV_MachineCheck)
92
93 ; ---------------------------------------------
94 ; Privilege Violation Exception Handler
95 ; ---------------------------------------------
96 ENTRY(EV_PrivilegeV)
97
98         EXCEPTION_PROLOGUE
99
100         lr  r0, [efa]
101         mov r1, sp
102
103         FAKE_RET_FROM_EXCPN
104
105         bl  do_privilege_fault
106         b   ret_from_exception
107 END(EV_PrivilegeV)
108
109 ; ---------------------------------------------
110 ; Extension Instruction Exception Handler
111 ; ---------------------------------------------
112 ENTRY(EV_Extension)
113
114         EXCEPTION_PROLOGUE
115
116         lr  r0, [efa]
117         mov r1, sp
118
119         FAKE_RET_FROM_EXCPN
120
121         bl  do_extension_fault
122         b   ret_from_exception
123 END(EV_Extension)
124
125 ;################ Trap Handling (Syscall, Breakpoint) ##################
126
127 ; ---------------------------------------------
128 ; syscall Tracing
129 ; ---------------------------------------------
130 tracesys:
131         ; save EFA in case tracer wants the PC of traced task
132         ; using ERET won't work since next-PC has already committed
133         lr  r12, [efa]
134         GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r11
135         st  r12, [r11, THREAD_FAULT_ADDR]       ; thread.fault_address
136
137         ; PRE Sys Call Ptrace hook
138         mov r0, sp                      ; pt_regs needed
139         bl  @syscall_trace_entry
140
141         ; Tracing code now returns the syscall num (orig or modif)
142         mov r8, r0
143
144         ; Do the Sys Call as we normally would.
145         ; Validate the Sys Call number
146         cmp     r8,  NR_syscalls
147         mov.hi  r0, -ENOSYS
148         bhi     tracesys_exit
149
150         ; Restore the sys-call args. Mere invocation of the hook abv could have
151         ; clobbered them (since they are in scratch regs). The tracer could also
152         ; have deliberately changed the syscall args: r0-r7
153         ld  r0, [sp, PT_r0]
154         ld  r1, [sp, PT_r1]
155         ld  r2, [sp, PT_r2]
156         ld  r3, [sp, PT_r3]
157         ld  r4, [sp, PT_r4]
158         ld  r5, [sp, PT_r5]
159         ld  r6, [sp, PT_r6]
160         ld  r7, [sp, PT_r7]
161         ld.as   r9, [sys_call_table, r8]
162         jl      [r9]        ; Entry into Sys Call Handler
163
164 tracesys_exit:
165         st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
166
167         ;POST Sys Call Ptrace Hook
168         bl  @syscall_trace_exit
169         b   ret_from_exception ; NOT ret_from_system_call at is saves r0 which
170         ; we'd done before calling post hook above
171
172 ; ---------------------------------------------
173 ; Breakpoint TRAP
174 ; ---------------------------------------------
175 trap_with_param:
176
177         ; stop_pc info by gdb needs this info
178         lr  r0, [efa]
179         mov r1, sp
180
181         ; Now that we have read EFA, it is safe to do "fake" rtie
182         ;   and get out of CPU exception mode
183         FAKE_RET_FROM_EXCPN
184
185         ; Save callee regs in case gdb wants to have a look
186         ; SP will grow up by size of CALLEE Reg-File
187         ; NOTE: clobbers r12
188         SAVE_CALLEE_SAVED_USER
189
190         ; save location of saved Callee Regs @ thread_struct->pc
191         GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
192         st  sp, [r10, THREAD_CALLEE_REG]
193
194         ; Call the trap handler
195         bl  do_non_swi_trap
196
197         ; unwind stack to discard Callee saved Regs
198         DISCARD_CALLEE_SAVED_USER
199
200         b   ret_from_exception
201
202 ; ---------------------------------------------
203 ; syscall TRAP
204 ; ABI: (r0-r7) upto 8 args, (r8) syscall number
205 ; ---------------------------------------------
206
207 ENTRY(EV_Trap)
208
209         EXCEPTION_PROLOGUE
210
211         ;============ TRAP 1   :breakpoints
212         lr     r10, [ecr]
213         bmsk.f 0, r10, 7
214         bnz    trap_with_param
215
216         ;============ TRAP  (no param): syscall top level
217
218         ; First return from Exception to pure K mode (Exception/IRQs renabled)
219         FAKE_RET_FROM_EXCPN
220
221         ; If syscall tracing ongoing, invoke pre-post-hooks
222         GET_CURR_THR_INFO_FLAGS   r10
223         btst r10, TIF_SYSCALL_TRACE
224         bnz tracesys  ; this never comes back
225
226         ;============ Normal syscall case
227
228         ; syscall num shd not exceed the total system calls avail
229         cmp     r8,  NR_syscalls
230         mov.hi  r0, -ENOSYS
231         bhi     ret_from_system_call
232
233         ; Offset into the syscall_table and call handler
234         ld.as   r9,[sys_call_table, r8]
235         jl      [r9]        ; Entry into Sys Call Handler
236
237         ; fall through to ret_from_system_call
238 END(EV_Trap)
239
240 ENTRY(ret_from_system_call)
241
242         st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
243
244         ; fall through yet again to ret_from_exception
245
246 ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
247 ;
248 ; If ret to user mode do we need to handle signals, schedule() et al.
249
250 ENTRY(ret_from_exception)
251
252         ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
253         ld  r8, [sp, PT_status32]   ; returning to User/Kernel Mode
254
255         bbit0  r8, STATUS_U_BIT, resume_kernel_mode
256
257         ; Before returning to User mode check-for-and-complete any pending work
258         ; such as rescheduling/signal-delivery etc.
259 resume_user_mode_begin:
260
261         ; Disable IRQs to ensures that chk for pending work itself is atomic
262         ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
263         ; interim IRQ).
264         IRQ_DISABLE     r10
265
266         ; Fast Path return to user mode if no pending work
267         GET_CURR_THR_INFO_FLAGS   r9
268         and.f  0,  r9, _TIF_WORK_MASK
269         bz     .Lrestore_regs
270
271         ; --- (Slow Path #1) task preemption ---
272         bbit0  r9, TIF_NEED_RESCHED, .Lchk_pend_signals
273         mov    blink, resume_user_mode_begin  ; tail-call to U mode ret chks
274         b      @schedule        ; BTST+Bnz causes relo error in link
275
276 .Lchk_pend_signals:
277         IRQ_ENABLE      r10
278
279         ; --- (Slow Path #2) pending signal  ---
280         mov r0, sp      ; pt_regs for arg to do_signal()/do_notify_resume()
281
282         GET_CURR_THR_INFO_FLAGS   r9
283         bbit0  r9, TIF_SIGPENDING, .Lchk_notify_resume
284
285         ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
286         ; in pt_reg since the "C" ABI (kernel code) will automatically
287         ; save/restore callee-saved regs.
288         ;
289         ; However, here we need to explicitly save callee regs because
290         ; (i)  If this signal causes coredump - full regfile needed
291         ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
292         ;      tracer might call PEEKUSR(CALLEE reg)
293         ;
294         ; NOTE: SP will grow up by size of CALLEE Reg-File
295         SAVE_CALLEE_SAVED_USER          ; clobbers r12
296
297         ; save location of saved Callee Regs @ thread_struct->callee
298         GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
299         st  sp, [r10, THREAD_CALLEE_REG]
300
301         bl  @do_signal
302
303         ; Ideally we want to discard the Callee reg above, however if this was
304         ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
305         RESTORE_CALLEE_SAVED_USER
306
307         b      resume_user_mode_begin   ; loop back to start of U mode ret
308
309         ; --- (Slow Path #3) notify_resume ---
310 .Lchk_notify_resume:
311         btst   r9, TIF_NOTIFY_RESUME
312         blnz   @do_notify_resume
313         b      resume_user_mode_begin   ; unconditionally back to U mode ret chks
314                                         ; for single exit point from this block
315
316 resume_kernel_mode:
317
318         ; Disable Interrupts from this point on
319         ; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
320         ; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
321         IRQ_DISABLE     r9
322
323 #ifdef CONFIG_PREEMPT
324
325         ; Can't preempt if preemption disabled
326         GET_CURR_THR_INFO_FROM_SP   r10
327         ld  r8, [r10, THREAD_INFO_PREEMPT_COUNT]
328         brne  r8, 0, .Lrestore_regs
329
330         ; check if this task's NEED_RESCHED flag set
331         ld  r9, [r10, THREAD_INFO_FLAGS]
332         bbit0  r9, TIF_NEED_RESCHED, .Lrestore_regs
333
334         ; Invoke PREEMPTION
335         bl      preempt_schedule_irq
336
337         ; preempt_schedule_irq() always returns with IRQ disabled
338 #endif
339
340         b       .Lrestore_regs
341 END(ret_from_exception)
342
343 ENTRY(ret_from_fork)
344         ; when the forked child comes here from the __switch_to function
345         ; r0 has the last task pointer.
346         ; put last task in scheduler queue
347         bl   @schedule_tail
348
349         ld   r9, [sp, PT_status32]
350         brne r9, 0, 1f
351
352         jl.d [r14]              ; kernel thread entry point
353         mov  r0, r13            ; (see PF_KTHREAD block in copy_thread)
354
355 1:
356         ; Return to user space
357         ; 1. Any forked task (Reach here via BRne above)
358         ; 2. First ever init task (Reach here via return from JL above)
359         ;    This is the historic "kernel_execve" use-case, to return to init
360         ;    user mode, in a round about way since that is always done from
361         ;    a kernel thread which is executed via JL above but always returns
362         ;    out whenever kernel_execve (now inline do_fork()) is involved
363         b    ret_from_exception
364 END(ret_from_fork)
365
366 ;################### Special Sys Call Wrappers ##########################
367
368 ENTRY(sys_clone_wrapper)
369         SAVE_CALLEE_SAVED_USER
370         bl  @sys_clone
371         DISCARD_CALLEE_SAVED_USER
372
373         GET_CURR_THR_INFO_FLAGS   r10
374         btst r10, TIF_SYSCALL_TRACE
375         bnz  tracesys_exit
376
377         b ret_from_system_call
378 END(sys_clone_wrapper)
379
380 #ifdef CONFIG_ARC_DW2_UNWIND
381 ; Workaround for bug 94179 (STAR ):
382 ; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
383 ; section (.debug_frame) as loadable. So we force it here.
384 ; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
385 ; would not work after a clean build due to kernel build system dependencies.
386 .section .debug_frame, "wa",@progbits
387
388 ; Reset to .text as this file is included in entry-<isa>.S
389 .section .text, "ax",@progbits
390 #endif