1b8b572e1SStephen Rothwell /* 2b8b572e1SStephen Rothwell * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan. 3b8b572e1SStephen Rothwell */ 4b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PPC_ASM_H 5b8b572e1SStephen Rothwell #define _ASM_POWERPC_PPC_ASM_H 6b8b572e1SStephen Rothwell 7b8b572e1SStephen Rothwell #include <linux/stringify.h> 8b8b572e1SStephen Rothwell #include <asm/asm-compat.h> 9b8b572e1SStephen Rothwell #include <asm/processor.h> 1016c57b36SKumar Gala #include <asm/ppc-opcode.h> 11cf9efce0SPaul Mackerras #include <asm/firmware.h> 122c86cd18SChristophe Leroy #include <asm/feature-fixups.h> 131e688dd2SChristophe Leroy #include <asm/extable.h> 14b8b572e1SStephen Rothwell 15e3f2c6c3SMichael Ellerman #ifdef __ASSEMBLY__ 16b8b572e1SStephen Rothwell 17b8b572e1SStephen Rothwell #define SZL (BITS_PER_LONG/8) 18b8b572e1SStephen Rothwell 19b8b572e1SStephen Rothwell /* 20aebd1fb4SNicholas Piggin * This expands to a sequence of operations with reg incrementing from 21aebd1fb4SNicholas Piggin * start to end inclusive, of this form: 22aebd1fb4SNicholas Piggin * 23aebd1fb4SNicholas Piggin * op reg, (offset + (width * reg))(base) 24aebd1fb4SNicholas Piggin * 25aebd1fb4SNicholas Piggin * Note that offset is not the offset of the first operation unless start 26aebd1fb4SNicholas Piggin * is zero (or width is zero). 27aebd1fb4SNicholas Piggin */ 28aebd1fb4SNicholas Piggin .macro OP_REGS op, width, start, end, base, offset 29aebd1fb4SNicholas Piggin .Lreg=\start 30aebd1fb4SNicholas Piggin .rept (\end - \start + 1) 31aebd1fb4SNicholas Piggin \op .Lreg, \offset + \width * .Lreg(\base) 32aebd1fb4SNicholas Piggin .Lreg=.Lreg+1 33aebd1fb4SNicholas Piggin .endr 34aebd1fb4SNicholas Piggin .endm 35aebd1fb4SNicholas Piggin 36aebd1fb4SNicholas Piggin /* 379d54a5ceSRohan McLure * This expands to a sequence of register clears for regs start to end 389d54a5ceSRohan McLure * inclusive, of the form: 399d54a5ceSRohan McLure * 409d54a5ceSRohan McLure * li rN, 0 419d54a5ceSRohan McLure */ 429d54a5ceSRohan McLure .macro ZEROIZE_REGS start, end 439d54a5ceSRohan McLure .Lreg=\start 449d54a5ceSRohan McLure .rept (\end - \start + 1) 459d54a5ceSRohan McLure li .Lreg, 0 469d54a5ceSRohan McLure .Lreg=.Lreg+1 479d54a5ceSRohan McLure .endr 489d54a5ceSRohan McLure .endm 499d54a5ceSRohan McLure 509d54a5ceSRohan McLure /* 51b8b572e1SStephen Rothwell * Macros for storing registers into and loading registers from 52b8b572e1SStephen Rothwell * exception frames. 53b8b572e1SStephen Rothwell */ 54b8b572e1SStephen Rothwell #ifdef __powerpc64__ 55aebd1fb4SNicholas Piggin #define SAVE_GPRS(start, end, base) OP_REGS std, 8, start, end, base, GPR0 56aebd1fb4SNicholas Piggin #define REST_GPRS(start, end, base) OP_REGS ld, 8, start, end, base, GPR0 57aebd1fb4SNicholas Piggin #define SAVE_NVGPRS(base) SAVE_GPRS(14, 31, base) 58aebd1fb4SNicholas Piggin #define REST_NVGPRS(base) REST_GPRS(14, 31, base) 59b8b572e1SStephen Rothwell #else 60aebd1fb4SNicholas Piggin #define SAVE_GPRS(start, end, base) OP_REGS stw, 4, start, end, base, GPR0 61aebd1fb4SNicholas Piggin #define REST_GPRS(start, end, base) OP_REGS lwz, 4, start, end, base, GPR0 62aebd1fb4SNicholas Piggin #define SAVE_NVGPRS(base) SAVE_GPRS(13, 31, base) 63aebd1fb4SNicholas Piggin #define REST_NVGPRS(base) REST_GPRS(13, 31, base) 64b8b572e1SStephen Rothwell #endif 65b8b572e1SStephen Rothwell 669d54a5ceSRohan McLure #define ZEROIZE_GPRS(start, end) ZEROIZE_REGS start, end 679d54a5ceSRohan McLure #ifdef __powerpc64__ 689d54a5ceSRohan McLure #define ZEROIZE_NVGPRS() ZEROIZE_GPRS(14, 31) 699d54a5ceSRohan McLure #else 709d54a5ceSRohan McLure #define ZEROIZE_NVGPRS() ZEROIZE_GPRS(13, 31) 719d54a5ceSRohan McLure #endif 729d54a5ceSRohan McLure #define ZEROIZE_GPR(n) ZEROIZE_GPRS(n, n) 739d54a5ceSRohan McLure 74aebd1fb4SNicholas Piggin #define SAVE_GPR(n, base) SAVE_GPRS(n, n, base) 75aebd1fb4SNicholas Piggin #define REST_GPR(n, base) REST_GPRS(n, n, base) 76b8b572e1SStephen Rothwell 77cbf892baSRohan McLure /* macros for handling user register sanitisation */ 78cbf892baSRohan McLure #ifdef CONFIG_INTERRUPT_SANITIZE_REGISTERS 79cbf892baSRohan McLure #define SANITIZE_SYSCALL_GPRS() ZEROIZE_GPR(0); \ 80cbf892baSRohan McLure ZEROIZE_GPRS(5, 12); \ 81cbf892baSRohan McLure ZEROIZE_NVGPRS() 82cbf892baSRohan McLure #define SANITIZE_GPR(n) ZEROIZE_GPR(n) 83cbf892baSRohan McLure #define SANITIZE_GPRS(start, end) ZEROIZE_GPRS(start, end) 84cbf892baSRohan McLure #define SANITIZE_NVGPRS() ZEROIZE_NVGPRS() 85cbf892baSRohan McLure #define SANITIZE_RESTORE_NVGPRS() REST_NVGPRS(r1) 86cbf892baSRohan McLure #define HANDLER_RESTORE_NVGPRS() 87cbf892baSRohan McLure #else 88cbf892baSRohan McLure #define SANITIZE_SYSCALL_GPRS() 89cbf892baSRohan McLure #define SANITIZE_GPR(n) 90cbf892baSRohan McLure #define SANITIZE_GPRS(start, end) 91cbf892baSRohan McLure #define SANITIZE_NVGPRS() 92cbf892baSRohan McLure #define SANITIZE_RESTORE_NVGPRS() 93cbf892baSRohan McLure #define HANDLER_RESTORE_NVGPRS() REST_NVGPRS(r1) 94cbf892baSRohan McLure #endif /* CONFIG_INTERRUPT_SANITIZE_REGISTERS */ 95cbf892baSRohan McLure 96de79f7b9SPaul Mackerras #define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base) 97b8b572e1SStephen Rothwell #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base) 98b8b572e1SStephen Rothwell #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base) 99b8b572e1SStephen Rothwell #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base) 100b8b572e1SStephen Rothwell #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base) 101b8b572e1SStephen Rothwell #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base) 102de79f7b9SPaul Mackerras #define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base) 103b8b572e1SStephen Rothwell #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base) 104b8b572e1SStephen Rothwell #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base) 105b8b572e1SStephen Rothwell #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base) 106b8b572e1SStephen Rothwell #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base) 107b8b572e1SStephen Rothwell #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base) 108b8b572e1SStephen Rothwell 109de79f7b9SPaul Mackerras #define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b 110b8b572e1SStephen Rothwell #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base) 111b8b572e1SStephen Rothwell #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base) 112b8b572e1SStephen Rothwell #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base) 113b8b572e1SStephen Rothwell #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base) 114b8b572e1SStephen Rothwell #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base) 115de79f7b9SPaul Mackerras #define REST_VR(n,b,base) li b,16*(n); lvx n,base,b 116b8b572e1SStephen Rothwell #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base) 117b8b572e1SStephen Rothwell #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base) 118b8b572e1SStephen Rothwell #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base) 119b8b572e1SStephen Rothwell #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base) 120b8b572e1SStephen Rothwell #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base) 121b8b572e1SStephen Rothwell 122926f160fSAnton Blanchard #ifdef __BIG_ENDIAN__ 123926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base) 124926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base) 125926f160fSAnton Blanchard #else 126926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \ 127926f160fSAnton Blanchard STXVD2X(n,b,base); \ 128926f160fSAnton Blanchard XXSWAPD(n,n) 129926f160fSAnton Blanchard 130926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \ 131926f160fSAnton Blanchard XXSWAPD(n,n) 132926f160fSAnton Blanchard #endif 133b8b572e1SStephen Rothwell /* Save the lower 32 VSRs in the thread VSR region */ 1343ad26e5cSBenjamin Herrenschmidt #define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b) 135b8b572e1SStephen Rothwell #define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base) 136b8b572e1SStephen Rothwell #define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base) 137b8b572e1SStephen Rothwell #define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base) 138b8b572e1SStephen Rothwell #define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base) 139b8b572e1SStephen Rothwell #define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base) 1403ad26e5cSBenjamin Herrenschmidt #define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b) 141b8b572e1SStephen Rothwell #define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base) 142b8b572e1SStephen Rothwell #define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base) 143b8b572e1SStephen Rothwell #define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base) 144b8b572e1SStephen Rothwell #define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base) 145b8b572e1SStephen Rothwell #define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base) 146b8b572e1SStephen Rothwell 147c51584d5SScott Wood /* 148c51584d5SScott Wood * b = base register for addressing, o = base offset from register of 1st EVR 149c51584d5SScott Wood * n = first EVR, s = scratch 150c51584d5SScott Wood */ 151c51584d5SScott Wood #define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b) 152c51584d5SScott Wood #define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o) 153c51584d5SScott Wood #define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o) 154c51584d5SScott Wood #define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o) 155c51584d5SScott Wood #define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o) 156c51584d5SScott Wood #define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o) 157c51584d5SScott Wood #define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n 158c51584d5SScott Wood #define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o) 159c51584d5SScott Wood #define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o) 160c51584d5SScott Wood #define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o) 161c51584d5SScott Wood #define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o) 162c51584d5SScott Wood #define REST_32EVRS(n,s,b,o) REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o) 163b8b572e1SStephen Rothwell 164b8b572e1SStephen Rothwell /* Macros to adjust thread priority for hardware multithreading */ 165b8b572e1SStephen Rothwell #define HMT_VERY_LOW or 31,31,31 # very low priority 166b8b572e1SStephen Rothwell #define HMT_LOW or 1,1,1 167b8b572e1SStephen Rothwell #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority 168b8b572e1SStephen Rothwell #define HMT_MEDIUM or 2,2,2 169b8b572e1SStephen Rothwell #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority 170b8b572e1SStephen Rothwell #define HMT_HIGH or 3,3,3 17150fb8ebeSBenjamin Herrenschmidt #define HMT_EXTRA_HIGH or 7,7,7 # power7 only 172b8b572e1SStephen Rothwell 173d72be892SMichael Neuling #ifdef CONFIG_PPC64 174d72be892SMichael Neuling #define ULONG_SIZE 8 175d72be892SMichael Neuling #else 176d72be892SMichael Neuling #define ULONG_SIZE 4 177d72be892SMichael Neuling #endif 1780b7673c3SMichael Neuling #define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE)) 1790b7673c3SMichael Neuling #define VCPU_GPR(n) __VCPU_GPR(__REG_##n) 180d72be892SMichael Neuling 181b8b572e1SStephen Rothwell #ifdef __KERNEL__ 1822eda7f11SMichael Ellerman 1832eda7f11SMichael Ellerman /* 1844e991e3cSNicholas Piggin * Used to name C functions called from asm 1854e991e3cSNicholas Piggin */ 186*77e69ee7SNicholas Piggin #ifdef CONFIG_PPC_KERNEL_PCREL 1877e3a68beSNicholas Piggin #define CFUNC(name) name@notoc 1887e3a68beSNicholas Piggin #else 1894e991e3cSNicholas Piggin #define CFUNC(name) name 1907e3a68beSNicholas Piggin #endif 1914e991e3cSNicholas Piggin 1924e991e3cSNicholas Piggin /* 1932eda7f11SMichael Ellerman * We use __powerpc64__ here because we want the compat VDSO to use the 32-bit 1942eda7f11SMichael Ellerman * version below in the else case of the ifdef. 1952eda7f11SMichael Ellerman */ 1962eda7f11SMichael Ellerman #ifdef __powerpc64__ 197b8b572e1SStephen Rothwell 19844ce6a5eSMichael Neuling #define STACKFRAMESIZE 256 1990b7673c3SMichael Neuling #define __STK_REG(i) (112 + ((i)-14)*8) 2000b7673c3SMichael Neuling #define STK_REG(i) __STK_REG(__REG_##i) 20144ce6a5eSMichael Neuling 2027d40aff8SChristophe Leroy #ifdef CONFIG_PPC64_ELF_ABI_V2 2036403105bSAnton Blanchard #define STK_GOT 24 204b37c10d1SAnton Blanchard #define __STK_PARAM(i) (32 + ((i)-3)*8) 205b37c10d1SAnton Blanchard #else 2066403105bSAnton Blanchard #define STK_GOT 40 2070b7673c3SMichael Neuling #define __STK_PARAM(i) (48 + ((i)-3)*8) 208b37c10d1SAnton Blanchard #endif 2090b7673c3SMichael Neuling #define STK_PARAM(i) __STK_PARAM(__REG_##i) 21044ce6a5eSMichael Neuling 2117d40aff8SChristophe Leroy #ifdef CONFIG_PPC64_ELF_ABI_V2 2127167af7cSAnton Blanchard 2137167af7cSAnton Blanchard #define _GLOBAL(name) \ 2147167af7cSAnton Blanchard .align 2 ; \ 2157167af7cSAnton Blanchard .type name,@function; \ 2167167af7cSAnton Blanchard .globl name; \ 2177167af7cSAnton Blanchard name: 2187167af7cSAnton Blanchard 219*77e69ee7SNicholas Piggin #ifdef CONFIG_PPC_KERNEL_PCREL 2207e3a68beSNicholas Piggin #define _GLOBAL_TOC _GLOBAL 2217e3a68beSNicholas Piggin #else 222169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) \ 223169c7ceeSAnton Blanchard .align 2 ; \ 224169c7ceeSAnton Blanchard .type name,@function; \ 225169c7ceeSAnton Blanchard .globl name; \ 226169c7ceeSAnton Blanchard name: \ 227169c7ceeSAnton Blanchard 0: addis r2,r12,(.TOC.-0b)@ha; \ 228169c7ceeSAnton Blanchard addi r2,r2,(.TOC.-0b)@l; \ 229169c7ceeSAnton Blanchard .localentry name,.-name 2307e3a68beSNicholas Piggin #endif 231169c7ceeSAnton Blanchard 2327167af7cSAnton Blanchard #define DOTSYM(a) a 2337167af7cSAnton Blanchard 2347167af7cSAnton Blanchard #else 2357167af7cSAnton Blanchard 236b8b572e1SStephen Rothwell #define XGLUE(a,b) a##b 237b8b572e1SStephen Rothwell #define GLUE(a,b) XGLUE(a,b) 238b8b572e1SStephen Rothwell 239b8b572e1SStephen Rothwell #define _GLOBAL(name) \ 240b8b572e1SStephen Rothwell .align 2 ; \ 241b8b572e1SStephen Rothwell .globl name; \ 242b8b572e1SStephen Rothwell .globl GLUE(.,name); \ 243bea2dcccSMichael Ellerman .pushsection ".opd","aw"; \ 244b8b572e1SStephen Rothwell name: \ 245b8b572e1SStephen Rothwell .quad GLUE(.,name); \ 246b8b572e1SStephen Rothwell .quad .TOC.@tocbase; \ 247b8b572e1SStephen Rothwell .quad 0; \ 248bea2dcccSMichael Ellerman .popsection; \ 249b8b572e1SStephen Rothwell .type GLUE(.,name),@function; \ 250b8b572e1SStephen Rothwell GLUE(.,name): 251b8b572e1SStephen Rothwell 252169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) _GLOBAL(name) 253169c7ceeSAnton Blanchard 254c1fb0194SAnton Blanchard #define DOTSYM(a) GLUE(.,a) 255c1fb0194SAnton Blanchard 2567167af7cSAnton Blanchard #endif 2577167af7cSAnton Blanchard 258b8b572e1SStephen Rothwell #else /* 32-bit */ 259b8b572e1SStephen Rothwell 260b8b572e1SStephen Rothwell #define _GLOBAL(n) \ 261b8b572e1SStephen Rothwell .globl n; \ 262b8b572e1SStephen Rothwell n: 263b8b572e1SStephen Rothwell 2649715a2e8SAlexander Graf #define _GLOBAL_TOC(name) _GLOBAL(name) 2659715a2e8SAlexander Graf 266ce7d8056SChristophe Leroy #define DOTSYM(a) a 267ce7d8056SChristophe Leroy 268b8b572e1SStephen Rothwell #endif 269b8b572e1SStephen Rothwell 2706f698df1SNicholas Piggin /* 2716f698df1SNicholas Piggin * __kprobes (the C annotation) puts the symbol into the .kprobes.text 2726f698df1SNicholas Piggin * section, which gets emitted at the end of regular text. 2736f698df1SNicholas Piggin * 2746f698df1SNicholas Piggin * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to 2756f698df1SNicholas Piggin * a blacklist. The former is for core kprobe functions/data, the 2766f698df1SNicholas Piggin * latter is for those that incdentially must be excluded from probing 2776f698df1SNicholas Piggin * and allows them to be linked at more optimal location within text. 2786f698df1SNicholas Piggin */ 279c0a51491SNicholas Piggin #ifdef CONFIG_KPROBES 2806f698df1SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry) \ 2816f698df1SNicholas Piggin .pushsection "_kprobe_blacklist","aw"; \ 2826f698df1SNicholas Piggin PPC_LONG (entry) ; \ 2836f698df1SNicholas Piggin .popsection 284c0a51491SNicholas Piggin #else 285c0a51491SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry) 286c0a51491SNicholas Piggin #endif 2876f698df1SNicholas Piggin 288151f2511SAnton Blanchard #define FUNC_START(name) _GLOBAL(name) 289151f2511SAnton Blanchard #define FUNC_END(name) 290151f2511SAnton Blanchard 291b8b572e1SStephen Rothwell /* 292b8b572e1SStephen Rothwell * LOAD_REG_IMMEDIATE(rn, expr) 293b8b572e1SStephen Rothwell * Loads the value of the constant expression 'expr' into register 'rn' 294b8b572e1SStephen Rothwell * using immediate instructions only. Use this when it's important not 295b8b572e1SStephen Rothwell * to reference other data (i.e. on ppc64 when the TOC pointer is not 296e31aa453SPaul Mackerras * valid) and when 'expr' is a constant or absolute address. 297b8b572e1SStephen Rothwell * 298b8b572e1SStephen Rothwell * LOAD_REG_ADDR(rn, name) 299b8b572e1SStephen Rothwell * Loads the address of label 'name' into register 'rn'. Use this when 300b8b572e1SStephen Rothwell * you don't particularly need immediate instructions only, but you need 301b8b572e1SStephen Rothwell * the whole address in one register (e.g. it's a structure address and 302b8b572e1SStephen Rothwell * you want to access various offsets within it). On ppc32 this is 303b8b572e1SStephen Rothwell * identical to LOAD_REG_IMMEDIATE. 304b8b572e1SStephen Rothwell * 3051c49abecSKevin Hao * LOAD_REG_ADDR_PIC(rn, name) 3061c49abecSKevin Hao * Loads the address of label 'name' into register 'run'. Use this when 3071c49abecSKevin Hao * the kernel doesn't run at the linked or relocated address. Please 3081c49abecSKevin Hao * note that this macro will clobber the lr register. 3091c49abecSKevin Hao * 310b8b572e1SStephen Rothwell * LOAD_REG_ADDRBASE(rn, name) 311b8b572e1SStephen Rothwell * ADDROFF(name) 312b8b572e1SStephen Rothwell * LOAD_REG_ADDRBASE loads part of the address of label 'name' into 313b8b572e1SStephen Rothwell * register 'rn'. ADDROFF(name) returns the remainder of the address as 314b8b572e1SStephen Rothwell * a constant expression. ADDROFF(name) is a signed expression < 16 bits 315b8b572e1SStephen Rothwell * in size, so is suitable for use directly as an offset in load and store 316b8b572e1SStephen Rothwell * instructions. Use this when loading/storing a single word or less as: 317b8b572e1SStephen Rothwell * LOAD_REG_ADDRBASE(rX, name) 318b8b572e1SStephen Rothwell * ld rY,ADDROFF(name)(rX) 319b8b572e1SStephen Rothwell */ 3201c49abecSKevin Hao 3211c49abecSKevin Hao /* Be careful, this will clobber the lr register. */ 3221c49abecSKevin Hao #define LOAD_REG_ADDR_PIC(reg, name) \ 323f5007dbfSChristophe Leroy bcl 20,31,$+4; \ 3241c49abecSKevin Hao 0: mflr reg; \ 3251c49abecSKevin Hao addis reg,reg,(name - 0b)@ha; \ 3261c49abecSKevin Hao addi reg,reg,(name - 0b)@l; 3271c49abecSKevin Hao 328c691b4b8SChristophe Leroy #if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH) 3297998eb3dSGuenter Roeck #define __AS_ATHIGH high 3307998eb3dSGuenter Roeck #else 3317998eb3dSGuenter Roeck #define __AS_ATHIGH h 3327998eb3dSGuenter Roeck #endif 333c691b4b8SChristophe Leroy 334c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE_32 r, x 335c691b4b8SChristophe Leroy .if (\x) >= 0x8000 || (\x) < -0x8000 336c691b4b8SChristophe Leroy lis \r, (\x)@__AS_ATHIGH 337c691b4b8SChristophe Leroy .if (\x) & 0xffff != 0 338c691b4b8SChristophe Leroy ori \r, \r, (\x)@l 339c691b4b8SChristophe Leroy .endif 340c691b4b8SChristophe Leroy .else 341c691b4b8SChristophe Leroy li \r, (\x)@l 342c691b4b8SChristophe Leroy .endif 343c691b4b8SChristophe Leroy .endm 344c691b4b8SChristophe Leroy 345c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE r, x 346c691b4b8SChristophe Leroy .if (\x) >= 0x80000000 || (\x) < -0x80000000 347c691b4b8SChristophe Leroy __LOAD_REG_IMMEDIATE_32 \r, (\x) >> 32 348c691b4b8SChristophe Leroy sldi \r, \r, 32 349c691b4b8SChristophe Leroy .if (\x) & 0xffff0000 != 0 350c691b4b8SChristophe Leroy oris \r, \r, (\x)@__AS_ATHIGH 351c691b4b8SChristophe Leroy .endif 352c691b4b8SChristophe Leroy .if (\x) & 0xffff != 0 353c691b4b8SChristophe Leroy ori \r, \r, (\x)@l 354c691b4b8SChristophe Leroy .endif 355c691b4b8SChristophe Leroy .else 356c691b4b8SChristophe Leroy __LOAD_REG_IMMEDIATE_32 \r, \x 357c691b4b8SChristophe Leroy .endif 358c691b4b8SChristophe Leroy .endm 359c691b4b8SChristophe Leroy 360c691b4b8SChristophe Leroy #ifdef __powerpc64__ 361c691b4b8SChristophe Leroy 3627e3a68beSNicholas Piggin #ifdef CONFIG_PPC_KERNEL_PCREL 3637e3a68beSNicholas Piggin #define __LOAD_PACA_TOC(reg) \ 3647e3a68beSNicholas Piggin li reg,-1 3657e3a68beSNicholas Piggin #else 3668e93fb33SNicholas Piggin #define __LOAD_PACA_TOC(reg) \ 3678e93fb33SNicholas Piggin ld reg,PACATOC(r13) 3687e3a68beSNicholas Piggin #endif 3698e93fb33SNicholas Piggin 3708e93fb33SNicholas Piggin #define LOAD_PACA_TOC() \ 3718e93fb33SNicholas Piggin __LOAD_PACA_TOC(r2) 3728e93fb33SNicholas Piggin 373c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE reg, expr 374c691b4b8SChristophe Leroy 375d7fb5b18SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg, tmp, expr) \ 376d7fb5b18SChristophe Leroy lis tmp, (expr)@highest; \ 377d7fb5b18SChristophe Leroy lis reg, (expr)@__AS_ATHIGH; \ 378d7fb5b18SChristophe Leroy ori tmp, tmp, (expr)@higher; \ 379d7fb5b18SChristophe Leroy ori reg, reg, (expr)@l; \ 380d7fb5b18SChristophe Leroy rldimi reg, tmp, 32, 0 381b8b572e1SStephen Rothwell 382*77e69ee7SNicholas Piggin #ifdef CONFIG_PPC_KERNEL_PCREL 3837e3a68beSNicholas Piggin #define LOAD_REG_ADDR(reg,name) \ 3847e3a68beSNicholas Piggin pla reg,name@pcrel 3857e3a68beSNicholas Piggin 3867e3a68beSNicholas Piggin #else 387b8b572e1SStephen Rothwell #define LOAD_REG_ADDR(reg,name) \ 388754f6117SNicholas Piggin addis reg,r2,name@toc@ha; \ 389754f6117SNicholas Piggin addi reg,reg,name@toc@l 3907e3a68beSNicholas Piggin #endif 391b8b572e1SStephen Rothwell 3923569d84bSNicholas Piggin #ifdef CONFIG_PPC_BOOK3E_64 3933569d84bSNicholas Piggin /* 3943569d84bSNicholas Piggin * This is used in register-constrained interrupt handlers. Not to be used 3953569d84bSNicholas Piggin * by BOOK3S. ld complains with "got/toc optimization is not supported" if r2 3963569d84bSNicholas Piggin * is not used for the TOC offset, so use @got(tocreg). If the interrupt 3973569d84bSNicholas Piggin * handlers saved r2 instead, LOAD_REG_ADDR could be used. 3983569d84bSNicholas Piggin */ 3993569d84bSNicholas Piggin #define LOAD_REG_ADDR_ALTTOC(reg,tocreg,name) \ 4003569d84bSNicholas Piggin ld reg,name@got(tocreg) 4013569d84bSNicholas Piggin #endif 4023569d84bSNicholas Piggin 403b8b572e1SStephen Rothwell #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name) 404b8b572e1SStephen Rothwell #define ADDROFF(name) 0 405b8b572e1SStephen Rothwell 406b8b572e1SStephen Rothwell /* offsets for stack frame layout */ 407b8b572e1SStephen Rothwell #define LRSAVE 16 408b8b572e1SStephen Rothwell 409b8b572e1SStephen Rothwell #else /* 32-bit */ 410b8b572e1SStephen Rothwell 411c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr 412c691b4b8SChristophe Leroy 413c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg,expr) \ 414564aa5cfSMichael Neuling lis reg,(expr)@ha; \ 415564aa5cfSMichael Neuling addi reg,reg,(expr)@l; 416b8b572e1SStephen Rothwell 417c691b4b8SChristophe Leroy #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE_SYM(reg, name) 418b8b572e1SStephen Rothwell 419564aa5cfSMichael Neuling #define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha 420b8b572e1SStephen Rothwell #define ADDROFF(name) name@l 421b8b572e1SStephen Rothwell 422b8b572e1SStephen Rothwell /* offsets for stack frame layout */ 423b8b572e1SStephen Rothwell #define LRSAVE 4 424b8b572e1SStephen Rothwell 425b8b572e1SStephen Rothwell #endif 426b8b572e1SStephen Rothwell 427b8b572e1SStephen Rothwell /* various errata or part fixups */ 4283e731858SChristophe Leroy #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_E500) 429b8b572e1SStephen Rothwell #define MFTB(dest) \ 430beb2dc0aSScott Wood 90: mfspr dest, SPRN_TBRL; \ 431b8b572e1SStephen Rothwell BEGIN_FTR_SECTION_NESTED(96); \ 432b8b572e1SStephen Rothwell cmpwi dest,0; \ 433b8b572e1SStephen Rothwell beq- 90b; \ 434b8b572e1SStephen Rothwell END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96) 435b8b572e1SStephen Rothwell #else 43672e4b2cdSChristophe Leroy #define MFTB(dest) MFTBL(dest) 43772e4b2cdSChristophe Leroy #endif 43872e4b2cdSChristophe Leroy 43972e4b2cdSChristophe Leroy #ifdef CONFIG_PPC_8xx 44072e4b2cdSChristophe Leroy #define MFTBL(dest) mftb dest 44172e4b2cdSChristophe Leroy #define MFTBU(dest) mftbu dest 44272e4b2cdSChristophe Leroy #else 44372e4b2cdSChristophe Leroy #define MFTBL(dest) mfspr dest, SPRN_TBRL 44472e4b2cdSChristophe Leroy #define MFTBU(dest) mfspr dest, SPRN_TBRU 445b8b572e1SStephen Rothwell #endif 446b8b572e1SStephen Rothwell 4478b14e1dfSChristophe Leroy #ifndef CONFIG_SMP 44812c3f1fdSChristophe Leroy #define TLBSYNC 44912c3f1fdSChristophe Leroy #else 45012c3f1fdSChristophe Leroy #define TLBSYNC tlbsync; sync 451b8b572e1SStephen Rothwell #endif 452b8b572e1SStephen Rothwell 453694caf02SAnton Blanchard #ifdef CONFIG_PPC64 454694caf02SAnton Blanchard #define MTOCRF(FXM, RS) \ 455694caf02SAnton Blanchard BEGIN_FTR_SECTION_NESTED(848); \ 45686e32fdcSMichael Neuling mtcrf (FXM), RS; \ 457694caf02SAnton Blanchard FTR_SECTION_ELSE_NESTED(848); \ 45886e32fdcSMichael Neuling mtocrf (FXM), RS; \ 459694caf02SAnton Blanchard ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848) 460694caf02SAnton Blanchard #endif 461b8b572e1SStephen Rothwell 462b8b572e1SStephen Rothwell /* 463b8b572e1SStephen Rothwell * This instruction is not implemented on the PPC 603 or 601; however, on 464b8b572e1SStephen Rothwell * the 403GCX and 405GP tlbia IS defined and tlbie is not. 465b8b572e1SStephen Rothwell * All of these instructions exist in the 8xx, they have magical powers, 466b8b572e1SStephen Rothwell * and they must be used. 467b8b572e1SStephen Rothwell */ 468b8b572e1SStephen Rothwell 469968159c0SChristophe Leroy #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx) 470b8b572e1SStephen Rothwell #define tlbia \ 471b8b572e1SStephen Rothwell li r4,1024; \ 472b8b572e1SStephen Rothwell mtctr r4; \ 473b8b572e1SStephen Rothwell lis r4,KERNELBASE@h; \ 474e3824e42SRussell Currey .machine push; \ 475e3824e42SRussell Currey .machine "power4"; \ 476b8b572e1SStephen Rothwell 0: tlbie r4; \ 477e3824e42SRussell Currey .machine pop; \ 478b8b572e1SStephen Rothwell addi r4,r4,0x1000; \ 479b8b572e1SStephen Rothwell bdnz 0b 480b8b572e1SStephen Rothwell #endif 481b8b572e1SStephen Rothwell 482b8b572e1SStephen Rothwell 483b8b572e1SStephen Rothwell #ifdef CONFIG_IBM440EP_ERR42 484b8b572e1SStephen Rothwell #define PPC440EP_ERR42 isync 485b8b572e1SStephen Rothwell #else 486b8b572e1SStephen Rothwell #define PPC440EP_ERR42 487b8b572e1SStephen Rothwell #endif 488b8b572e1SStephen Rothwell 489a515348fSMichael Neuling /* The following stops all load and store data streams associated with stream 490a515348fSMichael Neuling * ID (ie. streams created explicitly). The embedded and server mnemonics for 49115a3204dSNicholas Piggin * dcbt are different so this must only be used for server. 492a515348fSMichael Neuling */ 49315a3204dSNicholas Piggin #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch) \ 494a515348fSMichael Neuling lis scratch,0x60000000@h; \ 49515a3204dSNicholas Piggin dcbt 0,scratch,0b01010 496a515348fSMichael Neuling 49744c58cccSBenjamin Herrenschmidt /* 49844c58cccSBenjamin Herrenschmidt * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them 49944c58cccSBenjamin Herrenschmidt * keep the address intact to be compatible with code shared with 50044c58cccSBenjamin Herrenschmidt * 32-bit classic. 50144c58cccSBenjamin Herrenschmidt * 50244c58cccSBenjamin Herrenschmidt * On the other hand, I find it useful to have them behave as expected 50344c58cccSBenjamin Herrenschmidt * by their name (ie always do the addition) on 64-bit BookE 50444c58cccSBenjamin Herrenschmidt */ 50544c58cccSBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64) 506b8b572e1SStephen Rothwell #define toreal(rd) 507b8b572e1SStephen Rothwell #define fromreal(rd) 508b8b572e1SStephen Rothwell 509b8b572e1SStephen Rothwell /* 510b8b572e1SStephen Rothwell * We use addis to ensure compatibility with the "classic" ppc versions of 511b8b572e1SStephen Rothwell * these macros, which use rs = 0 to get the tophys offset in rd, rather than 512b8b572e1SStephen Rothwell * converting the address in r0, and so this version has to do that too 513b8b572e1SStephen Rothwell * (i.e. set register rd to 0 when rs == 0). 514b8b572e1SStephen Rothwell */ 515b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 516b8b572e1SStephen Rothwell addis rd,rs,0 517b8b572e1SStephen Rothwell 518b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 519b8b572e1SStephen Rothwell addis rd,rs,0 520b8b572e1SStephen Rothwell 521b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC64) 522b8b572e1SStephen Rothwell #define toreal(rd) /* we can access c000... in real mode */ 523b8b572e1SStephen Rothwell #define fromreal(rd) 524b8b572e1SStephen Rothwell 525b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 526b8b572e1SStephen Rothwell clrldi rd,rs,2 527b8b572e1SStephen Rothwell 528b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 529b8b572e1SStephen Rothwell rotldi rd,rs,16; \ 530b8b572e1SStephen Rothwell ori rd,rd,((KERNELBASE>>48)&0xFFFF);\ 531b8b572e1SStephen Rothwell rotldi rd,rd,48 532b8b572e1SStephen Rothwell #else 533b8b572e1SStephen Rothwell #define toreal(rd) tophys(rd,rd) 534b8b572e1SStephen Rothwell #define fromreal(rd) tovirt(rd,rd) 535b8b572e1SStephen Rothwell 536c62ce9efSChristophe Leroy #define tophys(rd, rs) addis rd, rs, -PAGE_OFFSET@h 537c62ce9efSChristophe Leroy #define tovirt(rd, rs) addis rd, rs, PAGE_OFFSET@h 538b8b572e1SStephen Rothwell #endif 539b8b572e1SStephen Rothwell 54044c58cccSBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S_64 541b8b572e1SStephen Rothwell #define MTMSRD(r) mtmsrd r 542b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg) mtmsrd reg,1 543b8b572e1SStephen Rothwell #else 544b8b572e1SStephen Rothwell #define MTMSRD(r) mtmsr r 545b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg) mtmsr reg 546b8b572e1SStephen Rothwell #endif 547b8b572e1SStephen Rothwell 548b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 549b8b572e1SStephen Rothwell 550b8b572e1SStephen Rothwell /* The boring bits... */ 551b8b572e1SStephen Rothwell 552b8b572e1SStephen Rothwell /* Condition Register Bit Fields */ 553b8b572e1SStephen Rothwell 554b8b572e1SStephen Rothwell #define cr0 0 555b8b572e1SStephen Rothwell #define cr1 1 556b8b572e1SStephen Rothwell #define cr2 2 557b8b572e1SStephen Rothwell #define cr3 3 558b8b572e1SStephen Rothwell #define cr4 4 559b8b572e1SStephen Rothwell #define cr5 5 560b8b572e1SStephen Rothwell #define cr6 6 561b8b572e1SStephen Rothwell #define cr7 7 562b8b572e1SStephen Rothwell 563b8b572e1SStephen Rothwell 5649a13a524SMichael Neuling /* 5659a13a524SMichael Neuling * General Purpose Registers (GPRs) 5669a13a524SMichael Neuling * 5679a13a524SMichael Neuling * The lower case r0-r31 should be used in preference to the upper 5689a13a524SMichael Neuling * case R0-R31 as they provide more error checking in the assembler. 5699a13a524SMichael Neuling * Use R0-31 only when really nessesary. 5709a13a524SMichael Neuling */ 571b8b572e1SStephen Rothwell 5729a13a524SMichael Neuling #define r0 %r0 5739a13a524SMichael Neuling #define r1 %r1 5749a13a524SMichael Neuling #define r2 %r2 5759a13a524SMichael Neuling #define r3 %r3 5769a13a524SMichael Neuling #define r4 %r4 5779a13a524SMichael Neuling #define r5 %r5 5789a13a524SMichael Neuling #define r6 %r6 5799a13a524SMichael Neuling #define r7 %r7 5809a13a524SMichael Neuling #define r8 %r8 5819a13a524SMichael Neuling #define r9 %r9 5829a13a524SMichael Neuling #define r10 %r10 5839a13a524SMichael Neuling #define r11 %r11 5849a13a524SMichael Neuling #define r12 %r12 5859a13a524SMichael Neuling #define r13 %r13 5869a13a524SMichael Neuling #define r14 %r14 5879a13a524SMichael Neuling #define r15 %r15 5889a13a524SMichael Neuling #define r16 %r16 5899a13a524SMichael Neuling #define r17 %r17 5909a13a524SMichael Neuling #define r18 %r18 5919a13a524SMichael Neuling #define r19 %r19 5929a13a524SMichael Neuling #define r20 %r20 5939a13a524SMichael Neuling #define r21 %r21 5949a13a524SMichael Neuling #define r22 %r22 5959a13a524SMichael Neuling #define r23 %r23 5969a13a524SMichael Neuling #define r24 %r24 5979a13a524SMichael Neuling #define r25 %r25 5989a13a524SMichael Neuling #define r26 %r26 5999a13a524SMichael Neuling #define r27 %r27 6009a13a524SMichael Neuling #define r28 %r28 6019a13a524SMichael Neuling #define r29 %r29 6029a13a524SMichael Neuling #define r30 %r30 6039a13a524SMichael Neuling #define r31 %r31 604b8b572e1SStephen Rothwell 605b8b572e1SStephen Rothwell 606b8b572e1SStephen Rothwell /* Floating Point Registers (FPRs) */ 607b8b572e1SStephen Rothwell 608b8b572e1SStephen Rothwell #define fr0 0 609b8b572e1SStephen Rothwell #define fr1 1 610b8b572e1SStephen Rothwell #define fr2 2 611b8b572e1SStephen Rothwell #define fr3 3 612b8b572e1SStephen Rothwell #define fr4 4 613b8b572e1SStephen Rothwell #define fr5 5 614b8b572e1SStephen Rothwell #define fr6 6 615b8b572e1SStephen Rothwell #define fr7 7 616b8b572e1SStephen Rothwell #define fr8 8 617b8b572e1SStephen Rothwell #define fr9 9 618b8b572e1SStephen Rothwell #define fr10 10 619b8b572e1SStephen Rothwell #define fr11 11 620b8b572e1SStephen Rothwell #define fr12 12 621b8b572e1SStephen Rothwell #define fr13 13 622b8b572e1SStephen Rothwell #define fr14 14 623b8b572e1SStephen Rothwell #define fr15 15 624b8b572e1SStephen Rothwell #define fr16 16 625b8b572e1SStephen Rothwell #define fr17 17 626b8b572e1SStephen Rothwell #define fr18 18 627b8b572e1SStephen Rothwell #define fr19 19 628b8b572e1SStephen Rothwell #define fr20 20 629b8b572e1SStephen Rothwell #define fr21 21 630b8b572e1SStephen Rothwell #define fr22 22 631b8b572e1SStephen Rothwell #define fr23 23 632b8b572e1SStephen Rothwell #define fr24 24 633b8b572e1SStephen Rothwell #define fr25 25 634b8b572e1SStephen Rothwell #define fr26 26 635b8b572e1SStephen Rothwell #define fr27 27 636b8b572e1SStephen Rothwell #define fr28 28 637b8b572e1SStephen Rothwell #define fr29 29 638b8b572e1SStephen Rothwell #define fr30 30 639b8b572e1SStephen Rothwell #define fr31 31 640b8b572e1SStephen Rothwell 641b8b572e1SStephen Rothwell /* AltiVec Registers (VPRs) */ 642b8b572e1SStephen Rothwell 643c2ce6f9fSAnton Blanchard #define v0 0 644c2ce6f9fSAnton Blanchard #define v1 1 645c2ce6f9fSAnton Blanchard #define v2 2 646c2ce6f9fSAnton Blanchard #define v3 3 647c2ce6f9fSAnton Blanchard #define v4 4 648c2ce6f9fSAnton Blanchard #define v5 5 649c2ce6f9fSAnton Blanchard #define v6 6 650c2ce6f9fSAnton Blanchard #define v7 7 651c2ce6f9fSAnton Blanchard #define v8 8 652c2ce6f9fSAnton Blanchard #define v9 9 653c2ce6f9fSAnton Blanchard #define v10 10 654c2ce6f9fSAnton Blanchard #define v11 11 655c2ce6f9fSAnton Blanchard #define v12 12 656c2ce6f9fSAnton Blanchard #define v13 13 657c2ce6f9fSAnton Blanchard #define v14 14 658c2ce6f9fSAnton Blanchard #define v15 15 659c2ce6f9fSAnton Blanchard #define v16 16 660c2ce6f9fSAnton Blanchard #define v17 17 661c2ce6f9fSAnton Blanchard #define v18 18 662c2ce6f9fSAnton Blanchard #define v19 19 663c2ce6f9fSAnton Blanchard #define v20 20 664c2ce6f9fSAnton Blanchard #define v21 21 665c2ce6f9fSAnton Blanchard #define v22 22 666c2ce6f9fSAnton Blanchard #define v23 23 667c2ce6f9fSAnton Blanchard #define v24 24 668c2ce6f9fSAnton Blanchard #define v25 25 669c2ce6f9fSAnton Blanchard #define v26 26 670c2ce6f9fSAnton Blanchard #define v27 27 671c2ce6f9fSAnton Blanchard #define v28 28 672c2ce6f9fSAnton Blanchard #define v29 29 673c2ce6f9fSAnton Blanchard #define v30 30 674c2ce6f9fSAnton Blanchard #define v31 31 675b8b572e1SStephen Rothwell 676b8b572e1SStephen Rothwell /* VSX Registers (VSRs) */ 677b8b572e1SStephen Rothwell 678df99e6ebSAnton Blanchard #define vs0 0 679df99e6ebSAnton Blanchard #define vs1 1 680df99e6ebSAnton Blanchard #define vs2 2 681df99e6ebSAnton Blanchard #define vs3 3 682df99e6ebSAnton Blanchard #define vs4 4 683df99e6ebSAnton Blanchard #define vs5 5 684df99e6ebSAnton Blanchard #define vs6 6 685df99e6ebSAnton Blanchard #define vs7 7 686df99e6ebSAnton Blanchard #define vs8 8 687df99e6ebSAnton Blanchard #define vs9 9 688df99e6ebSAnton Blanchard #define vs10 10 689df99e6ebSAnton Blanchard #define vs11 11 690df99e6ebSAnton Blanchard #define vs12 12 691df99e6ebSAnton Blanchard #define vs13 13 692df99e6ebSAnton Blanchard #define vs14 14 693df99e6ebSAnton Blanchard #define vs15 15 694df99e6ebSAnton Blanchard #define vs16 16 695df99e6ebSAnton Blanchard #define vs17 17 696df99e6ebSAnton Blanchard #define vs18 18 697df99e6ebSAnton Blanchard #define vs19 19 698df99e6ebSAnton Blanchard #define vs20 20 699df99e6ebSAnton Blanchard #define vs21 21 700df99e6ebSAnton Blanchard #define vs22 22 701df99e6ebSAnton Blanchard #define vs23 23 702df99e6ebSAnton Blanchard #define vs24 24 703df99e6ebSAnton Blanchard #define vs25 25 704df99e6ebSAnton Blanchard #define vs26 26 705df99e6ebSAnton Blanchard #define vs27 27 706df99e6ebSAnton Blanchard #define vs28 28 707df99e6ebSAnton Blanchard #define vs29 29 708df99e6ebSAnton Blanchard #define vs30 30 709df99e6ebSAnton Blanchard #define vs31 31 710df99e6ebSAnton Blanchard #define vs32 32 711df99e6ebSAnton Blanchard #define vs33 33 712df99e6ebSAnton Blanchard #define vs34 34 713df99e6ebSAnton Blanchard #define vs35 35 714df99e6ebSAnton Blanchard #define vs36 36 715df99e6ebSAnton Blanchard #define vs37 37 716df99e6ebSAnton Blanchard #define vs38 38 717df99e6ebSAnton Blanchard #define vs39 39 718df99e6ebSAnton Blanchard #define vs40 40 719df99e6ebSAnton Blanchard #define vs41 41 720df99e6ebSAnton Blanchard #define vs42 42 721df99e6ebSAnton Blanchard #define vs43 43 722df99e6ebSAnton Blanchard #define vs44 44 723df99e6ebSAnton Blanchard #define vs45 45 724df99e6ebSAnton Blanchard #define vs46 46 725df99e6ebSAnton Blanchard #define vs47 47 726df99e6ebSAnton Blanchard #define vs48 48 727df99e6ebSAnton Blanchard #define vs49 49 728df99e6ebSAnton Blanchard #define vs50 50 729df99e6ebSAnton Blanchard #define vs51 51 730df99e6ebSAnton Blanchard #define vs52 52 731df99e6ebSAnton Blanchard #define vs53 53 732df99e6ebSAnton Blanchard #define vs54 54 733df99e6ebSAnton Blanchard #define vs55 55 734df99e6ebSAnton Blanchard #define vs56 56 735df99e6ebSAnton Blanchard #define vs57 57 736df99e6ebSAnton Blanchard #define vs58 58 737df99e6ebSAnton Blanchard #define vs59 59 738df99e6ebSAnton Blanchard #define vs60 60 739df99e6ebSAnton Blanchard #define vs61 61 740df99e6ebSAnton Blanchard #define vs62 62 741df99e6ebSAnton Blanchard #define vs63 63 742b8b572e1SStephen Rothwell 743b8b572e1SStephen Rothwell /* SPE Registers (EVPRs) */ 744b8b572e1SStephen Rothwell 745b8b572e1SStephen Rothwell #define evr0 0 746b8b572e1SStephen Rothwell #define evr1 1 747b8b572e1SStephen Rothwell #define evr2 2 748b8b572e1SStephen Rothwell #define evr3 3 749b8b572e1SStephen Rothwell #define evr4 4 750b8b572e1SStephen Rothwell #define evr5 5 751b8b572e1SStephen Rothwell #define evr6 6 752b8b572e1SStephen Rothwell #define evr7 7 753b8b572e1SStephen Rothwell #define evr8 8 754b8b572e1SStephen Rothwell #define evr9 9 755b8b572e1SStephen Rothwell #define evr10 10 756b8b572e1SStephen Rothwell #define evr11 11 757b8b572e1SStephen Rothwell #define evr12 12 758b8b572e1SStephen Rothwell #define evr13 13 759b8b572e1SStephen Rothwell #define evr14 14 760b8b572e1SStephen Rothwell #define evr15 15 761b8b572e1SStephen Rothwell #define evr16 16 762b8b572e1SStephen Rothwell #define evr17 17 763b8b572e1SStephen Rothwell #define evr18 18 764b8b572e1SStephen Rothwell #define evr19 19 765b8b572e1SStephen Rothwell #define evr20 20 766b8b572e1SStephen Rothwell #define evr21 21 767b8b572e1SStephen Rothwell #define evr22 22 768b8b572e1SStephen Rothwell #define evr23 23 769b8b572e1SStephen Rothwell #define evr24 24 770b8b572e1SStephen Rothwell #define evr25 25 771b8b572e1SStephen Rothwell #define evr26 26 772b8b572e1SStephen Rothwell #define evr27 27 773b8b572e1SStephen Rothwell #define evr28 28 774b8b572e1SStephen Rothwell #define evr29 29 775b8b572e1SStephen Rothwell #define evr30 30 776b8b572e1SStephen Rothwell #define evr31 31 777b8b572e1SStephen Rothwell 7787fa95f9aSNicholas Piggin #define RFSCV .long 0x4c0000a4 7797fa95f9aSNicholas Piggin 7805c0484e2SBenjamin Herrenschmidt /* 7815c0484e2SBenjamin Herrenschmidt * Create an endian fixup trampoline 7825c0484e2SBenjamin Herrenschmidt * 7835c0484e2SBenjamin Herrenschmidt * This starts with a "tdi 0,0,0x48" instruction which is 7845c0484e2SBenjamin Herrenschmidt * essentially a "trap never", and thus akin to a nop. 7855c0484e2SBenjamin Herrenschmidt * 7865c0484e2SBenjamin Herrenschmidt * The opcode for this instruction read with the wrong endian 7875c0484e2SBenjamin Herrenschmidt * however results in a b . + 8 7885c0484e2SBenjamin Herrenschmidt * 7895c0484e2SBenjamin Herrenschmidt * So essentially we use that trick to execute the following 7905c0484e2SBenjamin Herrenschmidt * trampoline in "reverse endian" if we are running with the 7915c0484e2SBenjamin Herrenschmidt * MSR_LE bit set the "wrong" way for whatever endianness the 7925c0484e2SBenjamin Herrenschmidt * kernel is built for. 7935c0484e2SBenjamin Herrenschmidt */ 794b8b572e1SStephen Rothwell 795e0d68273SChristophe Leroy #ifdef CONFIG_PPC_BOOK3E_64 7965c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN 7975c0484e2SBenjamin Herrenschmidt #else 7988ca9c08dSNicholas Piggin /* 799db10f550SRandy Dunlap * This version may be used in HV or non-HV context. 8008ca9c08dSNicholas Piggin * MSR[EE] must be disabled. 8018ca9c08dSNicholas Piggin */ 8025c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN \ 8035c0484e2SBenjamin Herrenschmidt tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ 804f848ea7fSNicholas Piggin b 191f; /* Skip trampoline if endian is good */ \ 8055c0484e2SBenjamin Herrenschmidt .long 0xa600607d; /* mfmsr r11 */ \ 8065c0484e2SBenjamin Herrenschmidt .long 0x01006b69; /* xori r11,r11,1 */ \ 807f1fe5252SNicholas Piggin .long 0x00004039; /* li r10,0 */ \ 808f1fe5252SNicholas Piggin .long 0x6401417d; /* mtmsrd r10,1 */ \ 809f1fe5252SNicholas Piggin .long 0x05009f42; /* bcl 20,31,$+4 */ \ 810f1fe5252SNicholas Piggin .long 0xa602487d; /* mflr r10 */ \ 811f1fe5252SNicholas Piggin .long 0x14004a39; /* addi r10,r10,20 */ \ 8125c0484e2SBenjamin Herrenschmidt .long 0xa6035a7d; /* mtsrr0 r10 */ \ 8135c0484e2SBenjamin Herrenschmidt .long 0xa6037b7d; /* mtsrr1 r11 */ \ 814f848ea7fSNicholas Piggin .long 0x2400004c; /* rfid */ \ 815f848ea7fSNicholas Piggin 191: 816f1fe5252SNicholas Piggin 8178ca9c08dSNicholas Piggin /* 8188ca9c08dSNicholas Piggin * This version that may only be used with MSR[HV]=1 8198ca9c08dSNicholas Piggin * - Does not clear MSR[RI], so more robust. 8208ca9c08dSNicholas Piggin * - Slightly smaller and faster. 8218ca9c08dSNicholas Piggin */ 8228ca9c08dSNicholas Piggin #define FIXUP_ENDIAN_HV \ 8238ca9c08dSNicholas Piggin tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ 8248ca9c08dSNicholas Piggin b 191f; /* Skip trampoline if endian is good */ \ 8258ca9c08dSNicholas Piggin .long 0xa600607d; /* mfmsr r11 */ \ 8268ca9c08dSNicholas Piggin .long 0x01006b69; /* xori r11,r11,1 */ \ 8278ca9c08dSNicholas Piggin .long 0x05009f42; /* bcl 20,31,$+4 */ \ 8288ca9c08dSNicholas Piggin .long 0xa602487d; /* mflr r10 */ \ 8298ca9c08dSNicholas Piggin .long 0x14004a39; /* addi r10,r10,20 */ \ 8308ca9c08dSNicholas Piggin .long 0xa64b5a7d; /* mthsrr0 r10 */ \ 8318ca9c08dSNicholas Piggin .long 0xa64b7b7d; /* mthsrr1 r11 */ \ 8328ca9c08dSNicholas Piggin .long 0x2402004c; /* hrfid */ \ 8338ca9c08dSNicholas Piggin 191: 8348ca9c08dSNicholas Piggin 835e0d68273SChristophe Leroy #endif /* !CONFIG_PPC_BOOK3E_64 */ 836e3f2c6c3SMichael Ellerman 8375c0484e2SBenjamin Herrenschmidt #endif /* __ASSEMBLY__ */ 838e3f2c6c3SMichael Ellerman 839325678fdSNicholas Piggin #define SOFT_MASK_TABLE(_start, _end) \ 840325678fdSNicholas Piggin stringify_in_c(.section __soft_mask_table,"a";)\ 841325678fdSNicholas Piggin stringify_in_c(.balign 8;) \ 842325678fdSNicholas Piggin stringify_in_c(.llong (_start);) \ 843325678fdSNicholas Piggin stringify_in_c(.llong (_end);) \ 844325678fdSNicholas Piggin stringify_in_c(.previous) 845325678fdSNicholas Piggin 846f23699c9SNicholas Piggin #define RESTART_TABLE(_start, _end, _target) \ 847f23699c9SNicholas Piggin stringify_in_c(.section __restart_table,"a";)\ 848f23699c9SNicholas Piggin stringify_in_c(.balign 8;) \ 849f23699c9SNicholas Piggin stringify_in_c(.llong (_start);) \ 850f23699c9SNicholas Piggin stringify_in_c(.llong (_end);) \ 851f23699c9SNicholas Piggin stringify_in_c(.llong (_target);) \ 852f23699c9SNicholas Piggin stringify_in_c(.previous) 853f23699c9SNicholas Piggin 8543e731858SChristophe Leroy #ifdef CONFIG_PPC_E500 8551cbf8990SDiana Craciun #define BTB_FLUSH(reg) \ 8561cbf8990SDiana Craciun lis reg,BUCSR_INIT@h; \ 8571cbf8990SDiana Craciun ori reg,reg,BUCSR_INIT@l; \ 8581cbf8990SDiana Craciun mtspr SPRN_BUCSR,reg; \ 8591cbf8990SDiana Craciun isync; 8601cbf8990SDiana Craciun #else 8611cbf8990SDiana Craciun #define BTB_FLUSH(reg) 8623e731858SChristophe Leroy #endif /* CONFIG_PPC_E500 */ 8631cbf8990SDiana Craciun 864ac9c8901SNicholas Miehlbradt #if defined(CONFIG_PPC64_ELF_ABI_V1) 865ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 48 866ac9c8901SNicholas Miehlbradt #elif defined(CONFIG_PPC64_ELF_ABI_V2) 867ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 32 868ac9c8901SNicholas Miehlbradt #elif defined(CONFIG_PPC32) 869ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 8 870ac9c8901SNicholas Miehlbradt #endif 871ac9c8901SNicholas Miehlbradt 872b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PPC_ASM_H */ 873