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