2 * Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
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.
11 * -Vector table jumps (@8 bytes) converted into branches (@4 bytes)
12 * -To maintain the slot size of 8 bytes/vector, added nop, which is
13 * not executed at runtime.
15 * vineetg: Nov 2009 (Everything needed for TIF_RESTORE_SIGMASK)
16 * -do_signal()invoked upon TIF_RESTORE_SIGMASK as well
17 * -Wrappers for sys_{,rt_}sigsuspend() nolonger needed as they don't
21 * -In a rare scenario, Process gets a Priv-V exception and gets scheduled
22 * out. Since we don't do FAKE RTIE for Priv-V, CPU excpetion state remains
23 * active (AE bit enabled). This causes a double fault for a subseq valid
24 * exception. Thus FAKE RTIE needed in low level Priv-Violation handler.
25 * Instr Error could also cause similar scenario, so same there as well.
27 * Vineetg: Aug 28th 2008: Bug #94984
28 * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
29 * Normally CPU does this automatically, however when doing FAKE rtie,
30 * we need to explicitly do this. The problem in macros
31 * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
32 * was being "CLEARED" rather then "SET". Since it is Loop INHIBIT Bit,
33 * setting it and not clearing it clears ZOL context
35 * Vineetg: Dec 22, 2007
36 * Minor Surgery of Low Level ISR to make it SMP safe
37 * - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
38 * - _current_task is made an array of NR_CPUS
39 * - Access of _current_task wrapped inside a macro so that if hardware
40 * team agrees for a dedicated reg, no other code is touched
42 * Amit Bhor, Rahul Trivedi, Kanika Nema, Sameer Dhavale : Codito Tech 2004
45 /*------------------------------------------------------------------
47 *------------------------------------------------------------------
50 * Caller Saved Registers r0 - r12
51 * Callee Saved Registers r13- r25
52 * Global Pointer (gp) r26
53 * Frame Pointer (fp) r27
54 * Stack Pointer (sp) r28
55 * Interrupt link register (ilink1) r29
56 * Interrupt link register (ilink2) r30
57 * Branch link register (blink) r31
58 *------------------------------------------------------------------
63 ;############################ Vector Table #################################
66 #if 1 /* Just in case, build breaks */
74 .section .vector, "ax",@progbits
77 /* Each entry in the vector table must occupy 2 words. Since it is a jump
78 * across sections (.vector to .text) we are gauranteed that 'j somewhere'
79 * will use the 'j limm' form of the intrsuction as long as somewhere is in
80 * a section other than .vector.
83 ; ********* Critical System Events **********************
84 VECTOR res_service ; 0x0, Restart Vector (0x0)
85 VECTOR mem_service ; 0x8, Mem exception (0x1)
86 VECTOR instr_service ; 0x10, Instrn Error (0x2)
88 ; ******************** Device ISRs **********************
89 VECTOR handle_interrupt_level1
91 VECTOR handle_interrupt_level1
93 VECTOR handle_interrupt_level1
95 VECTOR handle_interrupt_level1
98 VECTOR handle_interrupt_level1 ; Other devices
101 /* FOR ARC600: timer = 0x3, uart = 0x8, emac = 0x10 */
103 ; ******************** Exceptions **********************
104 VECTOR EV_MachineCheck ; 0x100, Fatal Machine check (0x20)
105 VECTOR EV_TLBMissI ; 0x108, Intruction TLB miss (0x21)
106 VECTOR EV_TLBMissD ; 0x110, Data TLB miss (0x22)
107 VECTOR EV_TLBProtV ; 0x118, Protection Violation (0x23)
108 ; or Misaligned Access
109 VECTOR EV_PrivilegeV ; 0x120, Privilege Violation (0x24)
110 VECTOR EV_Trap ; 0x128, Trap exception (0x25)
111 VECTOR EV_Extension ; 0x130, Extn Intruction Excp (0x26)
114 VECTOR reserved ; Reserved Exceptions
117 #include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
118 #include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
119 #include <asm/errno.h>
120 #include <asm/arcregs.h>
121 #include <asm/irqflags.h>
123 ;##################### Scratch Mem for IRQ stack switching #############
125 .section .data ; NOT .global
127 .type int1_saved_reg, @object
128 .size int1_saved_reg, 4
132 ; ---------------------------------------------
133 .section .text, "ax",@progbits
135 res_service: ; processor restart
136 flag 0x1 ; not implemented
140 reserved: ; processor restart
141 rtie ; jump to processor initializations
143 ;##################### Interrupt Handling ##############################
145 ; ---------------------------------------------
147 ; ---------------------------------------------
148 ARC_ENTRY handle_interrupt_level1
150 /* free up r9 as scratchpad */
151 st r9, [@int1_saved_reg]
153 ;Which mode (user/kernel) was the system in when intr occured
166 sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
169 ARC_EXIT handle_interrupt_level1
171 ;################### Non TLB Exception Handling #############################
173 ; ---------------------------------------------
174 ; Instruction Error Exception Handler
175 ; ---------------------------------------------
177 ARC_ENTRY instr_service
179 EXCPN_PROLOG_FREEUP_REG r9
191 FAKE_RET_FROM_EXCPN r9
193 bl do_insterror_or_kprobe
195 ARC_EXIT instr_service
197 ; ---------------------------------------------
198 ; Memory Error Exception Handler
199 ; ---------------------------------------------
201 ARC_ENTRY mem_service
203 EXCPN_PROLOG_FREEUP_REG r9
217 ; ---------------------------------------------
218 ; Machine Check Exception Handler
219 ; ---------------------------------------------
221 ARC_ENTRY EV_MachineCheck
223 EXCPN_PROLOG_FREEUP_REG r9
233 brne r0, 0x200100, 1f
234 bl do_tlb_overlap_fault
238 ; DEAD END: can't do much, display Regs and HALT
239 SAVE_CALLEE_SAVED_USER
241 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
242 st sp, [r10, THREAD_CALLEE_REG]
244 j do_machine_check_fault
246 ARC_EXIT EV_MachineCheck
248 ; ---------------------------------------------
249 ; Protection Violation Exception Handler
250 ; ---------------------------------------------
252 ARC_ENTRY EV_TLBProtV
254 EXCPN_PROLOG_FREEUP_REG r9
256 ;Which mode (user/kernel) was the system in when Exception occured
262 ;---------(3) Save some more regs-----------------
263 ; vineetg: Mar 6th: Random Seg Fault issue #1
264 ; ecr and efa were not saved in case an Intr sneaks in
270 ; --------(4) Return from CPU Exception Mode ---------
271 ; Fake a rtie, but rtie to next label
272 ; That way, subsequently, do_page_fault ( ) executes in pure kernel
273 ; mode with further Exceptions enabled
275 FAKE_RET_FROM_EXCPN r9
277 ;------ (5) Type of Protection Violation? ----------
279 ; ProtV Hardware Exception is triggered for Access Faults of 2 types
280 ; -Access Violaton (WRITE to READ ONLY Page) - for linux COW
281 ; -Unaligned Access (READ/WRITE on odd boundary)
283 cmp r3, 0x230400 ; Misaligned data access ?
286 ;========= (6a) Access Violation Processing ========
288 mov r1, 0x0 ; if LD exception ? write = 0
289 mov.ne r1, 0x1 ; else write = 1
291 mov r2, r4 ; faulting address
296 ;========== (6b) Non aligned access ============
298 mov r0, r3 ; cause code
299 mov r1, r4 ; faulting address
302 bl do_misaligned_access
307 ; ---------------------------------------------
308 ; Privilege Violation Exception Handler
309 ; ---------------------------------------------
310 ARC_ENTRY EV_PrivilegeV
312 EXCPN_PROLOG_FREEUP_REG r9
323 FAKE_RET_FROM_EXCPN r9
325 bl do_privilege_fault
327 ARC_EXIT EV_PrivilegeV
329 ; ---------------------------------------------
330 ; Extension Instruction Exception Handler
331 ; ---------------------------------------------
332 ARC_ENTRY EV_Extension
334 EXCPN_PROLOG_FREEUP_REG r9
343 bl do_extension_fault
345 ARC_EXIT EV_Extension
347 ;################### Break Point TRAP ##########################
349 ; ======= (5b) Trap is due to Break-Point =========
353 ;make sure orig_r8 is a positive value
354 st NR_syscalls + 2, [sp, PT_orig_r8]
360 ; Now that we have read EFA, its safe to do "fake" rtie
361 ; and get out of CPU exception mode
362 FAKE_RET_FROM_EXCPN r11
364 ; Save callee regs in case gdb wants to have a look
365 ; SP will grow up by size of CALLEE Reg-File
367 SAVE_CALLEE_SAVED_USER
369 ; save location of saved Callee Regs @ thread_struct->pc
370 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
371 st sp, [r10, THREAD_CALLEE_REG]
373 ; Call the trap handler
376 ; unwind stack to discard Callee saved Regs
377 DISCARD_CALLEE_SAVED_USER
381 ;##################### Trap Handling ##############################
383 ; EV_Trap caused by TRAP_S and TRAP0 instructions.
384 ;------------------------------------------------------------------
386 ; :parameters in r0-r7.
387 ; :r8 has the system call number
389 ;------------------------------------------------------------------
393 ; Need at least 1 reg to code the early exception prolog
394 EXCPN_PROLOG_FREEUP_REG r9
396 ;Which mode (user/kernel) was the system in when intr occured
402 ;------- (4) What caused the Trap --------------
404 and.f 0, r12, ECR_PARAM_MASK
407 ; ======= (5a) Trap is due to System Call ========
409 ; Before doing anything, return from CPU Exception Mode
410 FAKE_RET_FROM_EXCPN r11
412 ;============ This is normal System Call case ==========
413 ; Sys-call num shd not exceed the total system calls avail
416 bhi ret_from_system_call
418 ; Offset into the syscall_table and call handler
419 ld.as r9,[sys_call_table, r8]
420 jl [r9] ; Entry into Sys Call Handler
422 ; fall through to ret_from_system_call
425 ARC_ENTRY ret_from_system_call
427 st r0, [sp, PT_r0] ; sys call return value in pt_regs
429 ; fall through yet again to ret_from_exception
431 ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
433 ; If ret to user mode do we need to handle signals, schedule() et al.
435 ARC_ENTRY ret_from_exception
437 ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
438 ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
440 #ifdef CONFIG_PREEMPT
441 bbit0 r8, STATUS_U_BIT, resume_kernel_mode
443 bbit0 r8, STATUS_U_BIT, restore_regs
446 ; Before returning to User mode check-for-and-complete any pending work
447 ; such as rescheduling/signal-delivery etc.
448 resume_user_mode_begin:
450 ; Disable IRQs to ensures that chk for pending work itself is atomic
451 ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
455 ; Fast Path return to user mode if no pending work
456 GET_CURR_THR_INFO_FLAGS r9
457 and.f 0, r9, _TIF_WORK_MASK
460 ; --- (Slow Path #1) task preemption ---
461 bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
462 mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
463 b @schedule ; BTST+Bnz causes relo error in link
468 ; --- (Slow Path #2) pending signal ---
469 mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
471 bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
473 ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
474 ; in pt_reg since the "C" ABI (kernel code) will automatically
475 ; save/restore callee-saved regs.
477 ; However, here we need to explicitly save callee regs because
478 ; (i) If this signal causes coredump - full regfile needed
479 ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
480 ; tracer might call PEEKUSR(CALLEE reg)
482 ; NOTE: SP will grow up by size of CALLEE Reg-File
483 SAVE_CALLEE_SAVED_USER ; clobbers r12
485 ; save location of saved Callee Regs @ thread_struct->callee
486 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
487 st sp, [r10, THREAD_CALLEE_REG]
491 ; Ideally we want to discard the Callee reg above, however if this was
492 ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
493 RESTORE_CALLEE_SAVED_USER
495 b resume_user_mode_begin ; loop back to start of U mode ret
497 ; --- (Slow Path #3) notify_resume ---
499 btst r9, TIF_NOTIFY_RESUME
500 blnz @do_notify_resume
501 b resume_user_mode_begin ; unconditionally back to U mode ret chks
502 ; for single exit point from this block
504 #ifdef CONFIG_PREEMPT
508 ; Can't preempt if preemption disabled
509 GET_CURR_THR_INFO_FROM_SP r10
510 ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
511 brne r8, 0, restore_regs
513 ; check if this task's NEED_RESCHED flag set
514 ld r9, [r10, THREAD_INFO_FLAGS]
515 bbit0 r9, TIF_NEED_RESCHED, restore_regs
520 bl preempt_schedule_irq
522 ; preempt_schedule_irq() always returns with IRQ disabled
527 ;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
529 ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
530 ; IRQ shd definitely not happen between now and rtie
534 ; Disable Interrupts while restoring reg-file back
535 ; XXX can this be optimised out
536 IRQ_DISABLE_SAVE r9, r10 ;@r10 has prisitine (pre-disable) copy
538 ; Restore REG File. In case multiple Events outstanding,
539 ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
540 ; Note that we use realtime STATUS32 (not pt_regs->status32) to
543 ; if Returning from Exception
544 bbit0 r10, STATUS_AE_BIT, not_exception
548 ; Not Exception so maybe Interrupts (Level 1 or 2)
552 bbit0 r10, STATUS_A1_BIT, not_level1_interrupt
560 not_level1_interrupt:
562 ;this case is for syscalls or Exceptions (with fake rtie)
565 debug_marker_syscall:
568 ARC_EXIT ret_from_exception
570 ARC_ENTRY ret_from_fork
571 ; when the forked child comes here from the __switch_to function
572 ; r0 has the last task pointer.
573 ; put last task in scheduler queue
576 ; If kernel thread, jump to it's entry-point
577 ld r9, [sp, PT_status32]
581 mov r0, r13 ; arg to payload
584 ; special case of kernel_thread entry point returning back due to
585 ; kernel_execve() - pretend return from syscall to ret to userland
587 ARC_EXIT ret_from_fork
589 ;################### Special Sys Call Wrappers ##########################
591 ; TBD: call do_fork directly from here
592 ARC_ENTRY sys_fork_wrapper
593 SAVE_CALLEE_SAVED_USER
595 DISCARD_CALLEE_SAVED_USER
597 b ret_from_system_call
598 ARC_EXIT sys_fork_wrapper
600 ARC_ENTRY sys_vfork_wrapper
601 SAVE_CALLEE_SAVED_USER
603 DISCARD_CALLEE_SAVED_USER
605 b ret_from_system_call
606 ARC_EXIT sys_vfork_wrapper
608 ARC_ENTRY sys_clone_wrapper
609 SAVE_CALLEE_SAVED_USER
611 DISCARD_CALLEE_SAVED_USER
613 b ret_from_system_call
614 ARC_EXIT sys_clone_wrapper