/* $NetBSD: asm.h,v 1.56 2025/01/06 10:46:44 martin Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* We use lis/ori instead of lis/addi in case tmp2 is r0.
*/
# define INIT_CPUINFO(er,sp,tmp1,tmp2) \
li tmp1,PAGE_MASK; \
add er,er,tmp1; \
andc er,er,tmp1; /* page align */ \
lis tmp1,_C_LABEL(cpu_info)@ha; \
addi tmp1,tmp1,_C_LABEL(cpu_info)@l; \
mtsprg0 tmp1; /* save for later use */ \
INIT_CPUINFO_INTSTK(er,tmp1); \
lis tmp2,_C_LABEL(emptyidlespin)@h; \
ori tmp2,tmp2,_C_LABEL(emptyidlespin)@l; \
stptr tmp2,CI_IDLESPIN(tmp1); \
li tmp2,-1; \
stint tmp2,CI_IDEPTH(tmp1); \
li tmp2,0; \
lis %r13,_C_LABEL(lwp0)@h; \
ori %r13,%r13,_C_LABEL(lwp0)@l; \
stptr er,L_PCB(%r13); /* XXXuvm_lwp_getuarea */ \
stptr tmp1,L_CPU(%r13); \
addis er,er,USPACE@ha; /* stackpointer for lwp0 */ \
addi er,er,USPACE@l; /* stackpointer for lwp0 */ \
addi sp,er,-FRAMELEN-CALLFRAMELEN; /* stackpointer for lwp0 */ \
stptr sp,L_MD_UTF(%r13); /* save in lwp0.l_md.md_utf */ \
/* er = end of mem reserved for kernel */ \
li tmp2,0; \
stptr tmp2,-CALLFRAMELEN(er); /* end of stack chain */ \
stptru tmp2,-CALLFRAMELEN(sp) /* end of stack chain */
/*
* Add some pseudo instructions to made sharing of assembly versions of
* ILP32 and LP64 code possible.
*/
#define ldint lwz /* not needed but for completeness */
#define ldintu lwzu /* not needed but for completeness */
#define stint stw /* not needed but for completeness */
#define stintu stwu /* not needed but for completeness */
#ifndef _LP64
# define ldlong lwz /* load "C" long */
# define ldlongu lwzu /* load "C" long with update */
# define stlong stw /* load "C" long */
# define stlongu stwu /* load "C" long with update */
# define ldptr lwz /* load "C" pointer */
# define ldptru lwzu /* load "C" pointer with update */
# define stptr stw /* load "C" pointer */
# define stptru stwu /* load "C" pointer with update */
# define ldreg lwz /* load PPC general register */
# define ldregu lwzu /* load PPC general register with update */
# define streg stw /* load PPC general register */
# define stregu stwu /* load PPC general register with update */
# define SZREG 4 /* 4 byte registers */
# define P2SZREG 2
# define lptrarx lwarx /* load "C" pointer with reservation */
# define llongarx lwarx /* load "C" long with reservation */
# define lregarx lwarx /* load PPC general register with reservation */
# define stptrcx stwcx /* store "C" pointer conditional */
# define stlongcx stwcx /* store "C" long conditional */
# define stregcx stwcx /* store PPC general register conditional */
# define clrrptri clrrwi /* clear right "C" pointer immediate */
# define clrrlongi clrrwi /* clear right "C" long immediate */
# define clrrregi clrrwi /* clear right PPC general register immediate */