asm.h revision 1.51 1 1.51 joerg /* $NetBSD: asm.h,v 1.51 2020/04/18 10:37:37 joerg 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.48 dennis # define SF_COMP 24
108 1.48 dennis # define SF_LD 32
109 1.48 dennis # define SF_TOC 40
110 1.39 christos # define SF_PARAM SF_HEADER_SZ
111 1.48 dennis # define SF_ALIGN(x) (((x) + 0xf) & ~0xf)
112 1.20 ross
113 1.46 matt # define _XENTRY(y) \
114 1.20 ross .globl y; \
115 1.44 matt .pushsection ".opd","aw"; \
116 1.20 ross .align 3; \
117 1.44 matt y: .quad .##y,.TOC.@tocbase,0; \
118 1.44 matt .popsection; \
119 1.20 ross .size y,24; \
120 1.44 matt .type .##y,@function; \
121 1.44 matt .globl .##y; \
122 1.21 ross .align 3; \
123 1.44 matt .##y:
124 1.21 ross
125 1.46 matt #define _ENTRY(x) .text; _XENTRY(x)
126 1.46 matt
127 1.40 christos # define ENTRY(y) _ENTRY(y)
128 1.40 christos
129 1.44 matt # define END(y) .size .##y,. - .##y
130 1.39 christos
131 1.39 christos # define CALL(y) \
132 1.21 ross bl .y; \
133 1.20 ross nop
134 1.20 ross
135 1.39 christos # define ENTRY_NOPROFILE(y) ENTRY(y)
136 1.39 christos # define ASENTRY(y) ENTRY(y)
137 1.39 christos #else /* !_LP64 */
138 1.20 ross
139 1.46 matt # define _XENTRY(x) .align 2; .globl x; .type x,@function; x:
140 1.46 matt # define _ENTRY(x) .text; _XENTRY(x)
141 1.20 ross
142 1.39 christos # define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
143 1.20 ross
144 1.39 christos # define END(y) .size _C_LABEL(y),.-_C_LABEL(y)
145 1.9 thorpej
146 1.39 christos # define CALL(y) \
147 1.20 ross bl y
148 1.20 ross
149 1.39 christos # define ENTRY_NOPROFILE(y) _ENTRY(_C_LABEL(y))
150 1.39 christos # define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
151 1.39 christos #endif /* __LP64__ */
152 1.20 ross
153 1.3 thorpej #define GLOBAL(y) _GLOBAL(_C_LABEL(y))
154 1.1 ws
155 1.1 ws #define ASMSTR .asciz
156 1.1 ws
157 1.34 matt #undef __RCSID
158 1.31 matt #define RCSID(x) __RCSID(x)
159 1.51 joerg #define __RCSID(x) .pushsection ".ident","MS",@progbits,1; \
160 1.50 joerg .asciz x; \
161 1.50 joerg .popsection
162 1.7 kleink
163 1.7 kleink #ifdef __ELF__
164 1.39 christos # define WEAK_ALIAS(alias,sym) \
165 1.7 kleink .weak alias; \
166 1.7 kleink alias = sym
167 1.39 christos #endif /* __ELF__ */
168 1.19 christos /*
169 1.19 christos * STRONG_ALIAS: create a strong alias.
170 1.19 christos */
171 1.19 christos #define STRONG_ALIAS(alias,sym) \
172 1.19 christos .globl alias; \
173 1.19 christos alias = sym
174 1.5 thorpej
175 1.5 thorpej #ifdef __STDC__
176 1.39 christos # define WARN_REFERENCES(sym,msg) \
177 1.30 joerg .pushsection .gnu.warning. ## sym; \
178 1.30 joerg .ascii msg; \
179 1.30 joerg .popsection
180 1.5 thorpej #else
181 1.39 christos # define WARN_REFERENCES(sym,msg) \
182 1.30 joerg .pushsection .gnu.warning./**/sym; \
183 1.30 joerg .ascii msg; \
184 1.30 joerg .popsection
185 1.5 thorpej #endif /* __STDC__ */
186 1.12 matt
187 1.12 matt #ifdef _KERNEL
188 1.12 matt /*
189 1.12 matt * Get cpu_info pointer for current processor. Always in SPRG0. *ALWAYS*
190 1.12 matt */
191 1.39 christos # define GET_CPUINFO(r) mfsprg r,0
192 1.12 matt /*
193 1.12 matt * IN:
194 1.12 matt * R4[er] = first free byte beyond end/esym.
195 1.12 matt *
196 1.12 matt * OUT:
197 1.12 matt * R1[sp] = new kernel stack
198 1.12 matt * R4[er] = kernelend
199 1.12 matt */
200 1.12 matt
201 1.39 christos # ifdef CI_INTSTK
202 1.39 christos # define INIT_CPUINFO_INTSTK(er,tmp1) \
203 1.41 kiyohara addis er,er,INTSTK@ha; \
204 1.41 kiyohara addi er,er,INTSTK@l; \
205 1.34 matt stptr er,CI_INTSTK(tmp1)
206 1.39 christos # else
207 1.39 christos # define INIT_CPUINFO_INTSTK(er,tmp1) /* nothing */
208 1.39 christos # endif /* CI_INTSTK */
209 1.34 matt
210 1.34 matt /*
211 1.34 matt * We use lis/ori instead of lis/addi in case tmp2 is r0.
212 1.34 matt */
213 1.39 christos # define INIT_CPUINFO(er,sp,tmp1,tmp2) \
214 1.34 matt li tmp1,PAGE_MASK; \
215 1.12 matt add er,er,tmp1; \
216 1.12 matt andc er,er,tmp1; /* page align */ \
217 1.12 matt lis tmp1,_C_LABEL(cpu_info)@ha; \
218 1.12 matt addi tmp1,tmp1,_C_LABEL(cpu_info)@l; \
219 1.15 matt mtsprg0 tmp1; /* save for later use */ \
220 1.34 matt INIT_CPUINFO_INTSTK(er,tmp1); \
221 1.17 simonb lis tmp2,_C_LABEL(emptyidlespin)@h; \
222 1.17 simonb ori tmp2,tmp2,_C_LABEL(emptyidlespin)@l; \
223 1.16 matt stptr tmp2,CI_IDLESPIN(tmp1); \
224 1.12 matt li tmp2,-1; \
225 1.34 matt stint tmp2,CI_IDEPTH(tmp1); \
226 1.12 matt li tmp2,0; \
227 1.37 matt lis %r13,_C_LABEL(lwp0)@h; \
228 1.37 matt ori %r13,%r13,_C_LABEL(lwp0)@l; \
229 1.37 matt stptr er,L_PCB(%r13); /* XXXuvm_lwp_getuarea */ \
230 1.38 matt stptr tmp1,L_CPU(%r13); \
231 1.41 kiyohara addis er,er,USPACE@ha; /* stackpointer for lwp0 */ \
232 1.41 kiyohara addi er,er,USPACE@l; /* stackpointer for lwp0 */ \
233 1.34 matt addi sp,er,-FRAMELEN-CALLFRAMELEN; /* stackpointer for lwp0 */ \
234 1.37 matt stptr sp,L_MD_UTF(%r13); /* save in lwp0.l_md.md_utf */ \
235 1.12 matt /* er = end of mem reserved for kernel */ \
236 1.34 matt li tmp2,0; \
237 1.34 matt stptr tmp2,-CALLFRAMELEN(er); /* end of stack chain */ \
238 1.15 matt stptru tmp2,-CALLFRAMELEN(sp) /* end of stack chain */
239 1.12 matt
240 1.39 christos #endif /* _KERNEL */
241 1.8 simonb
242 1.8 simonb
243 1.39 christos #if defined(_REGNAMES) && (defined(_KERNEL) || defined(_STANDALONE))
244 1.39 christos /* Condition Register Bit Fields */
245 1.39 christos # define cr0 0
246 1.39 christos # define cr1 1
247 1.39 christos # define cr2 2
248 1.39 christos # define cr3 3
249 1.39 christos # define cr4 4
250 1.39 christos # define cr5 5
251 1.39 christos # define cr6 6
252 1.39 christos # define cr7 7
253 1.39 christos /* General Purpose Registers (GPRs) */
254 1.39 christos # define r0 0
255 1.39 christos # define r1 1
256 1.39 christos # define r2 2
257 1.39 christos # define r3 3
258 1.39 christos # define r4 4
259 1.39 christos # define r5 5
260 1.39 christos # define r6 6
261 1.39 christos # define r7 7
262 1.39 christos # define r8 8
263 1.39 christos # define r9 9
264 1.39 christos # define r10 10
265 1.39 christos # define r11 11
266 1.39 christos # define r12 12
267 1.39 christos # define r13 13
268 1.39 christos # define r14 14
269 1.39 christos # define r15 15
270 1.39 christos # define r16 16
271 1.39 christos # define r17 17
272 1.39 christos # define r18 18
273 1.39 christos # define r19 19
274 1.39 christos # define r20 20
275 1.39 christos # define r21 21
276 1.39 christos # define r22 22
277 1.39 christos # define r23 23
278 1.39 christos # define r24 24
279 1.39 christos # define r25 25
280 1.39 christos # define r26 26
281 1.39 christos # define r27 27
282 1.39 christos # define r28 28
283 1.39 christos # define r29 29
284 1.39 christos # define r30 30
285 1.39 christos # define r31 31
286 1.39 christos /* Floating Point Registers (FPRs) */
287 1.39 christos # define fr0 0
288 1.39 christos # define fr1 1
289 1.39 christos # define fr2 2
290 1.39 christos # define fr3 3
291 1.39 christos # define fr4 4
292 1.39 christos # define fr5 5
293 1.39 christos # define fr6 6
294 1.39 christos # define fr7 7
295 1.39 christos # define fr8 8
296 1.39 christos # define fr9 9
297 1.39 christos # define fr10 10
298 1.39 christos # define fr11 11
299 1.39 christos # define fr12 12
300 1.39 christos # define fr13 13
301 1.39 christos # define fr14 14
302 1.39 christos # define fr15 15
303 1.39 christos # define fr16 16
304 1.39 christos # define fr17 17
305 1.39 christos # define fr18 18
306 1.39 christos # define fr19 19
307 1.39 christos # define fr20 20
308 1.39 christos # define fr21 21
309 1.39 christos # define fr22 22
310 1.39 christos # define fr23 23
311 1.39 christos # define fr24 24
312 1.39 christos # define fr25 25
313 1.39 christos # define fr26 26
314 1.39 christos # define fr27 27
315 1.39 christos # define fr28 28
316 1.39 christos # define fr29 29
317 1.39 christos # define fr30 30
318 1.39 christos # define fr31 31
319 1.39 christos #endif /* _REGNAMES && (_KERNEL || _STANDALONE) */
320 1.13 matt
321 1.13 matt /*
322 1.13 matt * Add some psuedo instructions to made sharing of assembly versions of
323 1.13 matt * ILP32 and LP64 code possible.
324 1.13 matt */
325 1.39 christos #define ldint lwz /* not needed but for completeness */
326 1.39 christos #define ldintu lwzu /* not needed but for completeness */
327 1.39 christos #define stint stw /* not needed but for completeness */
328 1.39 christos #define stintu stwu /* not needed but for completeness */
329 1.20 ross
330 1.13 matt #ifndef _LP64
331 1.20 ross
332 1.39 christos # define ldlong lwz /* load "C" long */
333 1.39 christos # define ldlongu lwzu /* load "C" long with udpate */
334 1.39 christos # define stlong stw /* load "C" long */
335 1.39 christos # define stlongu stwu /* load "C" long with udpate */
336 1.39 christos # define ldptr lwz /* load "C" pointer */
337 1.39 christos # define ldptru lwzu /* load "C" pointer with udpate */
338 1.39 christos # define stptr stw /* load "C" pointer */
339 1.39 christos # define stptru stwu /* load "C" pointer with udpate */
340 1.39 christos # define ldreg lwz /* load PPC general register */
341 1.39 christos # define ldregu lwzu /* load PPC general register with udpate */
342 1.39 christos # define streg stw /* load PPC general register */
343 1.39 christos # define stregu stwu /* load PPC general register with udpate */
344 1.39 christos # define SZREG 4 /* 4 byte registers */
345 1.43 matt # define P2SZREG 2
346 1.39 christos
347 1.39 christos # define lptrarx lwarx /* load "C" pointer with reservation */
348 1.39 christos # define llongarx lwarx /* load "C" long with reservation */
349 1.39 christos # define lregarx lwarx /* load PPC general register with reservation */
350 1.39 christos
351 1.39 christos # define stptrcx stwcx /* store "C" pointer conditional */
352 1.39 christos # define stlongcx stwcx /* store "C" long conditional */
353 1.39 christos # define stregcx stwcx /* store PPC general register conditional */
354 1.39 christos
355 1.39 christos # define clrrptri clrrwi /* clear right "C" pointer immediate */
356 1.39 christos # define clrrlongi clrrwi /* clear right "C" long immediate */
357 1.39 christos # define clrrregi clrrwi /* clear right PPC general register immediate */
358 1.39 christos
359 1.45 matt # define cmpptr cmpw
360 1.45 matt # define cmplong cmpw
361 1.45 matt # define cmpreg cmpw
362 1.45 matt # define cmpptri cmpwi
363 1.45 matt # define cmplongi cmpwi
364 1.45 matt # define cmpregi cmpwi
365 1.47 matt # define cmpptrl cmplw
366 1.47 matt # define cmplongl cmplw
367 1.47 matt # define cmpregl cmplw
368 1.47 matt # define cmpptrli cmplwi
369 1.47 matt # define cmplongli cmplwi
370 1.47 matt # define cmpregli cmplwi
371 1.45 matt
372 1.39 christos #else /* __LP64__ */
373 1.39 christos
374 1.39 christos # define ldlong ld /* load "C" long */
375 1.39 christos # define ldlongu ldu /* load "C" long with update */
376 1.39 christos # define stlong std /* store "C" long */
377 1.39 christos # define stlongu stdu /* store "C" long with update */
378 1.39 christos # define ldptr ld /* load "C" pointer */
379 1.39 christos # define ldptru ldu /* load "C" pointer with update */
380 1.39 christos # define stptr std /* store "C" pointer */
381 1.39 christos # define stptru stdu /* store "C" pointer with update */
382 1.39 christos # define ldreg ld /* load PPC general register */
383 1.39 christos # define ldregu ldu /* load PPC general register with update */
384 1.39 christos # define streg std /* store PPC general register */
385 1.39 christos # define stregu stdu /* store PPC general register with update */
386 1.14 matt /* redefined this to force an error on PPC64 to catch their use. */
387 1.39 christos # define lmw lmd /* load multiple PPC general registers */
388 1.39 christos # define stmw stmd /* store multiple PPC general registers */
389 1.39 christos # define SZREG 8 /* 8 byte registers */
390 1.43 matt # define P2SZREG 3
391 1.39 christos
392 1.39 christos # define lptrarx ldarx /* load "C" pointer with reservation */
393 1.39 christos # define llongarx ldarx /* load "C" long with reservation */
394 1.39 christos # define lregarx ldarx /* load PPC general register with reservation */
395 1.39 christos
396 1.39 christos # define stptrcx stdcx /* store "C" pointer conditional */
397 1.39 christos # define stlongcx stdcx /* store "C" long conditional */
398 1.39 christos # define stregax stdcx /* store PPC general register conditional */
399 1.39 christos
400 1.39 christos # define clrrptri clrrdi /* clear right "C" pointer immediate */
401 1.39 christos # define clrrlongi clrrdi /* clear right "C" long immediate */
402 1.39 christos # define clrrregi clrrdi /* clear right PPC general register immediate */
403 1.26 matt
404 1.45 matt # define cmpptr cmpd
405 1.45 matt # define cmplong cmpd
406 1.45 matt # define cmpreg cmpd
407 1.45 matt # define cmpptri cmpdi
408 1.45 matt # define cmplongi cmpdi
409 1.45 matt # define cmpregi cmpdi
410 1.47 matt # define cmpptrl cmpld
411 1.47 matt # define cmplongl cmpld
412 1.47 matt # define cmpregl cmpld
413 1.47 matt # define cmpptrli cmpldi
414 1.47 matt # define cmplongli cmpldi
415 1.47 matt # define cmpregli cmpldi
416 1.45 matt
417 1.39 christos #endif /* __LP64__ */
418 1.1 ws
419 1.23 ross #ifdef _LOCORE
420 1.22 ross .macro stmd r,dst
421 1.22 ross i = 0
422 1.22 ross .rept 32-\r
423 1.22 ross std i+\r, i*8+\dst
424 1.22 ross i = i + 1
425 1.22 ross .endr
426 1.22 ross .endm
427 1.22 ross
428 1.22 ross .macro lmd r,dst
429 1.22 ross i = 0
430 1.22 ross .rept 32-\r
431 1.22 ross ld i+\r, i*8+\dst
432 1.22 ross i = i + 1
433 1.22 ross .endr
434 1.22 ross .endm
435 1.39 christos #endif /* _LOCORE */
436 1.22 ross
437 1.49 rin #if defined(IBM405_ERRATA77) || \
438 1.49 rin ((defined(_MODULE) || !defined(_KERNEL)) && !defined(__LP64__))
439 1.49 rin /*
440 1.49 rin * Workaround for IBM405 Errata 77 (CPU_210): interrupted stwcx. may
441 1.49 rin * errantly write data to memory
442 1.49 rin *
443 1.49 rin * (1) Insert dcbt before every stwcx. instruction
444 1.49 rin * (2) Insert sync before every rfi/rfci instruction
445 1.49 rin */
446 1.49 rin #define IBM405_ERRATA77_DCBT(ra, rb) dcbt ra,rb
447 1.49 rin #define IBM405_ERRATA77_SYNC sync
448 1.49 rin #else
449 1.49 rin #define IBM405_ERRATA77_DCBT(ra, rb) /* nothing */
450 1.49 rin #define IBM405_ERRATA77_SYNC /* nothing */
451 1.49 rin #endif
452 1.49 rin
453 1.1 ws #endif /* !_PPC_ASM_H_ */
454