xref: /openbsd-src/sys/arch/sparc64/include/asm.h (revision 1ad61ae0a79a724d2d3ec69e69c8e1d1ff6b53a0)
1 /*	$OpenBSD: asm.h,v 1.18 2023/01/13 17:53:30 miod Exp $	*/
2 /*	$NetBSD: asm.h,v 1.15 2000/08/02 22:24:39 eeh Exp $ */
3 
4 /*
5  * Copyright (c) 1994 Allen Briggs
6  * All rights reserved.
7  *
8  * Gleaned from locore.s and sun3 asm.h which had the following copyrights:
9  * locore.s:
10  * Copyright (c) 1988 University of Utah.
11  * Copyright (c) 1982, 1990 The Regents of the University of California.
12  * sun3/include/asm.h:
13  * Copyright (c) 1993 Adam Glass
14  * Copyright (c) 1990 The Regents of the University of California.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  */
40 
41 #ifndef _MACHINE_ASM_H_
42 #define _MACHINE_ASM_H_
43 
44 /* Pull in CC64FSZ and BIAS from frame.h */
45 #ifndef _LOCORE
46 #define _LOCORE
47 #endif
48 #include <machine/frame.h>
49 
50 #define	_C_LABEL(name)		name
51 #define	_ASM_LABEL(name)	name
52 
53 #ifdef __PIC__
54 /*
55  * PIC_PROLOGUE() is akin to the compiler generated function prologue for
56  * PIC code. It leaves the address of the Global Offset Table in DEST,
57  * clobbering register TMP in the process. Using the temporary enables us
58  * to work without a stack frame (doing so requires saving %o7) .
59  */
60 #define PIC_PROLOGUE(dest,tmp) \
61 	sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \
62 	rd %pc, tmp; \
63 	or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \
64 	add dest,tmp,dest
65 #else
66 #define PIC_PROLOGUE(dest,tmp)
67 #endif
68 
69 #define FTYPE(x)		.type x,@function
70 #define OTYPE(x)		.type x,@object
71 
72 #define	_ENTRY_NB(name) \
73 	.align 4; .proc 1; FTYPE(name); name:
74 #define	_ENTRY(name)	.globl name; _ENTRY_NB(name)
75 
76 #if defined(PROF) || defined(GPROF)
77 #define _PROF_PROLOGUE \
78 	.data; .align 8; 1: .uaword 0; .uaword 0; \
79 	.text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \
80 	or %o0,%lo(1b),%o0; restore
81 #else
82 #define _PROF_PROLOGUE
83 #endif
84 
85 #define ENTRY(name)		_ENTRY(name); _PROF_PROLOGUE
86 #define NENTRY(name)		_ENTRY(name)
87 #define ENTRY_NB(name)		_ENTRY_NB(name); _PROF_PROLOGUE
88 #define	ASENTRY(name)		_ENTRY(name); _PROF_PROLOGUE
89 #define	FUNC(name)		ASENTRY(name)
90 #define	END(y)			.size y, . - y
91 
92 #define	STRONG_ALIAS(alias,sym)						\
93 	.global alias;							\
94 	alias = sym
95 #define	WEAK_ALIAS(alias,sym)						\
96 	.weak alias;							\
97 	alias = sym
98 
99 #endif /* _MACHINE_ASM_H_ */
100