]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. | |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | /* | |
29 | * Mach Operating System | |
30 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
31 | * All Rights Reserved. | |
32 | * | |
33 | * Permission to use, copy, modify and distribute this software and its | |
34 | * documentation is hereby granted, provided that both the copyright | |
35 | * notice and this permission notice appear in all copies of the | |
36 | * software, derivative works or modified versions, and any portions | |
37 | * thereof, and that both notices appear in supporting documentation. | |
38 | * | |
39 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
40 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
41 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
42 | * | |
43 | * Carnegie Mellon requests users of this software to return to | |
44 | * | |
45 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
46 | * School of Computer Science | |
47 | * Carnegie Mellon University | |
48 | * Pittsburgh PA 15213-3890 | |
49 | * | |
50 | * any improvements or extensions that they make and grant Carnegie Mellon | |
51 | * the rights to redistribute these changes. | |
52 | */ | |
53 | ||
54 | #ifndef _I386_ASM_H_ | |
55 | #define _I386_ASM_H_ | |
56 | ||
57 | #ifdef _KERNEL | |
58 | #include <gprof.h> | |
59 | #endif /* _KERNEL */ | |
60 | ||
61 | #ifdef MACH_KERNEL | |
62 | #include <mach_kdb.h> | |
63 | #else /* !MACH_KERNEL */ | |
64 | #define MACH_KDB 0 | |
65 | #endif /* !MACH_KERNEL */ | |
66 | ||
67 | ||
68 | #if defined(MACH_KERNEL) || defined(_KERNEL) | |
69 | #include <gprof.h> | |
70 | #endif /* MACH_KERNEL || _KERNEL */ | |
71 | ||
72 | ||
73 | #define S_ARG0 4(%esp) | |
74 | #define S_ARG1 8(%esp) | |
75 | #define S_ARG2 12(%esp) | |
76 | #define S_ARG3 16(%esp) | |
77 | ||
78 | #define FRAME pushl %ebp; movl %esp, %ebp | |
79 | #define EMARF leave | |
80 | ||
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 ; .data;\ | |
158 | .align ALIGN;\ | |
159 | LBc(x, 8) .long 0;\ | |
160 | .text;\ | |
161 | movl LBb(x,8),%edx;\ | |
162 | call *EXT(_mcount_ptr); | |
163 | ||
164 | #endif /* GPROF */ | |
165 | ||
166 | #ifdef __ELF__ | |
167 | #define ELF_FUNC(x) .type x,@function | |
168 | #define ELF_DATA(x) .type x,@object | |
169 | #define ELF_SIZE(x,s) .size x,s | |
170 | #else | |
171 | #define ELF_FUNC(x) | |
172 | #define ELF_DATA(x) | |
173 | #define ELF_SIZE(x,s) | |
174 | #endif | |
175 | ||
176 | #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x) | |
177 | #define ENTRY(x) Entry(x) MCOUNT | |
178 | #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \ | |
179 | ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \ | |
180 | .align FALIGN; LEXT(x); LEXT(y) \ | |
181 | MCOUNT | |
182 | #if __STDC__ | |
183 | #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT | |
184 | #else | |
185 | #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT | |
186 | #endif /* __STDC__ */ | |
187 | ||
188 | #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x) | |
189 | ||
190 | #define End(x) ELF_SIZE(x,.-x) | |
191 | #define END(x) End(EXT(x)) | |
192 | #define ENDDATA(x) END(x) | |
193 | #define Enddata(x) End(x) | |
194 | ||
195 | /* | |
196 | * ELF shared library accessor macros. | |
197 | * Gpush saves the %ebx register used for the GOT address | |
198 | * Gpop pops %ebx if we need a GOT | |
199 | * Gload loads %ebx with the GOT address if shared libraries are used | |
200 | * Gcall calls an external function. | |
201 | * Gotoff allows you to reference local labels. | |
202 | * Gotoff2 allows you to reference local labels with an index reg. | |
203 | * Gotoff3 allows you to reference local labels with an index reg & size. | |
204 | * Gaddr loads up a register with an address of an external item. | |
205 | * Gstack is the number of bytes that Gpush pushes on the stack. | |
206 | * | |
207 | * Varients of the above with E or L prefixes do EXT(name) or LCL(name) | |
208 | * respectively. | |
209 | */ | |
210 | ||
211 | #ifndef __SHARED__ | |
212 | #define Gpush | |
213 | #define Gpop | |
214 | #define Gload | |
215 | #define Gcall(func) call func | |
216 | #define Gotoff(lab) lab | |
217 | #define Gotoff2(l,r) l(r) | |
218 | #define Gotoff3(l,r,s) l(,r,s) | |
219 | #define Gaddr(to,lab) movl $lab,to | |
220 | #define Gcmp(lab,reg) cmpl $lab,reg | |
221 | #define Gmemload(lab,reg) movl lab,reg | |
222 | #define Gmemstore(reg,lab,tmp) movl reg,lab | |
223 | #define Gstack 0 | |
224 | ||
225 | #else | |
226 | #ifdef __ELF__ /* ELF shared libraries */ | |
227 | #define Gpush pushl %ebx | |
228 | #define Gpop popl %ebx | |
229 | #define Gload call 9f; 9: popl %ebx; addl $_GLOBAL_OFFSET_TABLE_+[.-9b],%ebx | |
230 | #define Gcall(func) call EXT(func)@PLT | |
231 | #define Gotoff(lab) lab@GOTOFF(%ebx) | |
232 | #define Gotoff2(l,r) l@GOTOFF(%ebx,r) | |
233 | #define Gotoff3(l,r,s) l@GOTOFF(%ebx,r,s) | |
234 | #define Gaddr(to,lab) movl lab@GOT(%ebx),to | |
235 | #define Gcmp(lab,reg) cmpl reg,lab@GOT(%ebx) | |
236 | #define Gmemload(lab,reg) movl lab@GOT(%ebx),reg; movl (reg),reg | |
237 | #define Gmemstore(reg,lab,tmp) movl lab@GOT(%ebx),tmp; movl reg,(tmp) | |
238 | #define Gstack 4 | |
239 | ||
240 | #else /* ROSE shared libraries */ | |
241 | #define Gpush | |
242 | #define Gpop | |
243 | #define Gload | |
244 | #define Gcall(func) call *9f; .data; .align ALIGN; 9: .long func; .text | |
245 | #define Gotoff(lab) lab | |
246 | #define Gotoff2(l,r) l(r) | |
247 | #define Gotoff3(l,r,s) l(,r,s) | |
248 | #define Gaddr(to,lab) movl 9f,to; .data; .align ALIGN; 9: .long lab; .text | |
249 | #define Gcmp(lab,reg) cmpl reg,9f; .data; .align ALIGN; 9: .long lab; .text | |
250 | #define Gmemload(lab,reg) movl 9f,reg; movl (reg),reg; .data; .align ALIGN; 9: .long lab; .text | |
251 | #define Gmemstore(reg,lab,tmp) movl 9f,tmp; movl reg,(tmp); .data; .align ALIGN; 9: .long lab; .text | |
252 | #define Gstack 0 | |
253 | #endif /* __ELF__ */ | |
254 | #endif /* __SHARED__ */ | |
255 | ||
256 | /* Egotoff is not provided, since external symbols should not use @GOTOFF | |
257 | relocations. */ | |
258 | #define Egcall(func) Gcall(EXT(func)) | |
259 | #define Egaddr(to,lab) Gaddr(to,EXT(lab)) | |
260 | #define Egcmp(lab,reg) Gcmp(EXT(lab),reg) | |
261 | #define Egmemload(lab,reg) Gmemload(EXT(lab),reg) | |
262 | #define Egmemstore(reg,lab,tmp) Gmemstore(reg,EXT(lab),tmp) | |
263 | ||
264 | #define Lgotoff(lab) Gotoff(LCL(lab)) | |
265 | #define Lgotoff2(l,r) Gotoff2(LCL(l),r) | |
266 | #define Lgotoff3(l,r,s) Gotoff3(LCL(l),r,s) | |
267 | #define Lgcmp(lab,reg) Gcmp(LCL(lab),reg) | |
268 | #define Lgmemload(lab,reg) movl Lgotoff(lab),reg | |
269 | #define Lgmemstore(reg,lab,tmp) movl reg,Lgotoff(lab) | |
270 | ||
271 | #ifdef ASSEMBLER | |
272 | #if MACH_KDB | |
273 | #include <ddb/stab.h> | |
274 | /* | |
275 | * This pseudo-assembler line is added so that there will be at least | |
276 | * one N_SO entry in the symbol stable to define the current file name. | |
277 | */ | |
278 | #endif /* MACH_KDB */ | |
279 | ||
280 | #else /* NOT ASSEMBLER */ | |
281 | ||
282 | /* These defines are here for .c files that wish to reference global symbols | |
283 | * within __asm__ statements. | |
284 | */ | |
285 | #ifndef __NO_UNDERSCORES__ | |
286 | #define CC_SYM_PREFIX "_" | |
287 | #else | |
288 | #define CC_SYM_PREFIX "" | |
289 | #endif /* __NO_UNDERSCORES__ */ | |
290 | #endif /* ASSEMBLER */ | |
291 | ||
292 | #endif /* _I386_ASM_H_ */ |