xref: /netbsd-src/sys/arch/mips/include/asm.h (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: asm.h,v 1.13 1997/07/20 09:47:03 jonathan Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Ralph Campbell.
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. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)machAsmDefs.h	8.1 (Berkeley) 6/10/93
39  */
40 
41 /*
42  * machAsmDefs.h --
43  *
44  *	Macros used when writing assembler programs.
45  *
46  *	Copyright (C) 1989 Digital Equipment Corporation.
47  *	Permission to use, copy, modify, and distribute this software and
48  *	its documentation for any purpose and without fee is hereby granted,
49  *	provided that the above copyright notice appears in all copies.
50  *	Digital Equipment Corporation makes no representations about the
51  *	suitability of this software for any purpose.  It is provided "as is"
52  *	without express or implied warranty.
53  *
54  * from: Header: /sprite/src/kernel/mach/ds3100.md/RCS/machAsmDefs.h,
55  *	v 1.2 89/08/15 18:28:24 rab Exp  SPRITE (DECWRL)
56  */
57 
58 #ifndef _MIPS_ASM_H
59 #define _MIPS_ASM_H
60 
61 #include <machine/regdef.h>
62 
63 /*
64  * Define -pg profile entry code.
65  * XXX assume .set noreorder for kernel, .set reorder for user code.
66  */
67 #define _KERN_MCOUNT \
68 	.set noat; \
69 	move $1,$31; \
70 	jal _mcount; \
71 	subu sp,sp,8; \
72 	.set at;
73 
74 
75 #ifdef GPROF
76 # if defined(_KERNEL) || defined(_LOCORE)
77 #  define MCOUNT _KERN_MCOUNT
78 # else
79 #  define MCOUNT .set noreorder; _KERN_MCOUNT ;  .set reorder;
80 # endif
81 #else
82 #define	MCOUNT
83 #endif
84 
85 #ifdef __NO_LEADING_UNDERSCORES__
86 # define _C_LABEL(x)	x
87 #else
88 # ifdef __STDC__
89 #  define _C_LABEL(x)	_ ## x
90 # else
91 #  define _C_LABEL(x)	_/**/x
92 # endif
93 #endif
94 
95 /*
96  * LEAF(x)
97  *
98  *	Declare a leaf routine.
99  */
100 #define LEAF(x) \
101 	.globl _C_LABEL(x); \
102 	.ent _C_LABEL(x), 0; \
103 _C_LABEL(x): ; \
104 	.frame sp, 0, ra; \
105 	MCOUNT
106 
107 /*
108  * NLEAF(x)
109  *
110  *	Declare a non-profiled leaf routine.
111  */
112 #define NLEAF(x) \
113 	.globl _C_LABEL(x); \
114 	.ent _C_LABEL(x), 0; \
115 _C_LABEL(x): ; \
116 	.frame sp, 0, ra
117 
118 /*
119  * ALEAF -- declare alternate entry to a leaf routine.
120  */
121 #ifdef USE_AENT
122 #define AENT(x) \
123 	.aent	x, 0
124 #else
125 #define AENT(x)
126 #endif
127 #define	ALEAF(x)					\
128 	.globl	_C_LABEL(x);				\
129 	AENT (_C_LABEL(x))				\
130 _C_LABEL(x):
131 
132 /*
133  * NON_LEAF(x)
134  *
135  *	Declare a non-leaf routine (a routine that makes other C calls).
136  */
137 #define NON_LEAF(x, fsize, retpc) \
138 	.globl _C_LABEL(x); \
139 	.ent _C_LABEL(x), 0; \
140 _C_LABEL(x): ; \
141 	.frame sp, fsize, retpc; \
142 	MCOUNT
143 
144 /*
145  * NNON_LEAF(x)
146  *
147  *	Declare a non-profiled non-leaf routine
148  *	(a routine that makes other C calls).
149  */
150 #define NNON_LEAF(x, fsize, retpc) \
151 	.globl _C_LABEL(x); \
152 	.ent _C_LABEL(x), 0; \
153 _C_LABEL(x): ; \
154 	.frame sp, fsize, retpc
155 
156 /*
157  * END(x)
158  *
159  *	Mark end of a procedure.
160  */
161 #define END(x) \
162 	.end _C_LABEL(x)
163 
164 #define STAND_FRAME_SIZE	24
165 #define STAND_RA_OFFSET		20
166 
167 /*
168  * Macros to panic and printf from assembly language.
169  */
170 #define PANIC(msg) \
171 	la	a0, 9f; \
172 	jal	_C_LABEL(panic); \
173 	MSG(msg)
174 
175 #define	PRINTF(msg) \
176 	la	a0, 9f; \
177 	jal	_C_LABEL(printf); \
178 	MSG(msg)
179 
180 #define	MSG(msg) \
181 	.rdata; \
182 9:	.asciiz	msg; \
183 	.text
184 
185 #define ASMSTR(str) \
186 	.asciiz str; \
187 	.align	3
188 
189 #endif /* _MIPS_ASM_H */
190