asm.h revision 1.7
11.7Sad/*	$NetBSD: asm.h,v 1.7 2007/02/09 21:55:01 ad 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.1Sfvdl#ifdef PIC
411.1Sfvdl#define PIC_PLT(x)	x@PLT
421.1Sfvdl#define PIC_GOT(x)	x@GOTPCREL(%rip)
431.1Sfvdl#else
441.1Sfvdl#define PIC_PLT(x)	x
451.1Sfvdl#define PIC_GOT(x)	x
461.1Sfvdl#endif
471.1Sfvdl
481.1Sfvdl# define _C_LABEL(x)	x
491.1Sfvdl#define	_ASM_LABEL(x)	x
501.1Sfvdl
511.1Sfvdl#define CVAROFF(x,y)		(_C_LABEL(x)+y)(%rip)
521.1Sfvdl
531.1Sfvdl#ifdef __STDC__
541.1Sfvdl# define __CONCAT(x,y)	x ## y
551.1Sfvdl# define __STRING(x)	#x
561.1Sfvdl#else
571.1Sfvdl# define __CONCAT(x,y)	x/**/y
581.1Sfvdl# define __STRING(x)	"x"
591.1Sfvdl#endif
601.1Sfvdl
611.1Sfvdl/* let kernels and others override entrypoint alignment */
621.1Sfvdl#ifndef _ALIGN_TEXT
631.1Sfvdl#define _ALIGN_TEXT .align 4
641.1Sfvdl#endif
651.1Sfvdl
661.1Sfvdl#define _ENTRY(x) \
671.1Sfvdl	.text; _ALIGN_TEXT; .globl x; .type x,@function; x:
681.7Sad#define _LABEL(x) \
691.7Sad	.globl x; x:
701.1Sfvdl
711.1Sfvdl#ifdef _KERNEL
721.1Sfvdl/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
731.1Sfvdl#ifdef __STDC__
741.2Syamt#define	IDTVEC(name) \
751.2Syamt	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
761.1Sfvdl#else
771.2Syamt#define	IDTVEC(name) \
781.2Syamt	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
791.1Sfvdl#endif /* __STDC__ */
801.1Sfvdl#endif /* _KERNEL */
811.1Sfvdl
821.1Sfvdl#ifdef __STDC__
831.1Sfvdl#define CPUVAR(off)	%gs:CPU_INFO_ ## off
841.1Sfvdl#else
851.1Sfvdl#define CPUVAR(off)     %gs:CPU_INFO_/**/off
861.1Sfvdl#endif
871.1Sfvdl
881.1Sfvdl
891.1Sfvdl#ifdef GPROF
901.1Sfvdl# define _PROF_PROLOGUE	\
911.1Sfvdl	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
921.1Sfvdl#else
931.1Sfvdl# define _PROF_PROLOGUE
941.1Sfvdl#endif
951.1Sfvdl
961.1Sfvdl#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
971.1Sfvdl#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
981.1Sfvdl#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
991.7Sad#define	LABEL(y)	_LABEL(_C_LABEL(y))
1001.1Sfvdl
1011.1Sfvdl#define	ASMSTR		.asciz
1021.1Sfvdl
1031.1Sfvdl#define RCSID(x)	.text; .asciz x
1041.1Sfvdl
1051.1Sfvdl#define	WEAK_ALIAS(alias,sym)						\
1061.1Sfvdl	.weak alias;							\
1071.1Sfvdl	alias = sym
1081.1Sfvdl
1091.5Schristos/*
1101.5Schristos * STRONG_ALIAS: create a strong alias.
1111.5Schristos */
1121.5Schristos#define STRONG_ALIAS(alias,sym)						\
1131.5Schristos	.globl alias;							\
1141.5Schristos	alias = sym
1151.5Schristos
1161.1Sfvdl/* XXXfvdl do not use stabs here */
1171.1Sfvdl#ifdef __STDC__
1181.1Sfvdl#define	WARN_REFERENCES(sym,msg)					\
1191.1Sfvdl	.stabs msg ## ,30,0,0,0 ;					\
1201.1Sfvdl	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
1211.1Sfvdl#else
1221.1Sfvdl#define	WARN_REFERENCES(sym,msg)					\
1231.1Sfvdl	.stabs msg,30,0,0,0 ;						\
1241.1Sfvdl	.stabs __STRING(sym),1,0,0,0
1251.1Sfvdl#endif /* __STDC__ */
1261.1Sfvdl
1271.1Sfvdl#endif /* !_AMD64_ASM_H_ */
128