xref: /linux/arch/arc/include/asm/entry.h (revision 283237a04fd332bddc2ac298e6ad7d23a1fc4b99)
19d42c84fSVineet Gupta /*
29d42c84fSVineet Gupta  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
39d42c84fSVineet Gupta  *
49d42c84fSVineet Gupta  * This program is free software; you can redistribute it and/or modify
59d42c84fSVineet Gupta  * it under the terms of the GNU General Public License version 2 as
69d42c84fSVineet Gupta  * published by the Free Software Foundation.
79d42c84fSVineet Gupta  *
84788a594SVineet Gupta  * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
94788a594SVineet Gupta  *  Stack switching code can no longer reliably rely on the fact that
104788a594SVineet Gupta  *  if we are NOT in user mode, stack is switched to kernel mode.
114788a594SVineet Gupta  *  e.g. L2 IRQ interrupted a L1 ISR which had not yet completed
124788a594SVineet Gupta  *  it's prologue including stack switching from user mode
134788a594SVineet Gupta  *
149d42c84fSVineet Gupta  * Vineetg: Aug 28th 2008: Bug #94984
159d42c84fSVineet Gupta  *  -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
169d42c84fSVineet Gupta  *   Normally CPU does this automatically, however when doing FAKE rtie,
179d42c84fSVineet Gupta  *   we also need to explicitly do this. The problem in macros
189d42c84fSVineet Gupta  *   FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
199d42c84fSVineet Gupta  *   was being "CLEARED" rather then "SET". Actually "SET" clears ZOL context
209d42c84fSVineet Gupta  *
219d42c84fSVineet Gupta  * Vineetg: May 5th 2008
22080c3747SVineet Gupta  *  -Modified CALLEE_REG save/restore macros to handle the fact that
23080c3747SVineet Gupta  *      r25 contains the kernel current task ptr
249d42c84fSVineet Gupta  *  - Defined Stack Switching Macro to be reused in all intr/excp hdlrs
259d42c84fSVineet Gupta  *  - Shaved off 11 instructions from RESTORE_ALL_INT1 by using the
269d42c84fSVineet Gupta  *      address Write back load ld.ab instead of seperate ld/add instn
279d42c84fSVineet Gupta  *
289d42c84fSVineet Gupta  * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
299d42c84fSVineet Gupta  */
309d42c84fSVineet Gupta 
319d42c84fSVineet Gupta #ifndef __ASM_ARC_ENTRY_H
329d42c84fSVineet Gupta #define __ASM_ARC_ENTRY_H
339d42c84fSVineet Gupta 
349d42c84fSVineet Gupta #ifdef __ASSEMBLY__
359d42c84fSVineet Gupta #include <asm/unistd.h>		/* For NR_syscalls defination */
369d42c84fSVineet Gupta #include <asm/asm-offsets.h>
379d42c84fSVineet Gupta #include <asm/arcregs.h>
389d42c84fSVineet Gupta #include <asm/ptrace.h>
39080c3747SVineet Gupta #include <asm/processor.h>	/* For VMALLOC_START */
409d42c84fSVineet Gupta #include <asm/thread_info.h>	/* For THREAD_SIZE */
419d42c84fSVineet Gupta 
429d42c84fSVineet Gupta /* Note on the LD/ST addr modes with addr reg wback
439d42c84fSVineet Gupta  *
449d42c84fSVineet Gupta  * LD.a same as LD.aw
459d42c84fSVineet Gupta  *
469d42c84fSVineet Gupta  * LD.a    reg1, [reg2, x]  => Pre Incr
479d42c84fSVineet Gupta  *      Eff Addr for load = [reg2 + x]
489d42c84fSVineet Gupta  *
499d42c84fSVineet Gupta  * LD.ab   reg1, [reg2, x]  => Post Incr
509d42c84fSVineet Gupta  *      Eff Addr for load = [reg2]
519d42c84fSVineet Gupta  */
529d42c84fSVineet Gupta 
539d42c84fSVineet Gupta /*--------------------------------------------------------------
549d42c84fSVineet Gupta  * Save caller saved registers (scratch registers) ( r0 - r12 )
559d42c84fSVineet Gupta  * Registers are pushed / popped in the order defined in struct ptregs
569d42c84fSVineet Gupta  * in asm/ptrace.h
579d42c84fSVineet Gupta  *-------------------------------------------------------------*/
589d42c84fSVineet Gupta .macro  SAVE_CALLER_SAVED
599d42c84fSVineet Gupta 	st.a    r0, [sp, -4]
609d42c84fSVineet Gupta 	st.a    r1, [sp, -4]
619d42c84fSVineet Gupta 	st.a    r2, [sp, -4]
629d42c84fSVineet Gupta 	st.a    r3, [sp, -4]
639d42c84fSVineet Gupta 	st.a    r4, [sp, -4]
649d42c84fSVineet Gupta 	st.a    r5, [sp, -4]
659d42c84fSVineet Gupta 	st.a    r6, [sp, -4]
669d42c84fSVineet Gupta 	st.a    r7, [sp, -4]
679d42c84fSVineet Gupta 	st.a    r8, [sp, -4]
689d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
699d42c84fSVineet Gupta 	st.a    r10, [sp, -4]
709d42c84fSVineet Gupta 	st.a    r11, [sp, -4]
719d42c84fSVineet Gupta 	st.a    r12, [sp, -4]
729d42c84fSVineet Gupta .endm
739d42c84fSVineet Gupta 
749d42c84fSVineet Gupta /*--------------------------------------------------------------
759d42c84fSVineet Gupta  * Restore caller saved registers (scratch registers)
769d42c84fSVineet Gupta  *-------------------------------------------------------------*/
779d42c84fSVineet Gupta .macro RESTORE_CALLER_SAVED
789d42c84fSVineet Gupta 	ld.ab   r12, [sp, 4]
799d42c84fSVineet Gupta 	ld.ab   r11, [sp, 4]
809d42c84fSVineet Gupta 	ld.ab   r10, [sp, 4]
819d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
829d42c84fSVineet Gupta 	ld.ab   r8, [sp, 4]
839d42c84fSVineet Gupta 	ld.ab   r7, [sp, 4]
849d42c84fSVineet Gupta 	ld.ab   r6, [sp, 4]
859d42c84fSVineet Gupta 	ld.ab   r5, [sp, 4]
869d42c84fSVineet Gupta 	ld.ab   r4, [sp, 4]
879d42c84fSVineet Gupta 	ld.ab   r3, [sp, 4]
889d42c84fSVineet Gupta 	ld.ab   r2, [sp, 4]
899d42c84fSVineet Gupta 	ld.ab   r1, [sp, 4]
909d42c84fSVineet Gupta 	ld.ab   r0, [sp, 4]
919d42c84fSVineet Gupta .endm
929d42c84fSVineet Gupta 
939d42c84fSVineet Gupta 
949d42c84fSVineet Gupta /*--------------------------------------------------------------
959d42c84fSVineet Gupta  * Save callee saved registers (non scratch registers) ( r13 - r25 )
969d42c84fSVineet Gupta  *  on kernel stack.
979d42c84fSVineet Gupta  * User mode callee regs need to be saved in case of
989d42c84fSVineet Gupta  *    -fork and friends for replicating from parent to child
999d42c84fSVineet Gupta  *    -before going into do_signal( ) for ptrace/core-dump
1009d42c84fSVineet Gupta  * Special case handling is required for r25 in case it is used by kernel
1019d42c84fSVineet Gupta  *  for caching task ptr. Low level exception/ISR save user mode r25
1029d42c84fSVineet Gupta  *  into task->thread.user_r25. So it needs to be retrieved from there and
1039d42c84fSVineet Gupta  *  saved into kernel stack with rest of callee reg-file
1049d42c84fSVineet Gupta  *-------------------------------------------------------------*/
1059d42c84fSVineet Gupta .macro SAVE_CALLEE_SAVED_USER
1069d42c84fSVineet Gupta 	st.a    r13, [sp, -4]
1079d42c84fSVineet Gupta 	st.a    r14, [sp, -4]
1089d42c84fSVineet Gupta 	st.a    r15, [sp, -4]
1099d42c84fSVineet Gupta 	st.a    r16, [sp, -4]
1109d42c84fSVineet Gupta 	st.a    r17, [sp, -4]
1119d42c84fSVineet Gupta 	st.a    r18, [sp, -4]
1129d42c84fSVineet Gupta 	st.a    r19, [sp, -4]
1139d42c84fSVineet Gupta 	st.a    r20, [sp, -4]
1149d42c84fSVineet Gupta 	st.a    r21, [sp, -4]
1159d42c84fSVineet Gupta 	st.a    r22, [sp, -4]
1169d42c84fSVineet Gupta 	st.a    r23, [sp, -4]
1179d42c84fSVineet Gupta 	st.a    r24, [sp, -4]
118080c3747SVineet Gupta 
119080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
120080c3747SVineet Gupta 	; Retrieve orig r25 and save it on stack
121080c3747SVineet Gupta 	ld      r12, [r25, TASK_THREAD + THREAD_USER_R25]
122080c3747SVineet Gupta 	st.a    r12, [sp, -4]
123080c3747SVineet Gupta #else
1249d42c84fSVineet Gupta 	st.a    r25, [sp, -4]
125080c3747SVineet Gupta #endif
1269d42c84fSVineet Gupta 
1279d42c84fSVineet Gupta 	/* move up by 1 word to "create" callee_regs->"stack_place_holder" */
1289d42c84fSVineet Gupta 	sub sp, sp, 4
1299d42c84fSVineet Gupta .endm
1309d42c84fSVineet Gupta 
1319d42c84fSVineet Gupta /*--------------------------------------------------------------
1329d42c84fSVineet Gupta  * Save callee saved registers (non scratch registers) ( r13 - r25 )
1339d42c84fSVineet Gupta  * kernel mode callee regs needed to be saved in case of context switch
1349d42c84fSVineet Gupta  * If r25 is used for caching task pointer then that need not be saved
1359d42c84fSVineet Gupta  * as it can be re-created from current task global
1369d42c84fSVineet Gupta  *-------------------------------------------------------------*/
1379d42c84fSVineet Gupta .macro SAVE_CALLEE_SAVED_KERNEL
1389d42c84fSVineet Gupta 	st.a    r13, [sp, -4]
1399d42c84fSVineet Gupta 	st.a    r14, [sp, -4]
1409d42c84fSVineet Gupta 	st.a    r15, [sp, -4]
1419d42c84fSVineet Gupta 	st.a    r16, [sp, -4]
1429d42c84fSVineet Gupta 	st.a    r17, [sp, -4]
1439d42c84fSVineet Gupta 	st.a    r18, [sp, -4]
1449d42c84fSVineet Gupta 	st.a    r19, [sp, -4]
1459d42c84fSVineet Gupta 	st.a    r20, [sp, -4]
1469d42c84fSVineet Gupta 	st.a    r21, [sp, -4]
1479d42c84fSVineet Gupta 	st.a    r22, [sp, -4]
1489d42c84fSVineet Gupta 	st.a    r23, [sp, -4]
1499d42c84fSVineet Gupta 	st.a    r24, [sp, -4]
150080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
151080c3747SVineet Gupta 	sub     sp, sp, 8
152080c3747SVineet Gupta #else
1539d42c84fSVineet Gupta 	st.a    r25, [sp, -4]
1549d42c84fSVineet Gupta 	sub     sp, sp, 4
155080c3747SVineet Gupta #endif
1569d42c84fSVineet Gupta .endm
1579d42c84fSVineet Gupta 
1589d42c84fSVineet Gupta /*--------------------------------------------------------------
1599d42c84fSVineet Gupta  * RESTORE_CALLEE_SAVED_KERNEL:
1609d42c84fSVineet Gupta  * Loads callee (non scratch) Reg File by popping from Kernel mode stack.
1619d42c84fSVineet Gupta  *  This is reverse of SAVE_CALLEE_SAVED,
1629d42c84fSVineet Gupta  *
1639d42c84fSVineet Gupta  * NOTE:
1649d42c84fSVineet Gupta  * Ideally this shd only be called in switch_to for loading
1659d42c84fSVineet Gupta  *  switched-IN task's CALLEE Reg File.
1669d42c84fSVineet Gupta  *  For all other cases RESTORE_CALLEE_SAVED_FAST must be used
1679d42c84fSVineet Gupta  *  which simply pops the stack w/o touching regs.
1689d42c84fSVineet Gupta  *-------------------------------------------------------------*/
1699d42c84fSVineet Gupta .macro RESTORE_CALLEE_SAVED_KERNEL
1709d42c84fSVineet Gupta 
171080c3747SVineet Gupta 
172080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
173080c3747SVineet Gupta 	add     sp, sp, 8  /* skip callee_reg gutter and user r25 placeholder */
174080c3747SVineet Gupta #else
1759d42c84fSVineet Gupta 	add     sp, sp, 4   /* skip "callee_regs->stack_place_holder" */
1769d42c84fSVineet Gupta 	ld.ab   r25, [sp, 4]
177080c3747SVineet Gupta #endif
178080c3747SVineet Gupta 
1799d42c84fSVineet Gupta 	ld.ab   r24, [sp, 4]
1809d42c84fSVineet Gupta 	ld.ab   r23, [sp, 4]
1819d42c84fSVineet Gupta 	ld.ab   r22, [sp, 4]
1829d42c84fSVineet Gupta 	ld.ab   r21, [sp, 4]
1839d42c84fSVineet Gupta 	ld.ab   r20, [sp, 4]
1849d42c84fSVineet Gupta 	ld.ab   r19, [sp, 4]
1859d42c84fSVineet Gupta 	ld.ab   r18, [sp, 4]
1869d42c84fSVineet Gupta 	ld.ab   r17, [sp, 4]
1879d42c84fSVineet Gupta 	ld.ab   r16, [sp, 4]
1889d42c84fSVineet Gupta 	ld.ab   r15, [sp, 4]
1899d42c84fSVineet Gupta 	ld.ab   r14, [sp, 4]
1909d42c84fSVineet Gupta 	ld.ab   r13, [sp, 4]
1919d42c84fSVineet Gupta 
1929d42c84fSVineet Gupta .endm
1939d42c84fSVineet Gupta 
1949d42c84fSVineet Gupta /*--------------------------------------------------------------
195c3581039SVineet Gupta  * RESTORE_CALLEE_SAVED_USER:
196c3581039SVineet Gupta  * This is called after do_signal where tracer might have changed callee regs
197c3581039SVineet Gupta  * thus we need to restore the reg file.
198c3581039SVineet Gupta  * Special case handling is required for r25 in case it is used by kernel
199c3581039SVineet Gupta  *  for caching task ptr. Ptrace would have modified on-kernel-stack value of
200c3581039SVineet Gupta  *  r25, which needs to be shoved back into task->thread.user_r25 where from
201c3581039SVineet Gupta  *  Low level exception/ISR return code will retrieve to populate with rest of
202c3581039SVineet Gupta  *  callee reg-file.
203c3581039SVineet Gupta  *-------------------------------------------------------------*/
204c3581039SVineet Gupta .macro RESTORE_CALLEE_SAVED_USER
205c3581039SVineet Gupta 
206c3581039SVineet Gupta 	add     sp, sp, 4   /* skip "callee_regs->stack_place_holder" */
207c3581039SVineet Gupta 
208c3581039SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
209c3581039SVineet Gupta 	ld.ab   r12, [sp, 4]
210c3581039SVineet Gupta 	st      r12, [r25, TASK_THREAD + THREAD_USER_R25]
211c3581039SVineet Gupta #else
212c3581039SVineet Gupta 	ld.ab   r25, [sp, 4]
213c3581039SVineet Gupta #endif
214c3581039SVineet Gupta 
215c3581039SVineet Gupta 	ld.ab   r24, [sp, 4]
216c3581039SVineet Gupta 	ld.ab   r23, [sp, 4]
217c3581039SVineet Gupta 	ld.ab   r22, [sp, 4]
218c3581039SVineet Gupta 	ld.ab   r21, [sp, 4]
219c3581039SVineet Gupta 	ld.ab   r20, [sp, 4]
220c3581039SVineet Gupta 	ld.ab   r19, [sp, 4]
221c3581039SVineet Gupta 	ld.ab   r18, [sp, 4]
222c3581039SVineet Gupta 	ld.ab   r17, [sp, 4]
223c3581039SVineet Gupta 	ld.ab   r16, [sp, 4]
224c3581039SVineet Gupta 	ld.ab   r15, [sp, 4]
225c3581039SVineet Gupta 	ld.ab   r14, [sp, 4]
226c3581039SVineet Gupta 	ld.ab   r13, [sp, 4]
227c3581039SVineet Gupta .endm
228c3581039SVineet Gupta 
229c3581039SVineet Gupta /*--------------------------------------------------------------
2309d42c84fSVineet Gupta  * Super FAST Restore callee saved regs by simply re-adjusting SP
2319d42c84fSVineet Gupta  *-------------------------------------------------------------*/
2329d42c84fSVineet Gupta .macro DISCARD_CALLEE_SAVED_USER
2339d42c84fSVineet Gupta 	add     sp, sp, 14 * 4
2349d42c84fSVineet Gupta .endm
2359d42c84fSVineet Gupta 
2369d42c84fSVineet Gupta /*--------------------------------------------------------------
2379d42c84fSVineet Gupta  * Restore User mode r25 saved in task_struct->thread.user_r25
2389d42c84fSVineet Gupta  *-------------------------------------------------------------*/
2399d42c84fSVineet Gupta .macro RESTORE_USER_R25
2409d42c84fSVineet Gupta 	ld  r25, [r25, TASK_THREAD + THREAD_USER_R25]
2419d42c84fSVineet Gupta .endm
2429d42c84fSVineet Gupta 
2439d42c84fSVineet Gupta /*-------------------------------------------------------------
2449d42c84fSVineet Gupta  * given a tsk struct, get to the base of it's kernel mode stack
2459d42c84fSVineet Gupta  * tsk->thread_info is really a PAGE, whose bottom hoists stack
2469d42c84fSVineet Gupta  * which grows upwards towards thread_info
2479d42c84fSVineet Gupta  *------------------------------------------------------------*/
2489d42c84fSVineet Gupta 
2499d42c84fSVineet Gupta .macro GET_TSK_STACK_BASE tsk, out
2509d42c84fSVineet Gupta 
2519d42c84fSVineet Gupta 	/* Get task->thread_info (this is essentially start of a PAGE) */
2529d42c84fSVineet Gupta 	ld  \out, [\tsk, TASK_THREAD_INFO]
2539d42c84fSVineet Gupta 
2549d42c84fSVineet Gupta 	/* Go to end of page where stack begins (grows upwards) */
255*283237a0SVineet Gupta 	add2 \out, \out, (THREAD_SIZE)/4
2569d42c84fSVineet Gupta 
2579d42c84fSVineet Gupta .endm
2589d42c84fSVineet Gupta 
2599d42c84fSVineet Gupta /*--------------------------------------------------------------
2609d42c84fSVineet Gupta  * Switch to Kernel Mode stack if SP points to User Mode stack
2619d42c84fSVineet Gupta  *
2629d42c84fSVineet Gupta  * Entry   : r9 contains pre-IRQ/exception/trap status32
2639d42c84fSVineet Gupta  * Exit    : SP is set to kernel mode stack pointer
264080c3747SVineet Gupta  *           If CURR_IN_REG, r25 set to "current" task pointer
2659d42c84fSVineet Gupta  * Clobbers: r9
2669d42c84fSVineet Gupta  *-------------------------------------------------------------*/
2679d42c84fSVineet Gupta 
2689d42c84fSVineet Gupta .macro SWITCH_TO_KERNEL_STK
2699d42c84fSVineet Gupta 
2709d42c84fSVineet Gupta 	/* User Mode when this happened ? Yes: Proceed to switch stack */
2719d42c84fSVineet Gupta 	bbit1   r9, STATUS_U_BIT, 88f
2729d42c84fSVineet Gupta 
2739d42c84fSVineet Gupta 	/* OK we were already in kernel mode when this event happened, thus can
2749d42c84fSVineet Gupta 	 * assume SP is kernel mode SP. _NO_ need to do any stack switching
2759d42c84fSVineet Gupta 	 */
2769d42c84fSVineet Gupta 
2774788a594SVineet Gupta #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
2784788a594SVineet Gupta 	/* However....
2794788a594SVineet Gupta 	 * If Level 2 Interrupts enabled, we may end up with a corner case:
2804788a594SVineet Gupta 	 * 1. User Task executing
2814788a594SVineet Gupta 	 * 2. L1 IRQ taken, ISR starts (CPU auto-switched to KERNEL mode)
2824788a594SVineet Gupta 	 * 3. But before it could switch SP from USER to KERNEL stack
2834788a594SVineet Gupta 	 *      a L2 IRQ "Interrupts" L1
2844788a594SVineet Gupta 	 * Thay way although L2 IRQ happened in Kernel mode, stack is still
2854788a594SVineet Gupta 	 * not switched.
2864788a594SVineet Gupta 	 * To handle this, we may need to switch stack even if in kernel mode
2874788a594SVineet Gupta 	 * provided SP has values in range of USER mode stack ( < 0x7000_0000 )
2884788a594SVineet Gupta 	 */
2894788a594SVineet Gupta 	brlo sp, VMALLOC_START, 88f
2904788a594SVineet Gupta 
2914788a594SVineet Gupta 	/* TODO: vineetg:
2924788a594SVineet Gupta 	 * We need to be a bit more cautious here. What if a kernel bug in
2934788a594SVineet Gupta 	 * L1 ISR, caused SP to go whaco (some small value which looks like
2944788a594SVineet Gupta 	 * USER stk) and then we take L2 ISR.
2954788a594SVineet Gupta 	 * Above brlo alone would treat it as a valid L1-L2 sceanrio
2964788a594SVineet Gupta 	 * instead of shouting alound
2974788a594SVineet Gupta 	 * The only feasible way is to make sure this L2 happened in
2984788a594SVineet Gupta 	 * L1 prelogue ONLY i.e. ilink2 is less than a pre-set marker in
2994788a594SVineet Gupta 	 * L1 ISR before it switches stack
3004788a594SVineet Gupta 	 */
3014788a594SVineet Gupta 
3024788a594SVineet Gupta #endif
3034788a594SVineet Gupta 
3049d42c84fSVineet Gupta 	/* Save Pre Intr/Exception KERNEL MODE SP on kernel stack
3059d42c84fSVineet Gupta 	 * safe-keeping not really needed, but it keeps the epilogue code
3069d42c84fSVineet Gupta 	 * (SP restore) simpler/uniform.
3079d42c84fSVineet Gupta 	 */
3089d42c84fSVineet Gupta 	b.d	77f
3099d42c84fSVineet Gupta 
3109d42c84fSVineet Gupta 	st.a	sp, [sp, -12]	; Make room for orig_r0 and orig_r8
3119d42c84fSVineet Gupta 
3129d42c84fSVineet Gupta 88: /*------Intr/Ecxp happened in user mode, "switch" stack ------ */
3139d42c84fSVineet Gupta 
3149d42c84fSVineet Gupta 	GET_CURR_TASK_ON_CPU   r9
3159d42c84fSVineet Gupta 
316080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
317080c3747SVineet Gupta 
318080c3747SVineet Gupta 	/* If current task pointer cached in r25, time to
319080c3747SVineet Gupta 	 *  -safekeep USER r25 in task->thread_struct->user_r25
320080c3747SVineet Gupta 	 *  -load r25 with current task ptr
321080c3747SVineet Gupta 	 */
322080c3747SVineet Gupta 	st.as	r25, [r9, (TASK_THREAD + THREAD_USER_R25)/4]
323080c3747SVineet Gupta 	mov	r25, r9
324080c3747SVineet Gupta #endif
325080c3747SVineet Gupta 
3269d42c84fSVineet Gupta 	/* With current tsk in r9, get it's kernel mode stack base */
3279d42c84fSVineet Gupta 	GET_TSK_STACK_BASE  r9, r9
3289d42c84fSVineet Gupta 
3299d42c84fSVineet Gupta 	/* Save Pre Intr/Exception User SP on kernel stack */
3309d42c84fSVineet Gupta 	st.a    sp, [r9, -12]	; Make room for orig_r0 and orig_r8
3319d42c84fSVineet Gupta 
3329d42c84fSVineet Gupta 	/* CAUTION:
3339d42c84fSVineet Gupta 	 * SP should be set at the very end when we are done with everything
3349d42c84fSVineet Gupta 	 * In case of 2 levels of interrupt we depend on value of SP to assume
3359d42c84fSVineet Gupta 	 * that everything else is done (loading r25 etc)
3369d42c84fSVineet Gupta 	 */
3379d42c84fSVineet Gupta 
3389d42c84fSVineet Gupta 	/* set SP to point to kernel mode stack */
3399d42c84fSVineet Gupta 	mov sp, r9
3409d42c84fSVineet Gupta 
3419d42c84fSVineet Gupta 77: /* ----- Stack Switched to kernel Mode, Now save REG FILE ----- */
3429d42c84fSVineet Gupta 
3439d42c84fSVineet Gupta .endm
3449d42c84fSVineet Gupta 
3459d42c84fSVineet Gupta /*------------------------------------------------------------
3469d42c84fSVineet Gupta  * "FAKE" a rtie to return from CPU Exception context
3479d42c84fSVineet Gupta  * This is to re-enable Exceptions within exception
3489d42c84fSVineet Gupta  * Look at EV_ProtV to see how this is actually used
3499d42c84fSVineet Gupta  *-------------------------------------------------------------*/
3509d42c84fSVineet Gupta 
3519d42c84fSVineet Gupta .macro FAKE_RET_FROM_EXCPN  reg
3529d42c84fSVineet Gupta 
3539d42c84fSVineet Gupta 	ld  \reg, [sp, PT_status32]
3549d42c84fSVineet Gupta 	bic  \reg, \reg, (STATUS_U_MASK|STATUS_DE_MASK)
3559d42c84fSVineet Gupta 	bset \reg, \reg, STATUS_L_BIT
3569d42c84fSVineet Gupta 	sr  \reg, [erstatus]
3579d42c84fSVineet Gupta 	mov \reg, 55f
3589d42c84fSVineet Gupta 	sr  \reg, [eret]
3599d42c84fSVineet Gupta 
3609d42c84fSVineet Gupta 	rtie
3619d42c84fSVineet Gupta 55:
3629d42c84fSVineet Gupta .endm
3639d42c84fSVineet Gupta 
3649d42c84fSVineet Gupta /*
3659d42c84fSVineet Gupta  * @reg [OUT] &thread_info of "current"
3669d42c84fSVineet Gupta  */
3679d42c84fSVineet Gupta .macro GET_CURR_THR_INFO_FROM_SP  reg
3689d42c84fSVineet Gupta 	and \reg, sp, ~(THREAD_SIZE - 1)
3699d42c84fSVineet Gupta .endm
3709d42c84fSVineet Gupta 
3719d42c84fSVineet Gupta /*
3729d42c84fSVineet Gupta  * @reg [OUT] thread_info->flags of "current"
3739d42c84fSVineet Gupta  */
3749d42c84fSVineet Gupta .macro GET_CURR_THR_INFO_FLAGS  reg
3759d42c84fSVineet Gupta 	GET_CURR_THR_INFO_FROM_SP  \reg
3769d42c84fSVineet Gupta 	ld  \reg, [\reg, THREAD_INFO_FLAGS]
3779d42c84fSVineet Gupta .endm
3789d42c84fSVineet Gupta 
3799d42c84fSVineet Gupta /*--------------------------------------------------------------
3809d42c84fSVineet Gupta  * For early Exception Prologue, a core reg is temporarily needed to
3819d42c84fSVineet Gupta  * code the rest of prolog (stack switching). This is done by stashing
3829d42c84fSVineet Gupta  * it to memory (non-SMP case) or SCRATCH0 Aux Reg (SMP).
3839d42c84fSVineet Gupta  *
3849d42c84fSVineet Gupta  * Before saving the full regfile - this reg is restored back, only
3859d42c84fSVineet Gupta  * to be saved again on kernel mode stack, as part of ptregs.
3869d42c84fSVineet Gupta  *-------------------------------------------------------------*/
3879d42c84fSVineet Gupta .macro EXCPN_PROLOG_FREEUP_REG	reg
38841195d23SVineet Gupta #ifdef CONFIG_SMP
38941195d23SVineet Gupta 	sr  \reg, [ARC_REG_SCRATCH_DATA0]
39041195d23SVineet Gupta #else
3919d42c84fSVineet Gupta 	st  \reg, [@ex_saved_reg1]
39241195d23SVineet Gupta #endif
3939d42c84fSVineet Gupta .endm
3949d42c84fSVineet Gupta 
3959d42c84fSVineet Gupta .macro EXCPN_PROLOG_RESTORE_REG	reg
39641195d23SVineet Gupta #ifdef CONFIG_SMP
39741195d23SVineet Gupta 	lr  \reg, [ARC_REG_SCRATCH_DATA0]
39841195d23SVineet Gupta #else
3999d42c84fSVineet Gupta 	ld  \reg, [@ex_saved_reg1]
40041195d23SVineet Gupta #endif
4019d42c84fSVineet Gupta .endm
4029d42c84fSVineet Gupta 
4039d42c84fSVineet Gupta /*--------------------------------------------------------------
4049d42c84fSVineet Gupta  * Save all registers used by Exceptions (TLB Miss, Prot-V, Mem err etc)
4059d42c84fSVineet Gupta  * Requires SP to be already switched to kernel mode Stack
4069d42c84fSVineet Gupta  * sp points to the next free element on the stack at exit of this macro.
4079d42c84fSVineet Gupta  * Registers are pushed / popped in the order defined in struct ptregs
4089d42c84fSVineet Gupta  * in asm/ptrace.h
4099d42c84fSVineet Gupta  * Note that syscalls are implemented via TRAP which is also a exception
4109d42c84fSVineet Gupta  * from CPU's point of view
4119d42c84fSVineet Gupta  *-------------------------------------------------------------*/
4129d42c84fSVineet Gupta .macro SAVE_ALL_EXCEPTION   marker
4139d42c84fSVineet Gupta 
414367f3fcdSVineet Gupta 	st      \marker, [sp, 8]	/* orig_r8 */
4155c39c0abSVineet Gupta 	st      r0, [sp, 4]    /* orig_r0, needed only for sys calls */
4165c39c0abSVineet Gupta 
4179d42c84fSVineet Gupta 	/* Restore r9 used to code the early prologue */
4189d42c84fSVineet Gupta 	EXCPN_PROLOG_RESTORE_REG  r9
4199d42c84fSVineet Gupta 
4209d42c84fSVineet Gupta 	SAVE_CALLER_SAVED
4219d42c84fSVineet Gupta 	st.a    r26, [sp, -4]   /* gp */
4229d42c84fSVineet Gupta 	st.a    fp, [sp, -4]
4239d42c84fSVineet Gupta 	st.a    blink, [sp, -4]
4249d42c84fSVineet Gupta 	lr	r9, [eret]
4259d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
4269d42c84fSVineet Gupta 	lr	r9, [erstatus]
4279d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
4289d42c84fSVineet Gupta 	st.a    lp_count, [sp, -4]
4299d42c84fSVineet Gupta 	lr	r9, [lp_end]
4309d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
4319d42c84fSVineet Gupta 	lr	r9, [lp_start]
4329d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
4339d42c84fSVineet Gupta 	lr	r9, [erbta]
4349d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
4359d42c84fSVineet Gupta 
4369d42c84fSVineet Gupta 	/* move up by 1 word to "create" pt_regs->"stack_place_holder" */
4379d42c84fSVineet Gupta 	sub sp, sp, 4
4389d42c84fSVineet Gupta .endm
4399d42c84fSVineet Gupta 
4409d42c84fSVineet Gupta /*--------------------------------------------------------------
4419d42c84fSVineet Gupta  * Save scratch regs for exceptions
4429d42c84fSVineet Gupta  *-------------------------------------------------------------*/
4439d42c84fSVineet Gupta .macro SAVE_ALL_SYS
4445c39c0abSVineet Gupta 	SAVE_ALL_EXCEPTION  orig_r8_IS_EXCPN
4459d42c84fSVineet Gupta .endm
4469d42c84fSVineet Gupta 
4479d42c84fSVineet Gupta /*--------------------------------------------------------------
4489d42c84fSVineet Gupta  * Save scratch regs for sys calls
4499d42c84fSVineet Gupta  *-------------------------------------------------------------*/
4509d42c84fSVineet Gupta .macro SAVE_ALL_TRAP
4515c39c0abSVineet Gupta 	/*
4525c39c0abSVineet Gupta 	 * Setup pt_regs->orig_r8.
4535c39c0abSVineet Gupta 	 * Encode syscall number (r8) in upper short word of event type (r9)
4545c39c0abSVineet Gupta 	 * N.B. #1: This is already endian safe (see ptrace.h)
4555c39c0abSVineet Gupta 	 *      #2: Only r9 can be used as scratch as it is already clobbered
4565c39c0abSVineet Gupta 	 *          and it's contents are no longer needed by the latter part
4575c39c0abSVineet Gupta 	 *          of exception prologue
4585c39c0abSVineet Gupta 	 */
4595c39c0abSVineet Gupta 	lsl  r9, r8, 16
4605c39c0abSVineet Gupta 	or   r9, r9, orig_r8_IS_SCALL
4615c39c0abSVineet Gupta 
4625c39c0abSVineet Gupta 	SAVE_ALL_EXCEPTION  r9
4639d42c84fSVineet Gupta .endm
4649d42c84fSVineet Gupta 
4659d42c84fSVineet Gupta /*--------------------------------------------------------------
4669d42c84fSVineet Gupta  * Restore all registers used by system call or Exceptions
4679d42c84fSVineet Gupta  * SP should always be pointing to the next free stack element
4689d42c84fSVineet Gupta  * when entering this macro.
4699d42c84fSVineet Gupta  *
4709d42c84fSVineet Gupta  * NOTE:
4719d42c84fSVineet Gupta  *
4729d42c84fSVineet Gupta  * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg
4739d42c84fSVineet Gupta  * for memory load operations. If used in that way interrupts are deffered
4749d42c84fSVineet Gupta  * by hardware and that is not good.
4759d42c84fSVineet Gupta  *-------------------------------------------------------------*/
4769d42c84fSVineet Gupta .macro RESTORE_ALL_SYS
4779d42c84fSVineet Gupta 
4789d42c84fSVineet Gupta 	add sp, sp, 4       /* hop over unused "pt_regs->stack_place_holder" */
4799d42c84fSVineet Gupta 
4809d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
4819d42c84fSVineet Gupta 	sr	r9, [erbta]
4829d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
4839d42c84fSVineet Gupta 	sr	r9, [lp_start]
4849d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
4859d42c84fSVineet Gupta 	sr	r9, [lp_end]
4869d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
4879d42c84fSVineet Gupta 	mov	lp_count, r9
4889d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
4899d42c84fSVineet Gupta 	sr	r9, [erstatus]
4909d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
4919d42c84fSVineet Gupta 	sr	r9, [eret]
4929d42c84fSVineet Gupta 	ld.ab   blink, [sp, 4]
4939d42c84fSVineet Gupta 	ld.ab   fp, [sp, 4]
4949d42c84fSVineet Gupta 	ld.ab   r26, [sp, 4]    /* gp */
4959d42c84fSVineet Gupta 	RESTORE_CALLER_SAVED
4969d42c84fSVineet Gupta 
4979d42c84fSVineet Gupta 	ld  sp, [sp] /* restore original sp */
4989d42c84fSVineet Gupta 	/* orig_r0 and orig_r8 skipped automatically */
4999d42c84fSVineet Gupta .endm
5009d42c84fSVineet Gupta 
5019d42c84fSVineet Gupta 
5029d42c84fSVineet Gupta /*--------------------------------------------------------------
5039d42c84fSVineet Gupta  * Save all registers used by interrupt handlers.
5049d42c84fSVineet Gupta  *-------------------------------------------------------------*/
5059d42c84fSVineet Gupta .macro SAVE_ALL_INT1
5069d42c84fSVineet Gupta 
5079d42c84fSVineet Gupta 	/* restore original r9 , saved in int1_saved_reg
5089d42c84fSVineet Gupta 	* It will be saved on stack in macro: SAVE_CALLER_SAVED
5099d42c84fSVineet Gupta 	*/
51041195d23SVineet Gupta #ifdef CONFIG_SMP
51141195d23SVineet Gupta 	lr  r9, [ARC_REG_SCRATCH_DATA0]
51241195d23SVineet Gupta #else
5139d42c84fSVineet Gupta 	ld  r9, [@int1_saved_reg]
51441195d23SVineet Gupta #endif
5159d42c84fSVineet Gupta 
5169d42c84fSVineet Gupta 	/* now we are ready to save the remaining context :) */
5175c39c0abSVineet Gupta 	st      orig_r8_IS_IRQ1, [sp, 8]    /* Event Type */
5189d42c84fSVineet Gupta 	st      0, [sp, 4]    /* orig_r0 , N/A for IRQ */
5199d42c84fSVineet Gupta 	SAVE_CALLER_SAVED
5209d42c84fSVineet Gupta 	st.a    r26, [sp, -4]   /* gp */
5219d42c84fSVineet Gupta 	st.a    fp, [sp, -4]
5229d42c84fSVineet Gupta 	st.a    blink, [sp, -4]
5239d42c84fSVineet Gupta 	st.a    ilink1, [sp, -4]
5249d42c84fSVineet Gupta 	lr	r9, [status32_l1]
5259d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
5269d42c84fSVineet Gupta 	st.a    lp_count, [sp, -4]
5279d42c84fSVineet Gupta 	lr	r9, [lp_end]
5289d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
5299d42c84fSVineet Gupta 	lr	r9, [lp_start]
5309d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
5319d42c84fSVineet Gupta 	lr	r9, [bta_l1]
5329d42c84fSVineet Gupta 	st.a    r9, [sp, -4]
5339d42c84fSVineet Gupta 
5349d42c84fSVineet Gupta 	/* move up by 1 word to "create" pt_regs->"stack_place_holder" */
5359d42c84fSVineet Gupta 	sub sp, sp, 4
5369d42c84fSVineet Gupta .endm
5379d42c84fSVineet Gupta 
5384788a594SVineet Gupta .macro SAVE_ALL_INT2
5394788a594SVineet Gupta 
5404788a594SVineet Gupta 	/* TODO-vineetg: SMP we can't use global nor can we use
5414788a594SVineet Gupta 	*   SCRATCH0 as we do for int1 because while int1 is using
5424788a594SVineet Gupta 	*   it, int2 can come
5434788a594SVineet Gupta 	*/
5444788a594SVineet Gupta 	/* retsore original r9 , saved in sys_saved_r9 */
5454788a594SVineet Gupta 	ld  r9, [@int2_saved_reg]
5464788a594SVineet Gupta 
5474788a594SVineet Gupta 	/* now we are ready to save the remaining context :) */
5484788a594SVineet Gupta 	st      orig_r8_IS_IRQ2, [sp, 8]    /* Event Type */
5494788a594SVineet Gupta 	st      0, [sp, 4]    /* orig_r0 , N/A for IRQ */
5504788a594SVineet Gupta 	SAVE_CALLER_SAVED
5514788a594SVineet Gupta 	st.a    r26, [sp, -4]   /* gp */
5524788a594SVineet Gupta 	st.a    fp, [sp, -4]
5534788a594SVineet Gupta 	st.a    blink, [sp, -4]
5544788a594SVineet Gupta 	st.a    ilink2, [sp, -4]
5554788a594SVineet Gupta 	lr	r9, [status32_l2]
5564788a594SVineet Gupta 	st.a    r9, [sp, -4]
5574788a594SVineet Gupta 	st.a    lp_count, [sp, -4]
5584788a594SVineet Gupta 	lr	r9, [lp_end]
5594788a594SVineet Gupta 	st.a    r9, [sp, -4]
5604788a594SVineet Gupta 	lr	r9, [lp_start]
5614788a594SVineet Gupta 	st.a    r9, [sp, -4]
5624788a594SVineet Gupta 	lr	r9, [bta_l2]
5634788a594SVineet Gupta 	st.a    r9, [sp, -4]
5644788a594SVineet Gupta 
5654788a594SVineet Gupta 	/* move up by 1 word to "create" pt_regs->"stack_place_holder" */
5664788a594SVineet Gupta 	sub sp, sp, 4
5674788a594SVineet Gupta .endm
5684788a594SVineet Gupta 
5699d42c84fSVineet Gupta /*--------------------------------------------------------------
5709d42c84fSVineet Gupta  * Restore all registers used by interrupt handlers.
5719d42c84fSVineet Gupta  *
5729d42c84fSVineet Gupta  * NOTE:
5739d42c84fSVineet Gupta  *
5749d42c84fSVineet Gupta  * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg
5759d42c84fSVineet Gupta  * for memory load operations. If used in that way interrupts are deffered
5769d42c84fSVineet Gupta  * by hardware and that is not good.
5779d42c84fSVineet Gupta  *-------------------------------------------------------------*/
5789d42c84fSVineet Gupta 
5799d42c84fSVineet Gupta .macro RESTORE_ALL_INT1
5809d42c84fSVineet Gupta 	add sp, sp, 4       /* hop over unused "pt_regs->stack_place_holder" */
5819d42c84fSVineet Gupta 
5829d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4] /* Actual reg file */
5839d42c84fSVineet Gupta 	sr	r9, [bta_l1]
5849d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
5859d42c84fSVineet Gupta 	sr	r9, [lp_start]
5869d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
5879d42c84fSVineet Gupta 	sr	r9, [lp_end]
5889d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
5899d42c84fSVineet Gupta 	mov	lp_count, r9
5909d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
5919d42c84fSVineet Gupta 	sr	r9, [status32_l1]
5929d42c84fSVineet Gupta 	ld.ab   r9, [sp, 4]
5939d42c84fSVineet Gupta 	mov	ilink1, r9
5949d42c84fSVineet Gupta 	ld.ab   blink, [sp, 4]
5959d42c84fSVineet Gupta 	ld.ab   fp, [sp, 4]
5969d42c84fSVineet Gupta 	ld.ab   r26, [sp, 4]    /* gp */
5979d42c84fSVineet Gupta 	RESTORE_CALLER_SAVED
5989d42c84fSVineet Gupta 
5999d42c84fSVineet Gupta 	ld  sp, [sp] /* restore original sp */
6009d42c84fSVineet Gupta 	/* orig_r0 and orig_r8 skipped automatically */
6019d42c84fSVineet Gupta .endm
6029d42c84fSVineet Gupta 
6034788a594SVineet Gupta .macro RESTORE_ALL_INT2
6044788a594SVineet Gupta 	add sp, sp, 4       /* hop over unused "pt_regs->stack_place_holder" */
6054788a594SVineet Gupta 
6064788a594SVineet Gupta 	ld.ab   r9, [sp, 4]
6074788a594SVineet Gupta 	sr	r9, [bta_l2]
6084788a594SVineet Gupta 	ld.ab   r9, [sp, 4]
6094788a594SVineet Gupta 	sr	r9, [lp_start]
6104788a594SVineet Gupta 	ld.ab   r9, [sp, 4]
6114788a594SVineet Gupta 	sr	r9, [lp_end]
6124788a594SVineet Gupta 	ld.ab   r9, [sp, 4]
6134788a594SVineet Gupta 	mov	lp_count, r9
6144788a594SVineet Gupta 	ld.ab   r9, [sp, 4]
6154788a594SVineet Gupta 	sr	r9, [status32_l2]
6164788a594SVineet Gupta 	ld.ab   r9, [sp, 4]
6174788a594SVineet Gupta 	mov	ilink2, r9
6184788a594SVineet Gupta 	ld.ab   blink, [sp, 4]
6194788a594SVineet Gupta 	ld.ab   fp, [sp, 4]
6204788a594SVineet Gupta 	ld.ab   r26, [sp, 4]    /* gp */
6214788a594SVineet Gupta 	RESTORE_CALLER_SAVED
6224788a594SVineet Gupta 
6234788a594SVineet Gupta 	ld  sp, [sp] /* restore original sp */
6244788a594SVineet Gupta 	/* orig_r0 and orig_r8 skipped automatically */
6254788a594SVineet Gupta 
6264788a594SVineet Gupta .endm
6274788a594SVineet Gupta 
6284788a594SVineet Gupta 
6299d42c84fSVineet Gupta /* Get CPU-ID of this core */
6309d42c84fSVineet Gupta .macro  GET_CPU_ID  reg
6319d42c84fSVineet Gupta 	lr  \reg, [identity]
6329d42c84fSVineet Gupta 	lsr \reg, \reg, 8
6339d42c84fSVineet Gupta 	bmsk \reg, \reg, 7
6349d42c84fSVineet Gupta .endm
6359d42c84fSVineet Gupta 
63641195d23SVineet Gupta #ifdef CONFIG_SMP
63741195d23SVineet Gupta 
63841195d23SVineet Gupta /*-------------------------------------------------
63941195d23SVineet Gupta  * Retrieve the current running task on this CPU
64041195d23SVineet Gupta  * 1. Determine curr CPU id.
64141195d23SVineet Gupta  * 2. Use it to index into _current_task[ ]
64241195d23SVineet Gupta  */
64341195d23SVineet Gupta .macro  GET_CURR_TASK_ON_CPU   reg
64441195d23SVineet Gupta 	GET_CPU_ID  \reg
64541195d23SVineet Gupta 	ld.as  \reg, [@_current_task, \reg]
64641195d23SVineet Gupta .endm
64741195d23SVineet Gupta 
64841195d23SVineet Gupta /*-------------------------------------------------
64941195d23SVineet Gupta  * Save a new task as the "current" task on this CPU
65041195d23SVineet Gupta  * 1. Determine curr CPU id.
65141195d23SVineet Gupta  * 2. Use it to index into _current_task[ ]
65241195d23SVineet Gupta  *
65341195d23SVineet Gupta  * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
65441195d23SVineet Gupta  * because ST r0, [r1, offset] can ONLY have s9 @offset
65541195d23SVineet Gupta  * while   LD can take s9 (4 byte insn) or LIMM (8 byte insn)
65641195d23SVineet Gupta  */
65741195d23SVineet Gupta 
65841195d23SVineet Gupta .macro  SET_CURR_TASK_ON_CPU    tsk, tmp
65941195d23SVineet Gupta 	GET_CPU_ID  \tmp
66041195d23SVineet Gupta 	add2 \tmp, @_current_task, \tmp
66141195d23SVineet Gupta 	st   \tsk, [\tmp]
66241195d23SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
66341195d23SVineet Gupta 	mov r25, \tsk
66441195d23SVineet Gupta #endif
66541195d23SVineet Gupta 
66641195d23SVineet Gupta .endm
66741195d23SVineet Gupta 
66841195d23SVineet Gupta 
66941195d23SVineet Gupta #else   /* Uniprocessor implementation of macros */
67041195d23SVineet Gupta 
6719d42c84fSVineet Gupta .macro  GET_CURR_TASK_ON_CPU    reg
6729d42c84fSVineet Gupta 	ld  \reg, [@_current_task]
6739d42c84fSVineet Gupta .endm
6749d42c84fSVineet Gupta 
6759d42c84fSVineet Gupta .macro  SET_CURR_TASK_ON_CPU    tsk, tmp
6769d42c84fSVineet Gupta 	st  \tsk, [@_current_task]
677080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
678080c3747SVineet Gupta 	mov r25, \tsk
679080c3747SVineet Gupta #endif
6809d42c84fSVineet Gupta .endm
6819d42c84fSVineet Gupta 
68241195d23SVineet Gupta #endif /* SMP / UNI */
68341195d23SVineet Gupta 
6849d42c84fSVineet Gupta /* ------------------------------------------------------------------
6859d42c84fSVineet Gupta  * Get the ptr to some field of Current Task at @off in task struct
686080c3747SVineet Gupta  *  -Uses r25 for Current task ptr if that is enabled
6879d42c84fSVineet Gupta  */
6889d42c84fSVineet Gupta 
689080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
690080c3747SVineet Gupta 
691080c3747SVineet Gupta .macro GET_CURR_TASK_FIELD_PTR  off,  reg
692080c3747SVineet Gupta 	add \reg, r25, \off
693080c3747SVineet Gupta .endm
694080c3747SVineet Gupta 
695080c3747SVineet Gupta #else
696080c3747SVineet Gupta 
6979d42c84fSVineet Gupta .macro GET_CURR_TASK_FIELD_PTR  off,  reg
6989d42c84fSVineet Gupta 	GET_CURR_TASK_ON_CPU  \reg
6999d42c84fSVineet Gupta 	add \reg, \reg, \off
7009d42c84fSVineet Gupta .endm
7019d42c84fSVineet Gupta 
702080c3747SVineet Gupta #endif	/* CONFIG_ARC_CURR_IN_REG */
703080c3747SVineet Gupta 
7049d42c84fSVineet Gupta #endif  /* __ASSEMBLY__ */
7059d42c84fSVineet Gupta 
7069d42c84fSVineet Gupta #endif  /* __ASM_ARC_ENTRY_H */
707