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