1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef __ASM_ARC_ENTRY_ARCV2_H
4 #define __ASM_ARC_ENTRY_ARCV2_H
6 #include <asm/asm-offsets.h>
7 #include <asm/irqflags-arcv2.h>
8 #include <asm/thread_info.h> /* For THREAD_SIZE */
11 * Interrupt/Exception stack layout (pt_regs) for ARCv2
12 * (End of struct aligned to end of page [unless nested])
16 * manual --------------------- manual
28 * hw autosave ---------------------
42 * ---------------------
43 * hw autosave | pc / eret |
44 * mandatory | stat32 / erstatus |
45 * ---------------------
48 /*------------------------------------------------------------------------*/
49 .macro INTERRUPT_PROLOGUE
51 ; (A) Before jumping to Interrupt Vector, hardware micro-ops did following:
52 ; 1. SP auto-switched to kernel mode stack
53 ; 2. STATUS32.Z flag set if in U mode at time of interrupt (U:1,K:0)
54 ; 3. Auto save: (mandatory) Push PC and STAT32 on stack
55 ; hardware does even if CONFIG_ARC_IRQ_NO_AUTOSAVE
56 ; 4. Auto save: (optional) r0-r11, blink, LPE,LPS,LPC, JLI,LDI,EI
58 ; (B) Manually saved some regs: r12,r25,r30, sp,fp,gp, ACCL pair
60 #ifdef CONFIG_ARC_IRQ_NO_AUTOSAVE
61 ; carve pt_regs on stack (case #3), PC/STAT32 already on stack
62 sub sp, sp, SZ_PT_REGS - 8
66 ; carve pt_regs on stack (case #4), which grew partially already
73 /*------------------------------------------------------------------------*/
74 .macro EXCEPTION_PROLOGUE
76 ; (A) Before jumping to Exception Vector, hardware micro-ops did following:
77 ; 1. SP auto-switched to kernel mode stack
78 ; 2. STATUS32.Z flag set if in U mode at time of exception (U:1,K:0)
80 ; (B) Manually save the complete reg file below
82 sub sp, sp, SZ_PT_REGS ; carve pt_regs
84 ; _HARD saves r10 clobbered by _SOFT as scratch hence comes first
97 ST2 r10, r11, PT_event
99 ; OUTPUT: r10 has ECR expected by EV_Trap
102 /*------------------------------------------------------------------------
103 * This macro saves the registers manually which would normally be autosaved
104 * by hardware on taken interrupts. It is used by
105 * - exception handlers (which don't have autosave)
106 * - interrupt autosave disabled due to CONFIG_ARC_IRQ_NO_AUTOSAVE
108 .macro __SAVE_REGFILE_HARD
117 st blink, [sp, PT_blink]
123 st lp_count, [sp, PT_lpc]
125 ; skip JLI, LDI, EI for now
128 /*------------------------------------------------------------------------
129 * This macros saves a bunch of other registers which can't be autosaved for
131 * - r12: the last caller saved scratch reg since hardware saves in pairs so r0-r11
132 * - r30: free reg, used by gcc as scratch
133 * - ACCL/ACCH pair when they exist
135 .macro __SAVE_REGFILE_SOFT
137 ST2 gp, fp, PT_r26 ; gp (r26), fp (r27)
139 st r12, [sp, PT_sp + 4]
140 st r30, [sp, PT_sp + 8]
142 ; Saving pt_regs->sp correctly requires some extra work due to the way
143 ; Auto stack switch works
144 ; - U mode: retrieve it from AUX_USER_SP
145 ; - K mode: add the offset from current SP where H/w starts auto push
147 ; 1. Utilize the fact that Z bit is set if Intr taken in U mode
148 ; 2. Upon entry SP is always saved (for any inspection, unwinding etc),
149 ; but on return, restored only if U mode
151 lr r10, [AUX_USER_SP] ; U mode SP
153 ; ISA requires ADD.nz to have same dest and src reg operands
155 add.nz r10, r10, SZ_PT_REGS ; K mode SP
157 st r10, [sp, PT_sp] ; SP (pt_regs->sp)
159 #ifdef CONFIG_ARC_CURR_IN_REG
160 st r25, [sp, PT_user_r25]
161 GET_CURR_TASK_ON_CPU r25
164 #ifdef CONFIG_ARC_HAS_ACCL_REGS
170 /*------------------------------------------------------------------------*/
171 .macro __RESTORE_REGFILE_SOFT
173 LD2 gp, fp, PT_r26 ; gp (r26), fp (r27)
178 ; Restore SP (into AUX_USER_SP) only if returning to U mode
179 ; - for K mode, it will be implicitly restored as stack is unwound
180 ; - Z flag set on K is inverse of what hardware does on interrupt entry
181 ; but that doesn't really matter
184 ld r10, [sp, PT_sp] ; SP (pt_regs->sp)
185 sr r10, [AUX_USER_SP]
188 #ifdef CONFIG_ARC_CURR_IN_REG
189 ld r25, [sp, PT_user_r25]
192 #ifdef CONFIG_ARC_HAS_ACCL_REGS
197 /*------------------------------------------------------------------------*/
198 .macro __RESTORE_REGFILE_HARD
200 ld blink, [sp, PT_blink]
206 ld r10, [sp, PT_lpc] ; lp_count can't be target of LD
218 /*------------------------------------------------------------------------*/
219 .macro INTERRUPT_EPILOGUE
221 ; INPUT: r0 has STAT32 of calling context
222 ; INPUT: Z flag set if returning to K mode
224 ; _SOFT clobbers r10 restored by _HARD hence the order
226 __RESTORE_REGFILE_SOFT
228 #ifdef CONFIG_ARC_IRQ_NO_AUTOSAVE
229 __RESTORE_REGFILE_HARD
230 add sp, sp, SZ_PT_REGS - 8
237 /*------------------------------------------------------------------------*/
238 .macro EXCEPTION_EPILOGUE
240 ; INPUT: r0 has STAT32 of calling context
242 btst r0, STATUS_U_BIT ; Z flag set if K, used in restoring SP
244 ld r10, [sp, PT_event + 4]
251 __RESTORE_REGFILE_SOFT
252 __RESTORE_REGFILE_HARD
254 add sp, sp, SZ_PT_REGS
257 .macro FAKE_RET_FROM_EXCPN
259 bic r9, r9, STATUS_AE_MASK
260 or r9, r9, STATUS_IE_MASK
264 /* Get thread_info of "current" tsk */
265 .macro GET_CURR_THR_INFO_FROM_SP reg
266 bmskn \reg, sp, THREAD_SHIFT - 1
269 /* Get CPU-ID of this core */
270 .macro GET_CPU_ID reg
272 xbfu \reg, \reg, 0xE8 /* 00111 01000 */