1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
7 #ifndef __ASM_ARC_ENTRY_H
8 #define __ASM_ARC_ENTRY_H
10 #include <asm/unistd.h> /* For NR_syscalls defination */
11 #include <asm/arcregs.h>
12 #include <asm/ptrace.h>
13 #include <asm/processor.h> /* For VMALLOC_START */
16 #ifdef CONFIG_ISA_ARCOMPACT
17 #include <asm/entry-compact.h> /* ISA specific bits */
19 #include <asm/entry-arcv2.h>
22 /* Note on the LD/ST addr modes with addr reg wback
26 * LD.a reg1, [reg2, x] => Pre Incr
27 * Eff Addr for load = [reg2 + x]
29 * LD.ab reg1, [reg2, x] => Post Incr
30 * Eff Addr for load = [reg2]
51 /*--------------------------------------------------------------
52 * Helpers to save/restore Scratch Regs:
53 * used by Interrupt/Exception Prologue/Epilogue
54 *-------------------------------------------------------------*/
71 .macro RESTORE_R12_TO_R0
88 /*--------------------------------------------------------------
89 * Helpers to save/restore callee-saved regs:
90 * used by several macros below
91 *-------------------------------------------------------------*/
92 .macro SAVE_R13_TO_R24
107 .macro RESTORE_R24_TO_R13
122 /*--------------------------------------------------------------
123 * Collect User Mode callee regs as struct callee_regs - needed by
124 * fork/do_signal/unaligned-access-emulation.
125 * (By default only scratch regs are saved on entry to kernel)
127 * Special handling for r25 if used for caching Task Pointer.
128 * It would have been saved in task->thread.user_r25 already, but to keep
129 * the interface same it is copied into regular r25 placeholder in
130 * struct callee_regs.
131 *-------------------------------------------------------------*/
132 .macro SAVE_CALLEE_SAVED_USER
134 mov r12
, sp
; save SP as ref to pt_regs
137 #ifdef CONFIG_ARC_CURR_IN_REG
138 ; Retrieve orig r25
and save it with rest of callee_regs
139 ld r12
, [r12
, PT_user_r25
]
147 /*--------------------------------------------------------------
148 * Save kernel Mode callee regs at the time of Contect Switch.
150 * Special handling for r25 if used for caching Task Pointer.
151 * Kernel simply skips saving it since it will be loaded with
152 * incoming task pointer anyways
153 *-------------------------------------------------------------*/
154 .macro SAVE_CALLEE_SAVED_KERNEL
158 #ifdef CONFIG_ARC_CURR_IN_REG
165 /*--------------------------------------------------------------
166 * Opposite of SAVE_CALLEE_SAVED_KERNEL
167 *-------------------------------------------------------------*/
168 .macro RESTORE_CALLEE_SAVED_KERNEL
170 #ifdef CONFIG_ARC_CURR_IN_REG
171 add sp
, sp
, 4 /* skip usual r25 placeholder */
178 /*--------------------------------------------------------------
179 * Opposite of SAVE_CALLEE_SAVED_USER
181 * ptrace tracer or unaligned-access fixup might have changed a user mode
182 * callee reg which is saved back to usual r25 storage location
183 *-------------------------------------------------------------*/
184 .macro RESTORE_CALLEE_SAVED_USER
186 #ifdef CONFIG_ARC_CURR_IN_REG
193 ; SP is back to start of pt_regs
194 #ifdef CONFIG_ARC_CURR_IN_REG
195 st r12
, [sp
, PT_user_r25
]
199 /*--------------------------------------------------------------
200 * Super FAST Restore callee saved regs by simply re-adjusting SP
201 *-------------------------------------------------------------*/
202 .macro DISCARD_CALLEE_SAVED_USER
203 add sp
, sp
, SZ_CALLEE_REGS
206 /*-------------------------------------------------------------
207 * given a tsk struct, get to the base of it's kernel mode stack
208 * tsk->thread_info is really a PAGE, whose bottom hoists stack
209 * which grows upwards towards thread_info
210 *------------------------------------------------------------*/
212 .macro GET_TSK_STACK_BASE tsk
, out
214 /* Get task->thread_info (this is essentially start of a PAGE) */
215 ld \out
, [\tsk
, TASK_THREAD_INFO
]
217 /* Go to end of page where stack begins (grows upwards) */
218 add2 \out
, \out
, (THREAD_SIZE
)/4
223 * @reg [OUT] thread_info->flags of "current"
225 .macro GET_CURR_THR_INFO_FLAGS reg
226 GET_CURR_THR_INFO_FROM_SP
\reg
227 ld
\reg
, [\reg
, THREAD_INFO_FLAGS
]
232 /*-------------------------------------------------
233 * Retrieve the current running task on this CPU
234 * 1. Determine curr CPU id.
235 * 2. Use it to index into _current_task[ ]
237 .macro GET_CURR_TASK_ON_CPU reg
239 ld
.as
\reg
, [@_current_task
, \reg
]
242 /*-------------------------------------------------
243 * Save a new task as the "current" task on this CPU
244 * 1. Determine curr CPU id.
245 * 2. Use it to index into _current_task[ ]
247 * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
248 * because ST r0, [r1, offset] can ONLY have s9 @offset
249 * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
252 .macro SET_CURR_TASK_ON_CPU tsk
, tmp
254 add2
\tmp
, @_current_task
, \tmp
256 #ifdef CONFIG_ARC_CURR_IN_REG
263 #else /* Uniprocessor implementation of macros */
265 .macro GET_CURR_TASK_ON_CPU reg
266 ld
\reg
, [@_current_task
]
269 .macro SET_CURR_TASK_ON_CPU tsk
, tmp
270 st
\tsk
, [@_current_task
]
271 #ifdef CONFIG_ARC_CURR_IN_REG
276 #endif /* SMP / UNI */
278 /* ------------------------------------------------------------------
279 * Get the ptr to some field of Current Task at @off in task struct
280 * -Uses r25 for Current task ptr if that is enabled
283 #ifdef CONFIG_ARC_CURR_IN_REG
285 .macro GET_CURR_TASK_FIELD_PTR off
, reg
291 .macro GET_CURR_TASK_FIELD_PTR off
, reg
292 GET_CURR_TASK_ON_CPU
\reg
296 #endif /* CONFIG_ARC_CURR_IN_REG */
298 #endif /* __ASM_ARC_ENTRY_H */