• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
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 *
10 * vineetg: May 2011
11 *  -Userspace unaligned access emulation
12 *
13 * 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 *
20 * 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 *
37 * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
38 *
39 * 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 *
47 * Vineetg: May 16th, 2008
48 *  - r25 now contains the Current Task when in kernel
49 *
50 * 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 **********************
104#ifdef CONFIG_ARC_IRQ3_LV2
105VECTOR   handle_interrupt_level2
106#else
107VECTOR   handle_interrupt_level1
108#endif
109
110VECTOR   handle_interrupt_level1
111
112#ifdef CONFIG_ARC_IRQ5_LV2
113VECTOR   handle_interrupt_level2
114#else
115VECTOR   handle_interrupt_level1
116#endif
117
118#ifdef CONFIG_ARC_IRQ6_LV2
119VECTOR   handle_interrupt_level2
120#else
121VECTOR   handle_interrupt_level1
122#endif
123
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>   /* {EXTRY,EXIT} */
145#include <asm/entry.h>       /* SAVE_ALL_{INT1,INT2,SYS...} */
146#include <asm/errno.h>
147#include <asm/arcregs.h>
148#include <asm/irqflags.h>
149
150;##################### Scratch Mem for IRQ stack switching #############
151
152ARCFP_DATA int1_saved_reg
153	.align 32
154	.type   int1_saved_reg, @object
155	.size   int1_saved_reg, 4
156int1_saved_reg:
157	.zero 4
158
159/* Each Interrupt level needs its own scratch */
160#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
161
162ARCFP_DATA int2_saved_reg
163	.type   int2_saved_reg, @object
164	.size   int2_saved_reg, 4
165int2_saved_reg:
166	.zero 4
167
168#endif
169
170; ---------------------------------------------
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
183#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
184; ---------------------------------------------
185;  Level 2 ISR: Can interrupt a Level 1 ISR
186; ---------------------------------------------
187ENTRY(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
228END(handle_interrupt_level2)
229
230#endif
231
232; ---------------------------------------------
233;  Level 1 ISR
234; ---------------------------------------------
235ENTRY(handle_interrupt_level1)
236
237	/* free up r9 as scratchpad */
238#ifdef CONFIG_SMP
239	sr  r9, [ARC_REG_SCRATCH_DATA0]
240#else
241	st   r9, [@int1_saved_reg]
242#endif
243
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#ifdef CONFIG_TRACE_IRQFLAGS
254	; icause1 needs to be read early, before calling tracing, which
255	; can clobber scratch regs, hence use of stack to stash it
256	push r0
257	TRACE_ASM_IRQ_DISABLE
258	pop  r0
259#endif
260
261	bl.d  @arch_do_IRQ
262	mov r1, sp
263
264	mov r8,0x1
265	sr r8, [AUX_IRQ_LV12]       ; clear bit in Sticky Status Reg
266
267	b   ret_from_exception
268END(handle_interrupt_level1)
269
270;################### Non TLB Exception Handling #############################
271
272; ---------------------------------------------
273; Instruction Error Exception Handler
274; ---------------------------------------------
275
276ENTRY(instr_service)
277
278	EXCEPTION_PROLOGUE
279
280	lr  r0, [efa]
281	mov r1, sp
282
283	FAKE_RET_FROM_EXCPN r9
284
285	bl  do_insterror_or_kprobe
286	b   ret_from_exception
287END(instr_service)
288
289; ---------------------------------------------
290; Memory Error Exception Handler
291; ---------------------------------------------
292
293ENTRY(mem_service)
294
295	EXCEPTION_PROLOGUE
296
297	lr  r0, [efa]
298	mov r1, sp
299
300	FAKE_RET_FROM_EXCPN r9
301
302	bl  do_memory_error
303	b   ret_from_exception
304END(mem_service)
305
306; ---------------------------------------------
307; Machine Check Exception Handler
308; ---------------------------------------------
309
310ENTRY(EV_MachineCheck)
311
312	EXCEPTION_PROLOGUE
313
314	lr  r2, [ecr]
315	lr  r0, [efa]
316	mov r1, sp
317
318	; hardware auto-disables MMU, re-enable it to allow kernel vaddr
319	; access for say stack unwinding of modules for crash dumps
320	lr	r3, [ARC_REG_PID]
321	or	r3, r3, MMU_ENABLE
322	sr	r3, [ARC_REG_PID]
323
324	lsr  	r3, r2, 8
325	bmsk 	r3, r3, 7
326	brne    r3, ECR_C_MCHK_DUP_TLB, 1f
327
328	bl      do_tlb_overlap_fault
329	b       ret_from_exception
330
3311:
332	; DEAD END: can't do much, display Regs and HALT
333	SAVE_CALLEE_SAVED_USER
334
335	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
336	st  sp, [r10, THREAD_CALLEE_REG]
337
338	j  do_machine_check_fault
339
340END(EV_MachineCheck)
341
342; ---------------------------------------------
343; Protection Violation Exception Handler
344; ---------------------------------------------
345
346ENTRY(EV_TLBProtV)
347
348	EXCEPTION_PROLOGUE
349
350	;---------(3) Save some more regs-----------------
351	;  vineetg: Mar 6th: Random Seg Fault issue #1
352	;  ecr and efa were not saved in case an Intr sneaks in
353	;  after fake rtie
354
355	lr  r2, [ecr]
356	lr  r0, [efa]	; Faulting Data address
357
358	; --------(4) Return from CPU Exception Mode ---------
359	;  Fake a rtie, but rtie to next label
360	;  That way, subsequently, do_page_fault ( ) executes in pure kernel
361	;  mode with further Exceptions enabled
362
363	FAKE_RET_FROM_EXCPN r9
364
365	mov   r1, sp
366
367	;------ (5) Type of Protection Violation? ----------
368	;
369	; ProtV Hardware Exception is triggered for Access Faults of 2 types
370	;   -Access Violaton	: 00_23_(00|01|02|03)_00
371	;			         x  r  w  r+w
372	;   -Unaligned Access	: 00_23_04_00
373	;
374	bbit1 r2, ECR_C_BIT_PROTV_MISALIG_DATA, 4f
375
376	;========= (6a) Access Violation Processing ========
377	bl  do_page_fault
378	b   ret_from_exception
379
380	;========== (6b) Non aligned access ============
3814:
382
383	SAVE_CALLEE_SAVED_USER
384	mov r2, sp              ; callee_regs
385
386	bl  do_misaligned_access
387
388	; TBD: optimize - do this only if a callee reg was involved
389	; either a dst of emulated LD/ST or src with address-writeback
390	RESTORE_CALLEE_SAVED_USER
391
392	b   ret_from_exception
393
394END(EV_TLBProtV)
395
396; ---------------------------------------------
397; Privilege Violation Exception Handler
398; ---------------------------------------------
399ENTRY(EV_PrivilegeV)
400
401	EXCEPTION_PROLOGUE
402
403	lr  r0, [efa]
404	mov r1, sp
405
406	FAKE_RET_FROM_EXCPN r9
407
408	bl  do_privilege_fault
409	b   ret_from_exception
410END(EV_PrivilegeV)
411
412; ---------------------------------------------
413; Extension Instruction Exception Handler
414; ---------------------------------------------
415ENTRY(EV_Extension)
416
417	EXCEPTION_PROLOGUE
418
419	lr  r0, [efa]
420	mov r1, sp
421
422	FAKE_RET_FROM_EXCPN r9
423
424	bl  do_extension_fault
425	b   ret_from_exception
426END(EV_Extension)
427
428;######################### System Call Tracing #########################
429
430tracesys:
431	; save EFA in case tracer wants the PC of traced task
432	; using ERET won't work since next-PC has already committed
433	lr  r12, [efa]
434	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r11
435	st  r12, [r11, THREAD_FAULT_ADDR]	; thread.fault_address
436
437	; PRE Sys Call Ptrace hook
438	mov r0, sp			; pt_regs needed
439	bl  @syscall_trace_entry
440
441	; Tracing code now returns the syscall num (orig or modif)
442	mov r8, r0
443
444	; Do the Sys Call as we normally would.
445	; Validate the Sys Call number
446	cmp     r8,  NR_syscalls
447	mov.hi  r0, -ENOSYS
448	bhi     tracesys_exit
449
450	; Restore the sys-call args. Mere invocation of the hook abv could have
451	; clobbered them (since they are in scratch regs). The tracer could also
452	; have deliberately changed the syscall args: r0-r7
453	ld  r0, [sp, PT_r0]
454	ld  r1, [sp, PT_r1]
455	ld  r2, [sp, PT_r2]
456	ld  r3, [sp, PT_r3]
457	ld  r4, [sp, PT_r4]
458	ld  r5, [sp, PT_r5]
459	ld  r6, [sp, PT_r6]
460	ld  r7, [sp, PT_r7]
461	ld.as   r9, [sys_call_table, r8]
462	jl      [r9]        ; Entry into Sys Call Handler
463
464tracesys_exit:
465	st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
466
467	;POST Sys Call Ptrace Hook
468	bl  @syscall_trace_exit
469	b   ret_from_exception ; NOT ret_from_system_call at is saves r0 which
470	; we'd done before calling post hook above
471
472;################### Break Point TRAP ##########################
473
474	; ======= (5b) Trap is due to Break-Point =========
475
476trap_with_param:
477
478	; stop_pc info by gdb needs this info
479	lr  r0, [efa]
480	mov r1, sp
481
482	; Now that we have read EFA, it is safe to do "fake" rtie
483	;   and get out of CPU exception mode
484	FAKE_RET_FROM_EXCPN r11
485
486	; Save callee regs in case gdb wants to have a look
487	; SP will grow up by size of CALLEE Reg-File
488	; NOTE: clobbers r12
489	SAVE_CALLEE_SAVED_USER
490
491	; save location of saved Callee Regs @ thread_struct->pc
492	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
493	st  sp, [r10, THREAD_CALLEE_REG]
494
495	; Call the trap handler
496	bl  do_non_swi_trap
497
498	; unwind stack to discard Callee saved Regs
499	DISCARD_CALLEE_SAVED_USER
500
501	b   ret_from_exception
502
503;##################### Trap Handling ##############################
504;
505; EV_Trap caused by TRAP_S and TRAP0 instructions.
506;------------------------------------------------------------------
507;   (1) System Calls
508;       :parameters in r0-r7.
509;       :r8 has the system call number
510;   (2) Break Points
511;------------------------------------------------------------------
512
513ENTRY(EV_Trap)
514
515	EXCEPTION_PROLOGUE
516
517	;------- (4) What caused the Trap --------------
518	lr     r12, [ecr]
519	bmsk.f 0, r12, 7
520	bnz    trap_with_param
521
522	; ======= (5a) Trap is due to System Call ========
523
524	; Before doing anything, return from CPU Exception Mode
525	FAKE_RET_FROM_EXCPN r11
526
527	; If syscall tracing ongoing, invoke pre-pos-hooks
528	GET_CURR_THR_INFO_FLAGS   r10
529	btst r10, TIF_SYSCALL_TRACE
530	bnz tracesys  ; this never comes back
531
532	;============ This is normal System Call case ==========
533	; Sys-call num shd not exceed the total system calls avail
534	cmp     r8,  NR_syscalls
535	mov.hi  r0, -ENOSYS
536	bhi     ret_from_system_call
537
538	; Offset into the syscall_table and call handler
539	ld.as   r9,[sys_call_table, r8]
540	jl      [r9]        ; Entry into Sys Call Handler
541
542	; fall through to ret_from_system_call
543END(EV_Trap)
544
545ENTRY(ret_from_system_call)
546
547	st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
548
549	; fall through yet again to ret_from_exception
550
551;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
552;
553; If ret to user mode do we need to handle signals, schedule() et al.
554
555ENTRY(ret_from_exception)
556
557	; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
558	ld  r8, [sp, PT_status32]   ; returning to User/Kernel Mode
559
560	bbit0  r8, STATUS_U_BIT, resume_kernel_mode
561
562	; Before returning to User mode check-for-and-complete any pending work
563	; such as rescheduling/signal-delivery etc.
564resume_user_mode_begin:
565
566	; Disable IRQs to ensures that chk for pending work itself is atomic
567	; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
568	; interim IRQ).
569	IRQ_DISABLE	r10
570
571	; Fast Path return to user mode if no pending work
572	GET_CURR_THR_INFO_FLAGS   r9
573	and.f  0,  r9, _TIF_WORK_MASK
574	bz     restore_regs
575
576	; --- (Slow Path #1) task preemption ---
577	bbit0  r9, TIF_NEED_RESCHED, .Lchk_pend_signals
578	mov    blink, resume_user_mode_begin  ; tail-call to U mode ret chks
579	b      @schedule 	; BTST+Bnz causes relo error in link
580
581.Lchk_pend_signals:
582	IRQ_ENABLE	r10
583
584	; --- (Slow Path #2) pending signal  ---
585	mov r0, sp	; pt_regs for arg to do_signal()/do_notify_resume()
586
587	GET_CURR_THR_INFO_FLAGS   r9
588	bbit0  r9, TIF_SIGPENDING, .Lchk_notify_resume
589
590	; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
591	; in pt_reg since the "C" ABI (kernel code) will automatically
592	; save/restore callee-saved regs.
593	;
594	; However, here we need to explicitly save callee regs because
595	; (i)  If this signal causes coredump - full regfile needed
596	; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
597	;      tracer might call PEEKUSR(CALLEE reg)
598	;
599	; NOTE: SP will grow up by size of CALLEE Reg-File
600	SAVE_CALLEE_SAVED_USER		; clobbers r12
601
602	; save location of saved Callee Regs @ thread_struct->callee
603	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
604	st  sp, [r10, THREAD_CALLEE_REG]
605
606	bl  @do_signal
607
608	; Ideally we want to discard the Callee reg above, however if this was
609	; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
610	RESTORE_CALLEE_SAVED_USER
611
612	b      resume_user_mode_begin	; loop back to start of U mode ret
613
614	; --- (Slow Path #3) notify_resume ---
615.Lchk_notify_resume:
616	btst   r9, TIF_NOTIFY_RESUME
617	blnz   @do_notify_resume
618	b      resume_user_mode_begin	; unconditionally back to U mode ret chks
619					; for single exit point from this block
620
621resume_kernel_mode:
622
623	; Disable Interrupts from this point on
624	; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
625	; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
626	IRQ_DISABLE	r9
627
628#ifdef CONFIG_PREEMPT
629
630	; Can't preempt if preemption disabled
631	GET_CURR_THR_INFO_FROM_SP   r10
632	ld  r8, [r10, THREAD_INFO_PREEMPT_COUNT]
633	brne  r8, 0, restore_regs
634
635	; check if this task's NEED_RESCHED flag set
636	ld  r9, [r10, THREAD_INFO_FLAGS]
637	bbit0  r9, TIF_NEED_RESCHED, restore_regs
638
639	; Invoke PREEMPTION
640	bl      preempt_schedule_irq
641
642	; preempt_schedule_irq() always returns with IRQ disabled
643#endif
644
645	; fall through
646
647;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
648;
649; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
650; IRQ shd definitely not happen between now and rtie
651; All 2 entry points to here already disable interrupts
652
653restore_regs :
654
655	TRACE_ASM_IRQ_ENABLE
656
657	lr	r10, [status32]
658
659	; Restore REG File. In case multiple Events outstanding,
660	; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
661	; Note that we use realtime STATUS32 (not pt_regs->status32) to
662	; decide that.
663
664	; if Returning from Exception
665	bbit0  r10, STATUS_AE_BIT, not_exception
666	RESTORE_ALL_SYS
667	rtie
668
669	; Not Exception so maybe Interrupts (Level 1 or 2)
670
671not_exception:
672
673#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
674
675	; Level 2 interrupt return Path - from hardware standpoint
676	bbit0  r10, STATUS_A2_BIT, not_level2_interrupt
677
678	;------------------------------------------------------------------
679	; However the context returning might not have taken L2 intr itself
680	; e.g. Task'A' user-code -> L2 intr -> schedule -> 'B' user-code ret
681	; Special considerations needed for the context which took L2 intr
682
683	ld   r9, [sp, PT_event]        ; Ensure this is L2 intr context
684	brne r9, event_IRQ2, 149f
685
686	;------------------------------------------------------------------
687	; if L2 IRQ interrupted an L1 ISR,  we'd disabled preemption earlier
688	; so that sched doesn't move to new task, causing L1 to be delayed
689	; undeterministically. Now that we've achieved that, let's reset
690	; things to what they were, before returning from L2 context
691	;----------------------------------------------------------------
692
693	ld r9, [sp, PT_status32]       ; get statu32_l2 (saved in pt_regs)
694	bbit0 r9, STATUS_A1_BIT, 149f  ; L1 not active when L2 IRQ, so normal
695
696	; decrement thread_info->preempt_count (re-enable preemption)
697	GET_CURR_THR_INFO_FROM_SP   r10
698	ld      r9, [r10, THREAD_INFO_PREEMPT_COUNT]
699
700	; paranoid check, given A1 was active when A2 happened, preempt count
701	; must not be 0 because we would have incremented it.
702	; If this does happen we simply HALT as it means a BUG !!!
703	cmp     r9, 0
704	bnz     2f
705	flag 1
706
7072:
708	sub     r9, r9, 1
709	st      r9, [r10, THREAD_INFO_PREEMPT_COUNT]
710
711149:
712	;return from level 2
713	RESTORE_ALL_INT2
714debug_marker_l2:
715	rtie
716
717not_level2_interrupt:
718
719#endif
720
721	bbit0  r10, STATUS_A1_BIT, not_level1_interrupt
722
723	;return from level 1
724
725	RESTORE_ALL_INT1
726debug_marker_l1:
727	rtie
728
729not_level1_interrupt:
730
731	;this case is for syscalls or Exceptions (with fake rtie)
732
733	RESTORE_ALL_SYS
734debug_marker_syscall:
735	rtie
736
737END(ret_from_exception)
738
739ENTRY(ret_from_fork)
740	; when the forked child comes here from the __switch_to function
741	; r0 has the last task pointer.
742	; put last task in scheduler queue
743	bl   @schedule_tail
744
745	; If kernel thread, jump to its entry-point
746	ld   r9, [sp, PT_status32]
747	brne r9, 0, 1f
748
749	jl.d [r14]
750	mov  r0, r13		; arg to payload
751
7521:
753	; special case of kernel_thread entry point returning back due to
754	; kernel_execve() - pretend return from syscall to ret to userland
755	b    ret_from_exception
756END(ret_from_fork)
757
758;################### Special Sys Call Wrappers ##########################
759
760ENTRY(sys_clone_wrapper)
761	SAVE_CALLEE_SAVED_USER
762	bl  @sys_clone
763	DISCARD_CALLEE_SAVED_USER
764
765	GET_CURR_THR_INFO_FLAGS   r10
766	btst r10, TIF_SYSCALL_TRACE
767	bnz  tracesys_exit
768
769	b ret_from_system_call
770END(sys_clone_wrapper)
771
772#ifdef CONFIG_ARC_DW2_UNWIND
773; Workaround for bug 94179 (STAR ):
774; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
775; section (.debug_frame) as loadable. So we force it here.
776; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
777; would not work after a clean build due to kernel build system dependencies.
778.section .debug_frame, "wa",@progbits
779#endif
780