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