asm.h revision 1.13
11.13Smrg/*	$NetBSD: asm.h,v 1.13 2008/10/26 00:08:15 mrg Exp $	*/
21.1Sfvdl
31.1Sfvdl/*-
41.1Sfvdl * Copyright (c) 1990 The Regents of the University of California.
51.1Sfvdl * All rights reserved.
61.1Sfvdl *
71.1Sfvdl * This code is derived from software contributed to Berkeley by
81.1Sfvdl * William Jolitz.
91.1Sfvdl *
101.1Sfvdl * Redistribution and use in source and binary forms, with or without
111.1Sfvdl * modification, are permitted provided that the following conditions
121.1Sfvdl * are met:
131.1Sfvdl * 1. Redistributions of source code must retain the above copyright
141.1Sfvdl *    notice, this list of conditions and the following disclaimer.
151.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright
161.1Sfvdl *    notice, this list of conditions and the following disclaimer in the
171.1Sfvdl *    documentation and/or other materials provided with the distribution.
181.3Sagc * 3. Neither the name of the University nor the names of its contributors
191.1Sfvdl *    may be used to endorse or promote products derived from this software
201.1Sfvdl *    without specific prior written permission.
211.1Sfvdl *
221.1Sfvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Sfvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Sfvdl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Sfvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Sfvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Sfvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Sfvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Sfvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Sfvdl * SUCH DAMAGE.
331.1Sfvdl *
341.1Sfvdl *	@(#)asm.h	5.5 (Berkeley) 5/7/91
351.1Sfvdl */
361.1Sfvdl
371.1Sfvdl#ifndef _AMD64_ASM_H_
381.1Sfvdl#define _AMD64_ASM_H_
391.1Sfvdl
401.13Smrg#ifdef __x86_64__
411.13Smrg
421.1Sfvdl#ifdef PIC
431.1Sfvdl#define PIC_PLT(x)	x@PLT
441.1Sfvdl#define PIC_GOT(x)	x@GOTPCREL(%rip)
451.1Sfvdl#else
461.1Sfvdl#define PIC_PLT(x)	x
471.1Sfvdl#define PIC_GOT(x)	x
481.1Sfvdl#endif
491.1Sfvdl
501.1Sfvdl# define _C_LABEL(x)	x
511.1Sfvdl#define	_ASM_LABEL(x)	x
521.1Sfvdl
531.1Sfvdl#define CVAROFF(x,y)		(_C_LABEL(x)+y)(%rip)
541.1Sfvdl
551.1Sfvdl#ifdef __STDC__
561.1Sfvdl# define __CONCAT(x,y)	x ## y
571.1Sfvdl# define __STRING(x)	#x
581.1Sfvdl#else
591.1Sfvdl# define __CONCAT(x,y)	x/**/y
601.1Sfvdl# define __STRING(x)	"x"
611.1Sfvdl#endif
621.1Sfvdl
631.1Sfvdl/* let kernels and others override entrypoint alignment */
641.1Sfvdl#ifndef _ALIGN_TEXT
651.8Sad# ifdef _STANDALONE
661.11Sad#  define _ALIGN_TEXT .align 4
671.8Sad# else
681.10Sad#  define _ALIGN_TEXT .align 16
691.8Sad# endif
701.1Sfvdl#endif
711.1Sfvdl
721.1Sfvdl#define _ENTRY(x) \
731.1Sfvdl	.text; _ALIGN_TEXT; .globl x; .type x,@function; x:
741.7Sad#define _LABEL(x) \
751.7Sad	.globl x; x:
761.1Sfvdl
771.1Sfvdl#ifdef _KERNEL
781.1Sfvdl/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
791.1Sfvdl#ifdef __STDC__
801.2Syamt#define	IDTVEC(name) \
811.2Syamt	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
821.1Sfvdl#else
831.2Syamt#define	IDTVEC(name) \
841.2Syamt	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
851.1Sfvdl#endif /* __STDC__ */
861.1Sfvdl#endif /* _KERNEL */
871.1Sfvdl
881.1Sfvdl#ifdef __STDC__
891.1Sfvdl#define CPUVAR(off)	%gs:CPU_INFO_ ## off
901.1Sfvdl#else
911.1Sfvdl#define CPUVAR(off)     %gs:CPU_INFO_/**/off
921.1Sfvdl#endif
931.1Sfvdl
941.1Sfvdl
951.1Sfvdl#ifdef GPROF
961.1Sfvdl# define _PROF_PROLOGUE	\
971.1Sfvdl	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
981.1Sfvdl#else
991.1Sfvdl# define _PROF_PROLOGUE
1001.1Sfvdl#endif
1011.1Sfvdl
1021.1Sfvdl#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
1031.1Sfvdl#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
1041.1Sfvdl#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
1051.7Sad#define	LABEL(y)	_LABEL(_C_LABEL(y))
1061.1Sfvdl
1071.1Sfvdl#define	ASMSTR		.asciz
1081.1Sfvdl
1091.12Sjoerg#define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
1101.1Sfvdl
1111.1Sfvdl#define	WEAK_ALIAS(alias,sym)						\
1121.1Sfvdl	.weak alias;							\
1131.1Sfvdl	alias = sym
1141.1Sfvdl
1151.5Schristos/*
1161.5Schristos * STRONG_ALIAS: create a strong alias.
1171.5Schristos */
1181.5Schristos#define STRONG_ALIAS(alias,sym)						\
1191.5Schristos	.globl alias;							\
1201.5Schristos	alias = sym
1211.5Schristos
1221.1Sfvdl/* XXXfvdl do not use stabs here */
1231.1Sfvdl#ifdef __STDC__
1241.1Sfvdl#define	WARN_REFERENCES(sym,msg)					\
1251.1Sfvdl	.stabs msg ## ,30,0,0,0 ;					\
1261.1Sfvdl	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
1271.1Sfvdl#else
1281.1Sfvdl#define	WARN_REFERENCES(sym,msg)					\
1291.1Sfvdl	.stabs msg,30,0,0,0 ;						\
1301.1Sfvdl	.stabs __STRING(sym),1,0,0,0
1311.1Sfvdl#endif /* __STDC__ */
1321.1Sfvdl
1331.13Smrg#else	/*	__x86_64__	*/
1341.13Smrg
1351.13Smrg#include <i386/asm.h>
1361.13Smrg
1371.13Smrg#endif	/*	__x86_64__	*/
1381.13Smrg
1391.1Sfvdl#endif /* !_AMD64_ASM_H_ */
140