2 * ARCv2 ISA based core Low Level Intr/Traps/Exceptions(non-TLB) Handling
4 * Copyright (C) 2013 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 #include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
12 #include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
13 #include <asm/errno.h>
14 #include <asm/arcregs.h>
15 #include <asm/irqflags.h>
21 ;############################ Vector Table #################################
23 .section .vector,"a",@progbits
26 # Initial 16 slots are Exception Vectors
27 VECTOR res_service ; Reset Vector
28 VECTOR mem_service ; Mem exception
29 VECTOR instr_service ; Instrn Error
30 VECTOR EV_MachineCheck ; Fatal Machine check
31 VECTOR EV_TLBMissI ; Intruction TLB miss
32 VECTOR EV_TLBMissD ; Data TLB miss
33 VECTOR EV_TLBProtV ; Protection Violation
34 VECTOR EV_PrivilegeV ; Privilege Violation
35 VECTOR EV_SWI ; Software Breakpoint
36 VECTOR EV_Trap ; Trap exception
37 VECTOR EV_Extension ; Extn Instruction Exception
38 VECTOR EV_DivZero ; Divide by Zero
39 VECTOR EV_DCError ; Data Cache Error
40 VECTOR EV_Misaligned ; Misaligned Data Access
41 VECTOR reserved ; Reserved slots
42 VECTOR reserved ; Reserved slots
44 # Begin Interrupt Vectors
45 VECTOR handle_interrupt ; (16) Timer0
46 VECTOR handle_interrupt ; unused (Timer1)
47 VECTOR handle_interrupt ; unused (WDT)
48 VECTOR handle_interrupt ; (19) Inter core Interrupt (IPI)
49 VECTOR handle_interrupt ; (20) perf Interrupt
50 VECTOR handle_interrupt ; (21) Software Triggered Intr (Self IPI)
51 VECTOR handle_interrupt ; unused
52 VECTOR handle_interrupt ; (23) unused
55 .rept CONFIG_ARC_NUMBER_OF_INTERRUPTS - 8
56 VECTOR handle_interrupt
59 .section .text, "ax",@progbits
62 flag 1 ; Unexpected event, halt
64 ;##################### Interrupt Handling ##############################
66 ENTRY(handle_interrupt)
68 INTERRUPT_PROLOGUE irq
70 clri ; To make status32.IE agree with CPU internal state
74 mov blink, ret_from_exception
81 ;################### Non TLB Exception Handling #############################
95 ; ---------------------------------------------
96 ; Memory Error Exception Handler
97 ; - Unlike ARCompact, handles Bus errors for both User/Kernel mode,
98 ; Instruction fetch or Data access, under a single Exception Vector
99 ; ---------------------------------------------
118 lr r0, [efa] ; Faulting Data address
123 SAVE_CALLEE_SAVED_USER
124 mov r2, sp ; callee_regs
126 bl do_misaligned_access
128 ; TBD: optimize - do this only if a callee reg was involved
129 ; either a dst of emulated LD/ST or src with address-writeback
130 RESTORE_CALLEE_SAVED_USER
135 ; ---------------------------------------------
136 ; Protection Violation Exception Handler
137 ; ---------------------------------------------
143 lr r0, [efa] ; Faulting Data address
148 mov blink, ret_from_exception
153 ; From Linux standpoint Slow Path I/D TLB Miss is same a ProtV as they
154 ; need to call do_page_fault().
155 ; ECR in pt_regs provides whether access was R/W/X
157 .global call_do_page_fault
158 .set call_do_page_fault, EV_TLBProtV
160 ;############# Common Handlers for ARCompact and ARCv2 ##############
164 ;############# Return from Intr/Excp/Trap (ARCv2 ISA Specifics) ##############
166 ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
167 ; IRQ shd definitely not happen between now and rtie
168 ; All 2 entry points to here already disable interrupts
172 ld r0, [sp, PT_status32] ; U/K mode at time of entry
173 lr r10, [AUX_IRQ_ACT]
175 bmsk r11, r10, 15 ; AUX_IRQ_ACT.ACTIVE
176 breq r11, 0, .Lexcept_ret ; No intr active, ret from Exception
178 ;####### Return from Intr #######
181 bbit1.nt r0, STATUS_DE_BIT, .Lintr_ret_to_delay_slot
184 ; Handle special case #1: (Entry via Exception, Return via IRQ)
186 ; Exception in U mode, preempted in kernel, Intr taken (K mode), orig
187 ; task now returning to U mode (riding the Intr)
188 ; AUX_IRQ_ACTIVE won't have U bit set (since intr in K mode), hence SP
189 ; won't be switched to correct U mode value (from AUX_SP)
190 ; So force AUX_IRQ_ACT.U for such a case
192 btst r0, STATUS_U_BIT ; Z flag set if K (Z clear for U)
193 bset.nz r11, r11, AUX_IRQ_ACT_BIT_U ; NZ means U
194 sr r11, [AUX_IRQ_ACT]
196 INTERRUPT_EPILOGUE irq
199 ;####### Return from Exception / pure kernel mode #######
201 .Lexcept_ret: ; Expects r0 has PT_status32
203 debug_marker_syscall:
207 ;####### Return from Intr to insn in delay slot #######
209 ; Handle special case #2: (Entry via Exception in Delay Slot, Return via IRQ)
211 ; Intr returning to a Delay Slot (DS) insn
212 ; (since IRQ NOT allowed in DS in ARCv2, this can only happen if orig
213 ; entry was via Exception in DS which got preempted in kernel).
215 ; IRQ RTIE won't reliably restore DE bit and/or BTA, needs workaround
217 ; Solution is return from Intr w/o any delay slot quirks into a kernel trampoline
218 ; and from pure kernel mode return to delay slot which handles DS bit/BTA correctly
220 .Lintr_ret_to_delay_slot:
223 ld r2, [@intr_to_DE_cnt]
225 st r2, [@intr_to_DE_cnt]
228 ld r3, [sp, PT_status32]
230 ; STAT32 for Int return created from scratch
231 ; (No delay dlot, disable Further intr in trampoline)
233 bic r0, r3, STATUS_U_MASK|STATUS_DE_MASK|STATUS_IE_MASK|STATUS_L_MASK
234 st r0, [sp, PT_status32]
236 mov r1, .Lintr_ret_to_delay_slot_2
239 ; Orig exception PC/STAT32 safekept @orig_r0 and @event stack slots
243 b .Lisr_ret_fast_path
245 .Lintr_ret_to_delay_slot_2:
246 ; Trampoline to restore orig exception PC/STAT32/BTA/AUX_USER_SP
247 sub sp, sp, SZ_PT_REGS
256 ; restore AUX_USER_SP if returning to U mode
257 bbit0 r9, STATUS_U_BIT, 1f
266 add sp, sp, SZ_PT_REGS
268 ; return from pure kernel mode to delay slot
271 END(ret_from_exception)