Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.30
      1 /*	$NetBSD: asm.h,v 1.30 2010/12/20 21:11:25 joerg Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by TooLs GmbH.
     19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #ifndef _PPC_ASM_H_
     35 #define _PPC_ASM_H_
     36 
     37 #ifdef _LP64
     38 
     39 /* ppc64 is always PIC, r2 is always the TOC */
     40 
     41 #define	PIC_PLT(x)	.x
     42 
     43 #else
     44 
     45 #ifdef PIC
     46 #define PIC_PROLOGUE	XXX
     47 #define PIC_EPILOGUE	XXX
     48 #define PIC_PLT(x)	x@plt
     49 #ifdef	__STDC__
     50 #define PIC_GOT(x)	XXX
     51 #define PIC_GOTOFF(x)	XXX
     52 #else	/* not __STDC__ */
     53 #define PIC_GOT(x)	XXX
     54 #define PIC_GOTOFF(x)	XXX
     55 #endif	/* __STDC__ */
     56 #else
     57 #define PIC_PROLOGUE
     58 #define PIC_EPILOGUE
     59 #define PIC_PLT(x)	x
     60 #define PIC_GOT(x)	x
     61 #define PIC_GOTOFF(x)	x
     62 #endif
     63 
     64 #endif
     65 
     66 #define	_C_LABEL(x)	x
     67 #define	_ASM_LABEL(x)	x
     68 
     69 #define	_GLOBAL(x) \
     70 	.data; .align 2; .globl x; x:
     71 
     72 #ifdef GPROF
     73 # define _PROF_PROLOGUE	mflr 0; stw 0,4(1); bl _mcount
     74 #else
     75 # define _PROF_PROLOGUE
     76 #endif
     77 
     78 #ifdef _LP64
     79 
     80 #define	SF_HEADER_SZ	48
     81 #define	SF_PARAM_SZ	64
     82 #define	SF_SZ		(SF_HEADER_SZ + SF_PARAM_SZ)
     83 
     84 #define	SF_SP		 0
     85 #define	SF_CR		 8
     86 #define	SF_LR		16
     87 #define	SF_PARAM	SF_HEADER_SZ
     88 
     89 #define	ENTRY(y)			\
     90 	.globl	y;			\
     91 	.section ".opd","aw";		\
     92 	.align	3;			\
     93 y:	.quad	.y,.TOC.@tocbase,0;	\
     94 	.previous;			\
     95 	.size	y,24;			\
     96 	.type	.y,@function;		\
     97 	.globl	.y;			\
     98 	.align	3;			\
     99 .y:
    100 
    101 #define	CALL(y)				\
    102 	bl	.y;			\
    103 	nop
    104 
    105 #define	ENTRY_NOPROFILE(y)	ENTRY(y)
    106 #define	ASENTRY(y)		ENTRY(y)
    107 #else
    108 
    109 #define _ENTRY(x) \
    110 	.text; .align 2; .globl x; .type x,@function; x:
    111 
    112 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
    113 
    114 #define	ENTRY_NOPROFILE(y) _ENTRY(_C_LABEL(y))
    115 
    116 #define	CALL(y)				\
    117 	bl	y
    118 
    119 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
    120 #endif
    121 
    122 #define	GLOBAL(y)	_GLOBAL(_C_LABEL(y))
    123 
    124 #define	ASMSTR		.asciz
    125 
    126 #define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
    127 
    128 #ifdef __ELF__
    129 #define	WEAK_ALIAS(alias,sym)						\
    130 	.weak alias;							\
    131 	alias = sym
    132 #endif
    133 /*
    134  * STRONG_ALIAS: create a strong alias.
    135  */
    136 #define STRONG_ALIAS(alias,sym)						\
    137 	.globl alias;							\
    138 	alias = sym
    139 
    140 #ifdef __STDC__
    141 #define	WARN_REFERENCES(sym,msg)					\
    142 	.pushsection .gnu.warning. ## sym;				\
    143 	.ascii msg;							\
    144 	.popsection
    145 #else
    146 #define	WARN_REFERENCES(sym,msg)					\
    147 	.pushsection .gnu.warning./**/sym;				\
    148 	.ascii msg;							\
    149 	.popsection
    150 #endif /* __STDC__ */
    151 
    152 #ifdef _KERNEL
    153 /*
    154  * Get cpu_info pointer for current processor.  Always in SPRG0. *ALWAYS*
    155  */
    156 #define	GET_CPUINFO(r)		mfsprg r,0
    157 /*
    158  * IN:
    159  *	R4[er] = first free byte beyond end/esym.
    160  *
    161  * OUT:
    162  *	R1[sp] = new kernel stack
    163  *	R4[er] = kernelend
    164  */
    165 
    166 #define	INIT_CPUINFO(er,sp,tmp1,tmp2) 					\
    167 	li	tmp1,PGOFSET;						\
    168 	add	er,er,tmp1;						\
    169 	andc	er,er,tmp1;		/* page align */		\
    170 	lis	tmp1,_C_LABEL(cpu_info)@ha;				\
    171 	addi	tmp1,tmp1,_C_LABEL(cpu_info)@l;				\
    172 	mtsprg0	tmp1;			/* save for later use */	\
    173 	addi	er,er,INTSTK;						\
    174 	stptr	er,CI_INTSTK(tmp1);					\
    175 	lis	tmp2,_C_LABEL(emptyidlespin)@h;				\
    176 	ori	tmp2,tmp2,_C_LABEL(emptyidlespin)@l;			\
    177 	stptr	tmp2,CI_IDLESPIN(tmp1);					\
    178 	li	tmp2,-1;						\
    179 	stint	tmp2,CI_INTRDEPTH(tmp1);				\
    180 	li	tmp2,0;							\
    181 	stptr	tmp2,-CALLFRAMELEN(er);	/* terminate idle stack chain */\
    182 	lis	tmp1,_C_LABEL(lwp0)+L_PCB@ha; /* XXXuvm_lwp_getuarea */	\
    183 	stptr	er,_C_LABEL(lwp0)+L_PCB@l(tmp1);			\
    184 	addi	er,er,USPACE;		/* stackpointer for proc0 */	\
    185 	addi	sp,er,-FRAMELEN;	/* stackpointer for proc0 */	\
    186 		/* er = end of mem reserved for kernel */		\
    187 	stptru	tmp2,-CALLFRAMELEN(sp)	/* end of stack chain */
    188 
    189 #endif
    190 
    191 /* Condition Register Bit Fields */
    192 
    193 #if !defined(_NOREGNAMES)
    194 #if defined(_KERNEL) || defined(_STANDALONE)
    195 #define cr0     0
    196 #define cr1     1
    197 #define cr2     2
    198 #define cr3     3
    199 #define cr4     4
    200 #define cr5     5
    201 #define cr6     6
    202 #define cr7     7
    203 #endif
    204 
    205 /* General Purpose Registers (GPRs) */
    206 
    207 #if defined(_KERNEL) || defined(_STANDALONE)
    208 #define r0      0
    209 #define r1      1
    210 #define r2      2
    211 #define r3      3
    212 #define r4      4
    213 #define r5      5
    214 #define r6      6
    215 #define r7      7
    216 #define r8      8
    217 #define r9      9
    218 #define r10     10
    219 #define r11     11
    220 #define r12     12
    221 #define r13     13
    222 #define r14     14
    223 #define r15     15
    224 #define r16     16
    225 #define r17     17
    226 #define r18     18
    227 #define r19     19
    228 #define r20     20
    229 #define r21     21
    230 #define r22     22
    231 #define r23     23
    232 #define r24     24
    233 #define r25     25
    234 #define r26     26
    235 #define r27     27
    236 #define r28     28
    237 #define r29     29
    238 #define r30     30
    239 #define r31     31
    240 #endif
    241 
    242 /* Floating Point Registers (FPRs) */
    243 
    244 #if defined(_KERNEL) || defined(_STANDALONE)
    245 #define fr0     0
    246 #define fr1     1
    247 #define fr2     2
    248 #define fr3     3
    249 #define fr4     4
    250 #define fr5     5
    251 #define fr6     6
    252 #define fr7     7
    253 #define fr8     8
    254 #define fr9     9
    255 #define fr10    10
    256 #define fr11    11
    257 #define fr12    12
    258 #define fr13    13
    259 #define fr14    14
    260 #define fr15    15
    261 #define fr16    16
    262 #define fr17    17
    263 #define fr18    18
    264 #define fr19    19
    265 #define fr20    20
    266 #define fr21    21
    267 #define fr22    22
    268 #define fr23    23
    269 #define fr24    24
    270 #define fr25    25
    271 #define fr26    26
    272 #define fr27    27
    273 #define fr28    28
    274 #define fr29    29
    275 #define fr30    30
    276 #define fr31    31
    277 #endif
    278 #endif /* !_NOREGNAMES */
    279 
    280 /*
    281  * Add some psuedo instructions to made sharing of assembly versions of
    282  * ILP32 and LP64 code possible.
    283  */
    284 #define ldint	lwz		/* not needed but for completeness */
    285 #define ldintu	lwzu		/* not needed but for completeness */
    286 #define stint	stw		/* not needed but for completeness */
    287 #define stintu	stwu		/* not needed but for completeness */
    288 
    289 #ifndef _LP64
    290 
    291 #define ldlong	lwz		/* load "C" long */
    292 #define ldlongu	lwzu		/* load "C" long with udpate */
    293 #define stlong	stw		/* load "C" long */
    294 #define stlongu	stwu		/* load "C" long with udpate */
    295 #define ldptr	lwz		/* load "C" pointer */
    296 #define ldptru	lwzu		/* load "C" pointer with udpate */
    297 #define stptr	stw		/* load "C" pointer */
    298 #define stptru	stwu		/* load "C" pointer with udpate */
    299 #define	ldreg	lwz		/* load PPC general register */
    300 #define	ldregu	lwzu		/* load PPC general register with udpate */
    301 #define	streg	stw		/* load PPC general register */
    302 #define	stregu	stwu		/* load PPC general register with udpate */
    303 #define	SZREG	4		/* 4 byte registers */
    304 
    305 #define	lptrarx	lwarx		/* load "C" pointer with reservation */
    306 #define	llongarx lwarx		/* load "C" long with reservation */
    307 #define	lregarx	lwarx		/* load PPC general register with reservation */
    308 
    309 #define	stptrcx  stwcx		/* store "C" pointer conditional */
    310 #define	stlongcx stwcx		/* store "C" long conditional */
    311 #define	stregcx  stwcx		/* store PPC general register conditional */
    312 
    313 #define	clrrptri  clrrwi	/* clear right "C" pointer immediate */
    314 #define	clrrlongi clrrwi	/* clear right "C" long immediate */
    315 #define	clrrregi  clrrwi	/* clear right PPC general register immediate */
    316 
    317 #else
    318 
    319 #define ldlong	ld		/* load "C" long */
    320 #define ldlongu	ldu		/* load "C" long with update */
    321 #define stlong	std		/* store "C" long */
    322 #define stlongu	stdu		/* store "C" long with update */
    323 #define ldptr	ld		/* load "C" pointer */
    324 #define ldptru	ldu		/* load "C" pointer with update */
    325 #define stptr	std		/* store "C" pointer */
    326 #define stptru	stdu		/* store "C" pointer with update */
    327 #define	ldreg	ld		/* load PPC general register */
    328 #define	ldregu	ldu		/* load PPC general register with update */
    329 #define	streg	std		/* store PPC general register */
    330 #define	stregu	stdu		/* store PPC general register with update */
    331 /* redefined this to force an error on PPC64 to catch their use.  */
    332 #define	lmw	lmd		/* load multiple PPC general registers */
    333 #define	stmw	stmd		/* store multiple PPC general registers */
    334 #define	SZREG	8		/* 8 byte registers */
    335 
    336 #define	lptrarx	ldarx		/* load "C" pointer with reservation */
    337 #define	llongarx ldarx		/* load "C" long with reservation */
    338 #define	lregarx	ldarx		/* load PPC general register with reservation */
    339 
    340 #define	stptrcx  stdcx		/* store "C" pointer conditional */
    341 #define	stlongcx stdcx		/* store "C" long conditional */
    342 #define	stregax  stdcx		/* store PPC general register conditional */
    343 
    344 #define	clrrptri  clrrdi	/* clear right "C" pointer immediate */
    345 #define	clrrlongi clrrdi	/* clear right "C" long immediate */
    346 #define	clrrregi  clrrdi	/* clear right PPC general register immediate */
    347 
    348 #endif
    349 
    350 #ifdef _LOCORE
    351 .macro	stmd	r,dst
    352 	i = 0
    353     .rept	32-\r
    354 	std	i+\r, i*8+\dst
    355 	i = i + 1
    356     .endr
    357 .endm
    358 
    359 .macro	lmd	r,dst
    360 	i = 0
    361     .rept	32-\r
    362 	ld	i+\r, i*8+\dst
    363 	i = i + 1
    364     .endr
    365 .endm
    366 #endif
    367 
    368 #endif /* !_PPC_ASM_H_ */
    369