]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/ppc/asm_help.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1996 NeXT Software, Inc. All rights reserved.
24 * File: architecture/ppc/asm_help.h
25 * Author: Mike DeMoney, NeXT Software, Inc.
27 * This header file defines macros useful when writing assembly code
28 * for the PowerPC processors.
29 * r12 is used as the tmp register / PICIFY base.
32 * 20-May-97 Umesh Vaishampayan (umeshv@apple.com)
33 * Implemented Dynamic / PIC macros.
35 * 28-Dec-96 Umesh Vaishampayan (umeshv@NeXT.com)
36 * added ".align" directive to various macros to avoid alignment
37 * faults. Moved Register Usage #defines to reg_help.h as that's
38 * where they should have been in the first place.
39 * Added Dynamic / PIC macroes for routines which refernce external
40 * symbols. Not implemented fully as yet.
42 * 05-Nov-92 Mike DeMoney (mike@next.com)
46 #ifndef _ARCH_PPC_ASM_HELP_H_
47 #define _ARCH_PPC_ASM_HELP_H_
49 #include <architecture/ppc/reg_help.h>
53 * ppc stack frames look like this after procedure prolog has
58 * +-------------------------------+
60 * +-------------------------------+
62 * +-------------------------------+
63 * Caller's SP->| caller's caller's sp | ^^ Caller's Frame ^^
64 * +===============================+ vv Called Rtn Frame vv
65 * | Save Area for | FPF 31
67 * | Caller's FPF's | FPF n
68 * +-------------------------------+
69 * | Save Area for | GRF 31
71 * | Caller's GRF's | GRF n
72 * +-------------------------------+
76 * +-------------------------------+
80 * +-------------------------------+
81 * SP + X -> | aN for FUTURE call |
82 * +-------------------------------+
84 * +-------------------------------+
85 * SP + 28 -> | a1 for FUTURE call |
86 * +-------------------------------+
87 * SP + 24 -> | a0 for FUTURE call |
88 * +-------------------------------+
89 * SP + 20 -> | caller's TOC |
90 * +-------------------------------+
91 * SP + 16 -> | reserved |
92 * +-------------------------------+
93 * SP + 12 -> | reserved |
94 * +-------------------------------+
95 * SP + 8 -> | LR callee-save for FUTURE call|
96 * +-------------------------------+
97 * SP + 4 -> | CR callee-save for FUTURE call|
98 * +-------------------------------+
99 * SP -> | caller's sp |
100 * +===============================+
103 * NOTE: All state with the exception of LR and CR are saved in the
104 * called routines frame. LR and CR are saved in the CALLER'S FRAME.
106 * ALSO NOTE: Args to the called routine are found in the caller's frame.
110 * ARG(n) -- stack offset to n'th argument
112 * NOTE CAREFULLY! These macros start numbering arguments at 1 (NOT 0)
113 * The first argument is ARG(1).
115 * ALSO NOTE: This stack offset is only valid if using routine
119 #define ARG(n) ((((n) - 1) * 4) + 24)
122 * Macros for building stack frame according to C calling conventions.
123 * lr, cr, and sp are saved.
125 * NOTE WELL: localvarsize is in bytes, maxargsout is a count of words,
126 * grfsaved and fpfsaved is a count of registers. BE SURE TO COUNT
127 * BOTH FP (r31) AND sN REGISTERS IN THE COUNT OF GRF REGISTERS SAVED!
128 * This will be TWO more than the N of the highest sN register you
129 * save: s2 implies you are saving s2, s1, s0, and fp => grfsaved
132 * FURTHER NOTE: These macros do NOT SAVE GRF or FPF registers. User
133 * must do that. GRF sN regs should be saved via
134 * stmw sN,SAVED_GRF_S(N)(sp)
135 * where N is the highest numbered s* register to be saved. E.g. if
136 * s0, s1, and s2 are to be saved use:
137 * stmw s2,SAVED_GRF_S(2)(sp)
138 * Note that this also saves fp.
139 * An individual saved grf can be loaded via:
140 * lwz s2,SAVED_GRF_S(2)(sp)
141 * Analogous stuff works for fpf's.
143 * NOTE: these simple routines will be replaced with more complicated
144 * ones once we know what the linker and gdb will require as for as
145 * register use masks and frame declarations.
147 * Warning: ROUND_TO_STACK is only to be used in assembly language;
148 * for C usage, use ROUND_FRAME() in reg_help.h.
150 #define ROUND_TO_STACK(len) \
151 (((len) + STACK_INCR - 1) / STACK_INCR * STACK_INCR)
153 #define BUILD_FRAME(localvarsize, maxargsout, grfsaved, fpfsaved) \
154 .set __argoutsize, ROUND_TO_STACK((maxargsout) * 4) @\
155 .if __argoutsize < 32 @\
156 .set __argoutsize,32 @\
158 .set __framesize, ROUND_TO_STACK( \
159 24 + __argoutsize + (localvarsize) \
160 + 4*(grfsaved) + 8*(fpfsaved)) @\
161 .set __grfbase,(__framesize - 4*(grfsaved) - 8*(fpfsaved)) @\
162 .set __fpfbase,(__framesize - 8*(fpfsaved)) @\
167 stwu r1,-__framesize(r1)
170 * Macros for referencing data in stack frame.
172 * NOTE WELL: ARG's and VAR's start at 1, NOT 0. Why ??? (FIXME)
174 #define LOCAL_VAR(n) (((n)-1)*4 + __argoutsize + 24)
175 #define SAVED_GRF_S(n) (__grfbase + ((grfsaved) - (n) - 2) * 4)
176 #define SAVED_FRF_FS(n) (__fpfbase + ((fpfsaved) - (n) - 1) * 4)
177 #define ARG_IN(n) (ARG(n) + __framesize)
178 #define ARG_OUT(n) (ARG(n) + 0)
179 #define SAVED_FP (__grfbase + ((grfsaved) - 1) * 4)
180 #define SAVED_LR (__framesize + 8)
181 #define SAVED_CR (__framesize + 4)
184 * Macros for unwinding stack frame.
185 * NOTE: GRF's and FPF's are NOT RESTORED. User must do this before
190 lwz32 r0,r1,SAVED_LR @\
191 lwz32 r12,r1,SAVED_CR @\
192 addic sp,r1,__framesize @\
202 * Macros for declaring procedures
204 * Use of these macros allows ctags to have a predictable way
205 * to find various types of declarations. They also simplify
206 * inserting appropriate symbol table information.
208 * NOTE: these simple stubs will be replaced with more
209 * complicated versions once we know what the linker and gdb
210 * will require as far as register use masks and frame declarations.
211 * These macros may also be ifdef'ed in the future to contain profiling
214 * FIXME: Document what makes a leaf a LEAF and a handler a HANDLER.
215 * (E.g. leaf's have return pc in lr, NESTED's have rpc in offset off
216 * sp, handlers have rpc in exception frame which is found via exception
221 * TEXT -- declare start of text segment
228 * LEAF -- declare global leaf procedure
229 * NOTE: Control SHOULD NOT FLOW into a LEAF! A LEAF should only
230 * be jumped to. (A leaf may do an align.) Use a LABEL() if you
231 * need control to flow into the label.
240 * X_LEAF -- declare alternate global label for leaf
242 #define X_LEAF(name, value) \
247 * P_LEAF -- declare private leaf procedure
249 #define P_LEAF(name) \
255 * LABEL -- declare a global code label
256 * MUST be used (rather than LEAF, NESTED, etc) if control
257 * "flows into" the label.
259 #define LABEL(name) \
265 * NESTED -- declare procedure that invokes other procedures
267 #define NESTED(name, localvarsize, maxargsout, grfsaved, fpfsaved)\
271 BUILD_FRAME(localvarsize, maxargsout, grfsaved, fpfsaved)
274 * X_NESTED -- declare alternate global label for nested proc
276 #define X_NESTED(name, value) \
281 * P_NESTED -- declare private nested procedure
283 #define P_NESTED(name, localvarsize, maxargsout, grfsaved, fpfsaved)\
286 BUILD_FRAME(locavarsize, maxargsout, grfsaved, fpfsaved)
289 * HANDLER -- declare procedure with exception frame rather than
292 #define HANDLER(name) \
298 * X_HANDLER -- declare alternate name for exception handler
299 * (Should appear immediately before a HANDLER declaration or
300 * another X_HANDLER declaration)
302 #define X_HANDLER(name) \
308 * P_HANDLER -- declare private handler
310 #define P_HANDLER(name) \
315 * END -- mark end of procedure
316 * FIXME: Unimplemented for now.
321 * BL -- call procedure (relative)
327 * Storage definition macros
328 * The main purpose of these is to allow an easy handle for ctags
332 * IMPORT -- import symbol
334 #define IMPORT(name) \
338 * ABS -- declare global absolute symbol
340 #define ABS(name, value) \
345 * P_ABS -- declare private absolute symbol
347 #define P_ABS(name, value) \
351 * EXPORT -- declare global label for data
353 #define EXPORT(name) \
359 * BSS -- declare global zero'ed storage
361 #define BSS(name,size) \
366 * P_BSS -- declare private zero'ed storage
368 #define P_BSS(name,size) \
372 * dynamic/PIC macros for routines which reference external symbols
374 #if defined(__DYNAMIC__)
375 #define PICIFY_REG r12
377 /* Assume that the lr is saved before calling any of these macros */
380 #define PICIFY(var) \
383 1: mflr PICIFY_REG @\
385 addis PICIFY_REG, PICIFY_REG, ha16(L ## var ## $non_lazy_ptr - 1b) @\
386 lwz PICIFY_REG, lo16(L ## var ## $non_lazy_ptr - 1b)(PICIFY_REG)
388 #define CALL_EXTERN_AGAIN(var) \
399 #define NON_LAZY_STUB(var) \
400 .non_lazy_symbol_pointer @\
402 L ## var ## $non_lazy_ptr: @\
403 .indirect_symbol var @\
408 #define BRANCH_EXTERN(var) \
414 #define CALL_EXTERN(var) \
415 CALL_EXTERN_AGAIN(var) @\
418 #define REG_TO_EXTERN(reg, var) \
420 stw reg, 0(PICIFY_REG) @\
423 #define EXTERN_TO_REG(reg, var) \
425 lwz reg, 0(PICIFY_REG) @\
428 #else /* ! __DYNAMIC__ */
430 #define BRANCH_EXTERN(var) \
433 #define CALL_EXTERN(var) \
436 #define CALL_EXTERN_AGAIN(var) \
439 #define REG_TO_EXTERN(reg, var) \
440 lis TMP_REG, ha16(var) @\
441 stw reg, lo16(var)(TMP_REG)
443 #define EXTERN_TO_REG(reg, var) \
444 lis reg, ha16(var) @\
445 lwz reg, lo16(var)(reg)
447 #endif /* __DYNAMIC__ */
449 #endif /* __ASSEMBLER__ */
450 #endif /* _ARCH_PPC_ASM_HELP_H_ */