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