18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * winmacro.h: Window loading-unloading macros.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _SPARC_WINMACRO_H
98c2ecf20Sopenharmony_ci#define _SPARC_WINMACRO_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Store the register window onto the 8-byte aligned area starting
148c2ecf20Sopenharmony_ci * at %reg.  It might be %sp, it might not, we don't care.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci#define STORE_WINDOW(reg) \
178c2ecf20Sopenharmony_ci	std	%l0, [%reg + RW_L0]; \
188c2ecf20Sopenharmony_ci	std	%l2, [%reg + RW_L2]; \
198c2ecf20Sopenharmony_ci	std	%l4, [%reg + RW_L4]; \
208c2ecf20Sopenharmony_ci	std	%l6, [%reg + RW_L6]; \
218c2ecf20Sopenharmony_ci	std	%i0, [%reg + RW_I0]; \
228c2ecf20Sopenharmony_ci	std	%i2, [%reg + RW_I2]; \
238c2ecf20Sopenharmony_ci	std	%i4, [%reg + RW_I4]; \
248c2ecf20Sopenharmony_ci	std	%i6, [%reg + RW_I6];
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Load a register window from the area beginning at %reg. */
278c2ecf20Sopenharmony_ci#define LOAD_WINDOW(reg) \
288c2ecf20Sopenharmony_ci	ldd	[%reg + RW_L0], %l0; \
298c2ecf20Sopenharmony_ci	ldd	[%reg + RW_L2], %l2; \
308c2ecf20Sopenharmony_ci	ldd	[%reg + RW_L4], %l4; \
318c2ecf20Sopenharmony_ci	ldd	[%reg + RW_L6], %l6; \
328c2ecf20Sopenharmony_ci	ldd	[%reg + RW_I0], %i0; \
338c2ecf20Sopenharmony_ci	ldd	[%reg + RW_I2], %i2; \
348c2ecf20Sopenharmony_ci	ldd	[%reg + RW_I4], %i4; \
358c2ecf20Sopenharmony_ci	ldd	[%reg + RW_I6], %i6;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* Loading and storing struct pt_reg trap frames. */
388c2ecf20Sopenharmony_ci#define LOAD_PT_INS(base_reg) \
398c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_I0], %i0; \
408c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_I2], %i2; \
418c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_I4], %i4; \
428c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_I6], %i6;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define LOAD_PT_GLOBALS(base_reg) \
458c2ecf20Sopenharmony_ci        ld      [%base_reg + STACKFRAME_SZ + PT_G1], %g1; \
468c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_G2], %g2; \
478c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_G4], %g4; \
488c2ecf20Sopenharmony_ci        ldd     [%base_reg + STACKFRAME_SZ + PT_G6], %g6;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define LOAD_PT_YREG(base_reg, scratch) \
518c2ecf20Sopenharmony_ci        ld      [%base_reg + STACKFRAME_SZ + PT_Y], %scratch; \
528c2ecf20Sopenharmony_ci        wr      %scratch, 0x0, %y;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define LOAD_PT_PRIV(base_reg, pt_psr, pt_pc, pt_npc) \
558c2ecf20Sopenharmony_ci        ld      [%base_reg + STACKFRAME_SZ + PT_PSR], %pt_psr; \
568c2ecf20Sopenharmony_ci        ld      [%base_reg + STACKFRAME_SZ + PT_PC], %pt_pc; \
578c2ecf20Sopenharmony_ci        ld      [%base_reg + STACKFRAME_SZ + PT_NPC], %pt_npc;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define LOAD_PT_ALL(base_reg, pt_psr, pt_pc, pt_npc, scratch) \
608c2ecf20Sopenharmony_ci        LOAD_PT_YREG(base_reg, scratch) \
618c2ecf20Sopenharmony_ci        LOAD_PT_INS(base_reg) \
628c2ecf20Sopenharmony_ci        LOAD_PT_GLOBALS(base_reg) \
638c2ecf20Sopenharmony_ci        LOAD_PT_PRIV(base_reg, pt_psr, pt_pc, pt_npc)
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define STORE_PT_INS(base_reg) \
668c2ecf20Sopenharmony_ci        std     %i0, [%base_reg + STACKFRAME_SZ + PT_I0]; \
678c2ecf20Sopenharmony_ci        std     %i2, [%base_reg + STACKFRAME_SZ + PT_I2]; \
688c2ecf20Sopenharmony_ci        std     %i4, [%base_reg + STACKFRAME_SZ + PT_I4]; \
698c2ecf20Sopenharmony_ci        std     %i6, [%base_reg + STACKFRAME_SZ + PT_I6];
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define STORE_PT_GLOBALS(base_reg) \
728c2ecf20Sopenharmony_ci        st      %g1, [%base_reg + STACKFRAME_SZ + PT_G1]; \
738c2ecf20Sopenharmony_ci        std     %g2, [%base_reg + STACKFRAME_SZ + PT_G2]; \
748c2ecf20Sopenharmony_ci        std     %g4, [%base_reg + STACKFRAME_SZ + PT_G4]; \
758c2ecf20Sopenharmony_ci        std     %g6, [%base_reg + STACKFRAME_SZ + PT_G6];
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define STORE_PT_YREG(base_reg, scratch) \
788c2ecf20Sopenharmony_ci        rd      %y, %scratch; \
798c2ecf20Sopenharmony_ci        st      %scratch, [%base_reg + STACKFRAME_SZ + PT_Y];
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define STORE_PT_PRIV(base_reg, pt_psr, pt_pc, pt_npc) \
828c2ecf20Sopenharmony_ci        st      %pt_psr, [%base_reg + STACKFRAME_SZ + PT_PSR]; \
838c2ecf20Sopenharmony_ci        st      %pt_pc,  [%base_reg + STACKFRAME_SZ + PT_PC]; \
848c2ecf20Sopenharmony_ci        st      %pt_npc, [%base_reg + STACKFRAME_SZ + PT_NPC];
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define STORE_PT_ALL(base_reg, reg_psr, reg_pc, reg_npc, g_scratch) \
878c2ecf20Sopenharmony_ci        STORE_PT_PRIV(base_reg, reg_psr, reg_pc, reg_npc) \
888c2ecf20Sopenharmony_ci        STORE_PT_GLOBALS(base_reg) \
898c2ecf20Sopenharmony_ci        STORE_PT_YREG(base_reg, g_scratch) \
908c2ecf20Sopenharmony_ci        STORE_PT_INS(base_reg)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define SAVE_BOLIXED_USER_STACK(cur_reg, scratch) \
938c2ecf20Sopenharmony_ci        ld       [%cur_reg + TI_W_SAVED], %scratch; \
948c2ecf20Sopenharmony_ci        sll      %scratch, 2, %scratch; \
958c2ecf20Sopenharmony_ci        add      %scratch, %cur_reg, %scratch; \
968c2ecf20Sopenharmony_ci        st       %sp, [%scratch + TI_RWIN_SPTRS]; \
978c2ecf20Sopenharmony_ci        sub      %scratch, %cur_reg, %scratch; \
988c2ecf20Sopenharmony_ci        sll      %scratch, 4, %scratch; \
998c2ecf20Sopenharmony_ci        add      %scratch, %cur_reg, %scratch; \
1008c2ecf20Sopenharmony_ci        STORE_WINDOW(scratch + TI_REG_WINDOW); \
1018c2ecf20Sopenharmony_ci        sub      %scratch, %cur_reg, %scratch; \
1028c2ecf20Sopenharmony_ci        srl      %scratch, 6, %scratch; \
1038c2ecf20Sopenharmony_ci        add      %scratch, 1, %scratch; \
1048c2ecf20Sopenharmony_ci        st       %scratch, [%cur_reg + TI_W_SAVED];
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
1078c2ecf20Sopenharmony_ci#define LOAD_CURRENT(dest_reg, idreg) 			\
1088c2ecf20Sopenharmony_ci661:	rd	%tbr, %idreg;				\
1098c2ecf20Sopenharmony_ci	srl	%idreg, 10, %idreg;			\
1108c2ecf20Sopenharmony_ci	and	%idreg, 0xc, %idreg;			\
1118c2ecf20Sopenharmony_ci	.section	.cpuid_patch, "ax";		\
1128c2ecf20Sopenharmony_ci	/* Instruction location. */			\
1138c2ecf20Sopenharmony_ci	.word		661b;				\
1148c2ecf20Sopenharmony_ci	/* SUN4D implementation. */			\
1158c2ecf20Sopenharmony_ci	lda	 [%g0] ASI_M_VIKING_TMP1, %idreg;	\
1168c2ecf20Sopenharmony_ci	sll	 %idreg, 2, %idreg;			\
1178c2ecf20Sopenharmony_ci	nop;						\
1188c2ecf20Sopenharmony_ci	/* LEON implementation. */			\
1198c2ecf20Sopenharmony_ci	rd 	%asr17, %idreg;				\
1208c2ecf20Sopenharmony_ci	srl	%idreg, 0x1c, %idreg;			\
1218c2ecf20Sopenharmony_ci	sll	%idreg, 0x02, %idreg;			\
1228c2ecf20Sopenharmony_ci	.previous;					\
1238c2ecf20Sopenharmony_ci	sethi    %hi(current_set), %dest_reg; 		\
1248c2ecf20Sopenharmony_ci	or       %dest_reg, %lo(current_set), %dest_reg;\
1258c2ecf20Sopenharmony_ci	ld       [%idreg + %dest_reg], %dest_reg;
1268c2ecf20Sopenharmony_ci#else
1278c2ecf20Sopenharmony_ci#define LOAD_CURRENT(dest_reg, idreg) \
1288c2ecf20Sopenharmony_ci        sethi    %hi(current_set), %idreg; \
1298c2ecf20Sopenharmony_ci        ld       [%idreg + %lo(current_set)], %dest_reg;
1308c2ecf20Sopenharmony_ci#endif
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#endif /* !(_SPARC_WINMACRO_H) */
133