xref: /freebsd/sys/amd64/include/asm.h (revision 3494f7c0)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifdef __i386__
36 #include <i386/asm.h>
37 #else /* !__i386__ */
38 
39 #ifndef _MACHINE_ASM_H_
40 #define	_MACHINE_ASM_H_
41 
42 #include <sys/cdefs.h>
43 
44 #ifdef PIC
45 #define	PIC_PLT(x)	x@PLT
46 #define	PIC_GOT(x)	x@GOTPCREL(%rip)
47 #else
48 #define	PIC_PLT(x)	x
49 #endif
50 
51 /*
52  * CNAME and HIDENAME manage the relationship between symbol names in C
53  * and the equivalent assembly language names.  CNAME is given a name as
54  * it would be used in a C program.  It expands to the equivalent assembly
55  * language name.  HIDENAME is given an assembly-language name, and expands
56  * to a possibly-modified form that will be invisible to C programs.
57  */
58 #define CNAME(csym)		csym
59 #define HIDENAME(asmsym)	.asmsym
60 
61 #define _START_ENTRY	.text; .p2align 4,0x90
62 
63 #define _ENTRY(x)	_START_ENTRY; \
64 			.globl CNAME(x); .type CNAME(x),@function; CNAME(x):; \
65 			.cfi_startproc
66 
67 #ifdef PROF
68 #define	ALTENTRY(x)	_ENTRY(x); \
69 			pushq %rbp; \
70 			.cfi_def_cfa_offset 16; \
71 			.cfi_offset %rbp, -16; \
72 			movq %rsp,%rbp; \
73 			call PIC_PLT(HIDENAME(mcount)); \
74 			popq %rbp; \
75 			.cfi_restore %rbp; \
76 			.cfi_def_cfa_offset 8; \
77 			jmp 9f
78 #define	ENTRY(x)	_ENTRY(x); \
79 			pushq %rbp; \
80 			.cfi_def_cfa_offset 16; \
81 			.cfi_offset %rbp, -16; \
82 			movq %rsp,%rbp; \
83 			call PIC_PLT(HIDENAME(mcount)); \
84 			popq %rbp; \
85 			.cfi_restore %rbp; \
86 			.cfi_def_cfa_offset 8; \
87 			9:
88 #else
89 #define	ALTENTRY(x)	_ENTRY(x)
90 #define	ENTRY(x)	_ENTRY(x)
91 #endif
92 
93 #define	END(x)		.size x, . - x; .cfi_endproc
94 /*
95  * WEAK_REFERENCE(): create a weak reference alias from sym.
96  * The macro is not a general asm macro that takes arbitrary names,
97  * but one that takes only C names. It does the non-null name
98  * translation inside the macro.
99  */
100 #define	WEAK_REFERENCE(sym, alias)					\
101 	.weak CNAME(alias);						\
102 	.equ CNAME(alias),CNAME(sym)
103 
104 #define RCSID(x)	.text; .asciz x
105 
106 #undef __FBSDID
107 #if !defined(STRIP_FBSDID)
108 #define __FBSDID(s)	.ident s
109 #else
110 #define __FBSDID(s)	/* nothing */
111 #endif /* !STRIP_FBSDID */
112 
113 #endif /* !_MACHINE_ASM_H_ */
114 
115 #endif /* __i386__ */
116