blob: f61032c53d51148a62c40750e7a953933ddc1ee9 [file] [log] [blame]
Vineet Gupta9d42c842013-01-18 15:12:18 +05301/*
Vineet Gupta6d1a20b2015-02-21 15:09:32 +05302 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
Vineet Gupta9d42c842013-01-18 15:12:18 +05303 * 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.
Vineet Gupta9d42c842013-01-18 15:12:18 +05308 */
9
10#ifndef __ASM_ARC_ENTRY_H
11#define __ASM_ARC_ENTRY_H
12
Vineet Gupta9d42c842013-01-18 15:12:18 +053013#include <asm/unistd.h> /* For NR_syscalls defination */
Vineet Gupta9d42c842013-01-18 15:12:18 +053014#include <asm/arcregs.h>
15#include <asm/ptrace.h>
Vineet Gupta080c3742013-02-11 19:52:57 +053016#include <asm/processor.h> /* For VMALLOC_START */
Vineet Gupta4ffd9e22013-07-26 15:29:40 -070017#include <asm/mmu.h>
Vineet Gupta9d42c842013-01-18 15:12:18 +053018
Vineet Gupta6d1a20b2015-02-21 15:09:32 +053019#include <asm/entry-compact.h> /* ISA specific bits */
20
Vineet Gupta9d42c842013-01-18 15:12:18 +053021/* Note on the LD/ST addr modes with addr reg wback
22 *
23 * LD.a same as LD.aw
24 *
25 * LD.a reg1, [reg2, x] => Pre Incr
26 * Eff Addr for load = [reg2 + x]
27 *
28 * LD.ab reg1, [reg2, x] => Post Incr
29 * Eff Addr for load = [reg2]
30 */
31
Vineet Gupta3ebedbb2013-05-28 13:24:43 +053032.macro PUSH reg
33 st.a \reg, [sp, -4]
34.endm
35
36.macro PUSHAX aux
37 lr r9, [\aux]
38 PUSH r9
39.endm
40
41.macro POP reg
42 ld.ab \reg, [sp, 4]
43.endm
44
45.macro POPAX aux
46 POP r9
47 sr r9, [\aux]
Vineet Gupta9d42c842013-01-18 15:12:18 +053048.endm
49
50/*--------------------------------------------------------------
Vineet Gupta3ebedbb2013-05-28 13:24:43 +053051 * Helpers to save/restore Scratch Regs:
52 * used by Interrupt/Exception Prologue/Epilogue
Vineet Gupta9d42c842013-01-18 15:12:18 +053053 *-------------------------------------------------------------*/
Vineet Gupta3ebedbb2013-05-28 13:24:43 +053054.macro SAVE_R0_TO_R12
55 PUSH r0
56 PUSH r1
57 PUSH r2
58 PUSH r3
59 PUSH r4
60 PUSH r5
61 PUSH r6
62 PUSH r7
63 PUSH r8
64 PUSH r9
65 PUSH r10
66 PUSH r11
67 PUSH r12
68.endm
69
70.macro RESTORE_R12_TO_R0
71 POP r12
72 POP r11
73 POP r10
74 POP r9
75 POP r8
76 POP r7
77 POP r6
78 POP r5
79 POP r4
80 POP r3
81 POP r2
82 POP r1
83 POP r0
Vineet Gupta359105b2013-05-28 13:50:41 +053084
85#ifdef CONFIG_ARC_CURR_IN_REG
86 ld r25, [sp, 12]
87#endif
Vineet Gupta3ebedbb2013-05-28 13:24:43 +053088.endm
89
90/*--------------------------------------------------------------
91 * Helpers to save/restore callee-saved regs:
92 * used by several macros below
93 *-------------------------------------------------------------*/
94.macro SAVE_R13_TO_R24
95 PUSH r13
96 PUSH r14
97 PUSH r15
98 PUSH r16
99 PUSH r17
100 PUSH r18
101 PUSH r19
102 PUSH r20
103 PUSH r21
104 PUSH r22
105 PUSH r23
106 PUSH r24
107.endm
108
109.macro RESTORE_R24_TO_R13
110 POP r24
111 POP r23
112 POP r22
113 POP r21
114 POP r20
115 POP r19
116 POP r18
117 POP r17
118 POP r16
119 POP r15
120 POP r14
121 POP r13
Vineet Gupta9d42c842013-01-18 15:12:18 +0530122.endm
123
Vineet Gupta359105b2013-05-28 13:50:41 +0530124#define OFF_USER_R25_FROM_R24 (SZ_CALLEE_REGS + SZ_PT_REGS - 8)/4
Vineet Gupta9d42c842013-01-18 15:12:18 +0530125
126/*--------------------------------------------------------------
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530127 * Collect User Mode callee regs as struct callee_regs - needed by
128 * fork/do_signal/unaligned-access-emulation.
129 * (By default only scratch regs are saved on entry to kernel)
130 *
131 * Special handling for r25 if used for caching Task Pointer.
132 * It would have been saved in task->thread.user_r25 already, but to keep
133 * the interface same it is copied into regular r25 placeholder in
134 * struct callee_regs.
Vineet Gupta9d42c842013-01-18 15:12:18 +0530135 *-------------------------------------------------------------*/
136.macro SAVE_CALLEE_SAVED_USER
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530137
138 SAVE_R13_TO_R24
Vineet Gupta080c3742013-02-11 19:52:57 +0530139
140#ifdef CONFIG_ARC_CURR_IN_REG
141 ; Retrieve orig r25 and save it on stack
Vineet Gupta359105b2013-05-28 13:50:41 +0530142 ld.as r12, [sp, OFF_USER_R25_FROM_R24]
Vineet Gupta080c3742013-02-11 19:52:57 +0530143 st.a r12, [sp, -4]
144#else
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530145 PUSH r25
Vineet Gupta080c3742013-02-11 19:52:57 +0530146#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530147
Vineet Gupta9d42c842013-01-18 15:12:18 +0530148.endm
149
150/*--------------------------------------------------------------
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530151 * Save kernel Mode callee regs at the time of Contect Switch.
152 *
153 * Special handling for r25 if used for caching Task Pointer.
154 * Kernel simply skips saving it since it will be loaded with
155 * incoming task pointer anyways
Vineet Gupta9d42c842013-01-18 15:12:18 +0530156 *-------------------------------------------------------------*/
157.macro SAVE_CALLEE_SAVED_KERNEL
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530158
159 SAVE_R13_TO_R24
160
Vineet Gupta080c3742013-02-11 19:52:57 +0530161#ifdef CONFIG_ARC_CURR_IN_REG
Vineet Gupta16f9afe2013-05-27 21:43:41 +0530162 sub sp, sp, 4
Vineet Gupta080c3742013-02-11 19:52:57 +0530163#else
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530164 PUSH r25
Vineet Gupta080c3742013-02-11 19:52:57 +0530165#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530166.endm
167
168/*--------------------------------------------------------------
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530169 * Opposite of SAVE_CALLEE_SAVED_KERNEL
Vineet Gupta9d42c842013-01-18 15:12:18 +0530170 *-------------------------------------------------------------*/
171.macro RESTORE_CALLEE_SAVED_KERNEL
172
Vineet Gupta080c3742013-02-11 19:52:57 +0530173#ifdef CONFIG_ARC_CURR_IN_REG
Vineet Gupta16f9afe2013-05-27 21:43:41 +0530174 add sp, sp, 4 /* skip usual r25 placeholder */
Vineet Gupta080c3742013-02-11 19:52:57 +0530175#else
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530176 POP r25
Vineet Gupta080c3742013-02-11 19:52:57 +0530177#endif
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530178 RESTORE_R24_TO_R13
Vineet Gupta9d42c842013-01-18 15:12:18 +0530179.endm
180
181/*--------------------------------------------------------------
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530182 * Opposite of SAVE_CALLEE_SAVED_USER
183 *
184 * ptrace tracer or unaligned-access fixup might have changed a user mode
185 * callee reg which is saved back to usual r25 storage location
Vineet Guptac3581032013-01-18 15:12:19 +0530186 *-------------------------------------------------------------*/
187.macro RESTORE_CALLEE_SAVED_USER
188
Vineet Guptac3581032013-01-18 15:12:19 +0530189#ifdef CONFIG_ARC_CURR_IN_REG
190 ld.ab r12, [sp, 4]
Vineet Gupta359105b2013-05-28 13:50:41 +0530191 st.as r12, [sp, OFF_USER_R25_FROM_R24]
Vineet Guptac3581032013-01-18 15:12:19 +0530192#else
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530193 POP r25
Vineet Guptac3581032013-01-18 15:12:19 +0530194#endif
Vineet Gupta3ebedbb2013-05-28 13:24:43 +0530195 RESTORE_R24_TO_R13
Vineet Guptac3581032013-01-18 15:12:19 +0530196.endm
197
198/*--------------------------------------------------------------
Vineet Gupta9d42c842013-01-18 15:12:18 +0530199 * Super FAST Restore callee saved regs by simply re-adjusting SP
200 *-------------------------------------------------------------*/
201.macro DISCARD_CALLEE_SAVED_USER
Vineet Gupta16f9afe2013-05-27 21:43:41 +0530202 add sp, sp, SZ_CALLEE_REGS
Vineet Gupta9d42c842013-01-18 15:12:18 +0530203.endm
204
Vineet Gupta9d42c842013-01-18 15:12:18 +0530205/*-------------------------------------------------------------
206 * given a tsk struct, get to the base of it's kernel mode stack
207 * tsk->thread_info is really a PAGE, whose bottom hoists stack
208 * which grows upwards towards thread_info
209 *------------------------------------------------------------*/
210
211.macro GET_TSK_STACK_BASE tsk, out
212
213 /* Get task->thread_info (this is essentially start of a PAGE) */
214 ld \out, [\tsk, TASK_THREAD_INFO]
215
216 /* Go to end of page where stack begins (grows upwards) */
Vineet Gupta283237a2013-05-28 09:34:45 +0530217 add2 \out, \out, (THREAD_SIZE)/4
Vineet Gupta9d42c842013-01-18 15:12:18 +0530218
219.endm
220
Vineet Gupta9d42c842013-01-18 15:12:18 +0530221/*
222 * @reg [OUT] thread_info->flags of "current"
223 */
224.macro GET_CURR_THR_INFO_FLAGS reg
225 GET_CURR_THR_INFO_FROM_SP \reg
226 ld \reg, [\reg, THREAD_INFO_FLAGS]
227.endm
228
Vineet Gupta41195d22013-01-18 15:12:23 +0530229#ifdef CONFIG_SMP
230
231/*-------------------------------------------------
232 * Retrieve the current running task on this CPU
233 * 1. Determine curr CPU id.
234 * 2. Use it to index into _current_task[ ]
235 */
236.macro GET_CURR_TASK_ON_CPU reg
237 GET_CPU_ID \reg
238 ld.as \reg, [@_current_task, \reg]
239.endm
240
241/*-------------------------------------------------
242 * Save a new task as the "current" task on this CPU
243 * 1. Determine curr CPU id.
244 * 2. Use it to index into _current_task[ ]
245 *
246 * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
247 * because ST r0, [r1, offset] can ONLY have s9 @offset
248 * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
249 */
250
251.macro SET_CURR_TASK_ON_CPU tsk, tmp
252 GET_CPU_ID \tmp
253 add2 \tmp, @_current_task, \tmp
254 st \tsk, [\tmp]
255#ifdef CONFIG_ARC_CURR_IN_REG
256 mov r25, \tsk
257#endif
258
259.endm
260
261
262#else /* Uniprocessor implementation of macros */
263
Vineet Gupta9d42c842013-01-18 15:12:18 +0530264.macro GET_CURR_TASK_ON_CPU reg
265 ld \reg, [@_current_task]
266.endm
267
268.macro SET_CURR_TASK_ON_CPU tsk, tmp
269 st \tsk, [@_current_task]
Vineet Gupta080c3742013-02-11 19:52:57 +0530270#ifdef CONFIG_ARC_CURR_IN_REG
271 mov r25, \tsk
272#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530273.endm
274
Vineet Gupta41195d22013-01-18 15:12:23 +0530275#endif /* SMP / UNI */
276
Vineet Gupta9d42c842013-01-18 15:12:18 +0530277/* ------------------------------------------------------------------
278 * Get the ptr to some field of Current Task at @off in task struct
Vineet Gupta080c3742013-02-11 19:52:57 +0530279 * -Uses r25 for Current task ptr if that is enabled
Vineet Gupta9d42c842013-01-18 15:12:18 +0530280 */
281
Vineet Gupta080c3742013-02-11 19:52:57 +0530282#ifdef CONFIG_ARC_CURR_IN_REG
283
284.macro GET_CURR_TASK_FIELD_PTR off, reg
285 add \reg, r25, \off
286.endm
287
288#else
289
Vineet Gupta9d42c842013-01-18 15:12:18 +0530290.macro GET_CURR_TASK_FIELD_PTR off, reg
291 GET_CURR_TASK_ON_CPU \reg
292 add \reg, \reg, \off
293.endm
294
Vineet Gupta080c3742013-02-11 19:52:57 +0530295#endif /* CONFIG_ARC_CURR_IN_REG */
296
Vineet Gupta9d42c842013-01-18 15:12:18 +0530297#endif /* __ASM_ARC_ENTRY_H */