asm.h revision 1.33 1 /* $NetBSD: asm.h,v 1.33 2011/01/17 08:23:56 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_TOCNAME(name) .LCTOC_##name
51 #else
52 #define PIC_TOCNAME(name) .LCTOC_/**/name
53 #endif
54 #define PIC_TOCSETUP(name, reg) \
55 .pushsection ".got2","aw" ;\
56 PIC_TOCNAME(name) = . + 32768 ;\
57 .popsection ;\
58 bcl 20,31,1001f ;\
59 1001: mflr reg ;\
60 addis reg,reg,PIC_TOCNAME(name)-1001b@ha ;\
61 addi reg,reg,PIC_TOCNAME(name)-1001b@l
62 #define PIC_GOTSETUP(reg) \
63 bcl 20,31,2002f ;\
64 2002: mflr reg ;\
65 addis reg,reg,_GLOBAL_OFFSET_TABLE_-2002b@ha ;\
66 addi reg,reg,_GLOBAL_OFFSET_TABLE_-2002b@l
67 #ifdef __STDC__
68 #define PIC_GOT(x) XXX
69 #define PIC_GOTOFF(x) XXX
70 #else /* not __STDC__ */
71 #define PIC_GOT(x) XXX
72 #define PIC_GOTOFF(x) XXX
73 #endif /* __STDC__ */
74 #else
75 #define PIC_PROLOGUE
76 #define PIC_EPILOGUE
77 #define PIC_PLT(x) x
78 #define PIC_GOT(x) x
79 #define PIC_GOTOFF(x) x
80 #define PIC_GOTSETUP(r)
81 #define PIC_TOCSETUP(n, r)
82 #endif
83
84 #endif
85
86 #define _C_LABEL(x) x
87 #define _ASM_LABEL(x) x
88
89 #define _GLOBAL(x) \
90 .data; .align 2; .globl x; x:
91
92 #ifdef GPROF
93 # define _PROF_PROLOGUE mflr 0; stw 0,4(1); bl _mcount
94 #else
95 # define _PROF_PROLOGUE
96 #endif
97
98 #ifdef _LP64
99
100 #define SF_HEADER_SZ 48
101 #define SF_PARAM_SZ 64
102 #define SF_SZ (SF_HEADER_SZ + SF_PARAM_SZ)
103
104 #define SF_SP 0
105 #define SF_CR 8
106 #define SF_LR 16
107 #define SF_PARAM SF_HEADER_SZ
108
109 #define ENTRY(y) \
110 .globl y; \
111 .section ".opd","aw"; \
112 .align 3; \
113 y: .quad .y,.TOC.@tocbase,0; \
114 .previous; \
115 .size y,24; \
116 .type .y,@function; \
117 .globl .y; \
118 .align 3; \
119 .y:
120
121 #define CALL(y) \
122 bl .y; \
123 nop
124
125 #define ENTRY_NOPROFILE(y) ENTRY(y)
126 #define ASENTRY(y) ENTRY(y)
127 #else
128
129 #define _ENTRY(x) \
130 .text; .align 2; .globl x; .type x,@function; x:
131
132 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
133 #define END(y) .size _C_LABEL(y),.-_C_LABEL(y)
134
135 #define ENTRY_NOPROFILE(y) _ENTRY(_C_LABEL(y))
136
137 #define CALL(y) \
138 bl y
139
140 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
141 #endif
142
143 #define GLOBAL(y) _GLOBAL(_C_LABEL(y))
144
145 #define ASMSTR .asciz
146
147 #define RCSID(x) __RCSID(x)
148 #define __RCSID(x) .pushsection .ident; .asciz x; .popsection
149
150 #ifdef __ELF__
151 #define WEAK_ALIAS(alias,sym) \
152 .weak alias; \
153 alias = sym
154 #endif
155 /*
156 * STRONG_ALIAS: create a strong alias.
157 */
158 #define STRONG_ALIAS(alias,sym) \
159 .globl alias; \
160 alias = sym
161
162 #ifdef __STDC__
163 #define WARN_REFERENCES(sym,msg) \
164 .pushsection .gnu.warning. ## sym; \
165 .ascii msg; \
166 .popsection
167 #else
168 #define WARN_REFERENCES(sym,msg) \
169 .pushsection .gnu.warning./**/sym; \
170 .ascii msg; \
171 .popsection
172 #endif /* __STDC__ */
173
174 #ifdef _KERNEL
175 /*
176 * Get cpu_info pointer for current processor. Always in SPRG0. *ALWAYS*
177 */
178 #define GET_CPUINFO(r) mfsprg r,0
179 /*
180 * IN:
181 * R4[er] = first free byte beyond end/esym.
182 *
183 * OUT:
184 * R1[sp] = new kernel stack
185 * R4[er] = kernelend
186 */
187
188 #define INIT_CPUINFO(er,sp,tmp1,tmp2) \
189 li tmp1,PGOFSET; \
190 add er,er,tmp1; \
191 andc er,er,tmp1; /* page align */ \
192 lis tmp1,_C_LABEL(cpu_info)@ha; \
193 addi tmp1,tmp1,_C_LABEL(cpu_info)@l; \
194 mtsprg0 tmp1; /* save for later use */ \
195 addi er,er,INTSTK; \
196 stptr er,CI_INTSTK(tmp1); \
197 lis tmp2,_C_LABEL(emptyidlespin)@h; \
198 ori tmp2,tmp2,_C_LABEL(emptyidlespin)@l; \
199 stptr tmp2,CI_IDLESPIN(tmp1); \
200 li tmp2,-1; \
201 stint tmp2,CI_INTRDEPTH(tmp1); \
202 li tmp2,0; \
203 stptr tmp2,-CALLFRAMELEN(er); /* terminate idle stack chain */\
204 lis tmp1,_C_LABEL(lwp0)+L_PCB@ha; /* XXXuvm_lwp_getuarea */ \
205 stptr er,_C_LABEL(lwp0)+L_PCB@l(tmp1); \
206 addi er,er,USPACE; /* stackpointer for proc0 */ \
207 addi sp,er,-FRAMELEN; /* stackpointer for proc0 */ \
208 /* er = end of mem reserved for kernel */ \
209 stptru tmp2,-CALLFRAMELEN(sp) /* end of stack chain */
210
211 #endif
212
213 /* Condition Register Bit Fields */
214
215 #if defined(_REGNAMES)
216 #if defined(_KERNEL) || defined(_STANDALONE)
217 #define cr0 0
218 #define cr1 1
219 #define cr2 2
220 #define cr3 3
221 #define cr4 4
222 #define cr5 5
223 #define cr6 6
224 #define cr7 7
225 #endif
226
227 /* General Purpose Registers (GPRs) */
228
229 #if defined(_KERNEL) || defined(_STANDALONE)
230 #define r0 0
231 #define r1 1
232 #define r2 2
233 #define r3 3
234 #define r4 4
235 #define r5 5
236 #define r6 6
237 #define r7 7
238 #define r8 8
239 #define r9 9
240 #define r10 10
241 #define r11 11
242 #define r12 12
243 #define r13 13
244 #define r14 14
245 #define r15 15
246 #define r16 16
247 #define r17 17
248 #define r18 18
249 #define r19 19
250 #define r20 20
251 #define r21 21
252 #define r22 22
253 #define r23 23
254 #define r24 24
255 #define r25 25
256 #define r26 26
257 #define r27 27
258 #define r28 28
259 #define r29 29
260 #define r30 30
261 #define r31 31
262 #endif
263
264 /* Floating Point Registers (FPRs) */
265
266 #if defined(_KERNEL) || defined(_STANDALONE)
267 #define fr0 0
268 #define fr1 1
269 #define fr2 2
270 #define fr3 3
271 #define fr4 4
272 #define fr5 5
273 #define fr6 6
274 #define fr7 7
275 #define fr8 8
276 #define fr9 9
277 #define fr10 10
278 #define fr11 11
279 #define fr12 12
280 #define fr13 13
281 #define fr14 14
282 #define fr15 15
283 #define fr16 16
284 #define fr17 17
285 #define fr18 18
286 #define fr19 19
287 #define fr20 20
288 #define fr21 21
289 #define fr22 22
290 #define fr23 23
291 #define fr24 24
292 #define fr25 25
293 #define fr26 26
294 #define fr27 27
295 #define fr28 28
296 #define fr29 29
297 #define fr30 30
298 #define fr31 31
299 #endif
300 #endif /* _REGNAMES */
301
302 /*
303 * Add some psuedo instructions to made sharing of assembly versions of
304 * ILP32 and LP64 code possible.
305 */
306 #define ldint lwz /* not needed but for completeness */
307 #define ldintu lwzu /* not needed but for completeness */
308 #define stint stw /* not needed but for completeness */
309 #define stintu stwu /* not needed but for completeness */
310
311 #ifndef _LP64
312
313 #define ldlong lwz /* load "C" long */
314 #define ldlongu lwzu /* load "C" long with udpate */
315 #define stlong stw /* load "C" long */
316 #define stlongu stwu /* load "C" long with udpate */
317 #define ldptr lwz /* load "C" pointer */
318 #define ldptru lwzu /* load "C" pointer with udpate */
319 #define stptr stw /* load "C" pointer */
320 #define stptru stwu /* load "C" pointer with udpate */
321 #define ldreg lwz /* load PPC general register */
322 #define ldregu lwzu /* load PPC general register with udpate */
323 #define streg stw /* load PPC general register */
324 #define stregu stwu /* load PPC general register with udpate */
325 #define SZREG 4 /* 4 byte registers */
326
327 #define lptrarx lwarx /* load "C" pointer with reservation */
328 #define llongarx lwarx /* load "C" long with reservation */
329 #define lregarx lwarx /* load PPC general register with reservation */
330
331 #define stptrcx stwcx /* store "C" pointer conditional */
332 #define stlongcx stwcx /* store "C" long conditional */
333 #define stregcx stwcx /* store PPC general register conditional */
334
335 #define clrrptri clrrwi /* clear right "C" pointer immediate */
336 #define clrrlongi clrrwi /* clear right "C" long immediate */
337 #define clrrregi clrrwi /* clear right PPC general register immediate */
338
339 #else
340
341 #define ldlong ld /* load "C" long */
342 #define ldlongu ldu /* load "C" long with update */
343 #define stlong std /* store "C" long */
344 #define stlongu stdu /* store "C" long with update */
345 #define ldptr ld /* load "C" pointer */
346 #define ldptru ldu /* load "C" pointer with update */
347 #define stptr std /* store "C" pointer */
348 #define stptru stdu /* store "C" pointer with update */
349 #define ldreg ld /* load PPC general register */
350 #define ldregu ldu /* load PPC general register with update */
351 #define streg std /* store PPC general register */
352 #define stregu stdu /* store PPC general register with update */
353 /* redefined this to force an error on PPC64 to catch their use. */
354 #define lmw lmd /* load multiple PPC general registers */
355 #define stmw stmd /* store multiple PPC general registers */
356 #define SZREG 8 /* 8 byte registers */
357
358 #define lptrarx ldarx /* load "C" pointer with reservation */
359 #define llongarx ldarx /* load "C" long with reservation */
360 #define lregarx ldarx /* load PPC general register with reservation */
361
362 #define stptrcx stdcx /* store "C" pointer conditional */
363 #define stlongcx stdcx /* store "C" long conditional */
364 #define stregax stdcx /* store PPC general register conditional */
365
366 #define clrrptri clrrdi /* clear right "C" pointer immediate */
367 #define clrrlongi clrrdi /* clear right "C" long immediate */
368 #define clrrregi clrrdi /* clear right PPC general register immediate */
369
370 #endif
371
372 #ifdef _LOCORE
373 .macro stmd r,dst
374 i = 0
375 .rept 32-\r
376 std i+\r, i*8+\dst
377 i = i + 1
378 .endr
379 .endm
380
381 .macro lmd r,dst
382 i = 0
383 .rept 32-\r
384 ld i+\r, i*8+\dst
385 i = i + 1
386 .endr
387 .endm
388 #endif
389
390 #endif /* !_PPC_ASM_H_ */
391