]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/asm.h
f1f0b51f96ff36e5e57fe476274fbcb10721447b
[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 * 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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * @OSF_COPYRIGHT@
25 */
26 /*
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
29 * All Rights Reserved.
30 *
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
36 *
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 *
41 * Carnegie Mellon requests users of this software to return to
42 *
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
47 *
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
50 */
51
52 #ifndef _I386_ASM_H_
53 #define _I386_ASM_H_
54
55 #ifdef _KERNEL
56 #include <gprof.h>
57 #endif /* _KERNEL */
58
59 #ifdef MACH_KERNEL
60 #include <mach_kdb.h>
61 #else /* !MACH_KERNEL */
62 #define MACH_KDB 0
63 #endif /* !MACH_KERNEL */
64
65
66 #if defined(MACH_KERNEL) || defined(_KERNEL)
67 #include <gprof.h>
68 #endif /* MACH_KERNEL || _KERNEL */
69
70
71 #define S_PC 0(%esp)
72 #define S_ARG0 4(%esp)
73 #define S_ARG1 8(%esp)
74 #define S_ARG2 12(%esp)
75 #define S_ARG3 16(%esp)
76
77 #define FRAME pushl %ebp; movl %esp, %ebp
78 #define EMARF leave
79
80 #define B_LINK 0(%ebp)
81 #define B_PC 4(%ebp)
82 #define B_ARG0 8(%ebp)
83 #define B_ARG1 12(%ebp)
84 #define B_ARG2 16(%ebp)
85 #define B_ARG3 20(%ebp)
86
87 /* There is another definition of ALIGN for .c sources */
88 #ifdef ASSEMBLER
89 #define ALIGN 2,0x90
90 #endif /* ASSEMBLER */
91
92 #ifndef FALIGN
93 #define FALIGN ALIGN
94 #endif
95
96 #define LB(x,n) n
97 #if __STDC__
98 #ifndef __NO_UNDERSCORES__
99 #define LCL(x) L ## x
100 #define EXT(x) _ ## x
101 #define LEXT(x) _ ## x ## :
102 #else
103 #define LCL(x) .L ## x
104 #define EXT(x) x
105 #define LEXT(x) x ## :
106 #endif
107 #define LBc(x,n) n ## :
108 #define LBb(x,n) n ## b
109 #define LBf(x,n) n ## f
110 #else /* __STDC__ */
111 #ifndef __NO_UNDERSCORES__
112 #define LCL(x) L/**/x
113 #define EXT(x) _/**/x
114 #define LEXT(x) _/**/x/**/:
115 #else /* __NO_UNDERSCORES__ */
116 #define LCL(x) .L/**/x
117 #define EXT(x) x
118 #define LEXT(x) x/**/:
119 #endif /* __NO_UNDERSCORES__ */
120 #define LBc(x,n) n/**/:
121 #define LBb(x,n) n/**/b
122 #define LBf(x,n) n/**/f
123 #endif /* __STDC__ */
124
125 #define SVC .byte 0x9a; .long 0; .word 0x7
126
127 #define RPC_SVC .byte 0x9a; .long 0; .word 0xf
128
129 #define String .asciz
130 #define Value .word
131 #define Times(a,b) (a*b)
132 #define Divide(a,b) (a/b)
133
134 #define INB inb %dx, %al
135 #define OUTB outb %al, %dx
136 #define INL inl %dx, %eax
137 #define OUTL outl %eax, %dx
138
139 #define data16 .byte 0x66
140 #define addr16 .byte 0x67
141
142 #if !GPROF
143 #define MCOUNT
144
145 #elif defined(__SHARED__)
146 #define MCOUNT ; .data;\
147 .align ALIGN;\
148 LBc(x, 8) .long 0;\
149 .text;\
150 Gpush;\
151 Gload;\
152 leal Gotoff(LBb(x,8)),%edx;\
153 Egaddr(%eax,_mcount_ptr);\
154 Gpop;\
155 call *(%eax);
156
157 #else /* !GPROF, !__SHARED__ */
158 #define MCOUNT ; call mcount;
159 #endif /* GPROF */
160
161 #ifdef __ELF__
162 #define ELF_FUNC(x) .type x,@function
163 #define ELF_DATA(x) .type x,@object
164 #define ELF_SIZE(x,s) .size x,s
165 #else
166 #define ELF_FUNC(x)
167 #define ELF_DATA(x)
168 #define ELF_SIZE(x,s)
169 #endif
170
171 #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x)
172 #define ENTRY(x) Entry(x) MCOUNT
173 #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \
174 ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \
175 .align FALIGN; LEXT(x); LEXT(y) \
176 MCOUNT
177 #if __STDC__
178 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
179 #else
180 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
181 #endif /* __STDC__ */
182
183 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
184
185 #define End(x) ELF_SIZE(x,.-x)
186 #define END(x) End(EXT(x))
187 #define ENDDATA(x) END(x)
188 #define Enddata(x) End(x)
189
190 /*
191 * ELF shared library accessor macros.
192 * Gpush saves the %ebx register used for the GOT address
193 * Gpop pops %ebx if we need a GOT
194 * Gload loads %ebx with the GOT address if shared libraries are used
195 * Gcall calls an external function.
196 * Gotoff allows you to reference local labels.
197 * Gotoff2 allows you to reference local labels with an index reg.
198 * Gotoff3 allows you to reference local labels with an index reg & size.
199 * Gaddr loads up a register with an address of an external item.
200 * Gstack is the number of bytes that Gpush pushes on the stack.
201 *
202 * Varients of the above with E or L prefixes do EXT(name) or LCL(name)
203 * respectively.
204 */
205
206 #ifndef __SHARED__
207 #define Gpush
208 #define Gpop
209 #define Gload
210 #define Gcall(func) call func
211 #define Gotoff(lab) lab
212 #define Gotoff2(l,r) l(r)
213 #define Gotoff3(l,r,s) l(,r,s)
214 #define Gaddr(to,lab) movl $lab,to
215 #define Gcmp(lab,reg) cmpl $lab,reg
216 #define Gmemload(lab,reg) movl lab,reg
217 #define Gmemstore(reg,lab,tmp) movl reg,lab
218 #define Gstack 0
219
220 #else
221 #ifdef __ELF__ /* ELF shared libraries */
222 #define Gpush pushl %ebx
223 #define Gpop popl %ebx
224 #define Gload call 9f; 9: popl %ebx; addl $_GLOBAL_OFFSET_TABLE_+[.-9b],%ebx
225 #define Gcall(func) call EXT(func)@PLT
226 #define Gotoff(lab) lab@GOTOFF(%ebx)
227 #define Gotoff2(l,r) l@GOTOFF(%ebx,r)
228 #define Gotoff3(l,r,s) l@GOTOFF(%ebx,r,s)
229 #define Gaddr(to,lab) movl lab@GOT(%ebx),to
230 #define Gcmp(lab,reg) cmpl reg,lab@GOT(%ebx)
231 #define Gmemload(lab,reg) movl lab@GOT(%ebx),reg; movl (reg),reg
232 #define Gmemstore(reg,lab,tmp) movl lab@GOT(%ebx),tmp; movl reg,(tmp)
233 #define Gstack 4
234
235 #else /* ROSE shared libraries */
236 #define Gpush
237 #define Gpop
238 #define Gload
239 #define Gcall(func) call *9f; .data; .align ALIGN; 9: .long func; .text
240 #define Gotoff(lab) lab
241 #define Gotoff2(l,r) l(r)
242 #define Gotoff3(l,r,s) l(,r,s)
243 #define Gaddr(to,lab) movl 9f,to; .data; .align ALIGN; 9: .long lab; .text
244 #define Gcmp(lab,reg) cmpl reg,9f; .data; .align ALIGN; 9: .long lab; .text
245 #define Gmemload(lab,reg) movl 9f,reg; movl (reg),reg; .data; .align ALIGN; 9: .long lab; .text
246 #define Gmemstore(reg,lab,tmp) movl 9f,tmp; movl reg,(tmp); .data; .align ALIGN; 9: .long lab; .text
247 #define Gstack 0
248 #endif /* __ELF__ */
249 #endif /* __SHARED__ */
250
251 /* Egotoff is not provided, since external symbols should not use @GOTOFF
252 relocations. */
253 #define Egcall(func) Gcall(EXT(func))
254 #define Egaddr(to,lab) Gaddr(to,EXT(lab))
255 #define Egcmp(lab,reg) Gcmp(EXT(lab),reg)
256 #define Egmemload(lab,reg) Gmemload(EXT(lab),reg)
257 #define Egmemstore(reg,lab,tmp) Gmemstore(reg,EXT(lab),tmp)
258
259 #define Lgotoff(lab) Gotoff(LCL(lab))
260 #define Lgotoff2(l,r) Gotoff2(LCL(l),r)
261 #define Lgotoff3(l,r,s) Gotoff3(LCL(l),r,s)
262 #define Lgcmp(lab,reg) Gcmp(LCL(lab),reg)
263 #define Lgmemload(lab,reg) movl Lgotoff(lab),reg
264 #define Lgmemstore(reg,lab,tmp) movl reg,Lgotoff(lab)
265
266 #ifdef ASSEMBLER
267 #if MACH_KDB
268 #include <ddb/stab.h>
269 /*
270 * This pseudo-assembler line is added so that there will be at least
271 * one N_SO entry in the symbol stable to define the current file name.
272 */
273 #endif /* MACH_KDB */
274
275 #else /* NOT ASSEMBLER */
276
277 /* These defines are here for .c files that wish to reference global symbols
278 * within __asm__ statements.
279 */
280 #ifndef __NO_UNDERSCORES__
281 #define CC_SYM_PREFIX "_"
282 #else
283 #define CC_SYM_PREFIX ""
284 #endif /* __NO_UNDERSCORES__ */
285 #endif /* ASSEMBLER */
286
287 #endif /* _I386_ASM_H_ */