xref: /linux/arch/arc/include/asm/entry.h (revision d2912cb15bdda8ba4a5dd73396ad62641af2f520)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
29d42c84fSVineet Gupta /*
36d1a20b1SVineet Gupta  * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
49d42c84fSVineet Gupta  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
59d42c84fSVineet Gupta  */
69d42c84fSVineet Gupta 
79d42c84fSVineet Gupta #ifndef __ASM_ARC_ENTRY_H
89d42c84fSVineet Gupta #define __ASM_ARC_ENTRY_H
99d42c84fSVineet Gupta 
109d42c84fSVineet Gupta #include <asm/unistd.h>		/* For NR_syscalls defination */
119d42c84fSVineet Gupta #include <asm/arcregs.h>
129d42c84fSVineet Gupta #include <asm/ptrace.h>
13080c3747SVineet Gupta #include <asm/processor.h>	/* For VMALLOC_START */
144ffd9e2cSVineet Gupta #include <asm/mmu.h>
159d42c84fSVineet Gupta 
161f6ccfffSVineet Gupta #ifdef CONFIG_ISA_ARCOMPACT
176d1a20b1SVineet Gupta #include <asm/entry-compact.h>	/* ISA specific bits */
181f6ccfffSVineet Gupta #else
191f6ccfffSVineet Gupta #include <asm/entry-arcv2.h>
201f6ccfffSVineet Gupta #endif
216d1a20b1SVineet Gupta 
229d42c84fSVineet Gupta /* Note on the LD/ST addr modes with addr reg wback
239d42c84fSVineet Gupta  *
249d42c84fSVineet Gupta  * LD.a same as LD.aw
259d42c84fSVineet Gupta  *
269d42c84fSVineet Gupta  * LD.a    reg1, [reg2, x]  => Pre Incr
279d42c84fSVineet Gupta  *      Eff Addr for load = [reg2 + x]
289d42c84fSVineet Gupta  *
299d42c84fSVineet Gupta  * LD.ab   reg1, [reg2, x]  => Post Incr
309d42c84fSVineet Gupta  *      Eff Addr for load = [reg2]
319d42c84fSVineet Gupta  */
329d42c84fSVineet Gupta 
333ebedbb2SVineet Gupta .macro PUSH reg
343ebedbb2SVineet Gupta 	st.a	\reg, [sp, -4]
353ebedbb2SVineet Gupta .endm
363ebedbb2SVineet Gupta 
373ebedbb2SVineet Gupta .macro PUSHAX aux
383ebedbb2SVineet Gupta 	lr	r9, [\aux]
393ebedbb2SVineet Gupta 	PUSH	r9
403ebedbb2SVineet Gupta .endm
413ebedbb2SVineet Gupta 
423ebedbb2SVineet Gupta .macro POP reg
433ebedbb2SVineet Gupta 	ld.ab	\reg, [sp, 4]
443ebedbb2SVineet Gupta .endm
453ebedbb2SVineet Gupta 
463ebedbb2SVineet Gupta .macro POPAX aux
473ebedbb2SVineet Gupta 	POP	r9
483ebedbb2SVineet Gupta 	sr	r9, [\aux]
499d42c84fSVineet Gupta .endm
509d42c84fSVineet Gupta 
519d42c84fSVineet Gupta /*--------------------------------------------------------------
523ebedbb2SVineet Gupta  * Helpers to save/restore Scratch Regs:
533ebedbb2SVineet Gupta  * used by Interrupt/Exception Prologue/Epilogue
549d42c84fSVineet Gupta  *-------------------------------------------------------------*/
553ebedbb2SVineet Gupta .macro  SAVE_R0_TO_R12
563ebedbb2SVineet Gupta 	PUSH	r0
573ebedbb2SVineet Gupta 	PUSH	r1
583ebedbb2SVineet Gupta 	PUSH	r2
593ebedbb2SVineet Gupta 	PUSH	r3
603ebedbb2SVineet Gupta 	PUSH	r4
613ebedbb2SVineet Gupta 	PUSH	r5
623ebedbb2SVineet Gupta 	PUSH	r6
633ebedbb2SVineet Gupta 	PUSH	r7
643ebedbb2SVineet Gupta 	PUSH	r8
653ebedbb2SVineet Gupta 	PUSH	r9
663ebedbb2SVineet Gupta 	PUSH	r10
673ebedbb2SVineet Gupta 	PUSH	r11
683ebedbb2SVineet Gupta 	PUSH	r12
693ebedbb2SVineet Gupta .endm
703ebedbb2SVineet Gupta 
713ebedbb2SVineet Gupta .macro RESTORE_R12_TO_R0
723ebedbb2SVineet Gupta 	POP	r12
733ebedbb2SVineet Gupta 	POP	r11
743ebedbb2SVineet Gupta 	POP	r10
753ebedbb2SVineet Gupta 	POP	r9
763ebedbb2SVineet Gupta 	POP	r8
773ebedbb2SVineet Gupta 	POP	r7
783ebedbb2SVineet Gupta 	POP	r6
793ebedbb2SVineet Gupta 	POP	r5
803ebedbb2SVineet Gupta 	POP	r4
813ebedbb2SVineet Gupta 	POP	r3
823ebedbb2SVineet Gupta 	POP	r2
833ebedbb2SVineet Gupta 	POP	r1
843ebedbb2SVineet Gupta 	POP	r0
85359105bdSVineet Gupta 
863ebedbb2SVineet Gupta .endm
873ebedbb2SVineet Gupta 
883ebedbb2SVineet Gupta /*--------------------------------------------------------------
893ebedbb2SVineet Gupta  * Helpers to save/restore callee-saved regs:
903ebedbb2SVineet Gupta  * used by several macros below
913ebedbb2SVineet Gupta  *-------------------------------------------------------------*/
923ebedbb2SVineet Gupta .macro SAVE_R13_TO_R24
933ebedbb2SVineet Gupta 	PUSH	r13
943ebedbb2SVineet Gupta 	PUSH	r14
953ebedbb2SVineet Gupta 	PUSH	r15
963ebedbb2SVineet Gupta 	PUSH	r16
973ebedbb2SVineet Gupta 	PUSH	r17
983ebedbb2SVineet Gupta 	PUSH	r18
993ebedbb2SVineet Gupta 	PUSH	r19
1003ebedbb2SVineet Gupta 	PUSH	r20
1013ebedbb2SVineet Gupta 	PUSH	r21
1023ebedbb2SVineet Gupta 	PUSH	r22
1033ebedbb2SVineet Gupta 	PUSH	r23
1043ebedbb2SVineet Gupta 	PUSH	r24
1053ebedbb2SVineet Gupta .endm
1063ebedbb2SVineet Gupta 
1073ebedbb2SVineet Gupta .macro RESTORE_R24_TO_R13
1083ebedbb2SVineet Gupta 	POP	r24
1093ebedbb2SVineet Gupta 	POP	r23
1103ebedbb2SVineet Gupta 	POP	r22
1113ebedbb2SVineet Gupta 	POP	r21
1123ebedbb2SVineet Gupta 	POP	r20
1133ebedbb2SVineet Gupta 	POP	r19
1143ebedbb2SVineet Gupta 	POP	r18
1153ebedbb2SVineet Gupta 	POP	r17
1163ebedbb2SVineet Gupta 	POP	r16
1173ebedbb2SVineet Gupta 	POP	r15
1183ebedbb2SVineet Gupta 	POP	r14
1193ebedbb2SVineet Gupta 	POP	r13
1209d42c84fSVineet Gupta .endm
1219d42c84fSVineet Gupta 
1229d42c84fSVineet Gupta /*--------------------------------------------------------------
1233ebedbb2SVineet Gupta  * Collect User Mode callee regs as struct callee_regs - needed by
1243ebedbb2SVineet Gupta  * fork/do_signal/unaligned-access-emulation.
1253ebedbb2SVineet Gupta  * (By default only scratch regs are saved on entry to kernel)
1263ebedbb2SVineet Gupta  *
1273ebedbb2SVineet Gupta  * Special handling for r25 if used for caching Task Pointer.
1283ebedbb2SVineet Gupta  * It would have been saved in task->thread.user_r25 already, but to keep
1293ebedbb2SVineet Gupta  * the interface same it is copied into regular r25 placeholder in
1303ebedbb2SVineet Gupta  * struct callee_regs.
1319d42c84fSVineet Gupta  *-------------------------------------------------------------*/
1329d42c84fSVineet Gupta .macro SAVE_CALLEE_SAVED_USER
1333ebedbb2SVineet Gupta 
1340d7b8855SVineet Gupta 	mov	r12, sp		; save SP as ref to pt_regs
1353ebedbb2SVineet Gupta 	SAVE_R13_TO_R24
136080c3747SVineet Gupta 
137080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
1380d7b8855SVineet Gupta 	; Retrieve orig r25 and save it with rest of callee_regs
13986147e3cSLiav Rehana 	ld	r12, [r12, PT_user_r25]
1400d7b8855SVineet Gupta 	PUSH	r12
141080c3747SVineet Gupta #else
1423ebedbb2SVineet Gupta 	PUSH	r25
143080c3747SVineet Gupta #endif
1449d42c84fSVineet Gupta 
1459d42c84fSVineet Gupta .endm
1469d42c84fSVineet Gupta 
1479d42c84fSVineet Gupta /*--------------------------------------------------------------
1483ebedbb2SVineet Gupta  * Save kernel Mode callee regs at the time of Contect Switch.
1493ebedbb2SVineet Gupta  *
1503ebedbb2SVineet Gupta  * Special handling for r25 if used for caching Task Pointer.
1513ebedbb2SVineet Gupta  * Kernel simply skips saving it since it will be loaded with
1523ebedbb2SVineet Gupta  * incoming task pointer anyways
1539d42c84fSVineet Gupta  *-------------------------------------------------------------*/
1549d42c84fSVineet Gupta .macro SAVE_CALLEE_SAVED_KERNEL
1553ebedbb2SVineet Gupta 
1563ebedbb2SVineet Gupta 	SAVE_R13_TO_R24
1573ebedbb2SVineet Gupta 
158080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
15916f9afe6SVineet Gupta 	sub     sp, sp, 4
160080c3747SVineet Gupta #else
1613ebedbb2SVineet Gupta 	PUSH	r25
162080c3747SVineet Gupta #endif
1639d42c84fSVineet Gupta .endm
1649d42c84fSVineet Gupta 
1659d42c84fSVineet Gupta /*--------------------------------------------------------------
1663ebedbb2SVineet Gupta  * Opposite of SAVE_CALLEE_SAVED_KERNEL
1679d42c84fSVineet Gupta  *-------------------------------------------------------------*/
1689d42c84fSVineet Gupta .macro RESTORE_CALLEE_SAVED_KERNEL
1699d42c84fSVineet Gupta 
170080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
17116f9afe6SVineet Gupta 	add     sp, sp, 4  /* skip usual r25 placeholder */
172080c3747SVineet Gupta #else
1733ebedbb2SVineet Gupta 	POP	r25
174080c3747SVineet Gupta #endif
1753ebedbb2SVineet Gupta 	RESTORE_R24_TO_R13
1769d42c84fSVineet Gupta .endm
1779d42c84fSVineet Gupta 
1789d42c84fSVineet Gupta /*--------------------------------------------------------------
1793ebedbb2SVineet Gupta  * Opposite of SAVE_CALLEE_SAVED_USER
1803ebedbb2SVineet Gupta  *
1813ebedbb2SVineet Gupta  * ptrace tracer or unaligned-access fixup might have changed a user mode
1823ebedbb2SVineet Gupta  * callee reg which is saved back to usual r25 storage location
183c3581039SVineet Gupta  *-------------------------------------------------------------*/
184c3581039SVineet Gupta .macro RESTORE_CALLEE_SAVED_USER
185c3581039SVineet Gupta 
186c3581039SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
1870d7b8855SVineet Gupta 	POP	r12
188c3581039SVineet Gupta #else
1893ebedbb2SVineet Gupta 	POP	r25
190c3581039SVineet Gupta #endif
1913ebedbb2SVineet Gupta 	RESTORE_R24_TO_R13
1920d7b8855SVineet Gupta 
1930d7b8855SVineet Gupta 	; SP is back to start of pt_regs
1940d7b8855SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
19586147e3cSLiav Rehana 	st	r12, [sp, PT_user_r25]
1960d7b8855SVineet Gupta #endif
197c3581039SVineet Gupta .endm
198c3581039SVineet Gupta 
199c3581039SVineet Gupta /*--------------------------------------------------------------
2009d42c84fSVineet Gupta  * Super FAST Restore callee saved regs by simply re-adjusting SP
2019d42c84fSVineet Gupta  *-------------------------------------------------------------*/
2029d42c84fSVineet Gupta .macro DISCARD_CALLEE_SAVED_USER
20316f9afe6SVineet Gupta 	add     sp, sp, SZ_CALLEE_REGS
2049d42c84fSVineet Gupta .endm
2059d42c84fSVineet Gupta 
2069d42c84fSVineet Gupta /*-------------------------------------------------------------
2079d42c84fSVineet Gupta  * given a tsk struct, get to the base of it's kernel mode stack
2089d42c84fSVineet Gupta  * tsk->thread_info is really a PAGE, whose bottom hoists stack
2099d42c84fSVineet Gupta  * which grows upwards towards thread_info
2109d42c84fSVineet Gupta  *------------------------------------------------------------*/
2119d42c84fSVineet Gupta 
2129d42c84fSVineet Gupta .macro GET_TSK_STACK_BASE tsk, out
2139d42c84fSVineet Gupta 
2149d42c84fSVineet Gupta 	/* Get task->thread_info (this is essentially start of a PAGE) */
2159d42c84fSVineet Gupta 	ld  \out, [\tsk, TASK_THREAD_INFO]
2169d42c84fSVineet Gupta 
2179d42c84fSVineet Gupta 	/* Go to end of page where stack begins (grows upwards) */
218283237a0SVineet Gupta 	add2 \out, \out, (THREAD_SIZE)/4
2199d42c84fSVineet Gupta 
2209d42c84fSVineet Gupta .endm
2219d42c84fSVineet Gupta 
2229d42c84fSVineet Gupta /*
2239d42c84fSVineet Gupta  * @reg [OUT] thread_info->flags of "current"
2249d42c84fSVineet Gupta  */
2259d42c84fSVineet Gupta .macro GET_CURR_THR_INFO_FLAGS  reg
2269d42c84fSVineet Gupta 	GET_CURR_THR_INFO_FROM_SP  \reg
2279d42c84fSVineet Gupta 	ld  \reg, [\reg, THREAD_INFO_FLAGS]
2289d42c84fSVineet Gupta .endm
2299d42c84fSVineet Gupta 
23041195d23SVineet Gupta #ifdef CONFIG_SMP
23141195d23SVineet Gupta 
23241195d23SVineet Gupta /*-------------------------------------------------
23341195d23SVineet Gupta  * Retrieve the current running task on this CPU
23441195d23SVineet Gupta  * 1. Determine curr CPU id.
23541195d23SVineet Gupta  * 2. Use it to index into _current_task[ ]
23641195d23SVineet Gupta  */
23741195d23SVineet Gupta .macro  GET_CURR_TASK_ON_CPU   reg
23841195d23SVineet Gupta 	GET_CPU_ID  \reg
23941195d23SVineet Gupta 	ld.as  \reg, [@_current_task, \reg]
24041195d23SVineet Gupta .endm
24141195d23SVineet Gupta 
24241195d23SVineet Gupta /*-------------------------------------------------
24341195d23SVineet Gupta  * Save a new task as the "current" task on this CPU
24441195d23SVineet Gupta  * 1. Determine curr CPU id.
24541195d23SVineet Gupta  * 2. Use it to index into _current_task[ ]
24641195d23SVineet Gupta  *
24741195d23SVineet Gupta  * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
24841195d23SVineet Gupta  * because ST r0, [r1, offset] can ONLY have s9 @offset
24941195d23SVineet Gupta  * while   LD can take s9 (4 byte insn) or LIMM (8 byte insn)
25041195d23SVineet Gupta  */
25141195d23SVineet Gupta 
25241195d23SVineet Gupta .macro  SET_CURR_TASK_ON_CPU    tsk, tmp
25341195d23SVineet Gupta 	GET_CPU_ID  \tmp
25441195d23SVineet Gupta 	add2 \tmp, @_current_task, \tmp
25541195d23SVineet Gupta 	st   \tsk, [\tmp]
25641195d23SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
25741195d23SVineet Gupta 	mov r25, \tsk
25841195d23SVineet Gupta #endif
25941195d23SVineet Gupta 
26041195d23SVineet Gupta .endm
26141195d23SVineet Gupta 
26241195d23SVineet Gupta 
26341195d23SVineet Gupta #else   /* Uniprocessor implementation of macros */
26441195d23SVineet Gupta 
2659d42c84fSVineet Gupta .macro  GET_CURR_TASK_ON_CPU    reg
2669d42c84fSVineet Gupta 	ld  \reg, [@_current_task]
2679d42c84fSVineet Gupta .endm
2689d42c84fSVineet Gupta 
2699d42c84fSVineet Gupta .macro  SET_CURR_TASK_ON_CPU    tsk, tmp
2709d42c84fSVineet Gupta 	st  \tsk, [@_current_task]
271080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
272080c3747SVineet Gupta 	mov r25, \tsk
273080c3747SVineet Gupta #endif
2749d42c84fSVineet Gupta .endm
2759d42c84fSVineet Gupta 
27641195d23SVineet Gupta #endif /* SMP / UNI */
27741195d23SVineet Gupta 
2789d42c84fSVineet Gupta /* ------------------------------------------------------------------
2799d42c84fSVineet Gupta  * Get the ptr to some field of Current Task at @off in task struct
280080c3747SVineet Gupta  *  -Uses r25 for Current task ptr if that is enabled
2819d42c84fSVineet Gupta  */
2829d42c84fSVineet Gupta 
283080c3747SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG
284080c3747SVineet Gupta 
285080c3747SVineet Gupta .macro GET_CURR_TASK_FIELD_PTR  off,  reg
286080c3747SVineet Gupta 	add \reg, r25, \off
287080c3747SVineet Gupta .endm
288080c3747SVineet Gupta 
289080c3747SVineet Gupta #else
290080c3747SVineet Gupta 
2919d42c84fSVineet Gupta .macro GET_CURR_TASK_FIELD_PTR  off,  reg
2929d42c84fSVineet Gupta 	GET_CURR_TASK_ON_CPU  \reg
2939d42c84fSVineet Gupta 	add \reg, \reg, \off
2949d42c84fSVineet Gupta .endm
2959d42c84fSVineet Gupta 
296080c3747SVineet Gupta #endif	/* CONFIG_ARC_CURR_IN_REG */
297080c3747SVineet Gupta 
2989d42c84fSVineet Gupta #endif  /* __ASM_ARC_ENTRY_H */
299