ARCv2: STAR 9000793984: Handle return from intr to Delay Slot
[linux-2.6-block.git] / arch / arc / include / asm / entry.h
CommitLineData
9d42c84f 1/*
6d1a20b1 2 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
9d42c84f
VG
3 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9d42c84f
VG
8 */
9
10#ifndef __ASM_ARC_ENTRY_H
11#define __ASM_ARC_ENTRY_H
12
9d42c84f 13#include <asm/unistd.h> /* For NR_syscalls defination */
9d42c84f
VG
14#include <asm/arcregs.h>
15#include <asm/ptrace.h>
080c3747 16#include <asm/processor.h> /* For VMALLOC_START */
4ffd9e2c 17#include <asm/mmu.h>
9d42c84f 18
1f6ccfff 19#ifdef CONFIG_ISA_ARCOMPACT
6d1a20b1 20#include <asm/entry-compact.h> /* ISA specific bits */
1f6ccfff
VG
21#else
22#include <asm/entry-arcv2.h>
23#endif
6d1a20b1 24
9d42c84f
VG
25/* Note on the LD/ST addr modes with addr reg wback
26 *
27 * LD.a same as LD.aw
28 *
29 * LD.a reg1, [reg2, x] => Pre Incr
30 * Eff Addr for load = [reg2 + x]
31 *
32 * LD.ab reg1, [reg2, x] => Post Incr
33 * Eff Addr for load = [reg2]
34 */
35
3ebedbb2
VG
36.macro PUSH reg
37 st.a \reg, [sp, -4]
38.endm
39
40.macro PUSHAX aux
41 lr r9, [\aux]
42 PUSH r9
43.endm
44
45.macro POP reg
46 ld.ab \reg, [sp, 4]
47.endm
48
49.macro POPAX aux
50 POP r9
51 sr r9, [\aux]
52.endm
53
9d42c84f 54/*--------------------------------------------------------------
3ebedbb2
VG
55 * Helpers to save/restore Scratch Regs:
56 * used by Interrupt/Exception Prologue/Epilogue
9d42c84f 57 *-------------------------------------------------------------*/
3ebedbb2
VG
58.macro SAVE_R0_TO_R12
59 PUSH r0
60 PUSH r1
61 PUSH r2
62 PUSH r3
63 PUSH r4
64 PUSH r5
65 PUSH r6
66 PUSH r7
67 PUSH r8
68 PUSH r9
69 PUSH r10
70 PUSH r11
71 PUSH r12
72.endm
73
74.macro RESTORE_R12_TO_R0
75 POP r12
76 POP r11
77 POP r10
78 POP r9
79 POP r8
80 POP r7
81 POP r6
82 POP r5
83 POP r4
84 POP r3
85 POP r2
86 POP r1
87 POP r0
359105bd
VG
88
89#ifdef CONFIG_ARC_CURR_IN_REG
90 ld r25, [sp, 12]
91#endif
9d42c84f
VG
92.endm
93
94/*--------------------------------------------------------------
3ebedbb2
VG
95 * Helpers to save/restore callee-saved regs:
96 * used by several macros below
9d42c84f 97 *-------------------------------------------------------------*/
3ebedbb2
VG
98.macro SAVE_R13_TO_R24
99 PUSH r13
100 PUSH r14
101 PUSH r15
102 PUSH r16
103 PUSH r17
104 PUSH r18
105 PUSH r19
106 PUSH r20
107 PUSH r21
108 PUSH r22
109 PUSH r23
110 PUSH r24
111.endm
112
113.macro RESTORE_R24_TO_R13
114 POP r24
115 POP r23
116 POP r22
117 POP r21
118 POP r20
119 POP r19
120 POP r18
121 POP r17
122 POP r16
123 POP r15
124 POP r14
125 POP r13
9d42c84f
VG
126.endm
127
359105bd 128#define OFF_USER_R25_FROM_R24 (SZ_CALLEE_REGS + SZ_PT_REGS - 8)/4
9d42c84f
VG
129
130/*--------------------------------------------------------------
3ebedbb2
VG
131 * Collect User Mode callee regs as struct callee_regs - needed by
132 * fork/do_signal/unaligned-access-emulation.
133 * (By default only scratch regs are saved on entry to kernel)
134 *
135 * Special handling for r25 if used for caching Task Pointer.
136 * It would have been saved in task->thread.user_r25 already, but to keep
137 * the interface same it is copied into regular r25 placeholder in
138 * struct callee_regs.
9d42c84f
VG
139 *-------------------------------------------------------------*/
140.macro SAVE_CALLEE_SAVED_USER
3ebedbb2
VG
141
142 SAVE_R13_TO_R24
080c3747
VG
143
144#ifdef CONFIG_ARC_CURR_IN_REG
145 ; Retrieve orig r25 and save it on stack
359105bd 146 ld.as r12, [sp, OFF_USER_R25_FROM_R24]
080c3747
VG
147 st.a r12, [sp, -4]
148#else
3ebedbb2 149 PUSH r25
080c3747 150#endif
9d42c84f 151
9d42c84f
VG
152.endm
153
154/*--------------------------------------------------------------
3ebedbb2
VG
155 * Save kernel Mode callee regs at the time of Contect Switch.
156 *
157 * Special handling for r25 if used for caching Task Pointer.
158 * Kernel simply skips saving it since it will be loaded with
159 * incoming task pointer anyways
9d42c84f
VG
160 *-------------------------------------------------------------*/
161.macro SAVE_CALLEE_SAVED_KERNEL
3ebedbb2
VG
162
163 SAVE_R13_TO_R24
164
080c3747 165#ifdef CONFIG_ARC_CURR_IN_REG
16f9afe6 166 sub sp, sp, 4
080c3747 167#else
3ebedbb2 168 PUSH r25
080c3747 169#endif
9d42c84f
VG
170.endm
171
172/*--------------------------------------------------------------
3ebedbb2 173 * Opposite of SAVE_CALLEE_SAVED_KERNEL
9d42c84f
VG
174 *-------------------------------------------------------------*/
175.macro RESTORE_CALLEE_SAVED_KERNEL
176
080c3747 177#ifdef CONFIG_ARC_CURR_IN_REG
16f9afe6 178 add sp, sp, 4 /* skip usual r25 placeholder */
080c3747 179#else
3ebedbb2 180 POP r25
080c3747 181#endif
3ebedbb2 182 RESTORE_R24_TO_R13
9d42c84f
VG
183.endm
184
c3581039 185/*--------------------------------------------------------------
3ebedbb2
VG
186 * Opposite of SAVE_CALLEE_SAVED_USER
187 *
188 * ptrace tracer or unaligned-access fixup might have changed a user mode
189 * callee reg which is saved back to usual r25 storage location
c3581039
VG
190 *-------------------------------------------------------------*/
191.macro RESTORE_CALLEE_SAVED_USER
192
c3581039
VG
193#ifdef CONFIG_ARC_CURR_IN_REG
194 ld.ab r12, [sp, 4]
359105bd 195 st.as r12, [sp, OFF_USER_R25_FROM_R24]
c3581039 196#else
3ebedbb2 197 POP r25
c3581039 198#endif
3ebedbb2 199 RESTORE_R24_TO_R13
c3581039
VG
200.endm
201
9d42c84f
VG
202/*--------------------------------------------------------------
203 * Super FAST Restore callee saved regs by simply re-adjusting SP
204 *-------------------------------------------------------------*/
205.macro DISCARD_CALLEE_SAVED_USER
16f9afe6 206 add sp, sp, SZ_CALLEE_REGS
9d42c84f
VG
207.endm
208
9d42c84f
VG
209/*-------------------------------------------------------------
210 * given a tsk struct, get to the base of it's kernel mode stack
211 * tsk->thread_info is really a PAGE, whose bottom hoists stack
212 * which grows upwards towards thread_info
213 *------------------------------------------------------------*/
214
215.macro GET_TSK_STACK_BASE tsk, out
216
217 /* Get task->thread_info (this is essentially start of a PAGE) */
218 ld \out, [\tsk, TASK_THREAD_INFO]
219
220 /* Go to end of page where stack begins (grows upwards) */
283237a0 221 add2 \out, \out, (THREAD_SIZE)/4
9d42c84f
VG
222
223.endm
224
9d42c84f
VG
225/*
226 * @reg [OUT] thread_info->flags of "current"
227 */
228.macro GET_CURR_THR_INFO_FLAGS reg
229 GET_CURR_THR_INFO_FROM_SP \reg
230 ld \reg, [\reg, THREAD_INFO_FLAGS]
231.endm
232
41195d23
VG
233#ifdef CONFIG_SMP
234
235/*-------------------------------------------------
236 * Retrieve the current running task on this CPU
237 * 1. Determine curr CPU id.
238 * 2. Use it to index into _current_task[ ]
239 */
240.macro GET_CURR_TASK_ON_CPU reg
241 GET_CPU_ID \reg
242 ld.as \reg, [@_current_task, \reg]
243.endm
244
245/*-------------------------------------------------
246 * Save a new task as the "current" task on this CPU
247 * 1. Determine curr CPU id.
248 * 2. Use it to index into _current_task[ ]
249 *
250 * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
251 * because ST r0, [r1, offset] can ONLY have s9 @offset
252 * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
253 */
254
255.macro SET_CURR_TASK_ON_CPU tsk, tmp
256 GET_CPU_ID \tmp
257 add2 \tmp, @_current_task, \tmp
258 st \tsk, [\tmp]
259#ifdef CONFIG_ARC_CURR_IN_REG
260 mov r25, \tsk
261#endif
262
263.endm
264
265
266#else /* Uniprocessor implementation of macros */
267
9d42c84f
VG
268.macro GET_CURR_TASK_ON_CPU reg
269 ld \reg, [@_current_task]
270.endm
271
272.macro SET_CURR_TASK_ON_CPU tsk, tmp
273 st \tsk, [@_current_task]
080c3747
VG
274#ifdef CONFIG_ARC_CURR_IN_REG
275 mov r25, \tsk
276#endif
9d42c84f
VG
277.endm
278
41195d23
VG
279#endif /* SMP / UNI */
280
9d42c84f
VG
281/* ------------------------------------------------------------------
282 * Get the ptr to some field of Current Task at @off in task struct
080c3747 283 * -Uses r25 for Current task ptr if that is enabled
9d42c84f
VG
284 */
285
080c3747
VG
286#ifdef CONFIG_ARC_CURR_IN_REG
287
288.macro GET_CURR_TASK_FIELD_PTR off, reg
289 add \reg, r25, \off
290.endm
291
292#else
293
9d42c84f
VG
294.macro GET_CURR_TASK_FIELD_PTR off, reg
295 GET_CURR_TASK_ON_CPU \reg
296 add \reg, \reg, \off
297.endm
298
080c3747
VG
299#endif /* CONFIG_ARC_CURR_IN_REG */
300
9d42c84f 301#endif /* __ASM_ARC_ENTRY_H */