2 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
3 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
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.
10 #ifndef __ASM_ARC_ENTRY_H
11 #define __ASM_ARC_ENTRY_H
13 #include <asm/unistd.h> /* For NR_syscalls defination */
14 #include <asm/arcregs.h>
15 #include <asm/ptrace.h>
16 #include <asm/processor.h> /* For VMALLOC_START */
19 #ifdef CONFIG_ISA_ARCOMPACT
20 #include <asm/entry-compact.h> /* ISA specific bits */
22 #include <asm/entry-arcv2.h>
25 /* Note on the LD/ST addr modes with addr reg wback
29 * LD.a reg1, [reg2, x] => Pre Incr
30 * Eff Addr for load = [reg2 + x]
32 * LD.ab reg1, [reg2, x] => Post Incr
33 * Eff Addr for load = [reg2]
54 /*--------------------------------------------------------------
55 * Helpers to save/restore Scratch Regs:
56 * used by Interrupt/Exception Prologue/Epilogue
57 *-------------------------------------------------------------*/
74 .macro RESTORE_R12_TO_R0
89 #ifdef CONFIG_ARC_CURR_IN_REG
94 /*--------------------------------------------------------------
95 * Helpers to save/restore callee-saved regs:
96 * used by several macros below
97 *-------------------------------------------------------------*/
98 .macro SAVE_R13_TO_R24
113 .macro RESTORE_R24_TO_R13
128 /*--------------------------------------------------------------
129 * Collect User Mode callee regs as struct callee_regs - needed by
130 * fork/do_signal/unaligned-access-emulation.
131 * (By default only scratch regs are saved on entry to kernel)
133 * Special handling for r25 if used for caching Task Pointer.
134 * It would have been saved in task->thread.user_r25 already, but to keep
135 * the interface same it is copied into regular r25 placeholder in
136 * struct callee_regs.
137 *-------------------------------------------------------------*/
138 .macro SAVE_CALLEE_SAVED_USER
140 mov r12
, sp
; save SP as ref to pt_regs
143 #ifdef CONFIG_ARC_CURR_IN_REG
144 ; Retrieve orig r25
and save it with rest of callee_regs
145 ld r12
, [r12
, PT_user_r25
]
153 /*--------------------------------------------------------------
154 * Save kernel Mode callee regs at the time of Contect Switch.
156 * Special handling for r25 if used for caching Task Pointer.
157 * Kernel simply skips saving it since it will be loaded with
158 * incoming task pointer anyways
159 *-------------------------------------------------------------*/
160 .macro SAVE_CALLEE_SAVED_KERNEL
164 #ifdef CONFIG_ARC_CURR_IN_REG
171 /*--------------------------------------------------------------
172 * Opposite of SAVE_CALLEE_SAVED_KERNEL
173 *-------------------------------------------------------------*/
174 .macro RESTORE_CALLEE_SAVED_KERNEL
176 #ifdef CONFIG_ARC_CURR_IN_REG
177 add sp
, sp
, 4 /* skip usual r25 placeholder */
184 /*--------------------------------------------------------------
185 * Opposite of SAVE_CALLEE_SAVED_USER
187 * ptrace tracer or unaligned-access fixup might have changed a user mode
188 * callee reg which is saved back to usual r25 storage location
189 *-------------------------------------------------------------*/
190 .macro RESTORE_CALLEE_SAVED_USER
192 #ifdef CONFIG_ARC_CURR_IN_REG
199 ; SP is back to start of pt_regs
200 #ifdef CONFIG_ARC_CURR_IN_REG
201 st r12
, [sp
, PT_user_r25
]
205 /*--------------------------------------------------------------
206 * Super FAST Restore callee saved regs by simply re-adjusting SP
207 *-------------------------------------------------------------*/
208 .macro DISCARD_CALLEE_SAVED_USER
209 add sp
, sp
, SZ_CALLEE_REGS
212 /*-------------------------------------------------------------
213 * given a tsk struct, get to the base of it's kernel mode stack
214 * tsk->thread_info is really a PAGE, whose bottom hoists stack
215 * which grows upwards towards thread_info
216 *------------------------------------------------------------*/
218 .macro GET_TSK_STACK_BASE tsk
, out
220 /* Get task->thread_info (this is essentially start of a PAGE) */
221 ld \out
, [\tsk
, TASK_THREAD_INFO
]
223 /* Go to end of page where stack begins (grows upwards) */
224 add2 \out
, \out
, (THREAD_SIZE
)/4
229 * @reg [OUT] thread_info->flags of "current"
231 .macro GET_CURR_THR_INFO_FLAGS reg
232 GET_CURR_THR_INFO_FROM_SP
\reg
233 ld
\reg
, [\reg
, THREAD_INFO_FLAGS
]
238 /*-------------------------------------------------
239 * Retrieve the current running task on this CPU
240 * 1. Determine curr CPU id.
241 * 2. Use it to index into _current_task[ ]
243 .macro GET_CURR_TASK_ON_CPU reg
245 ld
.as
\reg
, [@_current_task
, \reg
]
248 /*-------------------------------------------------
249 * Save a new task as the "current" task on this CPU
250 * 1. Determine curr CPU id.
251 * 2. Use it to index into _current_task[ ]
253 * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
254 * because ST r0, [r1, offset] can ONLY have s9 @offset
255 * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
258 .macro SET_CURR_TASK_ON_CPU tsk
, tmp
260 add2
\tmp
, @_current_task
, \tmp
262 #ifdef CONFIG_ARC_CURR_IN_REG
269 #else /* Uniprocessor implementation of macros */
271 .macro GET_CURR_TASK_ON_CPU reg
272 ld
\reg
, [@_current_task
]
275 .macro SET_CURR_TASK_ON_CPU tsk
, tmp
276 st
\tsk
, [@_current_task
]
277 #ifdef CONFIG_ARC_CURR_IN_REG
282 #endif /* SMP / UNI */
284 /* ------------------------------------------------------------------
285 * Get the ptr to some field of Current Task at @off in task struct
286 * -Uses r25 for Current task ptr if that is enabled
289 #ifdef CONFIG_ARC_CURR_IN_REG
291 .macro GET_CURR_TASK_FIELD_PTR off
, reg
297 .macro GET_CURR_TASK_FIELD_PTR off
, reg
298 GET_CURR_TASK_ON_CPU
\reg
302 #endif /* CONFIG_ARC_CURR_IN_REG */
304 #endif /* __ASM_ARC_ENTRY_H */