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