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