1 /**	$MirOS: src/sys/arch/sparc/include/asm.h,v 1.9 2014/03/23 20:36:10 tg Exp $ */
2 /*	$OpenBSD: asm.h,v 1.4 2003/06/04 22:08:17 deraadt Exp $	*/
3 /*	$NetBSD: asm.h,v 1.5 1997/07/16 15:16:43 christos Exp $ */
4 
5 /*
6  * Copyright (c) 1994 Allen Briggs
7  * All rights reserved.
8  *
9  * Gleaned from locore.s and sun3 asm.h which had the following copyrights:
10  * locore.s:
11  * Copyright (c) 1988 University of Utah.
12  * Copyright (c) 1982, 1990 The Regents of the University of California.
13  * sun3/include/asm.h:
14  * Copyright (c) 1993 Adam Glass
15  * Copyright (c) 1990 The Regents of the University of California.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  * 3. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  */
41 
42 #ifndef _SPARC_ASM_H_
43 #define _SPARC_ASM_H_
44 
45 #ifdef __ELF__
46 #define _C_LABEL(name)		name
47 #else
48 #ifdef __STDC__
49 #define _C_LABEL(name)		_ ## name
50 #else
51 #define _C_LABEL(name)		_/**/name
52 #endif
53 #endif
54 #define	_ASM_LABEL(name)	name
55 
56 /*
57  * WEAK_ALIAS: create a weak alias (ELF only)
58  */
59 #ifdef __ELF__
60 #define WEAK_ALIAS(alias,sym)		\
61 	.weak alias;			\
62 	alias = sym
63 #endif
64 
65 /*
66  * WARN_REFERENCES: create a warning if the specified symbol is referenced
67  * (ELF only).
68  */
69 #ifdef __ELF__
70 #define WARN_REFERENCES(_sym,_msg)	\
71 	.section .gnu.warning. ## _sym ; .ascii "REF! " _msg ; .previous
72 #endif /* __ELF__ */
73 
74 
75 #ifdef PIC
76 /*
77  * PIC_PROLOGUE() is akin to the compiler generated function prologue for
78  * PIC code. It leaves the address of the Global Offset Table in DEST,
79  * clobbering register TMP in the process. Using the temporary enables us
80  * to work without a stack frame (doing so requires saving %o7) .
81  */
82 #define PIC_PROLOGUE(dest,tmp) \
83 	mov %o7,tmp; 3: call 4f; nop; 4: \
84 	sethi %hi(_C_LABEL(_GLOBAL_OFFSET_TABLE_)-(3b-.)),dest; \
85 	or dest,%lo(_C_LABEL(_GLOBAL_OFFSET_TABLE_)-(3b-.)),dest; \
86 	add dest,%o7,dest; mov tmp,%o7
87 
88 /*
89  * PICCY_SET() does the equivalent of a `set var, %dest' instruction in
90  * a PIC-like way, but without involving the Global Offset Table. This
91  * only works for VARs defined in the same file *and* in the text segment.
92  */
93 #define PICCY_SET(var,dest,tmp) \
94 	mov %o7,tmp; 3: call 4f; nop; 4: \
95 	add %o7,(var-3b),dest; mov tmp,%o7
96 #else
97 #define PIC_PROLOGUE(dest,tmp)
98 #define PICCY_OFFSET(var,dest,tmp)
99 #endif
100 
101 /* let kernels and others override entrypoint alignment */
102 #ifndef _ALIGN_TEXT
103 #define _ALIGN_TEXT		.p2align 2
104 #endif
105 
106 #define FTYPE(x)		.type x,@function
107 #define OTYPE(x)		.type x,@object
108 
109 #define	_ENTRY(name) \
110 	.text; _ALIGN_TEXT; .globl name; .proc 1; FTYPE(name); name:
111 
112 /* no profiling */
113 #define _PROF_PROLOGUE
114 
115 #define ENTRY(name)		_ENTRY(_C_LABEL(name)); _PROF_PROLOGUE
116 #define NENTRY(name)		_ENTRY(_C_LABEL(name))
117 #define	ASENTRY(name)		_ENTRY(_ASM_LABEL(name)); _PROF_PROLOGUE
118 #define	FUNC(name)		ASENTRY(name)
119 
120 #define ALTENTRY(name) \
121 	.globl _C_LABEL(name); FTYPE(_C_LABEL(name)); _C_LABEL(name):
122 #define DENTRY(name) \
123 	.globl _C_LABEL(name); OTYPE(_C_LABEL(name)); _C_LABEL(name):
124 
125 #define ASMSTR			.asciz
126 
127 #define RCSID(x)		.section .comment; \
128 				.ascii "@(""#)rcsid: "; \
129 				.asciz x; \
130 				.previous
131 
132 #endif /* _SPARC_ASM_H_ */
133