]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/asm.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@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
60 #else /* !MACH_KERNEL */
62 #endif /* !MACH_KERNEL */
65 #if defined(MACH_KERNEL) || defined(_KERNEL)
67 #endif /* MACH_KERNEL || _KERNEL */
71 #define S_ARG0 4(%esp)
72 #define S_ARG1 8(%esp)
73 #define S_ARG2 12(%esp)
74 #define S_ARG3 16(%esp)
76 #define FRAME pushl %ebp; movl %esp, %ebp
79 #define B_LINK 0(%ebp)
81 #define B_ARG0 8(%ebp)
82 #define B_ARG1 12(%ebp)
83 #define B_ARG2 16(%ebp)
84 #define B_ARG3 20(%ebp)
86 /* There is another definition of ALIGN for .c sources */
89 #endif /* ASSEMBLER */
97 #ifndef __NO_UNDERSCORES__
100 #define LEXT(x) _ ## x ## :
102 #define LCL(x) .L ## x
104 #define LEXT(x) x ## :
106 #define LBc(x,n) n ## :
107 #define LBb(x,n) n ## b
108 #define LBf(x,n) n ## f
110 #ifndef __NO_UNDERSCORES__
111 #define LCL(x) L/**/x
112 #define EXT(x) _/**/x
113 #define LEXT(x) _/**/x/**/:
114 #else /* __NO_UNDERSCORES__ */
115 #define LCL(x) .L/**/x
117 #define LEXT(x) x/**/:
118 #endif /* __NO_UNDERSCORES__ */
119 #define LBc(x,n) n/**/:
120 #define LBb(x,n) n/**/b
121 #define LBf(x,n) n/**/f
122 #endif /* __STDC__ */
124 #define SVC .byte 0x9a; .long 0; .word 0x7
126 #define RPC_SVC .byte 0x9a; .long 0; .word 0xf
128 #define String .asciz
130 #define Times(a,b) (a*b)
131 #define Divide(a,b) (a/b)
133 #define INB inb %dx, %al
134 #define OUTB outb %al, %dx
135 #define INL inl %dx, %eax
136 #define OUTL outl %eax, %dx
138 #define data16 .byte 0x66
139 #define addr16 .byte 0x67
144 #elif defined(__SHARED__)
145 #define MCOUNT ; .data;\
151 leal Gotoff(LBb(x,8)),%edx;\
152 Egaddr(%eax,_mcount_ptr);\
156 #else /* !GPROF, !__SHARED__ */
157 #define MCOUNT ; call mcount;
161 #define ELF_FUNC(x) .type x,@function
162 #define ELF_DATA(x) .type x,@object
163 #define ELF_SIZE(x,s) .size x,s
167 #define ELF_SIZE(x,s)
170 #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x)
171 #define ENTRY(x) Entry(x) MCOUNT
172 #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \
173 ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \
174 .align FALIGN; LEXT(x); LEXT(y) \
177 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
179 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
180 #endif /* __STDC__ */
182 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
184 #define End(x) ELF_SIZE(x,.-x)
185 #define END(x) End(EXT(x))
186 #define ENDDATA(x) END(x)
187 #define Enddata(x) End(x)
190 * ELF shared library accessor macros.
191 * Gpush saves the %ebx register used for the GOT address
192 * Gpop pops %ebx if we need a GOT
193 * Gload loads %ebx with the GOT address if shared libraries are used
194 * Gcall calls an external function.
195 * Gotoff allows you to reference local labels.
196 * Gotoff2 allows you to reference local labels with an index reg.
197 * Gotoff3 allows you to reference local labels with an index reg & size.
198 * Gaddr loads up a register with an address of an external item.
199 * Gstack is the number of bytes that Gpush pushes on the stack.
201 * Varients of the above with E or L prefixes do EXT(name) or LCL(name)
209 #define Gcall(func) call func
210 #define Gotoff(lab) lab
211 #define Gotoff2(l,r) l(r)
212 #define Gotoff3(l,r,s) l(,r,s)
213 #define Gaddr(to,lab) movl $lab,to
214 #define Gcmp(lab,reg) cmpl $lab,reg
215 #define Gmemload(lab,reg) movl lab,reg
216 #define Gmemstore(reg,lab,tmp) movl reg,lab
220 #ifdef __ELF__ /* ELF shared libraries */
221 #define Gpush pushl %ebx
222 #define Gpop popl %ebx
223 #define Gload call 9f; 9: popl %ebx; addl $_GLOBAL_OFFSET_TABLE_+[.-9b],%ebx
224 #define Gcall(func) call EXT(func)@PLT
225 #define Gotoff(lab) lab@GOTOFF(%ebx)
226 #define Gotoff2(l,r) l@GOTOFF(%ebx,r)
227 #define Gotoff3(l,r,s) l@GOTOFF(%ebx,r,s)
228 #define Gaddr(to,lab) movl lab@GOT(%ebx),to
229 #define Gcmp(lab,reg) cmpl reg,lab@GOT(%ebx)
230 #define Gmemload(lab,reg) movl lab@GOT(%ebx),reg; movl (reg),reg
231 #define Gmemstore(reg,lab,tmp) movl lab@GOT(%ebx),tmp; movl reg,(tmp)
234 #else /* ROSE shared libraries */
238 #define Gcall(func) call *9f; .data; .align ALIGN; 9: .long func; .text
239 #define Gotoff(lab) lab
240 #define Gotoff2(l,r) l(r)
241 #define Gotoff3(l,r,s) l(,r,s)
242 #define Gaddr(to,lab) movl 9f,to; .data; .align ALIGN; 9: .long lab; .text
243 #define Gcmp(lab,reg) cmpl reg,9f; .data; .align ALIGN; 9: .long lab; .text
244 #define Gmemload(lab,reg) movl 9f,reg; movl (reg),reg; .data; .align ALIGN; 9: .long lab; .text
245 #define Gmemstore(reg,lab,tmp) movl 9f,tmp; movl reg,(tmp); .data; .align ALIGN; 9: .long lab; .text
248 #endif /* __SHARED__ */
250 /* Egotoff is not provided, since external symbols should not use @GOTOFF
252 #define Egcall(func) Gcall(EXT(func))
253 #define Egaddr(to,lab) Gaddr(to,EXT(lab))
254 #define Egcmp(lab,reg) Gcmp(EXT(lab),reg)
255 #define Egmemload(lab,reg) Gmemload(EXT(lab),reg)
256 #define Egmemstore(reg,lab,tmp) Gmemstore(reg,EXT(lab),tmp)
258 #define Lgotoff(lab) Gotoff(LCL(lab))
259 #define Lgotoff2(l,r) Gotoff2(LCL(l),r)
260 #define Lgotoff3(l,r,s) Gotoff3(LCL(l),r,s)
261 #define Lgcmp(lab,reg) Gcmp(LCL(lab),reg)
262 #define Lgmemload(lab,reg) movl Lgotoff(lab),reg
263 #define Lgmemstore(reg,lab,tmp) movl reg,Lgotoff(lab)
267 #include <ddb/stab.h>
269 * This pseudo-assembler line is added so that there will be at least
270 * one N_SO entry in the symbol stable to define the current file name.
272 #endif /* MACH_KDB */
274 #else /* NOT ASSEMBLER */
276 /* These defines are here for .c files that wish to reference global symbols
277 * within __asm__ statements.
279 #ifndef __NO_UNDERSCORES__
280 #define CC_SYM_PREFIX "_"
282 #define CC_SYM_PREFIX ""
283 #endif /* __NO_UNDERSCORES__ */
284 #endif /* ASSEMBLER */
286 #endif /* _I386_ASM_H_ */