asm.h revision 1.26.26.3 1 /* $NetBSD: asm.h,v 1.26.26.3 2011/01/26 08:51:12 matt Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef _PPC_ASM_H_
35 #define _PPC_ASM_H_
36
37 #ifdef _LP64
38
39 /* ppc64 is always PIC, r2 is always the TOC */
40
41 #define PIC_PLT(x) .x
42
43 #else
44
45 #ifdef PIC
46 #define PIC_PROLOGUE XXX
47 #define PIC_EPILOGUE XXX
48 #define PIC_PLT(x) x@plt
49 #ifdef __STDC__
50 #define PIC_GOT(x) XXX
51 #define PIC_GOTOFF(x) XXX
52 #else /* not __STDC__ */
53 #define PIC_GOT(x) XXX
54 #define PIC_GOTOFF(x) XXX
55 #endif /* __STDC__ */
56 #else
57 #define PIC_PROLOGUE
58 #define PIC_EPILOGUE
59 #define PIC_PLT(x) x
60 #define PIC_GOT(x) x
61 #define PIC_GOTOFF(x) x
62 #endif
63
64 #endif
65
66 #define _C_LABEL(x) x
67 #define _ASM_LABEL(x) x
68
69 #define _GLOBAL(x) \
70 .data; .align 2; .globl x; x:
71
72 #ifdef GPROF
73 # define _PROF_PROLOGUE mflr 0; stw 0,4(1); bl _mcount
74 #else
75 # define _PROF_PROLOGUE
76 #endif
77
78 #ifdef _LP64
79
80 #define SF_HEADER_SZ 48
81 #define SF_PARAM_SZ 64
82 #define SF_SZ (SF_HEADER_SZ + SF_PARAM_SZ)
83
84 #define SF_SP 0
85 #define SF_CR 8
86 #define SF_LR 16
87 #define SF_PARAM SF_HEADER_SZ
88
89 #define ENTRY(y) \
90 .globl y; \
91 .section ".opd","aw"; \
92 .align 3; \
93 y: .quad .y,.TOC.@tocbase,0; \
94 .previous; \
95 .size y,24; \
96 .type .y,@function; \
97 .globl .y; \
98 .align 3; \
99 .y:
100
101 #define CALL(y) \
102 bl .y; \
103 nop
104
105 #define ENTRY_NOPROFILE(y) ENTRY(y)
106 #define ASENTRY(y) ENTRY(y)
107 #else
108
109 #define _ENTRY(x) \
110 .text; .align 2; .globl x; .type x,@function; x:
111
112 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
113 #define END(x) .size _C_LABEL(x),.-_C_LABEL(x)
114
115 #define ENTRY_NOPROFILE(y) _ENTRY(_C_LABEL(y))
116
117 #define CALL(y) \
118 bl y
119
120 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
121 #endif
122
123 #define GLOBAL(y) _GLOBAL(_C_LABEL(y))
124
125 #define ASMSTR .asciz
126
127 #define RCSID(x) .pushsection ".ident"; .asciz x; .popsection
128
129 #ifdef __ELF__
130 #define WEAK_ALIAS(alias,sym) \
131 .weak alias; \
132 alias = sym
133 #endif
134 /*
135 * STRONG_ALIAS: create a strong alias.
136 */
137 #define STRONG_ALIAS(alias,sym) \
138 .globl alias; \
139 alias = sym
140
141 #ifdef __STDC__
142 #define WARN_REFERENCES(_sym,_msg) \
143 .section .gnu.warning. ## _sym ; .ascii _msg ; .text
144 #else
145 #define WARN_REFERENCES(_sym,_msg) \
146 .section .gnu.warning./**/_sym ; .ascii _msg ; .text
147 #endif /* __STDC__ */
148
149 #ifdef _KERNEL
150 /*
151 * Get cpu_info pointer for current processor. Always in SPRG0. *ALWAYS*
152 */
153 #define GET_CPUINFO(r) mfsprg r,0
154 /*
155 * IN:
156 * R4[er] = first free byte beyond end/esym.
157 *
158 * OUT:
159 * R1[sp] = new kernel stack
160 * R4[er] = kernelend
161 */
162
163 #ifdef CI_INTSTK
164 #define INIT_CPUINFO_INTSTK(er,tmp1) \
165 addi er,er,INTSTK; \
166 stptr er,CI_INTSTK(tmp1)
167 #else
168 #define INIT_CPUINFO_INTSTK(er,tmp1) /* nothing */
169 #endif
170
171 #define INIT_CPUINFO(er,sp,tmp1,tmp2) \
172 li tmp1,PGOFSET; \
173 add er,er,tmp1; \
174 andc er,er,tmp1; /* page align */ \
175 lis tmp1,_C_LABEL(cpu_info)@ha; \
176 addi tmp1,tmp1,_C_LABEL(cpu_info)@l; \
177 mtsprg0 tmp1; /* save for later use */ \
178 INIT_CPUINFO_INTSTK(er,tmp1); \
179 lis tmp2,_C_LABEL(emptyidlespin)@h; \
180 ori tmp2,tmp2,_C_LABEL(emptyidlespin)@l; \
181 stptr tmp2,CI_IDLESPIN(tmp1); \
182 li tmp2,-1; \
183 stint tmp2,CI_IDEPTH(tmp1); \
184 li tmp2,0; \
185 stptr er,CI_CURPCB(tmp1); \
186 lis tmp1,_C_LABEL(proc0paddr)@ha; \
187 stptr er,_C_LABEL(proc0paddr)@l(tmp1); \
188 addi er,er,USPACE; /* stackpointer for lwp0 */ \
189 addi sp,er,-(FRAMELEN+CALLFRAMELEN); /* sp for lwp0 */ \
190 /* er = end of mem reserved for kernel */ \
191 stptru tmp2,-CALLFRAMELEN(sp) /* end of stack chain */
192
193 #endif /* KERNEL */
194
195 /* Condition Register Bit Fields */
196
197 #if !defined(_NOREGNAMES)
198 #if defined(_KERNEL) || defined(_STANDALONE)
199 #define cr0 0
200 #define cr1 1
201 #define cr2 2
202 #define cr3 3
203 #define cr4 4
204 #define cr5 5
205 #define cr6 6
206 #define cr7 7
207 #endif
208
209 /* General Purpose Registers (GPRs) */
210
211 #if defined(_KERNEL) || defined(_STANDALONE)
212 #define r0 0
213 #define r1 1
214 #define r2 2
215 #define r3 3
216 #define r4 4
217 #define r5 5
218 #define r6 6
219 #define r7 7
220 #define r8 8
221 #define r9 9
222 #define r10 10
223 #define r11 11
224 #define r12 12
225 #define r13 13
226 #define r14 14
227 #define r15 15
228 #define r16 16
229 #define r17 17
230 #define r18 18
231 #define r19 19
232 #define r20 20
233 #define r21 21
234 #define r22 22
235 #define r23 23
236 #define r24 24
237 #define r25 25
238 #define r26 26
239 #define r27 27
240 #define r28 28
241 #define r29 29
242 #define r30 30
243 #define r31 31
244 #endif
245
246 /* Floating Point Registers (FPRs) */
247
248 #if defined(_KERNEL) || defined(_STANDALONE)
249 #define fr0 0
250 #define fr1 1
251 #define fr2 2
252 #define fr3 3
253 #define fr4 4
254 #define fr5 5
255 #define fr6 6
256 #define fr7 7
257 #define fr8 8
258 #define fr9 9
259 #define fr10 10
260 #define fr11 11
261 #define fr12 12
262 #define fr13 13
263 #define fr14 14
264 #define fr15 15
265 #define fr16 16
266 #define fr17 17
267 #define fr18 18
268 #define fr19 19
269 #define fr20 20
270 #define fr21 21
271 #define fr22 22
272 #define fr23 23
273 #define fr24 24
274 #define fr25 25
275 #define fr26 26
276 #define fr27 27
277 #define fr28 28
278 #define fr29 29
279 #define fr30 30
280 #define fr31 31
281 #endif
282 #endif /* !_NOREGNAMES */
283
284 /*
285 * Add some psuedo instructions to made sharing of assembly versions of
286 * ILP32 and LP64 code possible.
287 */
288 #define ldint lwz /* not needed but for completeness */
289 #define ldintu lwzu /* not needed but for completeness */
290 #define stint stw /* not needed but for completeness */
291 #define stintu stwu /* not needed but for completeness */
292
293 #ifndef _LP64
294
295 #define ldlong lwz /* load "C" long */
296 #define ldlongu lwzu /* load "C" long with udpate */
297 #define stlong stw /* load "C" long */
298 #define stlongu stwu /* load "C" long with udpate */
299 #define ldptr lwz /* load "C" pointer */
300 #define ldptru lwzu /* load "C" pointer with udpate */
301 #define stptr stw /* load "C" pointer */
302 #define stptru stwu /* load "C" pointer with udpate */
303 #define ldreg lwz /* load PPC general register */
304 #define ldregu lwzu /* load PPC general register with udpate */
305 #define streg stw /* load PPC general register */
306 #define stregu stwu /* load PPC general register with udpate */
307 #define SZREG 4 /* 4 byte registers */
308
309 #define lptrarx lwarx /* load "C" pointer with reservation */
310 #define llongarx lwarx /* load "C" long with reservation */
311 #define lregarx lwarx /* load PPC general register with reservation */
312
313 #define stptrcx stwcx /* store "C" pointer conditional */
314 #define stlongcx stwcx /* store "C" long conditional */
315 #define stregcx stwcx /* store PPC general register conditional */
316
317 #define clrrptri clrrwi /* clear right "C" pointer immediate */
318 #define clrrlongi clrrwi /* clear right "C" long immediate */
319 #define clrrregi clrrwi /* clear right PPC general register immediate */
320
321 #else
322
323 #define ldlong ld /* load "C" long */
324 #define ldlongu ldu /* load "C" long with update */
325 #define stlong std /* store "C" long */
326 #define stlongu stdu /* store "C" long with update */
327 #define ldptr ld /* load "C" pointer */
328 #define ldptru ldu /* load "C" pointer with update */
329 #define stptr std /* store "C" pointer */
330 #define stptru stdu /* store "C" pointer with update */
331 #define ldreg ld /* load PPC general register */
332 #define ldregu ldu /* load PPC general register with update */
333 #define streg std /* store PPC general register */
334 #define stregu stdu /* store PPC general register with update */
335 /* redefined this to force an error on PPC64 to catch their use. */
336 #define lmw lmd /* load multiple PPC general registers */
337 #define stmw stmd /* store multiple PPC general registers */
338 #define SZREG 8 /* 8 byte registers */
339
340 #define lptrarx ldarx /* load "C" pointer with reservation */
341 #define llongarx ldarx /* load "C" long with reservation */
342 #define lregarx ldarx /* load PPC general register with reservation */
343
344 #define stptrcx stdcx /* store "C" pointer conditional */
345 #define stlongcx stdcx /* store "C" long conditional */
346 #define stregax stdcx /* store PPC general register conditional */
347
348 #define clrrptri clrrdi /* clear right "C" pointer immediate */
349 #define clrrlongi clrrdi /* clear right "C" long immediate */
350 #define clrrregi clrrdi /* clear right PPC general register immediate */
351
352 #endif
353
354 #ifdef _LOCORE
355 .macro stmd r,dst
356 i = 0
357 .rept 32-\r
358 std i+\r, i*8+\dst
359 i = i + 1
360 .endr
361 .endm
362
363 .macro lmd r,dst
364 i = 0
365 .rept 32-\r
366 ld i+\r, i*8+\dst
367 i = i + 1
368 .endr
369 .endm
370 #endif
371
372 #endif /* !_PPC_ASM_H_ */
373