asm.h revision 1.6 1 /* $NetBSD: asm.h,v 1.6 2013/01/15 13:30:12 kiyohara Exp $ */
2
3 /* -
4 * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
5 * All Rights Reserved.
6 *
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
12 *
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 *
17 * Carnegie Mellon requests users of this software to return to
18 *
19 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
23 *
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
26 */
27
28 /*
29 * Assembly coding style
30 *
31 * This file contains macros and register defines to
32 * aid in writing more readable assembly code.
33 * Some rules to make assembly code understandable by
34 * a debugger are also noted.
35 */
36
37 #define _C_LABEL(x) x
38
39 /*
40 * Macro to make a local label name.
41 */
42 #define LLABEL(name,num) L ## name ## num
43
44 /*
45 * MCOUNT
46 */
47 #if defined(GPROF)
48 #define MCOUNT \
49 alloc out0 = ar.pfs, 8, 0, 4, 0; \
50 mov out1 = r1; \
51 mov out2 = b0;; \
52 mov out3 = r0; \
53 br.call.sptk b0 = _mcount;;
54 #else
55 #define MCOUNT /* nothing */
56 #endif
57
58 /*
59 * ENTRY
60 * Declare a global leaf function.
61 * A leaf function does not call other functions.
62 */
63 #define ENTRY(_name_, _n_args_) \
64 .global _name_; \
65 .align 16; \
66 .proc _name_; \
67 _name_:; \
68 .regstk _n_args_, 0, 0, 0; \
69 MCOUNT
70
71 #define ENTRY_NOPROFILE(_name_, _n_args_) \
72 .global _name_; \
73 .align 16; \
74 .proc _name_; \
75 _name_:; \
76 .regstk _n_args_, 0, 0, 0
77
78 /*
79 * STATIC_ENTRY
80 * Declare a local leaf function.
81 */
82 #define STATIC_ENTRY(_name_, _n_args_) \
83 .align 16; \
84 .proc _name_; \
85 _name_:; \
86 .regstk _n_args_, 0, 0, 0 \
87 MCOUNT
88 /*
89 * XENTRY
90 * Global alias for a leaf function, or alternate entry point
91 */
92 #define XENTRY(_name_) \
93 .globl _name_; \
94 _name_:
95
96 /*
97 * STATIC_XENTRY
98 * Local alias for a leaf function, or alternate entry point
99 */
100 #define STATIC_XENTRY(_name_) \
101 _name_:
102
103
104 /*
105 * END
106 * Function delimiter
107 */
108 #define END(_name_) \
109 .endp _name_
110
111
112 /*
113 * EXPORT
114 * Export a symbol
115 */
116 #define EXPORT(_name_) \
117 .global _name_; \
118 _name_:
119
120
121 /*
122 * IMPORT
123 * Make an external name visible, typecheck the size
124 */
125 #define IMPORT(_name_, _size_) \
126 /* .extern _name_,_size_ */
127
128
129 /*
130 * ABS
131 * Define an absolute symbol
132 */
133 #define ABS(_name_, _value_) \
134 .globl _name_; \
135 _name_ = _value_
136
137
138 /*
139 * BSS
140 * Allocate un-initialized space for a global symbol
141 */
142 #define BSS(_name_,_numbytes_) \
143 .comm _name_,_numbytes_
144
145
146 /*
147 * MSG
148 * Allocate space for a message (a read-only ascii string)
149 */
150 #define ASCIZ .asciz
151 #define MSG(msg,reg,label) \
152 addl reg,@ltoff(label),gp;; \
153 ld8 reg=[reg];; \
154 .data; \
155 label: ASCIZ msg; \
156 .text;
157
158
159 /*
160 * System call glue.
161 */
162 #define SYSCALLNUM(name) ___CONCAT(SYS_,name)
163
164 #define CALLSYS_NOERROR(name) \
165 { .mmi ; \
166 alloc r9 = ar.pfs, 0, 0, 8, 0 ; \
167 mov r31 = ar.k5 ; \
168 mov r10 = b0 ;; } \
169 { .mib ; \
170 mov r8 = SYSCALLNUM(name) ; \
171 mov b7 = r31 ; \
172 br.call.sptk b0 = b7 ;; }
173
174
175 /*
176 * WEAK_ALIAS: create a weak alias (ELF only).
177 */
178 #define WEAK_ALIAS(alias,sym) \
179 .weak alias; \
180 alias = sym
181
182 /*
183 * STRONG_ALIAS: create a strong alias.
184 */
185 #define STRONG_ALIAS(alias,sym) \
186 .globl alias; \
187 alias = sym
188
189 /*
190 * WARN_REFERENCES: create a warning if the specified symbol is referenced.
191 */
192 #ifdef __STDC__
193 #define WARN_REFERENCES(sym,msg) \
194 .pushsection .gnu.warning. ## sym; \
195 .ascii msg; \
196 .popsection
197 #else
198 #define WARN_REFERENCES(sym,msg) \
199 .pushsection .gnu.warning./**/sym; \
200 .ascii msg; \
201 .popsection
202 #endif /* __STDC__ */
203
204
205 /*
206 * Kernel RCS ID tag and copyright macros
207 */
208
209 #ifdef _KERNEL
210
211 #define __KERNEL_SECTIONSTRING(_sec, _str) \
212 .pushsection _sec ; .asciz _str ; .popsection
213
214 #define __KERNEL_RCSID(_n, _s) __KERNEL_SECTIONSTRING(.ident, _s)
215 #define __KERNEL_COPYRIGHT(_n, _s) __KERNEL_SECTIONSTRING(.copyright, _s)
216
217 #ifdef NO_KERNEL_RCSIDS
218 #undef __KERNEL_RCSID
219 #define __KERNEL_RCSID(_n, _s) /* nothing */
220 #endif
221
222 #endif /* _KERNEL */
223