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