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