blob: 53655bf4c9d71b96816d1c17006896a0b9ff0d77 [file] [log] [blame]
Vineet Gupta9d42c842013-01-18 15:12:18 +05301/*
2 * Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
3 *
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
Vineet Gupta2e651ea2013-01-23 16:30:36 +053010 * vineetg: May 2011
11 * -Userspace unaligned access emulation
12 *
Vineet Gupta547f1122013-01-18 15:12:22 +053013 * vineetg: Feb 2011 (ptrace low level code fixes)
14 * -traced syscall return code (r0) was not saved into pt_regs for restoring
15 * into user reg-file when traded task rets to user space.
16 * -syscalls needing arch-wrappers (mainly for passing sp as pt_regs)
17 * were not invoking post-syscall trace hook (jumping directly into
18 * ret_from_system_call)
19 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053020 * vineetg: Nov 2010:
21 * -Vector table jumps (@8 bytes) converted into branches (@4 bytes)
22 * -To maintain the slot size of 8 bytes/vector, added nop, which is
23 * not executed at runtime.
24 *
25 * vineetg: Nov 2009 (Everything needed for TIF_RESTORE_SIGMASK)
26 * -do_signal()invoked upon TIF_RESTORE_SIGMASK as well
27 * -Wrappers for sys_{,rt_}sigsuspend() nolonger needed as they don't
28 * need ptregs anymore
29 *
30 * Vineetg: Oct 2009
31 * -In a rare scenario, Process gets a Priv-V exception and gets scheduled
32 * out. Since we don't do FAKE RTIE for Priv-V, CPU excpetion state remains
33 * active (AE bit enabled). This causes a double fault for a subseq valid
34 * exception. Thus FAKE RTIE needed in low level Priv-Violation handler.
35 * Instr Error could also cause similar scenario, so same there as well.
36 *
Vineet Gupta4788a592013-01-18 15:12:22 +053037 * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
38 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053039 * Vineetg: Aug 28th 2008: Bug #94984
40 * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
41 * Normally CPU does this automatically, however when doing FAKE rtie,
42 * we need to explicitly do this. The problem in macros
43 * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
44 * was being "CLEARED" rather then "SET". Since it is Loop INHIBIT Bit,
45 * setting it and not clearing it clears ZOL context
46 *
Vineet Gupta080c3742013-02-11 19:52:57 +053047 * Vineetg: May 16th, 2008
48 * - r25 now contains the Current Task when in kernel
49 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053050 * Vineetg: Dec 22, 2007
51 * Minor Surgery of Low Level ISR to make it SMP safe
52 * - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
53 * - _current_task is made an array of NR_CPUS
54 * - Access of _current_task wrapped inside a macro so that if hardware
55 * team agrees for a dedicated reg, no other code is touched
56 *
57 * Amit Bhor, Rahul Trivedi, Kanika Nema, Sameer Dhavale : Codito Tech 2004
58 */
59
60/*------------------------------------------------------------------
61 * Function ABI
62 *------------------------------------------------------------------
63 *
64 * Arguments r0 - r7
65 * Caller Saved Registers r0 - r12
66 * Callee Saved Registers r13- r25
67 * Global Pointer (gp) r26
68 * Frame Pointer (fp) r27
69 * Stack Pointer (sp) r28
70 * Interrupt link register (ilink1) r29
71 * Interrupt link register (ilink2) r30
72 * Branch link register (blink) r31
73 *------------------------------------------------------------------
74 */
75
76 .cpu A7
77
78;############################ Vector Table #################################
79
80.macro VECTOR lbl
81#if 1 /* Just in case, build breaks */
82 j \lbl
83#else
84 b \lbl
85 nop
86#endif
87.endm
88
89 .section .vector, "ax",@progbits
90 .align 4
91
92/* Each entry in the vector table must occupy 2 words. Since it is a jump
93 * across sections (.vector to .text) we are gauranteed that 'j somewhere'
94 * will use the 'j limm' form of the intrsuction as long as somewhere is in
95 * a section other than .vector.
96 */
97
98; ********* Critical System Events **********************
99VECTOR res_service ; 0x0, Restart Vector (0x0)
100VECTOR mem_service ; 0x8, Mem exception (0x1)
101VECTOR instr_service ; 0x10, Instrn Error (0x2)
102
103; ******************** Device ISRs **********************
Vineet Gupta4788a592013-01-18 15:12:22 +0530104#ifdef CONFIG_ARC_IRQ3_LV2
105VECTOR handle_interrupt_level2
106#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530107VECTOR handle_interrupt_level1
Vineet Gupta4788a592013-01-18 15:12:22 +0530108#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530109
110VECTOR handle_interrupt_level1
111
Vineet Gupta4788a592013-01-18 15:12:22 +0530112#ifdef CONFIG_ARC_IRQ5_LV2
113VECTOR handle_interrupt_level2
114#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530115VECTOR handle_interrupt_level1
Vineet Gupta4788a592013-01-18 15:12:22 +0530116#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530117
Vineet Gupta4788a592013-01-18 15:12:22 +0530118#ifdef CONFIG_ARC_IRQ6_LV2
119VECTOR handle_interrupt_level2
120#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530121VECTOR handle_interrupt_level1
Vineet Gupta4788a592013-01-18 15:12:22 +0530122#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530123
124.rept 25
125VECTOR handle_interrupt_level1 ; Other devices
126.endr
127
128/* FOR ARC600: timer = 0x3, uart = 0x8, emac = 0x10 */
129
130; ******************** Exceptions **********************
131VECTOR EV_MachineCheck ; 0x100, Fatal Machine check (0x20)
132VECTOR EV_TLBMissI ; 0x108, Intruction TLB miss (0x21)
133VECTOR EV_TLBMissD ; 0x110, Data TLB miss (0x22)
134VECTOR EV_TLBProtV ; 0x118, Protection Violation (0x23)
135 ; or Misaligned Access
136VECTOR EV_PrivilegeV ; 0x120, Privilege Violation (0x24)
137VECTOR EV_Trap ; 0x128, Trap exception (0x25)
138VECTOR EV_Extension ; 0x130, Extn Intruction Excp (0x26)
139
140.rept 24
141VECTOR reserved ; Reserved Exceptions
142.endr
143
144#include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
145#include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
146#include <asm/errno.h>
147#include <asm/arcregs.h>
148#include <asm/irqflags.h>
149
150;##################### Scratch Mem for IRQ stack switching #############
151
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530152ARCFP_DATA int1_saved_reg
Vineet Gupta9d42c842013-01-18 15:12:18 +0530153 .align 32
154 .type int1_saved_reg, @object
155 .size int1_saved_reg, 4
156int1_saved_reg:
157 .zero 4
158
Vineet Gupta4788a592013-01-18 15:12:22 +0530159/* Each Interrupt level needs it's own scratch */
160#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
161
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530162ARCFP_DATA int2_saved_reg
Vineet Gupta4788a592013-01-18 15:12:22 +0530163 .type int2_saved_reg, @object
164 .size int2_saved_reg, 4
165int2_saved_reg:
166 .zero 4
167
168#endif
169
Vineet Gupta9d42c842013-01-18 15:12:18 +0530170; ---------------------------------------------
171 .section .text, "ax",@progbits
172
173res_service: ; processor restart
174 flag 0x1 ; not implemented
175 nop
176 nop
177
178reserved: ; processor restart
179 rtie ; jump to processor initializations
180
181;##################### Interrupt Handling ##############################
182
Vineet Gupta4788a592013-01-18 15:12:22 +0530183#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
184; ---------------------------------------------
185; Level 2 ISR: Can interrupt a Level 1 ISR
186; ---------------------------------------------
187ARC_ENTRY handle_interrupt_level2
188
189 ; TODO-vineetg for SMP this wont work
190 ; free up r9 as scratchpad
191 st r9, [@int2_saved_reg]
192
193 ;Which mode (user/kernel) was the system in when intr occured
194 lr r9, [status32_l2]
195
196 SWITCH_TO_KERNEL_STK
197 SAVE_ALL_INT2
198
199 ;------------------------------------------------------
200 ; if L2 IRQ interrupted a L1 ISR, disable preemption
201 ;------------------------------------------------------
202
203 ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
204 bbit0 r9, STATUS_A1_BIT, 1f ; L1 not active when L2 IRQ, so normal
205
206 ; A1 is set in status32_l2
207 ; bump thread_info->preempt_count (Disable preemption)
208 GET_CURR_THR_INFO_FROM_SP r10
209 ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
210 add r9, r9, 1
211 st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
212
2131:
214 ;------------------------------------------------------
215 ; setup params for Linux common ISR and invoke it
216 ;------------------------------------------------------
217 lr r0, [icause2]
218 and r0, r0, 0x1f
219
220 bl.d @arch_do_IRQ
221 mov r1, sp
222
223 mov r8,0x2
224 sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
225
226 b ret_from_exception
227
228ARC_EXIT handle_interrupt_level2
229
230#endif
231
Vineet Gupta9d42c842013-01-18 15:12:18 +0530232; ---------------------------------------------
233; Level 1 ISR
234; ---------------------------------------------
235ARC_ENTRY handle_interrupt_level1
236
237 /* free up r9 as scratchpad */
Vineet Gupta41195d22013-01-18 15:12:23 +0530238#ifdef CONFIG_SMP
239 sr r9, [ARC_REG_SCRATCH_DATA0]
240#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530241 st r9, [@int1_saved_reg]
Vineet Gupta41195d22013-01-18 15:12:23 +0530242#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530243
244 ;Which mode (user/kernel) was the system in when intr occured
245 lr r9, [status32_l1]
246
247 SWITCH_TO_KERNEL_STK
248 SAVE_ALL_INT1
249
250 lr r0, [icause1]
251 and r0, r0, 0x1f
252
253 bl.d @arch_do_IRQ
254 mov r1, sp
255
256 mov r8,0x1
257 sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
258
259 b ret_from_exception
260ARC_EXIT handle_interrupt_level1
261
262;################### Non TLB Exception Handling #############################
263
264; ---------------------------------------------
265; Instruction Error Exception Handler
266; ---------------------------------------------
267
268ARC_ENTRY instr_service
269
270 EXCPN_PROLOG_FREEUP_REG r9
271
272 lr r9, [erstatus]
273
274 SWITCH_TO_KERNEL_STK
275 SAVE_ALL_SYS
276
277 lr r0, [ecr]
278 lr r1, [efa]
279
280 mov r2, sp
281
282 FAKE_RET_FROM_EXCPN r9
283
284 bl do_insterror_or_kprobe
285 b ret_from_exception
286ARC_EXIT instr_service
287
288; ---------------------------------------------
289; Memory Error Exception Handler
290; ---------------------------------------------
291
292ARC_ENTRY mem_service
293
294 EXCPN_PROLOG_FREEUP_REG r9
295
296 lr r9, [erstatus]
297
298 SWITCH_TO_KERNEL_STK
299 SAVE_ALL_SYS
300
301 lr r0, [ecr]
302 lr r1, [efa]
303 mov r2, sp
304 bl do_memory_error
305 b ret_from_exception
306ARC_EXIT mem_service
307
308; ---------------------------------------------
309; Machine Check Exception Handler
310; ---------------------------------------------
311
312ARC_ENTRY EV_MachineCheck
313
314 EXCPN_PROLOG_FREEUP_REG r9
315 lr r9, [erstatus]
316
317 SWITCH_TO_KERNEL_STK
318 SAVE_ALL_SYS
319
320 lr r0, [ecr]
321 lr r1, [efa]
322 mov r2, sp
323
324 brne r0, 0x200100, 1f
325 bl do_tlb_overlap_fault
326 b ret_from_exception
327
3281:
329 ; DEAD END: can't do much, display Regs and HALT
330 SAVE_CALLEE_SAVED_USER
331
332 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
333 st sp, [r10, THREAD_CALLEE_REG]
334
335 j do_machine_check_fault
336
337ARC_EXIT EV_MachineCheck
338
339; ---------------------------------------------
340; Protection Violation Exception Handler
341; ---------------------------------------------
342
343ARC_ENTRY EV_TLBProtV
344
345 EXCPN_PROLOG_FREEUP_REG r9
346
347 ;Which mode (user/kernel) was the system in when Exception occured
348 lr r9, [erstatus]
349
350 SWITCH_TO_KERNEL_STK
351 SAVE_ALL_SYS
352
353 ;---------(3) Save some more regs-----------------
354 ; vineetg: Mar 6th: Random Seg Fault issue #1
355 ; ecr and efa were not saved in case an Intr sneaks in
356 ; after fake rtie
357 ;
Vineet Gupta3e1ae442013-06-12 13:49:02 +0530358 lr r2, [ecr]
359 lr r1, [efa] ; Faulting Data address
Vineet Gupta9d42c842013-01-18 15:12:18 +0530360
361 ; --------(4) Return from CPU Exception Mode ---------
362 ; Fake a rtie, but rtie to next label
363 ; That way, subsequently, do_page_fault ( ) executes in pure kernel
364 ; mode with further Exceptions enabled
365
366 FAKE_RET_FROM_EXCPN r9
367
368 ;------ (5) Type of Protection Violation? ----------
369 ;
370 ; ProtV Hardware Exception is triggered for Access Faults of 2 types
371 ; -Access Violaton (WRITE to READ ONLY Page) - for linux COW
372 ; -Unaligned Access (READ/WRITE on odd boundary)
373 ;
Vineet Gupta3e1ae442013-06-12 13:49:02 +0530374 cmp r2, 0x230400 ; Misaligned data access ?
Vineet Gupta9d42c842013-01-18 15:12:18 +0530375 beq 4f
376
377 ;========= (6a) Access Violation Processing ========
Vineet Gupta9d42c842013-01-18 15:12:18 +0530378 mov r0, sp ; pt_regs
379 bl do_page_fault
380 b ret_from_exception
381
382 ;========== (6b) Non aligned access ============
3834:
Vineet Gupta3e1ae442013-06-12 13:49:02 +0530384 mov r0, r2 ; cause code
Vineet Gupta9d42c842013-01-18 15:12:18 +0530385 mov r2, sp ; pt_regs
386
Vineet Gupta2e651ea2013-01-23 16:30:36 +0530387#ifdef CONFIG_ARC_MISALIGN_ACCESS
388 SAVE_CALLEE_SAVED_USER
389 mov r3, sp ; callee_regs
Vineet Gupta2e651ea2013-01-23 16:30:36 +0530390
Vineet Gupta9d42c842013-01-18 15:12:18 +0530391 bl do_misaligned_access
Vineet Gupta2e651ea2013-01-23 16:30:36 +0530392
Vineet Guptace147c72013-04-06 17:11:58 +0530393 ; TBD: optimize - do this only if a callee reg was involved
394 ; either a dst of emulated LD/ST or src with address-writeback
395 RESTORE_CALLEE_SAVED_USER
Vineet Guptac723ea42013-04-04 14:37:52 +0530396#else
397 bl do_misaligned_error
Vineet Gupta2e651ea2013-01-23 16:30:36 +0530398#endif
399
Vineet Gupta9d42c842013-01-18 15:12:18 +0530400 b ret_from_exception
401
402ARC_EXIT EV_TLBProtV
403
404; ---------------------------------------------
405; Privilege Violation Exception Handler
406; ---------------------------------------------
407ARC_ENTRY EV_PrivilegeV
408
409 EXCPN_PROLOG_FREEUP_REG r9
410
411 lr r9, [erstatus]
412
413 SWITCH_TO_KERNEL_STK
414 SAVE_ALL_SYS
415
416 lr r0, [ecr]
417 lr r1, [efa]
418 mov r2, sp
419
420 FAKE_RET_FROM_EXCPN r9
421
422 bl do_privilege_fault
423 b ret_from_exception
424ARC_EXIT EV_PrivilegeV
425
426; ---------------------------------------------
427; Extension Instruction Exception Handler
428; ---------------------------------------------
429ARC_ENTRY EV_Extension
430
431 EXCPN_PROLOG_FREEUP_REG r9
432 lr r9, [erstatus]
433
434 SWITCH_TO_KERNEL_STK
435 SAVE_ALL_SYS
436
437 lr r0, [ecr]
438 lr r1, [efa]
439 mov r2, sp
440 bl do_extension_fault
441 b ret_from_exception
442ARC_EXIT EV_Extension
443
Vineet Gupta547f1122013-01-18 15:12:22 +0530444;######################### System Call Tracing #########################
445
446tracesys:
447 ; save EFA in case tracer wants the PC of traced task
448 ; using ERET won't work since next-PC has already committed
449 lr r12, [efa]
450 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
Vineet Gupta367f3fc2013-03-20 16:53:14 +0530451 st r12, [r11, THREAD_FAULT_ADDR] ; thread.fault_address
Vineet Gupta547f1122013-01-18 15:12:22 +0530452
453 ; PRE Sys Call Ptrace hook
454 mov r0, sp ; pt_regs needed
455 bl @syscall_trace_entry
456
457 ; Tracing code now returns the syscall num (orig or modif)
458 mov r8, r0
459
460 ; Do the Sys Call as we normally would.
461 ; Validate the Sys Call number
462 cmp r8, NR_syscalls
463 mov.hi r0, -ENOSYS
464 bhi tracesys_exit
465
466 ; Restore the sys-call args. Mere invocation of the hook abv could have
467 ; clobbered them (since they are in scratch regs). The tracer could also
468 ; have deliberately changed the syscall args: r0-r7
469 ld r0, [sp, PT_r0]
470 ld r1, [sp, PT_r1]
471 ld r2, [sp, PT_r2]
472 ld r3, [sp, PT_r3]
473 ld r4, [sp, PT_r4]
474 ld r5, [sp, PT_r5]
475 ld r6, [sp, PT_r6]
476 ld r7, [sp, PT_r7]
477 ld.as r9, [sys_call_table, r8]
478 jl [r9] ; Entry into Sys Call Handler
479
480tracesys_exit:
481 st r0, [sp, PT_r0] ; sys call return value in pt_regs
482
483 ;POST Sys Call Ptrace Hook
484 bl @syscall_trace_exit
485 b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
486 ; we'd done before calling post hook above
487
Vineet Gupta9d42c842013-01-18 15:12:18 +0530488;################### Break Point TRAP ##########################
489
490 ; ======= (5b) Trap is due to Break-Point =========
491
492trap_with_param:
493
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530494 ; stop_pc info by gdb needs this info
Vineet Gupta3eb3e7d2013-02-11 14:40:55 +0530495 stw orig_r8_IS_BRKPT, [sp, PT_orig_r8]
Vineet Gupta9d42c842013-01-18 15:12:18 +0530496
497 mov r0, r12
498 lr r1, [efa]
499 mov r2, sp
500
501 ; Now that we have read EFA, its safe to do "fake" rtie
502 ; and get out of CPU exception mode
503 FAKE_RET_FROM_EXCPN r11
504
505 ; Save callee regs in case gdb wants to have a look
506 ; SP will grow up by size of CALLEE Reg-File
507 ; NOTE: clobbers r12
508 SAVE_CALLEE_SAVED_USER
509
510 ; save location of saved Callee Regs @ thread_struct->pc
511 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
512 st sp, [r10, THREAD_CALLEE_REG]
513
514 ; Call the trap handler
515 bl do_non_swi_trap
516
517 ; unwind stack to discard Callee saved Regs
518 DISCARD_CALLEE_SAVED_USER
519
520 b ret_from_exception
521
522;##################### Trap Handling ##############################
523;
524; EV_Trap caused by TRAP_S and TRAP0 instructions.
525;------------------------------------------------------------------
526; (1) System Calls
527; :parameters in r0-r7.
528; :r8 has the system call number
529; (2) Break Points
530;------------------------------------------------------------------
531
532ARC_ENTRY EV_Trap
533
534 ; Need at least 1 reg to code the early exception prolog
535 EXCPN_PROLOG_FREEUP_REG r9
536
537 ;Which mode (user/kernel) was the system in when intr occured
538 lr r9, [erstatus]
539
540 SWITCH_TO_KERNEL_STK
541 SAVE_ALL_TRAP
542
543 ;------- (4) What caused the Trap --------------
544 lr r12, [ecr]
545 and.f 0, r12, ECR_PARAM_MASK
546 bnz trap_with_param
547
548 ; ======= (5a) Trap is due to System Call ========
549
550 ; Before doing anything, return from CPU Exception Mode
551 FAKE_RET_FROM_EXCPN r11
552
Vineet Gupta547f1122013-01-18 15:12:22 +0530553 ; If syscall tracing ongoing, invoke pre-pos-hooks
554 GET_CURR_THR_INFO_FLAGS r10
555 btst r10, TIF_SYSCALL_TRACE
556 bnz tracesys ; this never comes back
557
Vineet Gupta9d42c842013-01-18 15:12:18 +0530558 ;============ This is normal System Call case ==========
559 ; Sys-call num shd not exceed the total system calls avail
560 cmp r8, NR_syscalls
561 mov.hi r0, -ENOSYS
562 bhi ret_from_system_call
563
564 ; Offset into the syscall_table and call handler
565 ld.as r9,[sys_call_table, r8]
566 jl [r9] ; Entry into Sys Call Handler
567
568 ; fall through to ret_from_system_call
569ARC_EXIT EV_Trap
570
571ARC_ENTRY ret_from_system_call
572
573 st r0, [sp, PT_r0] ; sys call return value in pt_regs
574
575 ; fall through yet again to ret_from_exception
576
577;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
578;
579; If ret to user mode do we need to handle signals, schedule() et al.
580
581ARC_ENTRY ret_from_exception
582
583 ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
584 ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
585
586#ifdef CONFIG_PREEMPT
587 bbit0 r8, STATUS_U_BIT, resume_kernel_mode
588#else
589 bbit0 r8, STATUS_U_BIT, restore_regs
590#endif
591
592 ; Before returning to User mode check-for-and-complete any pending work
593 ; such as rescheduling/signal-delivery etc.
594resume_user_mode_begin:
595
596 ; Disable IRQs to ensures that chk for pending work itself is atomic
597 ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
598 ; interim IRQ).
599 IRQ_DISABLE r10
600
601 ; Fast Path return to user mode if no pending work
602 GET_CURR_THR_INFO_FLAGS r9
603 and.f 0, r9, _TIF_WORK_MASK
604 bz restore_regs
605
606 ; --- (Slow Path #1) task preemption ---
607 bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
608 mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
609 b @schedule ; BTST+Bnz causes relo error in link
610
611.Lchk_pend_signals:
612 IRQ_ENABLE r10
613
614 ; --- (Slow Path #2) pending signal ---
615 mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
616
617 bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
618
Vineet Guptac3581032013-01-18 15:12:19 +0530619 ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
620 ; in pt_reg since the "C" ABI (kernel code) will automatically
621 ; save/restore callee-saved regs.
622 ;
623 ; However, here we need to explicitly save callee regs because
Vineet Gupta9d42c842013-01-18 15:12:18 +0530624 ; (i) If this signal causes coredump - full regfile needed
625 ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
626 ; tracer might call PEEKUSR(CALLEE reg)
627 ;
628 ; NOTE: SP will grow up by size of CALLEE Reg-File
629 SAVE_CALLEE_SAVED_USER ; clobbers r12
630
631 ; save location of saved Callee Regs @ thread_struct->callee
632 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
633 st sp, [r10, THREAD_CALLEE_REG]
634
635 bl @do_signal
636
Vineet Guptac3581032013-01-18 15:12:19 +0530637 ; Ideally we want to discard the Callee reg above, however if this was
638 ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
639 RESTORE_CALLEE_SAVED_USER
Vineet Gupta9d42c842013-01-18 15:12:18 +0530640
641 b resume_user_mode_begin ; loop back to start of U mode ret
642
643 ; --- (Slow Path #3) notify_resume ---
644.Lchk_notify_resume:
645 btst r9, TIF_NOTIFY_RESUME
646 blnz @do_notify_resume
647 b resume_user_mode_begin ; unconditionally back to U mode ret chks
648 ; for single exit point from this block
649
650#ifdef CONFIG_PREEMPT
651
652resume_kernel_mode:
653
654 ; Can't preempt if preemption disabled
655 GET_CURR_THR_INFO_FROM_SP r10
656 ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
657 brne r8, 0, restore_regs
658
659 ; check if this task's NEED_RESCHED flag set
660 ld r9, [r10, THREAD_INFO_FLAGS]
661 bbit0 r9, TIF_NEED_RESCHED, restore_regs
662
663 IRQ_DISABLE r9
664
665 ; Invoke PREEMPTION
666 bl preempt_schedule_irq
667
668 ; preempt_schedule_irq() always returns with IRQ disabled
669#endif
670
671 ; fall through
672
673;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
674;
675; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
676; IRQ shd definitely not happen between now and rtie
677
678restore_regs :
679
680 ; Disable Interrupts while restoring reg-file back
681 ; XXX can this be optimised out
682 IRQ_DISABLE_SAVE r9, r10 ;@r10 has prisitine (pre-disable) copy
683
Vineet Gupta080c3742013-02-11 19:52:57 +0530684#ifdef CONFIG_ARC_CURR_IN_REG
685 ; Restore User R25
686 ; Earlier this used to be only for returning to user mode
687 ; However with 2 levels of IRQ this can also happen even if
688 ; in kernel mode
689 ld r9, [sp, PT_sp]
690 brhs r9, VMALLOC_START, 8f
691 RESTORE_USER_R25
6928:
693#endif
694
Vineet Gupta9d42c842013-01-18 15:12:18 +0530695 ; Restore REG File. In case multiple Events outstanding,
696 ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
697 ; Note that we use realtime STATUS32 (not pt_regs->status32) to
698 ; decide that.
699
700 ; if Returning from Exception
701 bbit0 r10, STATUS_AE_BIT, not_exception
702 RESTORE_ALL_SYS
703 rtie
704
705 ; Not Exception so maybe Interrupts (Level 1 or 2)
706
707not_exception:
708
Vineet Gupta4788a592013-01-18 15:12:22 +0530709#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
710
711 bbit0 r10, STATUS_A2_BIT, not_level2_interrupt
712
713 ;------------------------------------------------------------------
714 ; if L2 IRQ interrupted a L1 ISR, we'd disbaled preemption earlier
715 ; so that sched doesnt move to new task, causing L1 to be delayed
716 ; undeterministically. Now that we've achieved that, lets reset
717 ; things to what they were, before returning from L2 context
718 ;----------------------------------------------------------------
719
Vineet Gupta3eb3e7d2013-02-11 14:40:55 +0530720 ldw r9, [sp, PT_orig_r8] ; get orig_r8 to make sure it is
Vineet Gupta4788a592013-01-18 15:12:22 +0530721 brne r9, orig_r8_IS_IRQ2, 149f ; infact a L2 ISR ret path
722
723 ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
724 bbit0 r9, STATUS_A1_BIT, 149f ; L1 not active when L2 IRQ, so normal
725
726 ; A1 is set in status32_l2
727 ; decrement thread_info->preempt_count (re-enable preemption)
728 GET_CURR_THR_INFO_FROM_SP r10
729 ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
730
731 ; paranoid check, given A1 was active when A2 happened, preempt count
732 ; must not be 0 beccause we would have incremented it.
733 ; If this does happen we simply HALT as it means a BUG !!!
734 cmp r9, 0
735 bnz 2f
736 flag 1
737
7382:
739 sub r9, r9, 1
740 st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
741
742149:
743 ;return from level 2
744 RESTORE_ALL_INT2
745debug_marker_l2:
746 rtie
747
748not_level2_interrupt:
749
750#endif
751
Vineet Gupta9d42c842013-01-18 15:12:18 +0530752 bbit0 r10, STATUS_A1_BIT, not_level1_interrupt
753
754 ;return from level 1
755
756 RESTORE_ALL_INT1
757debug_marker_l1:
758 rtie
759
760not_level1_interrupt:
761
762 ;this case is for syscalls or Exceptions (with fake rtie)
763
764 RESTORE_ALL_SYS
765debug_marker_syscall:
766 rtie
767
768ARC_EXIT ret_from_exception
769
770ARC_ENTRY ret_from_fork
771 ; when the forked child comes here from the __switch_to function
772 ; r0 has the last task pointer.
773 ; put last task in scheduler queue
Vineet Guptabf90e1e2013-01-18 15:12:18 +0530774 bl @schedule_tail
775
776 ; If kernel thread, jump to it's entry-point
777 ld r9, [sp, PT_status32]
778 brne r9, 0, 1f
779
780 jl.d [r14]
781 mov r0, r13 ; arg to payload
782
7831:
784 ; special case of kernel_thread entry point returning back due to
785 ; kernel_execve() - pretend return from syscall to ret to userland
786 b ret_from_exception
Vineet Gupta9d42c842013-01-18 15:12:18 +0530787ARC_EXIT ret_from_fork
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530788
789;################### Special Sys Call Wrappers ##########################
790
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530791ARC_ENTRY sys_clone_wrapper
792 SAVE_CALLEE_SAVED_USER
793 bl @sys_clone
794 DISCARD_CALLEE_SAVED_USER
795
Vineet Gupta547f1122013-01-18 15:12:22 +0530796 GET_CURR_THR_INFO_FLAGS r10
797 btst r10, TIF_SYSCALL_TRACE
798 bnz tracesys_exit
799
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530800 b ret_from_system_call
801ARC_EXIT sys_clone_wrapper
Vineet Gupta854a0d92013-01-22 17:03:19 +0530802
803#ifdef CONFIG_ARC_DW2_UNWIND
804; Workaround for bug 94179 (STAR ):
805; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
806; section (.debug_frame) as loadable. So we force it here.
807; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
808; would not work after a clean build due to kernel build system dependencies.
809.section .debug_frame, "wa",@progbits
810#endif