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