]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/asm.h
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / i386 / asm.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
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.
35 *
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.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50
51 #ifndef _I386_ASM_H_
52 #define _I386_ASM_H_
53
54 #ifdef _KERNEL
55 #include <gprof.h>
56 #endif /* _KERNEL */
57
58 #ifdef MACH_KERNEL
59 #include <mach_kdb.h>
60 #else /* !MACH_KERNEL */
61 #define MACH_KDB 0
62 #endif /* !MACH_KERNEL */
63
64
65 #if defined(MACH_KERNEL) || defined(_KERNEL)
66 #include <gprof.h>
67 #endif /* MACH_KERNEL || _KERNEL */
68
69
70 #define S_PC 0(%esp)
71 #define S_ARG0 4(%esp)
72 #define S_ARG1 8(%esp)
73 #define S_ARG2 12(%esp)
74 #define S_ARG3 16(%esp)
75
76 #define FRAME pushl %ebp; movl %esp, %ebp
77 #define EMARF leave
78
79 #define B_LINK 0(%ebp)
80 #define B_PC 4(%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)
85
86 /* There is another definition of ALIGN for .c sources */
87 #ifdef ASSEMBLER
88 #define ALIGN 2,0x90
89 #endif /* ASSEMBLER */
90
91 #ifndef FALIGN
92 #define FALIGN ALIGN
93 #endif
94
95 #define LB(x,n) n
96 #if __STDC__
97 #ifndef __NO_UNDERSCORES__
98 #define LCL(x) L ## x
99 #define EXT(x) _ ## x
100 #define LEXT(x) _ ## x ## :
101 #else
102 #define LCL(x) .L ## x
103 #define EXT(x) x
104 #define LEXT(x) x ## :
105 #endif
106 #define LBc(x,n) n ## :
107 #define LBb(x,n) n ## b
108 #define LBf(x,n) n ## f
109 #else /* __STDC__ */
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
116 #define EXT(x) 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__ */
123
124 #define SVC .byte 0x9a; .long 0; .word 0x7
125
126 #define RPC_SVC .byte 0x9a; .long 0; .word 0xf
127
128 #define String .asciz
129 #define Value .word
130 #define Times(a,b) (a*b)
131 #define Divide(a,b) (a/b)
132
133 #define INB inb %dx, %al
134 #define OUTB outb %al, %dx
135 #define INL inl %dx, %eax
136 #define OUTL outl %eax, %dx
137
138 #define data16 .byte 0x66
139 #define addr16 .byte 0x67
140
141 #if !GPROF
142 #define MCOUNT
143
144 #elif defined(__SHARED__)
145 #define MCOUNT ; .data;\
146 .align ALIGN;\
147 LBc(x, 8) .long 0;\
148 .text;\
149 Gpush;\
150 Gload;\
151 leal Gotoff(LBb(x,8)),%edx;\
152 Egaddr(%eax,_mcount_ptr);\
153 Gpop;\
154 call *(%eax);
155
156 #else /* !GPROF, !__SHARED__ */
157 #define MCOUNT ; call mcount;
158 #endif /* GPROF */
159
160 #ifdef __ELF__
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
164 #else
165 #define ELF_FUNC(x)
166 #define ELF_DATA(x)
167 #define ELF_SIZE(x,s)
168 #endif
169
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) \
175 MCOUNT
176 #if __STDC__
177 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
178 #else
179 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
180 #endif /* __STDC__ */
181
182 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
183
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)
188
189 /*
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.
200 *
201 * Varients of the above with E or L prefixes do EXT(name) or LCL(name)
202 * respectively.
203 */
204
205 #ifndef __SHARED__
206 #define Gpush
207 #define Gpop
208 #define Gload
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
217 #define Gstack 0
218
219 #else
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)
232 #define Gstack 4
233
234 #else /* ROSE shared libraries */
235 #define Gpush
236 #define Gpop
237 #define Gload
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
246 #define Gstack 0
247 #endif /* __ELF__ */
248 #endif /* __SHARED__ */
249
250 /* Egotoff is not provided, since external symbols should not use @GOTOFF
251 relocations. */
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)
257
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)
264
265 #ifdef ASSEMBLER
266 #if MACH_KDB
267 #include <ddb/stab.h>
268 /*
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.
271 */
272 #endif /* MACH_KDB */
273
274 #else /* NOT ASSEMBLER */
275
276 /* These defines are here for .c files that wish to reference global symbols
277 * within __asm__ statements.
278 */
279 #ifndef __NO_UNDERSCORES__
280 #define CC_SYM_PREFIX "_"
281 #else
282 #define CC_SYM_PREFIX ""
283 #endif /* __NO_UNDERSCORES__ */
284 #endif /* ASSEMBLER */
285
286 #endif /* _I386_ASM_H_ */