]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/i386/asm_help.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
24 * File: architecture/i386/asm_help.h
25 * Author: Mike DeMoney, NeXT Computer, Inc.
26 * Modified for i386 by: Bruce Martin, NeXT Computer, Inc.
28 * This header file defines macros useful when writing assembly code
29 * for the Intel i386 family processors.
32 * 10-Mar-92 Bruce Martin (bmartin@next.com)
34 * 23-Jan-91 Mike DeMoney (mike@next.com)
38 #ifndef _ARCH_I386_ASM_HELP_H_
39 #define _ARCH_I386_ASM_HELP_H_
41 #include <architecture/i386/reg_help.h>
49 #define ROUND_TO_STACK(len) \
50 (((len) + STACK_INCR - 1) / STACK_INCR * STACK_INCR)
67 * Prologue for functions that may call other functions. Saves
68 * registers and sets up a C frame.
70 #define NESTED_FUNCTION_PROLOGUE(localvarsize) \
71 .set __framesize,ROUND_TO_STACK(localvarsize) ;\
72 .set __nested_function, 1 ;\
77 subl $__framesize, %esp ;\
84 * Prologue for functions that do not call other functions. Does not
85 * save registers (this is the functions responsibility). Does set
88 #define LEAF_FUNCTION_PROLOGUE(localvarsize) \
89 .set __framesize,ROUND_TO_STACK(localvarsize) ;\
90 .set __nested_function, 0 ;\
95 subl $__framesize, %esp ;\
99 * Prologue for any function.
101 * We assume that all Leaf functions will be responsible for saving any
102 * local registers they clobber.
104 #define FUNCTION_EPILOGUE \
105 .if __nested_function ;\
118 * Macros for declaring procedures
120 * Use of these macros allows ctags to have a predictable way
121 * to find various types of declarations. They also simplify
122 * inserting appropriate symbol table information.
124 * NOTE: these simple stubs will be replaced with more
125 * complicated versions once we know what the linker and gdb
126 * will require as far as register use masks and frame declarations.
127 * These macros may also be ifdef'ed in the future to contain profiling
133 * TEXT -- declare start of text segment
139 * DATA -- declare start of data segment
145 * LEAF -- declare global leaf procedure
146 * NOTE: Control SHOULD NOT FLOW into a LEAF! A LEAF should only
147 * be jumped to. (A leaf may do an align.) Use a LABEL() if you
148 * need control to flow into the label.
150 #define LEAF(name, localvarsize) \
154 LEAF_FUNCTION_PROLOGUE(localvarsize)
157 * X_LEAF -- declare alternate global label for leaf
159 #define X_LEAF(name, value) \
164 * P_LEAF -- declare private leaf procedure
166 #define P_LEAF(name, localvarsize) \
169 LEAF_FUNCTION_PROLOGUE(localvarsize)
172 * LABEL -- declare a global code label
173 * MUST be used (rather than LEAF, NESTED, etc) if control
174 * "flows into" the label.
176 #define LABEL(name) \
181 * NESTED -- declare procedure that invokes other procedures
183 #define NESTED(name, localvarsize) \
187 NESTED_FUNCTION_PROLOGUE(localvarsize)
190 * X_NESTED -- declare alternate global label for nested proc
192 #define X_NESTED(name, value) \
197 * P_NESTED -- declare private nested procedure
199 #define P_NESTED(name, localvarsize) \
202 NESTED_FUNCTION_PROLOGUE(localvarsize)
205 * END -- mark end of procedure
212 * Storage definition macros
213 * The main purpose of these is to allow an easy handle for ctags
217 * IMPORT -- import symbol
219 #define IMPORT(name) \
223 * ABS -- declare global absolute symbol
225 #define ABS(name, value) \
230 * P_ABS -- declare private absolute symbol
232 #define P_ABS(name, value) \
236 * EXPORT -- declare global label for data
238 #define EXPORT(name) \
243 * BSS -- declare global zero'ed storage
245 #define BSS(name,size) \
250 * P_BSS -- declare private zero'ed storage
252 #define P_BSS(name,size) \
256 * dynamic/PIC macros for routines which reference external symbols
259 #if defined(__DYNAMIC__)
260 #define PICIFY(var) \
264 movl L ## var ## $non_lazy_ptr-1b(%edx),%edx
266 #define CALL_EXTERN_AGAIN(func) \
270 #define NON_LAZY_STUB(var) \
271 .non_lazy_symbol_pointer ; \
272 L ## var ## $non_lazy_ptr: ; \
273 .indirect_symbol var ; \
277 #define CALL_EXTERN(func) \
278 CALL_EXTERN_AGAIN(func) ; \
281 #define BRANCH_EXTERN(func) \
286 #define PUSH_EXTERN(var) \
292 #define REG_TO_EXTERN(reg, var) \
297 #define EXTERN_TO_REG(var, reg) \
301 movl L ## var ##$non_lazy_ptr-1b(%edx),reg ; \
306 #define BRANCH_EXTERN(func) jmp func
307 #define PUSH_EXTERN(var) pushl var
308 #define CALL_EXTERN(func) call func
309 #define CALL_EXTERN_AGAIN(func) call func
310 #define REG_TO_EXTERN(reg, var) movl reg, var
311 #define EXTERN_TO_REG(var, reg) movl $ ## var, reg
314 #endif /* __ASSEMBLER__ */
316 #endif /* _ARCH_I386_ASM_HELP_H_ */