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