]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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_ARG0 4(%esp) | |
71 | #define S_ARG1 8(%esp) | |
72 | #define S_ARG2 12(%esp) | |
73 | #define S_ARG3 16(%esp) | |
74 | ||
75 | #define FRAME pushl %ebp; movl %esp, %ebp | |
76 | #define EMARF leave | |
77 | ||
78 | #define B_ARG0 8(%ebp) | |
79 | #define B_ARG1 12(%ebp) | |
80 | #define B_ARG2 16(%ebp) | |
81 | #define B_ARG3 20(%ebp) | |
82 | ||
83 | /* There is another definition of ALIGN for .c sources */ | |
84 | #ifdef ASSEMBLER | |
85 | #define ALIGN 2 | |
86 | #endif /* ASSEMBLER */ | |
87 | ||
88 | #ifndef FALIGN | |
89 | #define FALIGN ALIGN | |
90 | #endif | |
91 | ||
92 | #define LB(x,n) n | |
93 | #if __STDC__ | |
94 | #ifndef __NO_UNDERSCORES__ | |
95 | #define LCL(x) L ## x | |
96 | #define EXT(x) _ ## x | |
97 | #define LEXT(x) _ ## x ## : | |
98 | #else | |
99 | #define LCL(x) .L ## x | |
100 | #define EXT(x) x | |
101 | #define LEXT(x) x ## : | |
102 | #endif | |
103 | #define LBc(x,n) n ## : | |
104 | #define LBb(x,n) n ## b | |
105 | #define LBf(x,n) n ## f | |
106 | #else /* __STDC__ */ | |
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 | |
113 | #define EXT(x) 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__ */ | |
120 | ||
121 | #define SVC .byte 0x9a; .long 0; .word 0x7 | |
122 | ||
123 | #define RPC_SVC .byte 0x9a; .long 0; .word 0xf | |
124 | ||
125 | #define String .asciz | |
126 | #define Value .word | |
127 | #define Times(a,b) (a*b) | |
128 | #define Divide(a,b) (a/b) | |
129 | ||
130 | #define INB inb %dx, %al | |
131 | #define OUTB outb %al, %dx | |
132 | #define INL inl %dx, %eax | |
133 | #define OUTL outl %eax, %dx | |
134 | ||
135 | #define data16 .byte 0x66 | |
136 | #define addr16 .byte 0x67 | |
137 | ||
138 | #if !GPROF | |
139 | #define MCOUNT | |
140 | ||
141 | #elif defined(__SHARED__) | |
142 | #define MCOUNT ; .data;\ | |
143 | .align ALIGN;\ | |
144 | LBc(x, 8) .long 0;\ | |
145 | .text;\ | |
146 | Gpush;\ | |
147 | Gload;\ | |
148 | leal Gotoff(LBb(x,8)),%edx;\ | |
149 | Egaddr(%eax,_mcount_ptr);\ | |
150 | Gpop;\ | |
151 | call *(%eax); | |
152 | ||
153 | #else /* !GPROF, !__SHARED__ */ | |
154 | #define MCOUNT ; .data;\ | |
155 | .align ALIGN;\ | |
156 | LBc(x, 8) .long 0;\ | |
157 | .text;\ | |
158 | movl $LBb(x,8),%edx;\ | |
159 | call *EXT(_mcount_ptr); | |
160 | ||
161 | #endif /* GPROF */ | |
162 | ||
163 | #ifdef __ELF__ | |
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 | |
167 | #else | |
168 | #define ELF_FUNC(x) | |
169 | #define ELF_DATA(x) | |
170 | #define ELF_SIZE(x,s) | |
171 | #endif | |
172 | ||
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) \ | |
178 | MCOUNT | |
179 | #if __STDC__ | |
180 | #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT | |
181 | #else | |
182 | #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT | |
183 | #endif /* __STDC__ */ | |
184 | ||
185 | #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x) | |
186 | ||
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) | |
191 | ||
192 | /* | |
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. | |
203 | * | |
204 | * Varients of the above with E or L prefixes do EXT(name) or LCL(name) | |
205 | * respectively. | |
206 | */ | |
207 | ||
208 | #ifndef __SHARED__ | |
209 | #define Gpush | |
210 | #define Gpop | |
211 | #define Gload | |
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 | |
220 | #define Gstack 0 | |
221 | ||
222 | #else | |
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) | |
235 | #define Gstack 4 | |
236 | ||
237 | #else /* ROSE shared libraries */ | |
238 | #define Gpush | |
239 | #define Gpop | |
240 | #define Gload | |
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 | |
249 | #define Gstack 0 | |
250 | #endif /* __ELF__ */ | |
251 | #endif /* __SHARED__ */ | |
252 | ||
253 | /* Egotoff is not provided, since external symbols should not use @GOTOFF | |
254 | relocations. */ | |
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) | |
260 | ||
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) | |
267 | ||
268 | #ifdef ASSEMBLER | |
269 | #if MACH_KDB | |
270 | #include <ddb/stab.h> | |
271 | /* | |
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. | |
274 | */ | |
275 | #endif /* MACH_KDB */ | |
276 | ||
277 | #else /* NOT ASSEMBLER */ | |
278 | ||
279 | /* These defines are here for .c files that wish to reference global symbols | |
280 | * within __asm__ statements. | |
281 | */ | |
282 | #ifndef __NO_UNDERSCORES__ | |
283 | #define CC_SYM_PREFIX "_" | |
284 | #else | |
285 | #define CC_SYM_PREFIX "" | |
286 | #endif /* __NO_UNDERSCORES__ */ | |
287 | #endif /* ASSEMBLER */ | |
288 | ||
289 | #endif /* _I386_ASM_H_ */ |