]> git.saurik.com Git - apple/libc.git/blob - include/asm.h
c320363b84091cd66304f629ea29768d6099603e
[apple/libc.git] / include / asm.h
1 /*
2 * Copyright (c) 2003 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 /*
24 * @OSF_COPYRIGHT@
25 */
26
27 #ifndef _PPC_ASM_H_
28 #define _PPC_ASM_H_
29
30 #ifdef __ELF__
31 #define __NO_UNDERSCORES__ 1
32 #define __ASMNL__ ;
33 #else
34 #define __ASMNL__ @
35 #endif
36
37 #ifdef ASSEMBLER
38
39 #ifdef __ELF__
40 #define r0 0
41 #define r1 1
42 #define r2 2
43 #define r3 3
44 #define r4 4
45 #define r5 5
46 #define r6 6
47 #define r7 7
48 #define r8 8
49 #define r9 9
50 #define r10 10
51 #define r11 11
52 #define r12 12
53 #define r13 13
54 #define r14 14
55 #define r15 15
56 #define r16 16
57 #define r17 17
58 #define r18 18
59 #define r19 19
60 #define r20 20
61 #define r21 21
62 #define r22 22
63 #define r23 23
64 #define r24 24
65 #define r25 25
66 #define r26 26
67 #define r27 27
68 #define r28 28
69 #define r29 29
70 #define r30 30
71 #define r31 31
72
73 #define f0 0
74 #define f1 1
75 #define f2 2
76 #define f3 3
77 #define f4 4
78 #define f5 5
79 #define f6 6
80 #define f7 7
81 #define f8 8
82 #define f9 9
83 #define f10 10
84 #define f11 11
85 #define f12 12
86 #define f13 13
87 #define f14 14
88 #define f15 15
89 #define f16 16
90 #define f17 17
91 #define f18 18
92 #define f19 19
93 #define f20 20
94 #define f21 21
95 #define f22 22
96 #define f23 23
97 #define f24 24
98 #define f25 25
99 #define f26 26
100 #define f27 27
101 #define f28 28
102 #define f29 29
103 #define f30 30
104 #define f31 31
105
106 #define sr0 0
107 #define sr1 1
108 #define sr2 2
109 #define sr3 3
110 #define sr4 4
111 #define sr5 5
112 #define sr6 6
113 #define sr7 7
114 #define sr8 8
115 #define sr9 9
116 #define sr10 10
117 #define sr11 11
118 #define sr12 12
119 #define sr13 13
120 #define sr14 14
121 #define sr15 15
122 #define sr16 16
123 #define sr17 17
124 #define sr18 18
125 #define sr19 19
126 #define sr20 20
127 #define sr21 21
128 #define sr22 22
129 #define sr23 23
130 #define sr24 24
131 #define sr25 25
132 #define sr26 26
133 #define sr27 27
134 #define sr28 28
135 #define sr29 29
136 #define sr30 30
137 #define sr31 31
138 #endif
139
140 #define ARG0 r3
141 #define ARG1 r4
142 #define ARG2 r5
143 #define ARG3 r6
144 #define ARG4 r7
145 #define ARG5 r8
146 #define ARG6 r9
147 #define ARG7 r10
148
149 #define tmp0 r0 /* Temporary GPR remapping (603e specific) */
150 #define tmp1 r1
151 #define tmp2 r2
152 #define tmp3 r3
153
154 /* SPR registers */
155
156 #define dmiss 976 /* ea that missed */
157 #define dcmp 977 /* compare value for the va that missed */
158 #define hash1 978 /* pointer to first hash pteg */
159 #define hash2 979 /* pointer to second hash pteg */
160 #define imiss 980 /* ea that missed */
161 #define icmp 981 /* compare value for the va that missed */
162 #define rpa 982 /* required physical address register */
163
164 #define iabr 1010 /* instruction address breakpoint register */
165 #define pir 1023 /* Processor ID Register */
166
167 /* MQ register on the 601 */
168 #define mq 0 /* spr number for mq register on 601 */
169
170 #define IBAT0U 528
171 #define IBAT0L 529
172 #define IBAT1U 530
173 #define IBAT1L 531
174 #define IBAT2U 532
175 #define IBAT2L 533
176 #define IBAT3U 534
177 #define IBAT3L 535
178 #define ibat0u 528
179 #define ibat0l 529
180 #define ibat1u 530
181 #define ibat1l 531
182 #define ibat2u 532
183 #define ibat2l 533
184 #define ibat3u 534
185 #define ibat3l 535
186
187 #define DBAT0U 536
188 #define DBAT0L 537
189 #define DBAT1U 538
190 #define DBAT1L 539
191 #define DBAT2U 540
192 #define DBAT2L 541
193 #define DBAT3U 542
194 #define DBAT3L 543
195 #define dbat0u 536
196 #define dbat0l 537
197 #define dbat1u 538
198 #define dbat1l 539
199 #define dbat2u 540
200 #define dbat2l 541
201 #define dbat3u 542
202 #define dbat3l 543
203
204 #define HID0 1008
205 #define hid0 1008
206 #define HID1 1009
207 #define hid1 1009
208 #define SDR1 25
209 #define sprg0 272
210 #define sprg1 273
211 #define sprg2 274
212 #define sprg3 275
213 #define ppcDAR 19
214 #define ppcdar 19
215 #define srr0 26
216 #define srr1 27
217
218 #define CR0 0
219 #define CR1 1
220 #define CR2 2
221 #define CR3 3
222 #define CR4 4
223 #define CR5 5
224 #define CR6 6
225 #define CR7 7
226
227 #ifdef __ELF__
228 #define cr0 0
229 #define cr1 1
230 #define cr2 2
231 #define cr3 3
232 #define cr4 4
233 #define cr5 5
234 #define cr6 6
235 #define cr7 7
236 #endif
237
238 #define cr0_lt 0
239 #define cr0_gt 1
240 #define cr0_eq 2
241 #define cr0_so 3
242 #define cr0_un 3
243
244 /*
245 * Macros to access high and low word values of an address
246 */
247
248 #ifndef __ELF__
249 #define HIGH_CADDR(x) ha16(x)
250 #define HIGH_ADDR(x) hi16(x)
251 #define LOW_ADDR(x) lo16(x)
252 #else
253 #define HIGH_CADDR(x) x@ha
254 #define HIGH_ADDR(x) x@h
255 #define LOW_ADDR(x) x@l
256 #endif /* __ELF__ */
257
258 #endif /* ASSEMBLER */
259
260 /* Tags are placed before Immediately Following Code (IFC) for the debugger
261 * to be able to deduce where to find various registers when backtracing
262 *
263 * We only define the values as we use them, see SVR4 ABI PowerPc Supplement
264 * for more details (defined in ELF spec).
265 */
266
267 #define TAG_NO_FRAME_USED 0x00000000
268
269 /* (should use genassym to get these offsets) */
270
271 #define FM_BACKPTR 0
272 /* TODO NMGS FM_SIZE 8 is ok according to EABI specs, but gcc uses 16 */
273 #ifdef __ELF__
274 #define FM_LR_SAVE 4 /* gcc 2.7.1 is now following eabi spec correctly */
275 #define FM_SIZE 16 /* minimum frame contents, backptr and LR save */
276 #define FM_ARG0 8
277 #else
278 #define FM_CR_SAVE 4
279 #define FM_LR_SAVE 8 /* Rhapsody iS NOT following the ABI at the moment.. */
280 #define FM_SIZE 72 /* minimum frame contents, backptr and LR save */
281 #define FM_ARG0 56
282 #endif
283
284 #define FM_ELF_ARG0 8
285 #define FM_MACHO_ARG0 56
286 #define MACHO_SYSCALL_BEGIN 0x2000
287 #define PK_SYSCALL_BEGIN 0x7000
288
289
290 /* redzone is the area under the stack pointer which must be preserved
291 * when taking a trap, interrupt etc. This is no longer needed as gcc
292 * (2.7.2 and above) now follows ELF spec correctly and never loads/stores
293 * below the frame pointer
294 */
295 #ifdef __ELF__
296 #define FM_REDZONE 0 /* was ((32-14+1)*4) */
297 #else
298 #define FM_REDZONE 224 /* is ((32-14+1)*4) */
299 #endif
300
301 #define COPYIN_ARG0_OFFSET FM_ARG0
302
303 #ifdef MACH_KERNEL_BUILD
304 #include <mach_kdb.h>
305 #else /* MACH_KERNEL */
306 #define MACH_KDB 0
307 #endif /* MACH_KERNEL */
308
309 #define BREAKPOINT_TRAP twge r2,r2
310
311 /* There is another definition of ALIGN for .c sources */
312 #ifndef __LANGUAGE_ASSEMBLY
313 #define ALIGN 2
314 #endif /* __LANGUAGE_ASSEMBLY */
315
316 #ifndef FALIGN
317 #define FALIGN 2 /* Align functions on words for now. Cachelines is better */
318 #endif
319
320 #define LB(x,n) n
321 #if __STDC__
322 #ifndef __NO_UNDERSCORES__
323 #define LCL(x) L ## x
324 #define EXT(x) _ ## x
325 #define LEXT(x) _ ## x ## :
326 #else
327 #define LCL(x) .L ## x
328 #define EXT(x) x
329 #define LEXT(x) x ## :
330 #endif
331 #define LBc(x,n) n ## :
332 #define LBb(x,n) n ## b
333 #define LBf(x,n) n ## f
334 #else /* __STDC__ */
335 #ifndef __NO_UNDERSCORES__
336 #define LCL(x) L/**/x
337 #define EXT(x) _/**/x
338 #define LEXT(x) _/**/x/**/:
339 #else /* __NO_UNDERSCORES__ */
340 #define LCL(x) .L/**/x
341 #define EXT(x) x
342 #define LEXT(x) x/**/:
343 #endif /* __NO_UNDERSCORES__ */
344 #define LBc(x,n) n/**/:
345 #define LBb(x,n) n/**/b
346 #define LBf(x,n) n/**/f
347 #endif /* __STDC__ */
348
349 #define String .asciz
350 #define Value .word
351 #define Times(a,b) (a*b)
352 #define Divide(a,b) (a/b)
353
354 #define data16 .byte 0x66
355 #define addr16 .byte 0x67
356
357 #if !GPROF
358 #define MCOUNT
359
360 #elif defined(__SHARED__)
361 #define MCOUNT ; .data;\
362 .align ALIGN;\
363 LBc(x, 8) .long 0;\
364 .text;\
365 Gpush;\
366 Gload;\
367 leal Gotoff(LBb(x,8)),%edx;\
368 Egaddr(%eax,_mcount_ptr);\
369 Gpop;\
370 call *(%eax);
371
372 #else /* !GPROF, !__SHARED__ */
373 #define MCOUNT ; .data;\
374 .align ALIGN;\
375 LBc(x, 8) .long 0;\
376 .text;\
377 movl $LBb(x,8),%edx;\
378 call *EXT(_mcount_ptr);
379
380 #endif /* GPROF */
381
382 #ifdef __ELF__
383 #define ELF_FUNC(x) .type x,@function
384 #define ELF_DATA(x) .type x,@object
385 #define ELF_SIZE(x,s) .size x,s
386 #else
387 #define ELF_FUNC(x)
388 #define ELF_DATA(x)
389 #define ELF_SIZE(x,s)
390 #endif
391
392 #ifdef __ELF__
393 #define Entry(x,tag) .globl EXT(x); ELF_FUNC(EXT(x)); .long tag;.align FALIGN; LEXT(x)
394 #define ENTRY(x,tag) Entry(x,tag) MCOUNT
395 #define ENTRY2(x,y,tag) .globl EXT(x); .globl EXT(y); \
396 ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \
397 .align FALIGN; LEXT(x); LEXT(y) \
398 MCOUNT
399 #if __STDC__
400 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
401 #else
402 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
403 #endif /* __STDC__ */
404 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
405
406 #else /* __ELF__ */
407
408 #define Entry(x,tag) .text@.align FALIGN@ .globl EXT(x)@ LEXT(x)
409 #define ENTRY(x,tag) Entry(x,tag)@MCOUNT
410 #define ENTRY2(x,y,tag) .text@ .align FALIGN@ .globl EXT(x)@ .globl EXT(y)@ \
411 LEXT(x)@ LEXT(y) @\
412 MCOUNT
413 #if __STDC__
414 #define ASENTRY(x) .globl x @ .align FALIGN; x ## @ MCOUNT
415 #else
416 #define ASENTRY(x) .globl x @ .align FALIGN; x @ MCOUNT
417 #endif /* __STDC__ */
418 #define DATA(x) .globl EXT(x) @ .align ALIGN @ LEXT(x)
419 #endif
420
421
422
423 #define End(x) ELF_SIZE(x,.-x)
424 #define END(x) End(EXT(x))
425 #define ENDDATA(x) END(x)
426 #define Enddata(x) End(x)
427
428 /* These defines are here for .c files that wish to reference global symbols
429 * within __asm__ statements.
430 */
431 #ifndef __NO_UNDERSCORES__
432 #define CC_SYM_PREFIX "_"
433 #else
434 #define CC_SYM_PREFIX ""
435 #endif /* __NO_UNDERSCORES__ */
436
437 #endif /* _PPC_ASM_H_ */