Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.32
      1  1.32      matt /*	$NetBSD: asm.h,v 1.32 2011/01/16 02:41:55 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.32      matt #ifdef __STDC__
     50  1.32      matt #define	PIC_TOCNAME(name) 	.LCTOC_##name
     51  1.32      matt #else
     52  1.32      matt #define	PIC_TOCNAME(name) 	.LCTOC_/**/name
     53  1.32      matt #endif
     54  1.32      matt #define	PIC_TOCSETUP(name, reg)						\
     55  1.32      matt 		.pushsection ".got2","aw"				;\
     56  1.32      matt 	PIC_TOCNAME(name) = . + 32768					;\
     57  1.32      matt 		.popsection						;\
     58  1.32      matt 		bcl	20,31,1001f					;\
     59  1.32      matt 	1001:	mflr	reg						;\
     60  1.32      matt 		addis	reg,reg,PIC_TOCNAME(name)-1001b@ha		;\
     61  1.32      matt 		addi	reg,reg,PIC_TOCNAME(name)-1001b@l
     62  1.32      matt #define	PIC_GOTSETUP(reg)						\
     63  1.32      matt 		bcl	20,31,2002f					;\
     64  1.32      matt 	2002:	mflr	reg						;\
     65  1.32      matt 		addis	reg,reg,_GLOBAL_OFFSET_TABLE_-2002b@ha		;\
     66  1.32      matt 		addi	reg,reg,_GLOBAL_OFFSET_TABLE_-2002b@l
     67   1.1        ws #ifdef	__STDC__
     68   1.1        ws #define PIC_GOT(x)	XXX
     69   1.1        ws #define PIC_GOTOFF(x)	XXX
     70   1.1        ws #else	/* not __STDC__ */
     71   1.1        ws #define PIC_GOT(x)	XXX
     72   1.1        ws #define PIC_GOTOFF(x)	XXX
     73   1.1        ws #endif	/* __STDC__ */
     74   1.1        ws #else
     75   1.1        ws #define PIC_PROLOGUE
     76   1.1        ws #define PIC_EPILOGUE
     77   1.1        ws #define PIC_PLT(x)	x
     78   1.1        ws #define PIC_GOT(x)	x
     79   1.1        ws #define PIC_GOTOFF(x)	x
     80  1.32      matt #define	PIC_GOTSETUP(r)
     81  1.32      matt #define	PIC_TOCSETUP(n, r)
     82   1.1        ws #endif
     83   1.1        ws 
     84  1.21      ross #endif
     85  1.21      ross 
     86   1.3   thorpej #define	_C_LABEL(x)	x
     87   1.1        ws #define	_ASM_LABEL(x)	x
     88   1.1        ws 
     89   1.3   thorpej #define	_GLOBAL(x) \
     90   1.3   thorpej 	.data; .align 2; .globl x; x:
     91   1.3   thorpej 
     92   1.2       jtc #ifdef GPROF
     93   1.6    tsubai # define _PROF_PROLOGUE	mflr 0; stw 0,4(1); bl _mcount
     94   1.1        ws #else
     95   1.1        ws # define _PROF_PROLOGUE
     96   1.1        ws #endif
     97   1.1        ws 
     98  1.20      ross #ifdef _LP64
     99  1.20      ross 
    100  1.20      ross #define	SF_HEADER_SZ	48
    101  1.20      ross #define	SF_PARAM_SZ	64
    102  1.21      ross #define	SF_SZ		(SF_HEADER_SZ + SF_PARAM_SZ)
    103  1.20      ross 
    104  1.20      ross #define	SF_SP		 0
    105  1.20      ross #define	SF_CR		 8
    106  1.20      ross #define	SF_LR		16
    107  1.20      ross #define	SF_PARAM	SF_HEADER_SZ
    108  1.20      ross 
    109  1.20      ross #define	ENTRY(y)			\
    110  1.20      ross 	.globl	y;			\
    111  1.20      ross 	.section ".opd","aw";		\
    112  1.20      ross 	.align	3;			\
    113  1.20      ross y:	.quad	.y,.TOC.@tocbase,0;	\
    114  1.20      ross 	.previous;			\
    115  1.20      ross 	.size	y,24;			\
    116  1.20      ross 	.type	.y,@function;		\
    117  1.20      ross 	.globl	.y;			\
    118  1.21      ross 	.align	3;			\
    119  1.20      ross .y:
    120  1.21      ross 
    121  1.20      ross #define	CALL(y)				\
    122  1.21      ross 	bl	.y;			\
    123  1.20      ross 	nop
    124  1.20      ross 
    125  1.20      ross #define	ENTRY_NOPROFILE(y)	ENTRY(y)
    126  1.20      ross #define	ASENTRY(y)		ENTRY(y)
    127  1.20      ross #else
    128  1.20      ross 
    129  1.20      ross #define _ENTRY(x) \
    130  1.20      ross 	.text; .align 2; .globl x; .type x,@function; x:
    131  1.20      ross 
    132   1.1        ws #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
    133  1.31      matt #define	END(y)		.size _C_LABEL(y),.-_C_LABEL(y)
    134  1.20      ross 
    135   1.9   thorpej #define	ENTRY_NOPROFILE(y) _ENTRY(_C_LABEL(y))
    136   1.9   thorpej 
    137  1.20      ross #define	CALL(y)				\
    138  1.20      ross 	bl	y
    139  1.20      ross 
    140   1.1        ws #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
    141  1.20      ross #endif
    142  1.20      ross 
    143   1.3   thorpej #define	GLOBAL(y)	_GLOBAL(_C_LABEL(y))
    144   1.1        ws 
    145   1.1        ws #define	ASMSTR		.asciz
    146   1.1        ws 
    147  1.31      matt #define RCSID(x)	__RCSID(x)
    148  1.31      matt #define	__RCSID(x)	.pushsection .ident; .asciz x; .popsection
    149   1.7    kleink 
    150   1.7    kleink #ifdef __ELF__
    151   1.7    kleink #define	WEAK_ALIAS(alias,sym)						\
    152   1.7    kleink 	.weak alias;							\
    153   1.7    kleink 	alias = sym
    154   1.7    kleink #endif
    155  1.19  christos /*
    156  1.19  christos  * STRONG_ALIAS: create a strong alias.
    157  1.19  christos  */
    158  1.19  christos #define STRONG_ALIAS(alias,sym)						\
    159  1.19  christos 	.globl alias;							\
    160  1.19  christos 	alias = sym
    161   1.5   thorpej 
    162   1.5   thorpej #ifdef __STDC__
    163  1.30     joerg #define	WARN_REFERENCES(sym,msg)					\
    164  1.30     joerg 	.pushsection .gnu.warning. ## sym;				\
    165  1.30     joerg 	.ascii msg;							\
    166  1.30     joerg 	.popsection
    167   1.5   thorpej #else
    168  1.30     joerg #define	WARN_REFERENCES(sym,msg)					\
    169  1.30     joerg 	.pushsection .gnu.warning./**/sym;				\
    170  1.30     joerg 	.ascii msg;							\
    171  1.30     joerg 	.popsection
    172   1.5   thorpej #endif /* __STDC__ */
    173  1.12      matt 
    174  1.12      matt #ifdef _KERNEL
    175  1.12      matt /*
    176  1.12      matt  * Get cpu_info pointer for current processor.  Always in SPRG0. *ALWAYS*
    177  1.12      matt  */
    178  1.12      matt #define	GET_CPUINFO(r)		mfsprg r,0
    179  1.12      matt /*
    180  1.12      matt  * IN:
    181  1.12      matt  *	R4[er] = first free byte beyond end/esym.
    182  1.12      matt  *
    183  1.12      matt  * OUT:
    184  1.12      matt  *	R1[sp] = new kernel stack
    185  1.12      matt  *	R4[er] = kernelend
    186  1.12      matt  */
    187  1.12      matt 
    188  1.12      matt #define	INIT_CPUINFO(er,sp,tmp1,tmp2) 					\
    189  1.12      matt 	li	tmp1,PGOFSET;						\
    190  1.12      matt 	add	er,er,tmp1;						\
    191  1.12      matt 	andc	er,er,tmp1;		/* page align */		\
    192  1.12      matt 	lis	tmp1,_C_LABEL(cpu_info)@ha;				\
    193  1.12      matt 	addi	tmp1,tmp1,_C_LABEL(cpu_info)@l;				\
    194  1.15      matt 	mtsprg0	tmp1;			/* save for later use */	\
    195  1.12      matt 	addi	er,er,INTSTK;						\
    196  1.15      matt 	stptr	er,CI_INTSTK(tmp1);					\
    197  1.17    simonb 	lis	tmp2,_C_LABEL(emptyidlespin)@h;				\
    198  1.17    simonb 	ori	tmp2,tmp2,_C_LABEL(emptyidlespin)@l;			\
    199  1.16      matt 	stptr	tmp2,CI_IDLESPIN(tmp1);					\
    200  1.12      matt 	li	tmp2,-1;						\
    201  1.15      matt 	stint	tmp2,CI_INTRDEPTH(tmp1);				\
    202  1.12      matt 	li	tmp2,0;							\
    203  1.15      matt 	stptr	tmp2,-CALLFRAMELEN(er);	/* terminate idle stack chain */\
    204  1.28     rmind 	lis	tmp1,_C_LABEL(lwp0)+L_PCB@ha; /* XXXuvm_lwp_getuarea */	\
    205  1.28     rmind 	stptr	er,_C_LABEL(lwp0)+L_PCB@l(tmp1);			\
    206  1.12      matt 	addi	er,er,USPACE;		/* stackpointer for proc0 */	\
    207  1.12      matt 	addi	sp,er,-FRAMELEN;	/* stackpointer for proc0 */	\
    208  1.12      matt 		/* er = end of mem reserved for kernel */		\
    209  1.15      matt 	stptru	tmp2,-CALLFRAMELEN(sp)	/* end of stack chain */
    210  1.12      matt 
    211  1.12      matt #endif
    212   1.8    simonb 
    213   1.8    simonb /* Condition Register Bit Fields */
    214   1.8    simonb 
    215  1.11      matt #if !defined(_NOREGNAMES)
    216  1.10      matt #if defined(_KERNEL) || defined(_STANDALONE)
    217   1.8    simonb #define cr0     0
    218   1.8    simonb #define cr1     1
    219   1.8    simonb #define cr2     2
    220   1.8    simonb #define cr3     3
    221   1.8    simonb #define cr4     4
    222   1.8    simonb #define cr5     5
    223   1.8    simonb #define cr6     6
    224   1.8    simonb #define cr7     7
    225  1.10      matt #endif
    226   1.8    simonb 
    227   1.8    simonb /* General Purpose Registers (GPRs) */
    228   1.8    simonb 
    229  1.10      matt #if defined(_KERNEL) || defined(_STANDALONE)
    230   1.8    simonb #define r0      0
    231   1.8    simonb #define r1      1
    232   1.8    simonb #define r2      2
    233   1.8    simonb #define r3      3
    234   1.8    simonb #define r4      4
    235   1.8    simonb #define r5      5
    236   1.8    simonb #define r6      6
    237   1.8    simonb #define r7      7
    238   1.8    simonb #define r8      8
    239   1.8    simonb #define r9      9
    240   1.8    simonb #define r10     10
    241   1.8    simonb #define r11     11
    242   1.8    simonb #define r12     12
    243   1.8    simonb #define r13     13
    244   1.8    simonb #define r14     14
    245   1.8    simonb #define r15     15
    246   1.8    simonb #define r16     16
    247   1.8    simonb #define r17     17
    248   1.8    simonb #define r18     18
    249   1.8    simonb #define r19     19
    250   1.8    simonb #define r20     20
    251   1.8    simonb #define r21     21
    252   1.8    simonb #define r22     22
    253   1.8    simonb #define r23     23
    254   1.8    simonb #define r24     24
    255   1.8    simonb #define r25     25
    256   1.8    simonb #define r26     26
    257   1.8    simonb #define r27     27
    258   1.8    simonb #define r28     28
    259   1.8    simonb #define r29     29
    260   1.8    simonb #define r30     30
    261   1.8    simonb #define r31     31
    262  1.10      matt #endif
    263   1.8    simonb 
    264   1.8    simonb /* Floating Point Registers (FPRs) */
    265   1.8    simonb 
    266  1.10      matt #if defined(_KERNEL) || defined(_STANDALONE)
    267   1.8    simonb #define fr0     0
    268   1.8    simonb #define fr1     1
    269   1.8    simonb #define fr2     2
    270   1.8    simonb #define fr3     3
    271   1.8    simonb #define fr4     4
    272   1.8    simonb #define fr5     5
    273   1.8    simonb #define fr6     6
    274   1.8    simonb #define fr7     7
    275   1.8    simonb #define fr8     8
    276   1.8    simonb #define fr9     9
    277   1.8    simonb #define fr10    10
    278   1.8    simonb #define fr11    11
    279   1.8    simonb #define fr12    12
    280   1.8    simonb #define fr13    13
    281   1.8    simonb #define fr14    14
    282   1.8    simonb #define fr15    15
    283   1.8    simonb #define fr16    16
    284   1.8    simonb #define fr17    17
    285   1.8    simonb #define fr18    18
    286   1.8    simonb #define fr19    19
    287   1.8    simonb #define fr20    20
    288   1.8    simonb #define fr21    21
    289   1.8    simonb #define fr22    22
    290   1.8    simonb #define fr23    23
    291   1.8    simonb #define fr24    24
    292   1.8    simonb #define fr25    25
    293   1.8    simonb #define fr26    26
    294   1.8    simonb #define fr27    27
    295   1.8    simonb #define fr28    28
    296   1.8    simonb #define fr29    29
    297   1.8    simonb #define fr30    30
    298   1.8    simonb #define fr31    31
    299  1.10      matt #endif
    300  1.11      matt #endif /* !_NOREGNAMES */
    301  1.13      matt 
    302  1.13      matt /*
    303  1.13      matt  * Add some psuedo instructions to made sharing of assembly versions of
    304  1.13      matt  * ILP32 and LP64 code possible.
    305  1.13      matt  */
    306  1.13      matt #define ldint	lwz		/* not needed but for completeness */
    307  1.13      matt #define ldintu	lwzu		/* not needed but for completeness */
    308  1.13      matt #define stint	stw		/* not needed but for completeness */
    309  1.13      matt #define stintu	stwu		/* not needed but for completeness */
    310  1.20      ross 
    311  1.13      matt #ifndef _LP64
    312  1.20      ross 
    313  1.13      matt #define ldlong	lwz		/* load "C" long */
    314  1.13      matt #define ldlongu	lwzu		/* load "C" long with udpate */
    315  1.13      matt #define stlong	stw		/* load "C" long */
    316  1.13      matt #define stlongu	stwu		/* load "C" long with udpate */
    317  1.13      matt #define ldptr	lwz		/* load "C" pointer */
    318  1.13      matt #define ldptru	lwzu		/* load "C" pointer with udpate */
    319  1.13      matt #define stptr	stw		/* load "C" pointer */
    320  1.13      matt #define stptru	stwu		/* load "C" pointer with udpate */
    321  1.13      matt #define	ldreg	lwz		/* load PPC general register */
    322  1.13      matt #define	ldregu	lwzu		/* load PPC general register with udpate */
    323  1.13      matt #define	streg	stw		/* load PPC general register */
    324  1.13      matt #define	stregu	stwu		/* load PPC general register with udpate */
    325  1.13      matt #define	SZREG	4		/* 4 byte registers */
    326  1.20      ross 
    327  1.26      matt #define	lptrarx	lwarx		/* load "C" pointer with reservation */
    328  1.26      matt #define	llongarx lwarx		/* load "C" long with reservation */
    329  1.26      matt #define	lregarx	lwarx		/* load PPC general register with reservation */
    330  1.26      matt 
    331  1.26      matt #define	stptrcx  stwcx		/* store "C" pointer conditional */
    332  1.26      matt #define	stlongcx stwcx		/* store "C" long conditional */
    333  1.26      matt #define	stregcx  stwcx		/* store PPC general register conditional */
    334  1.26      matt 
    335  1.26      matt #define	clrrptri  clrrwi	/* clear right "C" pointer immediate */
    336  1.26      matt #define	clrrlongi clrrwi	/* clear right "C" long immediate */
    337  1.26      matt #define	clrrregi  clrrwi	/* clear right PPC general register immediate */
    338  1.26      matt 
    339  1.13      matt #else
    340  1.20      ross 
    341  1.13      matt #define ldlong	ld		/* load "C" long */
    342  1.13      matt #define ldlongu	ldu		/* load "C" long with update */
    343  1.13      matt #define stlong	std		/* store "C" long */
    344  1.13      matt #define stlongu	stdu		/* store "C" long with update */
    345  1.13      matt #define ldptr	ld		/* load "C" pointer */
    346  1.13      matt #define ldptru	ldu		/* load "C" pointer with update */
    347  1.13      matt #define stptr	std		/* store "C" pointer */
    348  1.13      matt #define stptru	stdu		/* store "C" pointer with update */
    349  1.13      matt #define	ldreg	ld		/* load PPC general register */
    350  1.13      matt #define	ldregu	ldu		/* load PPC general register with update */
    351  1.13      matt #define	streg	std		/* store PPC general register */
    352  1.13      matt #define	stregu	stdu		/* store PPC general register with update */
    353  1.14      matt /* redefined this to force an error on PPC64 to catch their use.  */
    354  1.14      matt #define	lmw	lmd		/* load multiple PPC general registers */
    355  1.14      matt #define	stmw	stmd		/* store multiple PPC general registers */
    356  1.13      matt #define	SZREG	8		/* 8 byte registers */
    357  1.20      ross 
    358  1.26      matt #define	lptrarx	ldarx		/* load "C" pointer with reservation */
    359  1.26      matt #define	llongarx ldarx		/* load "C" long with reservation */
    360  1.26      matt #define	lregarx	ldarx		/* load PPC general register with reservation */
    361  1.26      matt 
    362  1.26      matt #define	stptrcx  stdcx		/* store "C" pointer conditional */
    363  1.26      matt #define	stlongcx stdcx		/* store "C" long conditional */
    364  1.26      matt #define	stregax  stdcx		/* store PPC general register conditional */
    365  1.26      matt 
    366  1.26      matt #define	clrrptri  clrrdi	/* clear right "C" pointer immediate */
    367  1.26      matt #define	clrrlongi clrrdi	/* clear right "C" long immediate */
    368  1.26      matt #define	clrrregi  clrrdi	/* clear right PPC general register immediate */
    369  1.26      matt 
    370  1.13      matt #endif
    371   1.1        ws 
    372  1.23      ross #ifdef _LOCORE
    373  1.22      ross .macro	stmd	r,dst
    374  1.22      ross 	i = 0
    375  1.22      ross     .rept	32-\r
    376  1.22      ross 	std	i+\r, i*8+\dst
    377  1.22      ross 	i = i + 1
    378  1.22      ross     .endr
    379  1.22      ross .endm
    380  1.22      ross 
    381  1.22      ross .macro	lmd	r,dst
    382  1.22      ross 	i = 0
    383  1.22      ross     .rept	32-\r
    384  1.22      ross 	ld	i+\r, i*8+\dst
    385  1.22      ross 	i = i + 1
    386  1.22      ross     .endr
    387  1.22      ross .endm
    388  1.23      ross #endif
    389  1.22      ross 
    390   1.1        ws #endif /* !_PPC_ASM_H_ */
    391