162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * winmacro.h: Window loading-unloading macros. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef _SPARC_WINMACRO_H 962306a36Sopenharmony_ci#define _SPARC_WINMACRO_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <asm/ptrace.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* Store the register window onto the 8-byte aligned area starting 1462306a36Sopenharmony_ci * at %reg. It might be %sp, it might not, we don't care. 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci#define STORE_WINDOW(reg) \ 1762306a36Sopenharmony_ci std %l0, [%reg + RW_L0]; \ 1862306a36Sopenharmony_ci std %l2, [%reg + RW_L2]; \ 1962306a36Sopenharmony_ci std %l4, [%reg + RW_L4]; \ 2062306a36Sopenharmony_ci std %l6, [%reg + RW_L6]; \ 2162306a36Sopenharmony_ci std %i0, [%reg + RW_I0]; \ 2262306a36Sopenharmony_ci std %i2, [%reg + RW_I2]; \ 2362306a36Sopenharmony_ci std %i4, [%reg + RW_I4]; \ 2462306a36Sopenharmony_ci std %i6, [%reg + RW_I6]; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* Load a register window from the area beginning at %reg. */ 2762306a36Sopenharmony_ci#define LOAD_WINDOW(reg) \ 2862306a36Sopenharmony_ci ldd [%reg + RW_L0], %l0; \ 2962306a36Sopenharmony_ci ldd [%reg + RW_L2], %l2; \ 3062306a36Sopenharmony_ci ldd [%reg + RW_L4], %l4; \ 3162306a36Sopenharmony_ci ldd [%reg + RW_L6], %l6; \ 3262306a36Sopenharmony_ci ldd [%reg + RW_I0], %i0; \ 3362306a36Sopenharmony_ci ldd [%reg + RW_I2], %i2; \ 3462306a36Sopenharmony_ci ldd [%reg + RW_I4], %i4; \ 3562306a36Sopenharmony_ci ldd [%reg + RW_I6], %i6; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci/* Loading and storing struct pt_reg trap frames. */ 3862306a36Sopenharmony_ci#define LOAD_PT_INS(base_reg) \ 3962306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_I0], %i0; \ 4062306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_I2], %i2; \ 4162306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_I4], %i4; \ 4262306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_I6], %i6; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define LOAD_PT_GLOBALS(base_reg) \ 4562306a36Sopenharmony_ci ld [%base_reg + STACKFRAME_SZ + PT_G1], %g1; \ 4662306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_G2], %g2; \ 4762306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_G4], %g4; \ 4862306a36Sopenharmony_ci ldd [%base_reg + STACKFRAME_SZ + PT_G6], %g6; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define LOAD_PT_YREG(base_reg, scratch) \ 5162306a36Sopenharmony_ci ld [%base_reg + STACKFRAME_SZ + PT_Y], %scratch; \ 5262306a36Sopenharmony_ci wr %scratch, 0x0, %y; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define LOAD_PT_PRIV(base_reg, pt_psr, pt_pc, pt_npc) \ 5562306a36Sopenharmony_ci ld [%base_reg + STACKFRAME_SZ + PT_PSR], %pt_psr; \ 5662306a36Sopenharmony_ci ld [%base_reg + STACKFRAME_SZ + PT_PC], %pt_pc; \ 5762306a36Sopenharmony_ci ld [%base_reg + STACKFRAME_SZ + PT_NPC], %pt_npc; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci#define LOAD_PT_ALL(base_reg, pt_psr, pt_pc, pt_npc, scratch) \ 6062306a36Sopenharmony_ci LOAD_PT_YREG(base_reg, scratch) \ 6162306a36Sopenharmony_ci LOAD_PT_INS(base_reg) \ 6262306a36Sopenharmony_ci LOAD_PT_GLOBALS(base_reg) \ 6362306a36Sopenharmony_ci LOAD_PT_PRIV(base_reg, pt_psr, pt_pc, pt_npc) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define STORE_PT_INS(base_reg) \ 6662306a36Sopenharmony_ci std %i0, [%base_reg + STACKFRAME_SZ + PT_I0]; \ 6762306a36Sopenharmony_ci std %i2, [%base_reg + STACKFRAME_SZ + PT_I2]; \ 6862306a36Sopenharmony_ci std %i4, [%base_reg + STACKFRAME_SZ + PT_I4]; \ 6962306a36Sopenharmony_ci std %i6, [%base_reg + STACKFRAME_SZ + PT_I6]; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#define STORE_PT_GLOBALS(base_reg) \ 7262306a36Sopenharmony_ci st %g1, [%base_reg + STACKFRAME_SZ + PT_G1]; \ 7362306a36Sopenharmony_ci std %g2, [%base_reg + STACKFRAME_SZ + PT_G2]; \ 7462306a36Sopenharmony_ci std %g4, [%base_reg + STACKFRAME_SZ + PT_G4]; \ 7562306a36Sopenharmony_ci std %g6, [%base_reg + STACKFRAME_SZ + PT_G6]; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#define STORE_PT_YREG(base_reg, scratch) \ 7862306a36Sopenharmony_ci rd %y, %scratch; \ 7962306a36Sopenharmony_ci st %scratch, [%base_reg + STACKFRAME_SZ + PT_Y]; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#define STORE_PT_PRIV(base_reg, pt_psr, pt_pc, pt_npc) \ 8262306a36Sopenharmony_ci st %pt_psr, [%base_reg + STACKFRAME_SZ + PT_PSR]; \ 8362306a36Sopenharmony_ci st %pt_pc, [%base_reg + STACKFRAME_SZ + PT_PC]; \ 8462306a36Sopenharmony_ci st %pt_npc, [%base_reg + STACKFRAME_SZ + PT_NPC]; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#define STORE_PT_ALL(base_reg, reg_psr, reg_pc, reg_npc, g_scratch) \ 8762306a36Sopenharmony_ci STORE_PT_PRIV(base_reg, reg_psr, reg_pc, reg_npc) \ 8862306a36Sopenharmony_ci STORE_PT_GLOBALS(base_reg) \ 8962306a36Sopenharmony_ci STORE_PT_YREG(base_reg, g_scratch) \ 9062306a36Sopenharmony_ci STORE_PT_INS(base_reg) 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define SAVE_BOLIXED_USER_STACK(cur_reg, scratch) \ 9362306a36Sopenharmony_ci ld [%cur_reg + TI_W_SAVED], %scratch; \ 9462306a36Sopenharmony_ci sll %scratch, 2, %scratch; \ 9562306a36Sopenharmony_ci add %scratch, %cur_reg, %scratch; \ 9662306a36Sopenharmony_ci st %sp, [%scratch + TI_RWIN_SPTRS]; \ 9762306a36Sopenharmony_ci sub %scratch, %cur_reg, %scratch; \ 9862306a36Sopenharmony_ci sll %scratch, 4, %scratch; \ 9962306a36Sopenharmony_ci add %scratch, %cur_reg, %scratch; \ 10062306a36Sopenharmony_ci STORE_WINDOW(scratch + TI_REG_WINDOW); \ 10162306a36Sopenharmony_ci sub %scratch, %cur_reg, %scratch; \ 10262306a36Sopenharmony_ci srl %scratch, 6, %scratch; \ 10362306a36Sopenharmony_ci add %scratch, 1, %scratch; \ 10462306a36Sopenharmony_ci st %scratch, [%cur_reg + TI_W_SAVED]; 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#ifdef CONFIG_SMP 10762306a36Sopenharmony_ci#define LOAD_CURRENT(dest_reg, idreg) \ 10862306a36Sopenharmony_ci661: rd %tbr, %idreg; \ 10962306a36Sopenharmony_ci srl %idreg, 10, %idreg; \ 11062306a36Sopenharmony_ci and %idreg, 0xc, %idreg; \ 11162306a36Sopenharmony_ci .section .cpuid_patch, "ax"; \ 11262306a36Sopenharmony_ci /* Instruction location. */ \ 11362306a36Sopenharmony_ci .word 661b; \ 11462306a36Sopenharmony_ci /* SUN4D implementation. */ \ 11562306a36Sopenharmony_ci lda [%g0] ASI_M_VIKING_TMP1, %idreg; \ 11662306a36Sopenharmony_ci sll %idreg, 2, %idreg; \ 11762306a36Sopenharmony_ci nop; \ 11862306a36Sopenharmony_ci /* LEON implementation. */ \ 11962306a36Sopenharmony_ci rd %asr17, %idreg; \ 12062306a36Sopenharmony_ci srl %idreg, 0x1c, %idreg; \ 12162306a36Sopenharmony_ci sll %idreg, 0x02, %idreg; \ 12262306a36Sopenharmony_ci .previous; \ 12362306a36Sopenharmony_ci sethi %hi(current_set), %dest_reg; \ 12462306a36Sopenharmony_ci or %dest_reg, %lo(current_set), %dest_reg;\ 12562306a36Sopenharmony_ci ld [%idreg + %dest_reg], %dest_reg; 12662306a36Sopenharmony_ci#else 12762306a36Sopenharmony_ci#define LOAD_CURRENT(dest_reg, idreg) \ 12862306a36Sopenharmony_ci sethi %hi(current_set), %idreg; \ 12962306a36Sopenharmony_ci ld [%idreg + %lo(current_set)], %dest_reg; 13062306a36Sopenharmony_ci#endif 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#endif /* !(_SPARC_WINMACRO_H) */ 133