Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/i386/include/architecture/i386/asm_help.h

Source at commit 296 created 12 years 10 months ago.
By ifabio, add i386 folder
1/*
2 * Copyright (c) 1999 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/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
24 *
25 *File:architecture/i386/asm_help.h
26 *Author:Mike DeMoney, NeXT Computer, Inc.
27 *Modified for i386 by: Bruce Martin, NeXT Computer, Inc.
28 *
29 *This header file defines macros useful when writing assembly code
30 *for the Intel i386 family processors.
31 *
32 * HISTORY
33 * 10-Mar-92 Bruce Martin (bmartin@next.com)
34 *Adapted to i386
35 * 23-Jan-91 Mike DeMoney (mike@next.com)
36 *Created.
37 */
38
39#ifndef_ARCH_I386_ASM_HELP_H_
40#define_ARCH_I386_ASM_HELP_H_
41
42#include<architecture/i386/reg_help.h>
43
44
45#ifdef__ASSEMBLER__
46
47#define ALIGN\
48.align2, 0x90
49
50#defineROUND_TO_STACK(len)\
51(((len) + STACK_INCR - 1) / STACK_INCR * STACK_INCR)
52
53#ifdef notdef
54#if defined(__i386__)
55#define CALL_MCOUNT\
56pushl%ebp;\
57movl%esp, %ebp;\
58.data;\
591: .long 0;\
60.text;\
61lea 9b,%edx;\
62call mcount;\
63popl%ebp;
64#elif defined(__x86_64__)
65#define CALL_MCOUNT\
66pushq%rbp;\
67movq%rsp, %rbp;\
68.data;\
691: .quad 0;\
70.text;\
71lea 9b,%r13;\
72call mcount;\
73popq%rbp;
74#endif
75#else
76#define CALL_MCOUNT
77#endif
78
79/*
80 * Prologue for functions that may call other functions. Saves
81 * registers and sets up a C frame.
82 */
83#if defined(__i386__)
84#define NESTED_FUNCTION_PROLOGUE(localvarsize)\
85.set__framesize,ROUND_TO_STACK(localvarsize);\
86.set__nested_function, 1;\
87CALL_MCOUNT\
88.if __framesize;\
89 pushl%ebp;\
90 movl%esp, %ebp;\
91 subl$__framesize, %esp;\
92.endif;\
93pushl%edi;\
94pushl%esi;\
95pushl%ebx
96#elif defined(__x86_64__)
97#define NESTED_FUNCTION_PROLOGUE(localvarsize)\
98.set__framesize,ROUND_TO_STACK(localvarsize);\
99.set__nested_function, 1;\
100CALL_MCOUNT\
101.if __framesize;\
102 pushq%rbp;\
103 movq%rsp, %rbp;\
104 subq$__framesize, %rsp;\
105.endif;
106#endif
107
108/*
109 * Prologue for functions that do not call other functions. Does not
110 * save registers (this is the functions responsibility). Does set
111 * up a C frame.
112 */
113#if defined(__i386__)
114#define LEAF_FUNCTION_PROLOGUE(localvarsize)\
115.set__framesize,ROUND_TO_STACK(localvarsize);\
116.set__nested_function, 0;\
117CALL_MCOUNT\
118.if __framesize;\
119 pushl%ebp;\
120 movl%esp, %ebp;\
121 subl$__framesize, %esp;\
122.endif
123#elif defined(__x86_64__)
124#define LEAF_FUNCTION_PROLOGUE(localvarsize)\
125.set__framesize,ROUND_TO_STACK(localvarsize);\
126.set__nested_function, 0;\
127CALL_MCOUNT\
128.if __framesize;\
129 pushq%rbp;\
130 movq%rsp, %rbp;\
131 subq$__framesize, %rsp;\
132.endif
133#endif
134
135/*
136 * Epilogue for any function.
137 *
138 * We assume that all Leaf functions will be responsible for saving any
139 * local registers they clobber.
140 */
141#if defined(__i386__)
142#define FUNCTION_EPILOGUE\
143.if __nested_function;\
144 popl%ebx;\
145 popl%esi;\
146 popl%edi;\
147.endif;\
148.if __framesize;\
149 movl%ebp, %esp;\
150 popl%ebp;\
151.endif;\
152ret
153#elif defined(__x86_64__)
154#define FUNCTION_EPILOGUE\
155.if __framesize;\
156 movq%rbp, %rsp;\
157 popq%rbp;\
158.endif;\
159ret
160#endif
161
162/*
163 * Macros for declaring procedures
164 *
165 * Use of these macros allows ctags to have a predictable way
166 * to find various types of declarations. They also simplify
167 * inserting appropriate symbol table information.
168 *
169 * NOTE: these simple stubs will be replaced with more
170 * complicated versions once we know what the linker and gdb
171 * will require as far as register use masks and frame declarations.
172 * These macros may also be ifdef'ed in the future to contain profiling
173 * code.
174 *
175 */
176
177/*
178 * TEXT -- declare start of text segment
179 */
180#defineTEXT\
181.text
182
183/*
184 * DATA -- declare start of data segment
185 */
186#define DATA\
187.data
188
189/*
190 * LEAF -- declare global leaf procedure
191 * NOTE: Control SHOULD NOT FLOW into a LEAF! A LEAF should only
192 * be jumped to. (A leaf may do an align.) Use a LABEL() if you
193 * need control to flow into the label.
194 */
195#defineLEAF(name, localvarsize)\
196.globlname;\
197ALIGN;\
198name:;\
199LEAF_FUNCTION_PROLOGUE(localvarsize)
200
201/*
202 * X_LEAF -- declare alternate global label for leaf
203 */
204#defineX_LEAF(name, value)\
205.globlname;\
206.setname,value
207
208/*
209 * P_LEAF -- declare private leaf procedure
210 */
211#defineP_LEAF(name, localvarsize)\
212ALIGN;\
213name:;\
214LEAF_FUNCTION_PROLOGUE(localvarsize)
215
216/*
217 * LABEL -- declare a global code label
218 * MUST be used (rather than LEAF, NESTED, etc) if control
219 * "flows into" the label.
220 */
221#defineLABEL(name)\
222.globlname;\
223name:
224
225/*
226 * NESTED -- declare procedure that invokes other procedures
227 */
228#defineNESTED(name, localvarsize)\
229.globlname;\
230ALIGN;\
231name:;\
232NESTED_FUNCTION_PROLOGUE(localvarsize)
233
234/*
235 * X_NESTED -- declare alternate global label for nested proc
236 */
237#defineX_NESTED(name, value)\
238.globlname;\
239.setname,value
240
241/*
242 * P_NESTED -- declare private nested procedure
243 */
244#defineP_NESTED(name, localvarsize)\
245ALIGN;\
246name:;\
247NESTED_FUNCTION_PROLOGUE(localvarsize)
248
249/*
250 * END -- mark end of procedure
251 */
252#defineEND(name)\
253FUNCTION_EPILOGUE
254
255
256/*
257 * Storage definition macros
258 * The main purpose of these is to allow an easy handle for ctags
259 */
260
261/*
262 * IMPORT -- import symbol
263 */
264#defineIMPORT(name)\
265.referencename
266
267/*
268 * ABS -- declare global absolute symbol
269 */
270#defineABS(name, value)\
271.globlname;\
272.setname,value
273
274/*
275 * P_ABS -- declare private absolute symbol
276 */
277#defineP_ABS(name, value)\
278.setname,value
279
280/*
281 * EXPORT -- declare global label for data
282 */
283#defineEXPORT(name)\
284.globlname;\
285name:
286
287/*
288 * BSS -- declare global zero'ed storage
289 */
290#defineBSS(name,size)\
291.commname,size
292
293
294/*
295 * P_BSS -- declare private zero'ed storage
296 */
297#defineP_BSS(name,size)\
298.lcommname,size
299
300/*
301 * dynamic/PIC macros for routines which reference external symbols
302 */
303
304#if defined(__DYNAMIC__)
305#if defined(__i386__)
306#define PICIFY(var)\
307call1f; \
3081:; \
309popl%edx; \
310movlL ## var ## __non_lazy_ptr-1b(%edx),%edx
311#elif defined(__x86_64__)
312#define PICIFY(var)\
313movqvar@GOTPCREL(%rip),%r11
314#endif
315
316#if defined(__i386__)
317#define CALL_EXTERN_AGAIN(func)\
318PICIFY(func); \
319call*%edx
320#elif defined(__x86_64__)
321#define CALL_EXTERN_AGAIN(func)\
322callfunc
323#endif
324
325#if defined(__i386__)
326#define NON_LAZY_STUB(var)\
327.section __IMPORT,__pointers,non_lazy_symbol_pointers; \
328L ## var ## __non_lazy_ptr:; \
329.indirect_symbol var; \
330.long 0; \
331.text
332#elif defined(__x86_64__)
333#define NON_LAZY_STUB(var)
334#endif
335
336#define CALL_EXTERN(func)\
337CALL_EXTERN_AGAIN(func); \
338NON_LAZY_STUB(func)
339
340#if defined(__i386__)
341#define BRANCH_EXTERN(func)\
342PICIFY(func); \
343jmp*%edx; \
344NON_LAZY_STUB(func)
345#elif defined(__x86_64__)
346#define BRANCH_EXTERN(func)\
347jmpfunc
348#endif
349
350#if defined(__i386__)
351#define PUSH_EXTERN(var)\
352PICIFY(var); \
353movl(%edx),%edx; \
354pushl%edx; \
355NON_LAZY_STUB(var)
356#endif
357
358#if defined(__i386__)
359#define REG_TO_EXTERN(reg, var)\
360PICIFY(var); \
361movlreg, (%edx); \
362NON_LAZY_STUB(var)
363#elif defined(__x86_64__)
364#define REG_TO_EXTERN(reg, var)\
365PICIFY(var); \
366movreg, (%r11)
367#endif
368
369#if defined(__i386__)
370#define EXTERN_TO_REG(var, reg)\
371call1f; \
3721:; \
373popl%edx; \
374movlL ## var ##__non_lazy_ptr-1b(%edx),reg; \
375NON_LAZY_STUB(var)
376#elif defined(__x86_64__)
377#define EXTERN_TO_REG(var, reg)\
378PICIFY(var); \
379mov (%r11), reg
380#endif
381
382#else
383#define BRANCH_EXTERN(func)jmpfunc
384#define PUSH_EXTERN(var)pushvar
385#define CALL_EXTERN(func)callfunc
386#define CALL_EXTERN_AGAIN(func)callfunc
387#if defined(__i386__)
388#define REG_TO_EXTERN(reg, var)movreg, var
389#define EXTERN_TO_REG(var, reg)mov$ ## var, reg
390#elif defined(__x86_64__)
391#define REG_TO_EXTERN(reg, var)movreg, var ## (%rip)
392#define EXTERN_TO_REG(var, reg)movvar ## (%rip), reg
393#endif
394#endif
395
396#endif/* __ASSEMBLER__ */
397
398#endif/* _ARCH_I386_ASM_HELP_H_ */
399

Archive Download this file

Revision: 296