11.24Sriastrad/*	$NetBSD: asm.h,v 1.24 2025/01/05 14:30:37 riastradh 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.18Sjoerg#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.19Suebayasi#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.17Suebayasi#define	IDTVEC_END(name) \
831.17Suebayasi	.size X ## name, . - X ## name
841.22Srillig#else
851.2Syamt#define	IDTVEC(name) \
861.2Syamt	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
871.17Suebayasi#define	IDTVEC_END(name) \
881.17Suebayasi	.size X/**/name, . - X/**/name
891.22Srillig#endif /* __STDC__ */
901.1Sfvdl#endif /* _KERNEL */
911.1Sfvdl
921.1Sfvdl#ifdef __STDC__
931.1Sfvdl#define CPUVAR(off)	%gs:CPU_INFO_ ## off
941.1Sfvdl#else
951.1Sfvdl#define CPUVAR(off)     %gs:CPU_INFO_/**/off
961.1Sfvdl#endif
971.1Sfvdl
981.1Sfvdl
991.1Sfvdl#ifdef GPROF
1001.1Sfvdl# define _PROF_PROLOGUE	\
1011.1Sfvdl	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
1021.1Sfvdl#else
1031.1Sfvdl# define _PROF_PROLOGUE
1041.1Sfvdl#endif
1051.1Sfvdl
1061.1Sfvdl#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
1071.1Sfvdl#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
1081.15Schs#define	ALTENTRY(x)	NENTRY(x)
1091.1Sfvdl#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
1101.7Sad#define	LABEL(y)	_LABEL(_C_LABEL(y))
1111.16Suebayasi#define	END(y)		.size y, . - y
1121.1Sfvdl
1131.1Sfvdl#define	ASMSTR		.asciz
1141.1Sfvdl
1151.23Sriastrad#define _IDENTSTR(x)	.pushsection ".ident","MS",@progbits,1;		\
1161.24Sriastrad			x;						\
1171.20Sjoerg			.popsection
1181.23Sriastrad#ifdef _NETBSD_REVISIONID
1191.23Sriastrad#define	RCSID(_s)							      \
1201.24Sriastrad	_IDENTSTR(.asciz _s);						      \
1211.24Sriastrad	_IDENTSTR(.ascii "$"; .ascii "NetBSD: "; .ascii __FILE__; .ascii " "; \
1221.24Sriastrad	    .ascii _NETBSD_REVISIONID; .asciz " $")
1231.23Sriastrad#else
1241.24Sriastrad#define	RCSID(_s)	_IDENTSTR(.asciz _s)
1251.23Sriastrad#endif
1261.1Sfvdl
1271.1Sfvdl#define	WEAK_ALIAS(alias,sym)						\
1281.1Sfvdl	.weak alias;							\
1291.1Sfvdl	alias = sym
1301.1Sfvdl
1311.5Schristos/*
1321.5Schristos * STRONG_ALIAS: create a strong alias.
1331.5Schristos */
1341.5Schristos#define STRONG_ALIAS(alias,sym)						\
1351.5Schristos	.globl alias;							\
1361.5Schristos	alias = sym
1371.5Schristos
1381.1Sfvdl#ifdef __STDC__
1391.1Sfvdl#define	WARN_REFERENCES(sym,msg)					\
1401.14Sjoerg	.pushsection .gnu.warning. ## sym;				\
1411.14Sjoerg	.ascii msg;							\
1421.14Sjoerg	.popsection
1431.1Sfvdl#else
1441.1Sfvdl#define	WARN_REFERENCES(sym,msg)					\
1451.14Sjoerg	.pushsection .gnu.warning./**/sym;				\
1461.14Sjoerg	.ascii msg;							\
1471.14Sjoerg	.popsection
1481.1Sfvdl#endif /* __STDC__ */
1491.1Sfvdl
1501.13Smrg#else	/*	__x86_64__	*/
1511.13Smrg
1521.13Smrg#include <i386/asm.h>
1531.13Smrg
1541.13Smrg#endif	/*	__x86_64__	*/
1551.13Smrg
1561.1Sfvdl#endif /* !_AMD64_ASM_H_ */
157