]>
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 */
70 #define S_ARG0 4(%esp)
71 #define S_ARG1 8(%esp)
72 #define S_ARG2 12(%esp)
73 #define S_ARG3 16(%esp)
75 #define FRAME pushl %ebp; movl %esp, %ebp
78 #define B_ARG0 8(%ebp)
79 #define B_ARG1 12(%ebp)
80 #define B_ARG2 16(%ebp)
81 #define B_ARG3 20(%ebp)
83 /* There is another definition of ALIGN for .c sources */
86 #endif /* ASSEMBLER */
94 #ifndef __NO_UNDERSCORES__
97 #define LEXT(x) _ ## x ## :
99 #define LCL(x) .L ## x
101 #define LEXT(x) x ## :
103 #define LBc(x,n) n ## :
104 #define LBb(x,n) n ## b
105 #define LBf(x,n) n ## f
107 #ifndef __NO_UNDERSCORES__
108 #define LCL(x) L/**/x
109 #define EXT(x) _/**/x
110 #define LEXT(x) _/**/x/**/:
111 #else /* __NO_UNDERSCORES__ */
112 #define LCL(x) .L/**/x
114 #define LEXT(x) x/**/:
115 #endif /* __NO_UNDERSCORES__ */
116 #define LBc(x,n) n/**/:
117 #define LBb(x,n) n/**/b
118 #define LBf(x,n) n/**/f
119 #endif /* __STDC__ */
121 #define SVC .byte 0x9a; .long 0; .word 0x7
123 #define RPC_SVC .byte 0x9a; .long 0; .word 0xf
125 #define String .asciz
127 #define Times(a,b) (a*b)
128 #define Divide(a,b) (a/b)
130 #define INB inb %dx, %al
131 #define OUTB outb %al, %dx
132 #define INL inl %dx, %eax
133 #define OUTL outl %eax, %dx
135 #define data16 .byte 0x66
136 #define addr16 .byte 0x67
141 #elif defined(__SHARED__)
142 #define MCOUNT ; .data;\
148 leal Gotoff(LBb(x,8)),%edx;\
149 Egaddr(%eax,_mcount_ptr);\
153 #else /* !GPROF, !__SHARED__ */
154 #define MCOUNT ; .data;\
158 movl $LBb(x,8),%edx;\
159 call *EXT(_mcount_ptr);
164 #define ELF_FUNC(x) .type x,@function
165 #define ELF_DATA(x) .type x,@object
166 #define ELF_SIZE(x,s) .size x,s
170 #define ELF_SIZE(x,s)
173 #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x)
174 #define ENTRY(x) Entry(x) MCOUNT
175 #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \
176 ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \
177 .align FALIGN; LEXT(x); LEXT(y) \
180 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
182 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
183 #endif /* __STDC__ */
185 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
187 #define End(x) ELF_SIZE(x,.-x)
188 #define END(x) End(EXT(x))
189 #define ENDDATA(x) END(x)
190 #define Enddata(x) End(x)
193 * ELF shared library accessor macros.
194 * Gpush saves the %ebx register used for the GOT address
195 * Gpop pops %ebx if we need a GOT
196 * Gload loads %ebx with the GOT address if shared libraries are used
197 * Gcall calls an external function.
198 * Gotoff allows you to reference local labels.
199 * Gotoff2 allows you to reference local labels with an index reg.
200 * Gotoff3 allows you to reference local labels with an index reg & size.
201 * Gaddr loads up a register with an address of an external item.
202 * Gstack is the number of bytes that Gpush pushes on the stack.
204 * Varients of the above with E or L prefixes do EXT(name) or LCL(name)
212 #define Gcall(func) call func
213 #define Gotoff(lab) lab
214 #define Gotoff2(l,r) l(r)
215 #define Gotoff3(l,r,s) l(,r,s)
216 #define Gaddr(to,lab) movl $lab,to
217 #define Gcmp(lab,reg) cmpl $lab,reg
218 #define Gmemload(lab,reg) movl lab,reg
219 #define Gmemstore(reg,lab,tmp) movl reg,lab
223 #ifdef __ELF__ /* ELF shared libraries */
224 #define Gpush pushl %ebx
225 #define Gpop popl %ebx
226 #define Gload call 9f; 9: popl %ebx; addl $_GLOBAL_OFFSET_TABLE_+[.-9b],%ebx
227 #define Gcall(func) call EXT(func)@PLT
228 #define Gotoff(lab) lab@GOTOFF(%ebx)
229 #define Gotoff2(l,r) l@GOTOFF(%ebx,r)
230 #define Gotoff3(l,r,s) l@GOTOFF(%ebx,r,s)
231 #define Gaddr(to,lab) movl lab@GOT(%ebx),to
232 #define Gcmp(lab,reg) cmpl reg,lab@GOT(%ebx)
233 #define Gmemload(lab,reg) movl lab@GOT(%ebx),reg; movl (reg),reg
234 #define Gmemstore(reg,lab,tmp) movl lab@GOT(%ebx),tmp; movl reg,(tmp)
237 #else /* ROSE shared libraries */
241 #define Gcall(func) call *9f; .data; .align ALIGN; 9: .long func; .text
242 #define Gotoff(lab) lab
243 #define Gotoff2(l,r) l(r)
244 #define Gotoff3(l,r,s) l(,r,s)
245 #define Gaddr(to,lab) movl 9f,to; .data; .align ALIGN; 9: .long lab; .text
246 #define Gcmp(lab,reg) cmpl reg,9f; .data; .align ALIGN; 9: .long lab; .text
247 #define Gmemload(lab,reg) movl 9f,reg; movl (reg),reg; .data; .align ALIGN; 9: .long lab; .text
248 #define Gmemstore(reg,lab,tmp) movl 9f,tmp; movl reg,(tmp); .data; .align ALIGN; 9: .long lab; .text
251 #endif /* __SHARED__ */
253 /* Egotoff is not provided, since external symbols should not use @GOTOFF
255 #define Egcall(func) Gcall(EXT(func))
256 #define Egaddr(to,lab) Gaddr(to,EXT(lab))
257 #define Egcmp(lab,reg) Gcmp(EXT(lab),reg)
258 #define Egmemload(lab,reg) Gmemload(EXT(lab),reg)
259 #define Egmemstore(reg,lab,tmp) Gmemstore(reg,EXT(lab),tmp)
261 #define Lgotoff(lab) Gotoff(LCL(lab))
262 #define Lgotoff2(l,r) Gotoff2(LCL(l),r)
263 #define Lgotoff3(l,r,s) Gotoff3(LCL(l),r,s)
264 #define Lgcmp(lab,reg) Gcmp(LCL(lab),reg)
265 #define Lgmemload(lab,reg) movl Lgotoff(lab),reg
266 #define Lgmemstore(reg,lab,tmp) movl reg,Lgotoff(lab)
270 #include <ddb/stab.h>
272 * This pseudo-assembler line is added so that there will be at least
273 * one N_SO entry in the symbol stable to define the current file name.
275 #endif /* MACH_KDB */
277 #else /* NOT ASSEMBLER */
279 /* These defines are here for .c files that wish to reference global symbols
280 * within __asm__ statements.
282 #ifndef __NO_UNDERSCORES__
283 #define CC_SYM_PREFIX "_"
285 #define CC_SYM_PREFIX ""
286 #endif /* __NO_UNDERSCORES__ */
287 #endif /* ASSEMBLER */
289 #endif /* _I386_ASM_H_ */