xref: /openbsd/sys/arch/sparc64/include/asm.h (revision db3296cf)
1 /*	$OpenBSD: asm.h,v 1.4 2003/06/12 01:07:30 deraadt 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 _ASM_H_
42 #define _ASM_H_
43 
44 #ifndef _LOCORE
45 #define _LOCORE
46 #endif
47 #include <machine/frame.h>
48 
49 /* Pull in CCFSZ, CC64FSZ, and BIAS from frame.h */
50 #ifndef _LOCORE
51 #define _LOCORE
52 #endif
53 #include <machine/frame.h>
54 
55 #ifdef __ELF__
56 #define	_C_LABEL(name)		name
57 #else
58 #ifdef __STDC__
59 #define _C_LABEL(name)		_ ## name
60 #else
61 #define _C_LABEL(name)		_/**/name
62 #endif
63 #endif
64 #define	_ASM_LABEL(name)	name
65 
66 #ifdef PIC
67 /*
68  * PIC_PROLOGUE() is akin to the compiler generated function prologue for
69  * PIC code. It leaves the address of the Global Offset Table in DEST,
70  * clobbering register TMP in the process. Using the temporary enables us
71  * to work without a stack frame (doing so requires saving %o7) .
72  */
73 #define PIC_PROLOGUE(dest,tmp) \
74 	sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \
75 	rd %pc, tmp; \
76 	or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \
77 	add dest,tmp,dest
78 
79 /*
80  * PICCY_SET() does the equivalent of a `set var, %dest' instruction in
81  * a PIC-like way, but without involving the Global Offset Table. This
82  * only works for VARs defined in the same file *and* in the text segment.
83  */
84 #define PICCY_SET(var,dest,tmp) \
85 	3: rd %pc, tmp; add tmp,(var-3b),dest
86 #else
87 #define PIC_PROLOGUE(dest,tmp)
88 #define PICCY_OFFSET(var,dest,tmp)
89 #endif
90 
91 #define FTYPE(x)		.type x,@function
92 #define OTYPE(x)		.type x,@object
93 
94 #define	_ENTRY(name) \
95 	.align 4; .globl name; .proc 1; FTYPE(name); name:
96 
97 #ifdef GPROF
98 #define _PROF_PROLOGUE \
99 	.data; .align 8; 1: .uaword 0; .uaword 0; \
100 	.text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \
101 	or %o0,%lo(1b),%o0; restore
102 #else
103 #define _PROF_PROLOGUE
104 #endif
105 
106 #define ENTRY(name)		_ENTRY(_C_LABEL(name)); _PROF_PROLOGUE
107 #define	ASENTRY(name)		_ENTRY(_ASM_LABEL(name)); _PROF_PROLOGUE
108 #define	FUNC(name)		ASENTRY(name)
109 #define RODATA(name)		.align 4; .text; .globl _C_LABEL(name); \
110 				OTYPE(_C_LABEL(name)); _C_LABEL(name):
111 
112 
113 #define ASMSTR			.asciz
114 
115 #define RCSID(name)		.asciz name
116 
117 #ifdef __ELF__
118 #define	WEAK_ALIAS(alias,sym)						\
119 	.weak alias;							\
120 	alias = sym
121 #endif
122 
123 /*
124  * WARN_REFERENCES: create a warning if the specified symbol is referenced.
125  */
126 #ifdef __ELF__
127 #ifdef __STDC__
128 #define	WARN_REFERENCES(_sym,_msg)				\
129 	.section .gnu.warning. ## _sym ; .ascii _msg ; .text
130 #else
131 #define	WARN_REFERENCES(_sym,_msg)				\
132 	.section .gnu.warning./**/_sym ; .ascii _msg ; .text
133 #endif /* __STDC__ */
134 #else
135 #ifdef __STDC__
136 #define	__STRING(x)			#x
137 #define	WARN_REFERENCES(sym,msg)					\
138 	.stabs msg ## ,30,0,0,0 ;					\
139 	.stabs __STRING(_ ## sym) ## ,1,0,0,0
140 #else
141 #define	__STRING(x)			"x"
142 #define	WARN_REFERENCES(sym,msg)					\
143 	.stabs msg,30,0,0,0 ;						\
144 	.stabs __STRING(_/**/sym),1,0,0,0
145 #endif /* __STDC__ */
146 #endif /* __ELF__ */
147 
148 #endif /* _ASM_H_ */
149