Chameleon

Chameleon Svn Source Tree

Root/tags/2.0/i386/include/architecture/ppc/asm_help.h

Source at commit 1672 created 12 years 8 months ago.
By blackosx, Reset language translations for the Welcome/Description and Conclusion files to english to match latest style I have for English (Sorry everyone who had previously translated). Localizable strings remain as they were as ErmaC had previously amended those to include my recent additions. French translation up to date - thanks Tenval. This will ease merging to the Trunk.
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) 1996 NeXT Software, Inc. All rights reserved.
24 *
25 *File:architecture/ppc/asm_help.h
26 *Author:Mike DeMoney, NeXT Software, Inc.
27 *
28 *This header file defines macros useful when writing assembly code
29 *for the PowerPC processors.
30 *r12 is used as the tmp register / PICIFY base.
31 *
32 * HISTORY
33 * 20-May-97 Umesh Vaishampayan (umeshv@apple.com)
34 *Implemented Dynamic / PIC macros.
35 *
36 * 28-Dec-96 Umesh Vaishampayan (umeshv@NeXT.com)
37 *added ".align" directive to various macros to avoid alignment
38 * faults. Moved Register Usage #defines to reg_help.h as that's
39 *where they should have been in the first place.
40 *Added Dynamic / PIC macroes for routines which refernce external
41 *symbols. Not implemented fully as yet.
42 *
43 * 05-Nov-92 Mike DeMoney (mike@next.com)
44 *Created.
45 */
46
47#ifndef_ARCH_PPC_ASM_HELP_H_
48#define_ARCH_PPC_ASM_HELP_H_
49
50#include<architecture/ppc/reg_help.h>
51
52#ifdef__ASSEMBLER__
53/*
54 * ppc stack frames look like this after procedure prolog has
55 * been executed:
56 *
57 * Higher address:
58 *.........
59 *+-------------------------------+
60 * | caller's LR|
61 *+-------------------------------+
62 * | caller's CR|
63 *+-------------------------------+
64 * Caller's SP->| caller's caller's sp| ^^ Caller's Frame ^^
65 *+===============================+ vv Called Rtn Frame vv
66 *|Save Area for| FPF 31
67 *..........
68 *| Caller's FPF's| FPF n
69 *+-------------------------------+
70 *|Save Area for| GRF 31
71 *..........
72 *| Caller's GRF's| GRF n
73 *+-------------------------------+
74 *|alignment pad|
75 *............
76 *|(if necessary)|
77 *+-------------------------------+
78 *|Local|
79 *........
80 *| Variables|
81 *+-------------------------------+
82 * SP + X ->| aN for FUTURE call|
83 *+-------------------------------+
84 *..........
85 *+-------------------------------+
86 * SP + 28 ->| a1 for FUTURE call|
87 *+-------------------------------+
88 * SP + 24 ->| a0 for FUTURE call|
89 *+-------------------------------+
90 * SP + 20 ->| caller's TOC|
91 *+-------------------------------+
92 * SP + 16 ->| reserved|
93 *+-------------------------------+
94 * SP + 12 ->| reserved|
95 *+-------------------------------+
96 * SP + 8 ->| LR callee-save for FUTURE call|
97 *+-------------------------------+
98 * SP + 4 ->| CR callee-save for FUTURE call|
99 *+-------------------------------+
100 * SP ->| caller's sp|
101 *+===============================+
102 * Lower address:
103 *
104 * NOTE: All state with the exception of LR and CR are saved in the
105 * called routines frame. LR and CR are saved in the CALLER'S FRAME.
106 *
107 * ALSO NOTE: Args to the called routine are found in the caller's frame.
108 */
109
110/*
111 * ARG(n) -- stack offset to n'th argument
112 *
113 * NOTE CAREFULLY! These macros start numbering arguments at 1 (NOT 0)
114 * The first argument is ARG(1).
115 *
116 * ALSO NOTE: This stack offset is only valid if using routine
117 * DOES NOT alter SP.
118 *
119 */
120#defineARG(n)((((n) - 1) * 4) + 24)
121
122/*
123 * Macros for building stack frame according to C calling conventions.
124 * lr, cr, and sp are saved.
125 *
126 * NOTE WELL: localvarsize is in bytes, maxargsout is a count of words,
127 * grfsaved and fpfsaved is a count of registers. BE SURE TO COUNT
128 * BOTH FP (r31) AND sN REGISTERS IN THE COUNT OF GRF REGISTERS SAVED!
129 * This will be TWO more than the N of the highest sN register you
130 * save: s2 implies you are saving s2, s1, s0, and fp => grfsaved
131 * should be 4!
132 *
133 * FURTHER NOTE: These macros do NOT SAVE GRF or FPF registers. User
134 * must do that. GRF sN regs should be saved via
135 *stmwsN,SAVED_GRF_S(N)(sp)
136 * where N is the highest numbered s* register to be saved. E.g. if
137 * s0, s1, and s2 are to be saved use:
138 *stmws2,SAVED_GRF_S(2)(sp)
139 * Note that this also saves fp.
140 * An individual saved grf can be loaded via:
141 *lwzs2,SAVED_GRF_S(2)(sp)
142 * Analogous stuff works for fpf's.
143 *
144 * NOTE: these simple routines will be replaced with more complicated
145 * ones once we know what the linker and gdb will require as for as
146 * register use masks and frame declarations.
147 *
148 * Warning: ROUND_TO_STACK is only to be used in assembly language;
149 * for C usage, use ROUND_FRAME() in reg_help.h.
150 */
151#defineROUND_TO_STACK(len)\
152(((len) + STACK_INCR - 1) / STACK_INCR * STACK_INCR)
153
154#defineBUILD_FRAME(localvarsize, maxargsout, grfsaved, fpfsaved)\
155.set__argoutsize, ROUND_TO_STACK((maxargsout) * 4)@\
156.if__argoutsize < 32@\
157 .set__argoutsize,32@\
158.endif@\
159.set__framesize, ROUND_TO_STACK(\
16024 + __argoutsize + (localvarsize)\
161+ 4*(grfsaved) + 8*(fpfsaved))@\
162.set__grfbase,(__framesize - 4*(grfsaved) - 8*(fpfsaved))@\
163.set__fpfbase,(__framesize - 8*(fpfsaved))@\
164mflrr0@\
165mfcrr12@\
166stwr0,8(sp)@\
167stwr12,4(sp)@\
168stwur1,-__framesize(r1)
169
170/*
171 * Macros for referencing data in stack frame.
172 *
173 * NOTE WELL: ARG's and VAR's start at 1, NOT 0. Why ??? (FIXME)
174 */
175#defineLOCAL_VAR(n)(((n)-1)*4 + __argoutsize + 24)
176#defineSAVED_GRF_S(n)(__grfbase + ((grfsaved) - (n) - 2) * 4)
177#defineSAVED_FRF_FS(n)(__fpfbase + ((fpfsaved) - (n) - 1) * 4)
178#defineARG_IN(n)(ARG(n) + __framesize)
179#defineARG_OUT(n)(ARG(n) + 0)
180#defineSAVED_FP(__grfbase + ((grfsaved) - 1) * 4)
181#defineSAVED_LR(__framesize + 8)
182#defineSAVED_CR(__framesize + 4)
183
184/*
185 * Macros for unwinding stack frame.
186 * NOTE: GRF's and FPF's are NOT RESTORED. User must do this before
187 * using this macro.
188 */
189#defineRETURN\
190.if__framesize@\
191 lwz32r0,r1,SAVED_LR@\
192 lwz32r12,r1,SAVED_CR@\
193 addicsp,r1,__framesize@\
194 mtlrr0@\
195 mtcrf0xff,r12@\
196 blr@\
197.else@\
198 blr@\
199.endif
200
201
202/*
203 * Macros for declaring procedures
204 *
205 * Use of these macros allows ctags to have a predictable way
206 * to find various types of declarations. They also simplify
207 * inserting appropriate symbol table information.
208 *
209 * NOTE: these simple stubs will be replaced with more
210 * complicated versions once we know what the linker and gdb
211 * will require as far as register use masks and frame declarations.
212 * These macros may also be ifdef'ed in the future to contain profiling
213 * code.
214 *
215 * FIXME: Document what makes a leaf a LEAF and a handler a HANDLER.
216 * (E.g. leaf's have return pc in lr, NESTED's have rpc in offset off
217 * sp, handlers have rpc in exception frame which is found via exception
218 * link, etc etc.)
219 */
220
221/*
222 * TEXT -- declare start of text segment
223 */
224#defineTEXT\
225.text@\
226.align 2
227
228/*
229 * LEAF -- declare global leaf procedure
230 * NOTE: Control SHOULD NOT FLOW into a LEAF! A LEAF should only
231 * be jumped to. (A leaf may do an align.) Use a LABEL() if you
232 * need control to flow into the label.
233 */
234#defineLEAF(name)\
235.align 2@\
236.globlname@\
237name:@\
238.set__framesize,0
239
240/*
241 * X_LEAF -- declare alternate global label for leaf
242 */
243#defineX_LEAF(name, value)\
244.globlname@\
245.setname,value
246
247/*
248 * P_LEAF -- declare private leaf procedure
249 */
250#defineP_LEAF(name)\
251.align 2@\
252name:@\
253.set__framesize,0
254
255/*
256 * LABEL -- declare a global code label
257 * MUST be used (rather than LEAF, NESTED, etc) if control
258 * "flows into" the label.
259 */
260#defineLABEL(name)\
261.align 2@\
262.globlname@\
263name:
264
265/*
266 * NESTED -- declare procedure that invokes other procedures
267 */
268#defineNESTED(name, localvarsize, maxargsout, grfsaved, fpfsaved)\
269.align 2@\
270.globlname@\
271name:@\
272BUILD_FRAME(localvarsize, maxargsout, grfsaved, fpfsaved)
273
274/*
275 * X_NESTED -- declare alternate global label for nested proc
276 */
277#defineX_NESTED(name, value)\
278.globlname@\
279.setname,value
280
281/*
282 * P_NESTED -- declare private nested procedure
283 */
284#defineP_NESTED(name, localvarsize, maxargsout, grfsaved, fpfsaved)\
285.align 2@\
286name:@\
287BUILD_FRAME(locavarsize, maxargsout, grfsaved, fpfsaved)
288
289/*
290 * HANDLER -- declare procedure with exception frame rather than
291 * standard C frame
292 */
293#defineHANDLER(name)\
294.align 2@\
295.globlname@\
296name:
297
298/*
299 * X_HANDLER -- declare alternate name for exception handler
300 * (Should appear immediately before a HANDLER declaration or
301 * another X_HANDLER declaration)
302 */
303#defineX_HANDLER(name)\
304.align 2@\
305.globlname@\
306name:
307
308/*
309 * P_HANDLER -- declare private handler
310 */
311#defineP_HANDLER(name)\
312.align 2@\
313name:
314
315/*
316 * END -- mark end of procedure
317 * FIXME: Unimplemented for now.
318 */
319#defineEND(name)
320
321/*
322 * BL -- call procedure (relative)
323 */
324#defineBL(name)\
325blname
326
327/*
328 * Storage definition macros
329 * The main purpose of these is to allow an easy handle for ctags
330 */
331
332/*
333 * IMPORT -- import symbol
334 */
335#defineIMPORT(name)\
336.referencename
337
338/*
339 * ABS -- declare global absolute symbol
340 */
341#defineABS(name, value)\
342.globlname@\
343.setname,value
344
345/*
346 * P_ABS -- declare private absolute symbol
347 */
348#defineP_ABS(name, value)\
349.setname,value
350
351/*
352 * EXPORT -- declare global label for data
353 */
354#defineEXPORT(name)\
355.align 2@\
356.globlname@\
357name:
358
359/*
360 * BSS -- declare global zero'ed storage
361 */
362#defineBSS(name,size)\
363.commname,size
364
365
366/*
367 * P_BSS -- declare private zero'ed storage
368 */
369#defineP_BSS(name,size)\
370.lcommname,size
371
372/*
373 * dynamic/PIC macros for routines which reference external symbols
374 */
375#if defined(__DYNAMIC__)
376#define PICIFY_REG r12
377
378/* Assume that the lr is saved before calling any of these macros */
379/* using PICIFY() */
380
381#define PICIFY(var)\
382mflrr0@\
383bcl20,31,1f@\
3841:mflrPICIFY_REG@\
385mtlrr0@\
386addisPICIFY_REG, PICIFY_REG, ha16(L ## var ## __non_lazy_ptr - 1b) @\
387lwzPICIFY_REG, lo16(L ## var ## __non_lazy_ptr - 1b)(PICIFY_REG)
388
389#define CALL_EXTERN_AGAIN(var)\
390PICIFY(var)@\
391mtctrPICIFY_REG@\
392mflrr0@\
393stwr0,8(r1)@\
394stwur1,-64(r1)@\
395bctrl@\
396addicr1,r1,64 @\
397lwzr0,8(r1)@\
398mtlrr0
399
400#define NON_LAZY_STUB(var)\
401.non_lazy_symbol_pointer@\
402.align 2@\
403L ## var ## __non_lazy_ptr:@\
404.indirect_symbol var@\
405.long 0@\
406.text@\
407.align 2
408
409#defineBRANCH_EXTERN(var)\
410PICIFY(var)@\
411mtctrPICIFY_REG@\
412bctr@\
413NON_LAZY_STUB(var)
414
415#define CALL_EXTERN(var)\
416CALL_EXTERN_AGAIN(var)@\
417NON_LAZY_STUB(var)
418
419#define REG_TO_EXTERN(reg, var)\
420PICIFY(var)@\
421stw reg, 0(PICIFY_REG)@\
422NON_LAZY_STUB(var)
423
424#define EXTERN_TO_REG(reg, var)\
425PICIFY(var)@\
426lwzreg, 0(PICIFY_REG)@\
427NON_LAZY_STUB(var)
428
429#else /* ! __DYNAMIC__ */
430#define TMP_REG r12
431#define BRANCH_EXTERN(var)\
432bvar
433
434#define CALL_EXTERN(var)\
435blvar
436
437#define CALL_EXTERN_AGAIN(var)\
438CALL_EXTERN(var)
439
440#define REG_TO_EXTERN(reg, var)\
441lisTMP_REG, ha16(var)@\
442stwreg, lo16(var)(TMP_REG)
443
444#define EXTERN_TO_REG(reg, var)\
445lisreg, ha16(var)@\
446lwzreg, lo16(var)(reg)
447
448#endif/* __DYNAMIC__ */
449
450#endif/* __ASSEMBLER__ */
451#endif/* _ARCH_PPC_ASM_HELP_H_ */
452

Archive Download this file

Revision: 1672