]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/i386/asm_help.h
45f820b8ca922f255ddcaa6c350420e1528ba0b8
[apple/xnu.git] / EXTERNAL_HEADERS / architecture / i386 / asm_help.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
24 *
25 * File: architecture/i386/asm_help.h
26 * Author: Mike DeMoney, NeXT Computer, Inc.
27 * Modified for i386 by: Bruce Martin, NeXT Computer, Inc.
28 *
29 * This header file defines macros useful when writing assembly code
30 * for the Intel i386 family processors.
31 *
32 * HISTORY
33 * 10-Mar-92 Bruce Martin (bmartin@next.com)
34 * Adapted to i386
35 * 23-Jan-91 Mike DeMoney (mike@next.com)
36 * Created.
37 */
38
39 #ifndef _ARCH_I386_ASM_HELP_H_
40 #define _ARCH_I386_ASM_HELP_H_
41
42 #include <architecture/i386/reg_help.h>
43
44
45 #ifdef __ASSEMBLER__
46
47 #define ALIGN \
48 .align 2, 0x90
49
50 #define ROUND_TO_STACK(len) \
51 (((len) + STACK_INCR - 1) / STACK_INCR * STACK_INCR)
52
53 #ifdef notdef
54 #define CALL_MCOUNT \
55 pushl %ebp ;\
56 movl %esp, %ebp ;\
57 .data ;\
58 1: .long 0 ;\
59 .text ;\
60 lea 9b,%edx ;\
61 call mcount ;\
62 popl %ebp ;
63 #else
64 #define CALL_MCOUNT
65 #endif
66
67 /*
68 * Prologue for functions that may call other functions. Saves
69 * registers and sets up a C frame.
70 */
71 #define NESTED_FUNCTION_PROLOGUE(localvarsize) \
72 .set __framesize,ROUND_TO_STACK(localvarsize) ;\
73 .set __nested_function, 1 ;\
74 CALL_MCOUNT \
75 .if __framesize ;\
76 pushl %ebp ;\
77 movl %esp, %ebp ;\
78 subl $__framesize, %esp ;\
79 .endif ;\
80 pushl %edi ;\
81 pushl %esi ;\
82 pushl %ebx
83
84 /*
85 * Prologue for functions that do not call other functions. Does not
86 * save registers (this is the functions responsibility). Does set
87 * up a C frame.
88 */
89 #define LEAF_FUNCTION_PROLOGUE(localvarsize) \
90 .set __framesize,ROUND_TO_STACK(localvarsize) ;\
91 .set __nested_function, 0 ;\
92 CALL_MCOUNT \
93 .if __framesize ;\
94 pushl %ebp ;\
95 movl %esp, %ebp ;\
96 subl $__framesize, %esp ;\
97 .endif
98
99 /*
100 * Prologue for any function.
101 *
102 * We assume that all Leaf functions will be responsible for saving any
103 * local registers they clobber.
104 */
105 #define FUNCTION_EPILOGUE \
106 .if __nested_function ;\
107 popl %ebx ;\
108 popl %esi ;\
109 popl %edi ;\
110 .endif ;\
111 .if __framesize ;\
112 movl %ebp, %esp ;\
113 popl %ebp ;\
114 .endif ;\
115 ret
116
117
118 /*
119 * Macros for declaring procedures
120 *
121 * Use of these macros allows ctags to have a predictable way
122 * to find various types of declarations. They also simplify
123 * inserting appropriate symbol table information.
124 *
125 * NOTE: these simple stubs will be replaced with more
126 * complicated versions once we know what the linker and gdb
127 * will require as far as register use masks and frame declarations.
128 * These macros may also be ifdef'ed in the future to contain profiling
129 * code.
130 *
131 */
132
133 /*
134 * TEXT -- declare start of text segment
135 */
136 #define TEXT \
137 .text
138
139 /*
140 * DATA -- declare start of data segment
141 */
142 #define DATA \
143 .data
144
145 /*
146 * LEAF -- declare global leaf procedure
147 * NOTE: Control SHOULD NOT FLOW into a LEAF! A LEAF should only
148 * be jumped to. (A leaf may do an align.) Use a LABEL() if you
149 * need control to flow into the label.
150 */
151 #define LEAF(name, localvarsize) \
152 .globl name ;\
153 ALIGN ;\
154 name: ;\
155 LEAF_FUNCTION_PROLOGUE(localvarsize)
156
157 /*
158 * X_LEAF -- declare alternate global label for leaf
159 */
160 #define X_LEAF(name, value) \
161 .globl name ;\
162 .set name,value
163
164 /*
165 * P_LEAF -- declare private leaf procedure
166 */
167 #define P_LEAF(name, localvarsize) \
168 ALIGN ;\
169 name: ;\
170 LEAF_FUNCTION_PROLOGUE(localvarsize)
171
172 /*
173 * LABEL -- declare a global code label
174 * MUST be used (rather than LEAF, NESTED, etc) if control
175 * "flows into" the label.
176 */
177 #define LABEL(name) \
178 .globl name ;\
179 name:
180
181 /*
182 * NESTED -- declare procedure that invokes other procedures
183 */
184 #define NESTED(name, localvarsize) \
185 .globl name ;\
186 ALIGN ;\
187 name: ;\
188 NESTED_FUNCTION_PROLOGUE(localvarsize)
189
190 /*
191 * X_NESTED -- declare alternate global label for nested proc
192 */
193 #define X_NESTED(name, value) \
194 .globl name ;\
195 .set name,value
196
197 /*
198 * P_NESTED -- declare private nested procedure
199 */
200 #define P_NESTED(name, localvarsize) \
201 ALIGN ;\
202 name: ;\
203 NESTED_FUNCTION_PROLOGUE(localvarsize)
204
205 /*
206 * END -- mark end of procedure
207 */
208 #define END(name) \
209 FUNCTION_EPILOGUE
210
211
212 /*
213 * Storage definition macros
214 * The main purpose of these is to allow an easy handle for ctags
215 */
216
217 /*
218 * IMPORT -- import symbol
219 */
220 #define IMPORT(name) \
221 .reference name
222
223 /*
224 * ABS -- declare global absolute symbol
225 */
226 #define ABS(name, value) \
227 .globl name ;\
228 .set name,value
229
230 /*
231 * P_ABS -- declare private absolute symbol
232 */
233 #define P_ABS(name, value) \
234 .set name,value
235
236 /*
237 * EXPORT -- declare global label for data
238 */
239 #define EXPORT(name) \
240 .globl name ;\
241 name:
242
243 /*
244 * BSS -- declare global zero'ed storage
245 */
246 #define BSS(name,size) \
247 .comm name,size
248
249
250 /*
251 * P_BSS -- declare private zero'ed storage
252 */
253 #define P_BSS(name,size) \
254 .lcomm name,size
255
256 /*
257 * dynamic/PIC macros for routines which reference external symbols
258 */
259
260 #if defined(__DYNAMIC__)
261 #define PICIFY(var) \
262 call 1f ; \
263 1: ; \
264 popl %edx ; \
265 movl L ## var ## $non_lazy_ptr-1b(%edx),%edx
266
267 #define CALL_EXTERN_AGAIN(func) \
268 PICIFY(func) ; \
269 call %edx
270
271 #define NON_LAZY_STUB(var) \
272 .non_lazy_symbol_pointer ; \
273 L ## var ## $non_lazy_ptr: ; \
274 .indirect_symbol var ; \
275 .long 0 ; \
276 .text
277
278 #define CALL_EXTERN(func) \
279 CALL_EXTERN_AGAIN(func) ; \
280 NON_LAZY_STUB(func)
281
282 #define BRANCH_EXTERN(func) \
283 PICIFY(func) ; \
284 jmp %edx ; \
285 NON_LAZY_STUB(func)
286
287 #define PUSH_EXTERN(var) \
288 PICIFY(var) ; \
289 movl (%edx),%edx ; \
290 pushl %edx ; \
291 NON_LAZY_STUB(var)
292
293 #define REG_TO_EXTERN(reg, var) \
294 PICIFY(var) ; \
295 movl reg, (%edx) ; \
296 NON_LAZY_STUB(var)
297
298 #define EXTERN_TO_REG(var, reg) \
299 call 1f ; \
300 1: ; \
301 popl %edx ; \
302 movl L ## var ##$non_lazy_ptr-1b(%edx),reg ; \
303 NON_LAZY_STUB(var)
304
305
306 #else
307 #define BRANCH_EXTERN(func) jmp func
308 #define PUSH_EXTERN(var) pushl var
309 #define CALL_EXTERN(func) call func
310 #define CALL_EXTERN_AGAIN(func) call func
311 #define REG_TO_EXTERN(reg, var) movl reg, var
312 #define EXTERN_TO_REG(var, reg) movl $ ## var, reg
313 #endif
314
315 #endif /* __ASSEMBLER__ */
316
317 #endif /* _ARCH_I386_ASM_HELP_H_ */