xref: /openbmc/linux/arch/ia64/kernel/minstate.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds 
31da177e4SLinus Torvalds #include <asm/cache.h>
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include "entry.h"
6e55645ecSLuis R. Rodriguez #include <asm/native/inst.h>
71da177e4SLinus Torvalds 
8abf917cdSFrederic Weisbecker #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
9b64f34cdSHidetoshi Seto /* read ar.itc in advance, and use it before leaving bank 0 */
10b64f34cdSHidetoshi Seto #define ACCOUNT_GET_STAMP				\
11b64f34cdSHidetoshi Seto (pUStk) mov.m r20=ar.itc;
12b64f34cdSHidetoshi Seto #define ACCOUNT_SYS_ENTER				\
13b64f34cdSHidetoshi Seto (pUStk) br.call.spnt rp=account_sys_enter		\
14b64f34cdSHidetoshi Seto 	;;
15b64f34cdSHidetoshi Seto #else
16b64f34cdSHidetoshi Seto #define ACCOUNT_GET_STAMP
17b64f34cdSHidetoshi Seto #define ACCOUNT_SYS_ENTER
18b64f34cdSHidetoshi Seto #endif
19b64f34cdSHidetoshi Seto 
20dafb9320SDenys Vlasenko .section ".data..patch.rse", "a"
214dcc29e1STony Luck .previous
224dcc29e1STony Luck 
231da177e4SLinus Torvalds /*
241da177e4SLinus Torvalds  * DO_SAVE_MIN switches to the kernel stacks (if necessary) and saves
251da177e4SLinus Torvalds  * the minimum state necessary that allows us to turn psr.ic back
261da177e4SLinus Torvalds  * on.
271da177e4SLinus Torvalds  *
281da177e4SLinus Torvalds  * Assumed state upon entry:
291da177e4SLinus Torvalds  *	psr.ic: off
301da177e4SLinus Torvalds  *	r31:	contains saved predicates (pr)
311da177e4SLinus Torvalds  *
321da177e4SLinus Torvalds  * Upon exit, the state is as follows:
331da177e4SLinus Torvalds  *	psr.ic: off
341da177e4SLinus Torvalds  *	 r2 = points to &pt_regs.r16
351da177e4SLinus Torvalds  *	 r8 = contents of ar.ccv
361da177e4SLinus Torvalds  *	 r9 = contents of ar.csd
371da177e4SLinus Torvalds  *	r10 = contents of ar.ssd
381da177e4SLinus Torvalds  *	r11 = FPSR_DEFAULT
391da177e4SLinus Torvalds  *	r12 = kernel sp (kernel virtual address)
401da177e4SLinus Torvalds  *	r13 = points to current task_struct (kernel virtual address)
411da177e4SLinus Torvalds  *	p15 = TRUE if psr.i is set in cr.ipsr
421da177e4SLinus Torvalds  *	predicate registers (other than p2, p3, and p15), b6, r3, r14, r15:
431da177e4SLinus Torvalds  *		preserved
441da177e4SLinus Torvalds  *
451da177e4SLinus Torvalds  * Note that psr.ic is NOT turned on by this macro.  This is so that
461da177e4SLinus Torvalds  * we can pass interruption state as arguments to a handler.
471da177e4SLinus Torvalds  */
4802e32e36SIsaku Yamahata #define IA64_NATIVE_DO_SAVE_MIN(__COVER,SAVE_IFS,EXTRA,WORKAROUND)				\
4905f335eaSKeith Owens 	mov r16=IA64_KR(CURRENT);	/* M */							\
501da177e4SLinus Torvalds 	mov r27=ar.rsc;			/* M */							\
511da177e4SLinus Torvalds 	mov r20=r1;			/* A */							\
521da177e4SLinus Torvalds 	mov r25=ar.unat;		/* M */							\
5302e32e36SIsaku Yamahata 	MOV_FROM_IPSR(p0,r29);		/* M */							\
541da177e4SLinus Torvalds 	mov r26=ar.pfs;			/* I */							\
5502e32e36SIsaku Yamahata 	MOV_FROM_IIP(r28);			/* M */						\
561da177e4SLinus Torvalds 	mov r21=ar.fpsr;		/* M */							\
5702e32e36SIsaku Yamahata 	__COVER;				/* B;; (or nothing) */				\
581da177e4SLinus Torvalds 	;;											\
591da177e4SLinus Torvalds 	adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16;						\
601da177e4SLinus Torvalds 	;;											\
611da177e4SLinus Torvalds 	ld1 r17=[r16];				/* load current->thread.on_ustack flag */	\
621da177e4SLinus Torvalds 	st1 [r16]=r0;				/* clear current->thread.on_ustack flag */	\
631da177e4SLinus Torvalds 	adds r1=-IA64_TASK_THREAD_ON_USTACK_OFFSET,r16						\
641da177e4SLinus Torvalds 	/* switch from user to kernel RBS: */							\
651da177e4SLinus Torvalds 	;;											\
661da177e4SLinus Torvalds 	invala;				/* M */							\
671da177e4SLinus Torvalds 	SAVE_IFS;										\
681da177e4SLinus Torvalds 	cmp.eq pKStk,pUStk=r0,r17;		/* are we in kernel mode already? */		\
691da177e4SLinus Torvalds 	;;											\
7005f335eaSKeith Owens (pUStk)	mov ar.rsc=0;		/* set enforced lazy mode, pl 0, little-endian, loadrs=0 */	\
7105f335eaSKeith Owens 	;;											\
7205f335eaSKeith Owens (pUStk)	mov.m r24=ar.rnat;									\
7305f335eaSKeith Owens (pUStk)	addl r22=IA64_RBS_OFFSET,r1;			/* compute base of RBS */		\
7405f335eaSKeith Owens (pKStk) mov r1=sp;					/* get sp  */				\
7505f335eaSKeith Owens 	;;											\
7605f335eaSKeith Owens (pUStk) lfetch.fault.excl.nt1 [r22];								\
7705f335eaSKeith Owens (pUStk)	addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r1;	/* compute base of memory stack */	\
7805f335eaSKeith Owens (pUStk)	mov r23=ar.bspstore;				/* save ar.bspstore */			\
7905f335eaSKeith Owens 	;;											\
8005f335eaSKeith Owens (pUStk)	mov ar.bspstore=r22;				/* switch to kernel RBS */		\
8105f335eaSKeith Owens (pKStk) addl r1=-IA64_PT_REGS_SIZE,r1;			/* if in kernel mode, use sp (r12) */	\
8205f335eaSKeith Owens 	;;											\
8305f335eaSKeith Owens (pUStk)	mov r18=ar.bsp;										\
8405f335eaSKeith Owens (pUStk)	mov ar.rsc=0x3;		/* set eager mode, pl 0, little-endian, loadrs=0 */		\
851da177e4SLinus Torvalds 	adds r17=2*L1_CACHE_BYTES,r1;		/* really: biggest cache-line size */		\
861da177e4SLinus Torvalds 	adds r16=PT(CR_IPSR),r1;								\
871da177e4SLinus Torvalds 	;;											\
881da177e4SLinus Torvalds 	lfetch.fault.excl.nt1 [r17],L1_CACHE_BYTES;						\
891da177e4SLinus Torvalds 	st8 [r16]=r29;		/* save cr.ipsr */						\
901da177e4SLinus Torvalds 	;;											\
911da177e4SLinus Torvalds 	lfetch.fault.excl.nt1 [r17];								\
921da177e4SLinus Torvalds 	tbit.nz p15,p0=r29,IA64_PSR_I_BIT;							\
931da177e4SLinus Torvalds 	mov r29=b0										\
941da177e4SLinus Torvalds 	;;											\
954dcc29e1STony Luck 	WORKAROUND;										\
961da177e4SLinus Torvalds 	adds r16=PT(R8),r1;	/* initialize first base pointer */				\
971da177e4SLinus Torvalds 	adds r17=PT(R9),r1;	/* initialize second base pointer */				\
981da177e4SLinus Torvalds (pKStk)	mov r18=r0;		/* make sure r18 isn't NaT */					\
991da177e4SLinus Torvalds 	;;											\
1001da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r16]=r8,16;								\
1011da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r17]=r9,16;								\
1021da177e4SLinus Torvalds         ;;											\
1031da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r16]=r10,24;							\
1041da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r17]=r11,24;							\
1051da177e4SLinus Torvalds         ;;											\
1061da177e4SLinus Torvalds 	st8 [r16]=r28,16;	/* save cr.iip */						\
1071da177e4SLinus Torvalds 	st8 [r17]=r30,16;	/* save cr.ifs */						\
1081da177e4SLinus Torvalds (pUStk)	sub r18=r18,r22;	/* r18=RSE.ndirty*8 */						\
1091da177e4SLinus Torvalds 	mov r8=ar.ccv;										\
1101da177e4SLinus Torvalds 	mov r9=ar.csd;										\
1111da177e4SLinus Torvalds 	mov r10=ar.ssd;										\
1121da177e4SLinus Torvalds 	movl r11=FPSR_DEFAULT;   /* L-unit */							\
1131da177e4SLinus Torvalds 	;;											\
1141da177e4SLinus Torvalds 	st8 [r16]=r25,16;	/* save ar.unat */						\
1151da177e4SLinus Torvalds 	st8 [r17]=r26,16;	/* save ar.pfs */						\
1161da177e4SLinus Torvalds 	shl r18=r18,16;		/* compute ar.rsc to be used for "loadrs" */			\
1171da177e4SLinus Torvalds 	;;											\
1181da177e4SLinus Torvalds 	st8 [r16]=r27,16;	/* save ar.rsc */						\
1191da177e4SLinus Torvalds (pUStk)	st8 [r17]=r24,16;	/* save ar.rnat */						\
1201da177e4SLinus Torvalds (pKStk)	adds r17=16,r17;	/* skip over ar_rnat field */					\
1211da177e4SLinus Torvalds 	;;			/* avoid RAW on r16 & r17 */					\
1221da177e4SLinus Torvalds (pUStk)	st8 [r16]=r23,16;	/* save ar.bspstore */						\
1231da177e4SLinus Torvalds 	st8 [r17]=r31,16;	/* save predicates */						\
1241da177e4SLinus Torvalds (pKStk)	adds r16=16,r16;	/* skip over ar_bspstore field */				\
1251da177e4SLinus Torvalds 	;;											\
1261da177e4SLinus Torvalds 	st8 [r16]=r29,16;	/* save b0 */							\
1271da177e4SLinus Torvalds 	st8 [r17]=r18,16;	/* save ar.rsc value for "loadrs" */				\
1281da177e4SLinus Torvalds 	cmp.eq pNonSys,pSys=r0,r0	/* initialize pSys=0, pNonSys=1 */			\
1291da177e4SLinus Torvalds 	;;											\
1301da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r16]=r20,16;	/* save original r1 */				\
1311da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r17]=r12,16;							\
1321da177e4SLinus Torvalds 	adds r12=-16,r1;	/* switch to kernel memory stack (with 16 bytes of scratch) */	\
1331da177e4SLinus Torvalds 	;;											\
1341da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r16]=r13,16;							\
1351da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r17]=r21,16;	/* save ar.fpsr */				\
1361da177e4SLinus Torvalds 	mov r13=IA64_KR(CURRENT);	/* establish `current' */				\
1371da177e4SLinus Torvalds 	;;											\
1381da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r16]=r15,16;							\
1391da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r17]=r14,16;							\
1401da177e4SLinus Torvalds 	;;											\
1411da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r16]=r2,16;								\
1421da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r17]=r3,16;								\
143b64f34cdSHidetoshi Seto 	ACCOUNT_GET_STAMP									\
1441da177e4SLinus Torvalds 	adds r2=IA64_PT_REGS_R16_OFFSET,r1;							\
1451da177e4SLinus Torvalds 	;;											\
1461da177e4SLinus Torvalds 	EXTRA;											\
1471da177e4SLinus Torvalds 	movl r1=__gp;		/* establish kernel global pointer */				\
1481da177e4SLinus Torvalds 	;;											\
149b64f34cdSHidetoshi Seto 	ACCOUNT_SYS_ENTER									\
15005f335eaSKeith Owens 	bsw.1;			/* switch back to bank 1 (must be last in insn group) */	\
15105f335eaSKeith Owens 	;;
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds /*
1541da177e4SLinus Torvalds  * SAVE_REST saves the remainder of pt_regs (with psr.ic on).
1551da177e4SLinus Torvalds  *
1561da177e4SLinus Torvalds  * Assumed state upon entry:
1571da177e4SLinus Torvalds  *	psr.ic: on
1581da177e4SLinus Torvalds  *	r2:	points to &pt_regs.r16
1591da177e4SLinus Torvalds  *	r3:	points to &pt_regs.r17
1601da177e4SLinus Torvalds  *	r8:	contents of ar.ccv
1611da177e4SLinus Torvalds  *	r9:	contents of ar.csd
1621da177e4SLinus Torvalds  *	r10:	contents of ar.ssd
1631da177e4SLinus Torvalds  *	r11:	FPSR_DEFAULT
1641da177e4SLinus Torvalds  *
1651da177e4SLinus Torvalds  * Registers r14 and r15 are guaranteed not to be touched by SAVE_REST.
1661da177e4SLinus Torvalds  */
1671da177e4SLinus Torvalds #define SAVE_REST				\
1681da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r16,16;		\
1691da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r17,16;		\
1701da177e4SLinus Torvalds 	;;					\
1711da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r18,16;		\
1721da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r19,16;		\
1731da177e4SLinus Torvalds 	;;					\
1741da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r20,16;		\
1751da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r21,16;		\
1761da177e4SLinus Torvalds 	mov r18=b6;				\
1771da177e4SLinus Torvalds 	;;					\
1781da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r22,16;		\
1791da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r23,16;		\
1801da177e4SLinus Torvalds 	mov r19=b7;				\
1811da177e4SLinus Torvalds 	;;					\
1821da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r24,16;		\
1831da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r25,16;		\
1841da177e4SLinus Torvalds 	;;					\
1851da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r26,16;		\
1861da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r27,16;		\
1871da177e4SLinus Torvalds 	;;					\
1881da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r28,16;		\
1891da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r29,16;		\
1901da177e4SLinus Torvalds 	;;					\
1911da177e4SLinus Torvalds .mem.offset 0,0; st8.spill [r2]=r30,16;		\
1921da177e4SLinus Torvalds .mem.offset 8,0; st8.spill [r3]=r31,32;		\
1931da177e4SLinus Torvalds 	;;					\
1941da177e4SLinus Torvalds 	mov ar.fpsr=r11;	/* M-unit */	\
1951da177e4SLinus Torvalds 	st8 [r2]=r8,8;		/* ar.ccv */	\
1961da177e4SLinus Torvalds 	adds r24=PT(B6)-PT(F7),r3;		\
1971da177e4SLinus Torvalds 	;;					\
1981da177e4SLinus Torvalds 	stf.spill [r2]=f6,32;			\
1991da177e4SLinus Torvalds 	stf.spill [r3]=f7,32;			\
2001da177e4SLinus Torvalds 	;;					\
2011da177e4SLinus Torvalds 	stf.spill [r2]=f8,32;			\
2021da177e4SLinus Torvalds 	stf.spill [r3]=f9,32;			\
2031da177e4SLinus Torvalds 	;;					\
2041da177e4SLinus Torvalds 	stf.spill [r2]=f10;			\
2051da177e4SLinus Torvalds 	stf.spill [r3]=f11;			\
2061da177e4SLinus Torvalds 	adds r25=PT(B7)-PT(F11),r3;		\
2071da177e4SLinus Torvalds 	;;					\
2081da177e4SLinus Torvalds 	st8 [r24]=r18,16;       /* b6 */	\
2091da177e4SLinus Torvalds 	st8 [r25]=r19,16;       /* b7 */	\
2101da177e4SLinus Torvalds 	;;					\
2111da177e4SLinus Torvalds 	st8 [r24]=r9;        	/* ar.csd */	\
2121da177e4SLinus Torvalds 	st8 [r25]=r10;      	/* ar.ssd */	\
2131da177e4SLinus Torvalds 	;;
2141da177e4SLinus Torvalds 
2154dcc29e1STony Luck #define RSE_WORKAROUND				\
2164dcc29e1STony Luck (pUStk) extr.u r17=r18,3,6;			\
2174dcc29e1STony Luck (pUStk)	sub r16=r18,r22;			\
2184dcc29e1STony Luck [1:](pKStk)	br.cond.sptk.many 1f;		\
219dafb9320SDenys Vlasenko 	.xdata4 ".data..patch.rse",1b-.		\
2204dcc29e1STony Luck 	;;					\
2214dcc29e1STony Luck 	cmp.ge p6,p7 = 33,r17;			\
2224dcc29e1STony Luck 	;;					\
2234dcc29e1STony Luck (p6)	mov r17=0x310;				\
2244dcc29e1STony Luck (p7)	mov r17=0x308;				\
2254dcc29e1STony Luck 	;;					\
2264dcc29e1STony Luck 	cmp.leu p1,p0=r16,r17;			\
2274dcc29e1STony Luck (p1)	br.cond.sptk.many 1f;			\
2284dcc29e1STony Luck 	dep.z r17=r26,0,62;			\
2294dcc29e1STony Luck 	movl r16=2f;				\
2304dcc29e1STony Luck 	;;					\
2314dcc29e1STony Luck 	mov ar.pfs=r17;				\
2324dcc29e1STony Luck 	dep r27=r0,r27,16,14;			\
2334dcc29e1STony Luck 	mov b0=r16;				\
2344dcc29e1STony Luck 	;;					\
2354dcc29e1STony Luck 	br.ret.sptk b0;				\
2364dcc29e1STony Luck 	;;					\
2374dcc29e1STony Luck 2:						\
2384dcc29e1STony Luck 	mov ar.rsc=r0				\
2394dcc29e1STony Luck 	;;					\
2404dcc29e1STony Luck 	flushrs;				\
2414dcc29e1STony Luck 	;;					\
2424dcc29e1STony Luck 	mov ar.bspstore=r22			\
2434dcc29e1STony Luck 	;;					\
2444dcc29e1STony Luck 	mov r18=ar.bsp;				\
2454dcc29e1STony Luck 	;;					\
2464dcc29e1STony Luck 1:						\
2474dcc29e1STony Luck 	.pred.rel "mutex", pKStk, pUStk
2484dcc29e1STony Luck 
24902e32e36SIsaku Yamahata #define SAVE_MIN_WITH_COVER	DO_SAVE_MIN(COVER, mov r30=cr.ifs, , RSE_WORKAROUND)
25002e32e36SIsaku Yamahata #define SAVE_MIN_WITH_COVER_R19	DO_SAVE_MIN(COVER, mov r30=cr.ifs, mov r15=r19, RSE_WORKAROUND)
2514dcc29e1STony Luck #define SAVE_MIN			DO_SAVE_MIN(     , mov r30=r0, , )
252