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