]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/asm.h
c4530a244ab7aefa3cd91f5987f5da2511d32d4c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
68 #else /* !MACH_KERNEL */
70 #endif /* !MACH_KERNEL */
73 #if defined(MACH_KERNEL) || defined(_KERNEL)
75 #endif /* MACH_KERNEL || _KERNEL */
79 #define S_ARG0 4(%esp)
80 #define S_ARG1 8(%esp)
81 #define S_ARG2 12(%esp)
82 #define S_ARG3 16(%esp)
84 #define FRAME pushl %ebp; movl %esp, %ebp
87 #define B_LINK 0(%ebp)
89 #define B_ARG0 8(%ebp)
90 #define B_ARG1 12(%ebp)
91 #define B_ARG2 16(%ebp)
92 #define B_ARG3 20(%ebp)
94 /* There is another definition of ALIGN for .c sources */
97 #endif /* ASSEMBLER */
105 #ifndef __NO_UNDERSCORES__
106 #define LCL(x) L ## x
107 #define EXT(x) _ ## x
108 #define LEXT(x) _ ## x ## :
110 #define LCL(x) .L ## x
112 #define LEXT(x) x ## :
114 #define LBc(x,n) n ## :
115 #define LBb(x,n) n ## b
116 #define LBf(x,n) n ## f
118 #ifndef __NO_UNDERSCORES__
119 #define LCL(x) L/**/x
120 #define EXT(x) _/**/x
121 #define LEXT(x) _/**/x/**/:
122 #else /* __NO_UNDERSCORES__ */
123 #define LCL(x) .L/**/x
125 #define LEXT(x) x/**/:
126 #endif /* __NO_UNDERSCORES__ */
127 #define LBc(x,n) n/**/:
128 #define LBb(x,n) n/**/b
129 #define LBf(x,n) n/**/f
130 #endif /* __STDC__ */
132 #define SVC .byte 0x9a; .long 0; .word 0x7
134 #define RPC_SVC .byte 0x9a; .long 0; .word 0xf
136 #define String .asciz
138 #define Times(a,b) (a*b)
139 #define Divide(a,b) (a/b)
141 #define INB inb %dx, %al
142 #define OUTB outb %al, %dx
143 #define INL inl %dx, %eax
144 #define OUTL outl %eax, %dx
146 #define data16 .byte 0x66
147 #define addr16 .byte 0x67
152 #elif defined(__SHARED__)
153 #define MCOUNT ; .data;\
159 leal Gotoff(LBb(x,8)),%edx;\
160 Egaddr(%eax,_mcount_ptr);\
164 #else /* !GPROF, !__SHARED__ */
165 #define MCOUNT ; call mcount;
169 #define ELF_FUNC(x) .type x,@function
170 #define ELF_DATA(x) .type x,@object
171 #define ELF_SIZE(x,s) .size x,s
175 #define ELF_SIZE(x,s)
178 #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x)
179 #define ENTRY(x) Entry(x) MCOUNT
180 #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \
181 ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \
182 .align FALIGN; LEXT(x); LEXT(y) \
185 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
187 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
188 #endif /* __STDC__ */
190 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
192 #define End(x) ELF_SIZE(x,.-x)
193 #define END(x) End(EXT(x))
194 #define ENDDATA(x) END(x)
195 #define Enddata(x) End(x)
198 * ELF shared library accessor macros.
199 * Gpush saves the %ebx register used for the GOT address
200 * Gpop pops %ebx if we need a GOT
201 * Gload loads %ebx with the GOT address if shared libraries are used
202 * Gcall calls an external function.
203 * Gotoff allows you to reference local labels.
204 * Gotoff2 allows you to reference local labels with an index reg.
205 * Gotoff3 allows you to reference local labels with an index reg & size.
206 * Gaddr loads up a register with an address of an external item.
207 * Gstack is the number of bytes that Gpush pushes on the stack.
209 * Varients of the above with E or L prefixes do EXT(name) or LCL(name)
217 #define Gcall(func) call func
218 #define Gotoff(lab) lab
219 #define Gotoff2(l,r) l(r)
220 #define Gotoff3(l,r,s) l(,r,s)
221 #define Gaddr(to,lab) movl $lab,to
222 #define Gcmp(lab,reg) cmpl $lab,reg
223 #define Gmemload(lab,reg) movl lab,reg
224 #define Gmemstore(reg,lab,tmp) movl reg,lab
228 #ifdef __ELF__ /* ELF shared libraries */
229 #define Gpush pushl %ebx
230 #define Gpop popl %ebx
231 #define Gload call 9f; 9: popl %ebx; addl $_GLOBAL_OFFSET_TABLE_+[.-9b],%ebx
232 #define Gcall(func) call EXT(func)@PLT
233 #define Gotoff(lab) lab@GOTOFF(%ebx)
234 #define Gotoff2(l,r) l@GOTOFF(%ebx,r)
235 #define Gotoff3(l,r,s) l@GOTOFF(%ebx,r,s)
236 #define Gaddr(to,lab) movl lab@GOT(%ebx),to
237 #define Gcmp(lab,reg) cmpl reg,lab@GOT(%ebx)
238 #define Gmemload(lab,reg) movl lab@GOT(%ebx),reg; movl (reg),reg
239 #define Gmemstore(reg,lab,tmp) movl lab@GOT(%ebx),tmp; movl reg,(tmp)
242 #else /* ROSE shared libraries */
246 #define Gcall(func) call *9f; .data; .align ALIGN; 9: .long func; .text
247 #define Gotoff(lab) lab
248 #define Gotoff2(l,r) l(r)
249 #define Gotoff3(l,r,s) l(,r,s)
250 #define Gaddr(to,lab) movl 9f,to; .data; .align ALIGN; 9: .long lab; .text
251 #define Gcmp(lab,reg) cmpl reg,9f; .data; .align ALIGN; 9: .long lab; .text
252 #define Gmemload(lab,reg) movl 9f,reg; movl (reg),reg; .data; .align ALIGN; 9: .long lab; .text
253 #define Gmemstore(reg,lab,tmp) movl 9f,tmp; movl reg,(tmp); .data; .align ALIGN; 9: .long lab; .text
256 #endif /* __SHARED__ */
258 /* Egotoff is not provided, since external symbols should not use @GOTOFF
260 #define Egcall(func) Gcall(EXT(func))
261 #define Egaddr(to,lab) Gaddr(to,EXT(lab))
262 #define Egcmp(lab,reg) Gcmp(EXT(lab),reg)
263 #define Egmemload(lab,reg) Gmemload(EXT(lab),reg)
264 #define Egmemstore(reg,lab,tmp) Gmemstore(reg,EXT(lab),tmp)
266 #define Lgotoff(lab) Gotoff(LCL(lab))
267 #define Lgotoff2(l,r) Gotoff2(LCL(l),r)
268 #define Lgotoff3(l,r,s) Gotoff3(LCL(l),r,s)
269 #define Lgcmp(lab,reg) Gcmp(LCL(lab),reg)
270 #define Lgmemload(lab,reg) movl Lgotoff(lab),reg
271 #define Lgmemstore(reg,lab,tmp) movl reg,Lgotoff(lab)
275 #include <ddb/stab.h>
277 * This pseudo-assembler line is added so that there will be at least
278 * one N_SO entry in the symbol stable to define the current file name.
280 #endif /* MACH_KDB */
282 #else /* NOT ASSEMBLER */
284 /* These defines are here for .c files that wish to reference global symbols
285 * within __asm__ statements.
287 #ifndef __NO_UNDERSCORES__
288 #define CC_SYM_PREFIX "_"
290 #define CC_SYM_PREFIX ""
291 #endif /* __NO_UNDERSCORES__ */
292 #endif /* ASSEMBLER */
294 #endif /* _I386_ASM_H_ */