Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.26
      1 /*	$NetBSD: asm.h,v 1.26 2008/02/23 19:38:47 matt 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)	.text; .asciz x
    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 	.section .gnu.warning. ## _sym ; .ascii _msg ; .text
    143 #else
    144 #define	WARN_REFERENCES(_sym,_msg)				\
    145 	.section .gnu.warning./**/_sym ; .ascii _msg ; .text
    146 #endif /* __STDC__ */
    147 
    148 #ifdef _KERNEL
    149 /*
    150  * Get cpu_info pointer for current processor.  Always in SPRG0. *ALWAYS*
    151  */
    152 #define	GET_CPUINFO(r)		mfsprg r,0
    153 /*
    154  * IN:
    155  *	R4[er] = first free byte beyond end/esym.
    156  *
    157  * OUT:
    158  *	R1[sp] = new kernel stack
    159  *	R4[er] = kernelend
    160  */
    161 
    162 #define	INIT_CPUINFO(er,sp,tmp1,tmp2) 					\
    163 	li	tmp1,PGOFSET;						\
    164 	add	er,er,tmp1;						\
    165 	andc	er,er,tmp1;		/* page align */		\
    166 	lis	tmp1,_C_LABEL(cpu_info)@ha;				\
    167 	addi	tmp1,tmp1,_C_LABEL(cpu_info)@l;				\
    168 	mtsprg0	tmp1;			/* save for later use */	\
    169 	addi	er,er,INTSTK;						\
    170 	stptr	er,CI_INTSTK(tmp1);					\
    171 	lis	tmp2,_C_LABEL(emptyidlespin)@h;				\
    172 	ori	tmp2,tmp2,_C_LABEL(emptyidlespin)@l;			\
    173 	stptr	tmp2,CI_IDLESPIN(tmp1);					\
    174 	li	tmp2,-1;						\
    175 	stint	tmp2,CI_INTRDEPTH(tmp1);				\
    176 	li	tmp2,0;							\
    177 	stptr	tmp2,-CALLFRAMELEN(er);	/* terminate idle stack chain */\
    178 	lis	tmp1,_C_LABEL(proc0paddr)@ha;				\
    179 	stptr	er,_C_LABEL(proc0paddr)@l(tmp1);			\
    180 	addi	er,er,USPACE;		/* stackpointer for proc0 */	\
    181 	addi	sp,er,-FRAMELEN;	/* stackpointer for proc0 */	\
    182 		/* er = end of mem reserved for kernel */		\
    183 	stptru	tmp2,-CALLFRAMELEN(sp)	/* end of stack chain */
    184 
    185 #endif
    186 
    187 /* Condition Register Bit Fields */
    188 
    189 #if !defined(_NOREGNAMES)
    190 #if defined(_KERNEL) || defined(_STANDALONE)
    191 #define cr0     0
    192 #define cr1     1
    193 #define cr2     2
    194 #define cr3     3
    195 #define cr4     4
    196 #define cr5     5
    197 #define cr6     6
    198 #define cr7     7
    199 #endif
    200 
    201 /* General Purpose Registers (GPRs) */
    202 
    203 #if defined(_KERNEL) || defined(_STANDALONE)
    204 #define r0      0
    205 #define r1      1
    206 #define r2      2
    207 #define r3      3
    208 #define r4      4
    209 #define r5      5
    210 #define r6      6
    211 #define r7      7
    212 #define r8      8
    213 #define r9      9
    214 #define r10     10
    215 #define r11     11
    216 #define r12     12
    217 #define r13     13
    218 #define r14     14
    219 #define r15     15
    220 #define r16     16
    221 #define r17     17
    222 #define r18     18
    223 #define r19     19
    224 #define r20     20
    225 #define r21     21
    226 #define r22     22
    227 #define r23     23
    228 #define r24     24
    229 #define r25     25
    230 #define r26     26
    231 #define r27     27
    232 #define r28     28
    233 #define r29     29
    234 #define r30     30
    235 #define r31     31
    236 #endif
    237 
    238 /* Floating Point Registers (FPRs) */
    239 
    240 #if defined(_KERNEL) || defined(_STANDALONE)
    241 #define fr0     0
    242 #define fr1     1
    243 #define fr2     2
    244 #define fr3     3
    245 #define fr4     4
    246 #define fr5     5
    247 #define fr6     6
    248 #define fr7     7
    249 #define fr8     8
    250 #define fr9     9
    251 #define fr10    10
    252 #define fr11    11
    253 #define fr12    12
    254 #define fr13    13
    255 #define fr14    14
    256 #define fr15    15
    257 #define fr16    16
    258 #define fr17    17
    259 #define fr18    18
    260 #define fr19    19
    261 #define fr20    20
    262 #define fr21    21
    263 #define fr22    22
    264 #define fr23    23
    265 #define fr24    24
    266 #define fr25    25
    267 #define fr26    26
    268 #define fr27    27
    269 #define fr28    28
    270 #define fr29    29
    271 #define fr30    30
    272 #define fr31    31
    273 #endif
    274 #endif /* !_NOREGNAMES */
    275 
    276 /*
    277  * Add some psuedo instructions to made sharing of assembly versions of
    278  * ILP32 and LP64 code possible.
    279  */
    280 #define ldint	lwz		/* not needed but for completeness */
    281 #define ldintu	lwzu		/* not needed but for completeness */
    282 #define stint	stw		/* not needed but for completeness */
    283 #define stintu	stwu		/* not needed but for completeness */
    284 
    285 #ifndef _LP64
    286 
    287 #define ldlong	lwz		/* load "C" long */
    288 #define ldlongu	lwzu		/* load "C" long with udpate */
    289 #define stlong	stw		/* load "C" long */
    290 #define stlongu	stwu		/* load "C" long with udpate */
    291 #define ldptr	lwz		/* load "C" pointer */
    292 #define ldptru	lwzu		/* load "C" pointer with udpate */
    293 #define stptr	stw		/* load "C" pointer */
    294 #define stptru	stwu		/* load "C" pointer with udpate */
    295 #define	ldreg	lwz		/* load PPC general register */
    296 #define	ldregu	lwzu		/* load PPC general register with udpate */
    297 #define	streg	stw		/* load PPC general register */
    298 #define	stregu	stwu		/* load PPC general register with udpate */
    299 #define	SZREG	4		/* 4 byte registers */
    300 
    301 #define	lptrarx	lwarx		/* load "C" pointer with reservation */
    302 #define	llongarx lwarx		/* load "C" long with reservation */
    303 #define	lregarx	lwarx		/* load PPC general register with reservation */
    304 
    305 #define	stptrcx  stwcx		/* store "C" pointer conditional */
    306 #define	stlongcx stwcx		/* store "C" long conditional */
    307 #define	stregcx  stwcx		/* store PPC general register conditional */
    308 
    309 #define	clrrptri  clrrwi	/* clear right "C" pointer immediate */
    310 #define	clrrlongi clrrwi	/* clear right "C" long immediate */
    311 #define	clrrregi  clrrwi	/* clear right PPC general register immediate */
    312 
    313 #else
    314 
    315 #define ldlong	ld		/* load "C" long */
    316 #define ldlongu	ldu		/* load "C" long with update */
    317 #define stlong	std		/* store "C" long */
    318 #define stlongu	stdu		/* store "C" long with update */
    319 #define ldptr	ld		/* load "C" pointer */
    320 #define ldptru	ldu		/* load "C" pointer with update */
    321 #define stptr	std		/* store "C" pointer */
    322 #define stptru	stdu		/* store "C" pointer with update */
    323 #define	ldreg	ld		/* load PPC general register */
    324 #define	ldregu	ldu		/* load PPC general register with update */
    325 #define	streg	std		/* store PPC general register */
    326 #define	stregu	stdu		/* store PPC general register with update */
    327 /* redefined this to force an error on PPC64 to catch their use.  */
    328 #define	lmw	lmd		/* load multiple PPC general registers */
    329 #define	stmw	stmd		/* store multiple PPC general registers */
    330 #define	SZREG	8		/* 8 byte registers */
    331 
    332 #define	lptrarx	ldarx		/* load "C" pointer with reservation */
    333 #define	llongarx ldarx		/* load "C" long with reservation */
    334 #define	lregarx	ldarx		/* load PPC general register with reservation */
    335 
    336 #define	stptrcx  stdcx		/* store "C" pointer conditional */
    337 #define	stlongcx stdcx		/* store "C" long conditional */
    338 #define	stregax  stdcx		/* store PPC general register conditional */
    339 
    340 #define	clrrptri  clrrdi	/* clear right "C" pointer immediate */
    341 #define	clrrlongi clrrdi	/* clear right "C" long immediate */
    342 #define	clrrregi  clrrdi	/* clear right PPC general register immediate */
    343 
    344 #endif
    345 
    346 #ifdef _LOCORE
    347 .macro	stmd	r,dst
    348 	i = 0
    349     .rept	32-\r
    350 	std	i+\r, i*8+\dst
    351 	i = i + 1
    352     .endr
    353 .endm
    354 
    355 .macro	lmd	r,dst
    356 	i = 0
    357     .rept	32-\r
    358 	ld	i+\r, i*8+\dst
    359 	i = i + 1
    360     .endr
    361 .endm
    362 #endif
    363 
    364 #endif /* !_PPC_ASM_H_ */
    365