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 */ 18677e69ee7SNicholas 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 21977e69ee7SNicholas 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 38277e69ee7SNicholas 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 409*afc63868SNicholas Piggin /* 410*afc63868SNicholas Piggin * GCC stack frames follow a different pattern on 32 vs 64. This can be used 411*afc63868SNicholas Piggin * to make asm frames be consistent with C. 412*afc63868SNicholas Piggin */ 413*afc63868SNicholas Piggin #define PPC_CREATE_STACK_FRAME(size) \ 414*afc63868SNicholas Piggin mflr r0; \ 415*afc63868SNicholas Piggin std r0,16(r1); \ 416*afc63868SNicholas Piggin stdu r1,-(size)(r1) 417*afc63868SNicholas Piggin 418b8b572e1SStephen Rothwell #else /* 32-bit */ 419b8b572e1SStephen Rothwell 420c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr 421c691b4b8SChristophe Leroy 422c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg,expr) \ 423564aa5cfSMichael Neuling lis reg,(expr)@ha; \ 424564aa5cfSMichael Neuling addi reg,reg,(expr)@l; 425b8b572e1SStephen Rothwell 426c691b4b8SChristophe Leroy #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE_SYM(reg, name) 427b8b572e1SStephen Rothwell 428564aa5cfSMichael Neuling #define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha 429b8b572e1SStephen Rothwell #define ADDROFF(name) name@l 430b8b572e1SStephen Rothwell 431b8b572e1SStephen Rothwell /* offsets for stack frame layout */ 432b8b572e1SStephen Rothwell #define LRSAVE 4 433b8b572e1SStephen Rothwell 434*afc63868SNicholas Piggin #define PPC_CREATE_STACK_FRAME(size) \ 435*afc63868SNicholas Piggin stwu r1,-(size)(r1); \ 436*afc63868SNicholas Piggin mflr r0; \ 437*afc63868SNicholas Piggin stw r0,(size+4)(r1) 438*afc63868SNicholas Piggin 439b8b572e1SStephen Rothwell #endif 440b8b572e1SStephen Rothwell 441b8b572e1SStephen Rothwell /* various errata or part fixups */ 4423e731858SChristophe Leroy #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_E500) 443b8b572e1SStephen Rothwell #define MFTB(dest) \ 444beb2dc0aSScott Wood 90: mfspr dest, SPRN_TBRL; \ 445b8b572e1SStephen Rothwell BEGIN_FTR_SECTION_NESTED(96); \ 446b8b572e1SStephen Rothwell cmpwi dest,0; \ 447b8b572e1SStephen Rothwell beq- 90b; \ 448b8b572e1SStephen Rothwell END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96) 449b8b572e1SStephen Rothwell #else 45072e4b2cdSChristophe Leroy #define MFTB(dest) MFTBL(dest) 45172e4b2cdSChristophe Leroy #endif 45272e4b2cdSChristophe Leroy 45372e4b2cdSChristophe Leroy #ifdef CONFIG_PPC_8xx 45472e4b2cdSChristophe Leroy #define MFTBL(dest) mftb dest 45572e4b2cdSChristophe Leroy #define MFTBU(dest) mftbu dest 45672e4b2cdSChristophe Leroy #else 45772e4b2cdSChristophe Leroy #define MFTBL(dest) mfspr dest, SPRN_TBRL 45872e4b2cdSChristophe Leroy #define MFTBU(dest) mfspr dest, SPRN_TBRU 459b8b572e1SStephen Rothwell #endif 460b8b572e1SStephen Rothwell 4618b14e1dfSChristophe Leroy #ifndef CONFIG_SMP 46212c3f1fdSChristophe Leroy #define TLBSYNC 46312c3f1fdSChristophe Leroy #else 46412c3f1fdSChristophe Leroy #define TLBSYNC tlbsync; sync 465b8b572e1SStephen Rothwell #endif 466b8b572e1SStephen Rothwell 467694caf02SAnton Blanchard #ifdef CONFIG_PPC64 468694caf02SAnton Blanchard #define MTOCRF(FXM, RS) \ 469694caf02SAnton Blanchard BEGIN_FTR_SECTION_NESTED(848); \ 47086e32fdcSMichael Neuling mtcrf (FXM), RS; \ 471694caf02SAnton Blanchard FTR_SECTION_ELSE_NESTED(848); \ 47286e32fdcSMichael Neuling mtocrf (FXM), RS; \ 473694caf02SAnton Blanchard ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848) 474694caf02SAnton Blanchard #endif 475b8b572e1SStephen Rothwell 476b8b572e1SStephen Rothwell /* 477b8b572e1SStephen Rothwell * This instruction is not implemented on the PPC 603 or 601; however, on 478b8b572e1SStephen Rothwell * the 403GCX and 405GP tlbia IS defined and tlbie is not. 479b8b572e1SStephen Rothwell * All of these instructions exist in the 8xx, they have magical powers, 480b8b572e1SStephen Rothwell * and they must be used. 481b8b572e1SStephen Rothwell */ 482b8b572e1SStephen Rothwell 483968159c0SChristophe Leroy #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx) 484b8b572e1SStephen Rothwell #define tlbia \ 485b8b572e1SStephen Rothwell li r4,1024; \ 486b8b572e1SStephen Rothwell mtctr r4; \ 487b8b572e1SStephen Rothwell lis r4,KERNELBASE@h; \ 488e3824e42SRussell Currey .machine push; \ 489e3824e42SRussell Currey .machine "power4"; \ 490b8b572e1SStephen Rothwell 0: tlbie r4; \ 491e3824e42SRussell Currey .machine pop; \ 492b8b572e1SStephen Rothwell addi r4,r4,0x1000; \ 493b8b572e1SStephen Rothwell bdnz 0b 494b8b572e1SStephen Rothwell #endif 495b8b572e1SStephen Rothwell 496b8b572e1SStephen Rothwell 497b8b572e1SStephen Rothwell #ifdef CONFIG_IBM440EP_ERR42 498b8b572e1SStephen Rothwell #define PPC440EP_ERR42 isync 499b8b572e1SStephen Rothwell #else 500b8b572e1SStephen Rothwell #define PPC440EP_ERR42 501b8b572e1SStephen Rothwell #endif 502b8b572e1SStephen Rothwell 503a515348fSMichael Neuling /* The following stops all load and store data streams associated with stream 504a515348fSMichael Neuling * ID (ie. streams created explicitly). The embedded and server mnemonics for 50515a3204dSNicholas Piggin * dcbt are different so this must only be used for server. 506a515348fSMichael Neuling */ 50715a3204dSNicholas Piggin #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch) \ 508a515348fSMichael Neuling lis scratch,0x60000000@h; \ 50915a3204dSNicholas Piggin dcbt 0,scratch,0b01010 510a515348fSMichael Neuling 51144c58cccSBenjamin Herrenschmidt /* 51244c58cccSBenjamin Herrenschmidt * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them 51344c58cccSBenjamin Herrenschmidt * keep the address intact to be compatible with code shared with 51444c58cccSBenjamin Herrenschmidt * 32-bit classic. 51544c58cccSBenjamin Herrenschmidt * 51644c58cccSBenjamin Herrenschmidt * On the other hand, I find it useful to have them behave as expected 51744c58cccSBenjamin Herrenschmidt * by their name (ie always do the addition) on 64-bit BookE 51844c58cccSBenjamin Herrenschmidt */ 51944c58cccSBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64) 520b8b572e1SStephen Rothwell #define toreal(rd) 521b8b572e1SStephen Rothwell #define fromreal(rd) 522b8b572e1SStephen Rothwell 523b8b572e1SStephen Rothwell /* 524b8b572e1SStephen Rothwell * We use addis to ensure compatibility with the "classic" ppc versions of 525b8b572e1SStephen Rothwell * these macros, which use rs = 0 to get the tophys offset in rd, rather than 526b8b572e1SStephen Rothwell * converting the address in r0, and so this version has to do that too 527b8b572e1SStephen Rothwell * (i.e. set register rd to 0 when rs == 0). 528b8b572e1SStephen Rothwell */ 529b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 530b8b572e1SStephen Rothwell addis rd,rs,0 531b8b572e1SStephen Rothwell 532b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 533b8b572e1SStephen Rothwell addis rd,rs,0 534b8b572e1SStephen Rothwell 535b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC64) 536b8b572e1SStephen Rothwell #define toreal(rd) /* we can access c000... in real mode */ 537b8b572e1SStephen Rothwell #define fromreal(rd) 538b8b572e1SStephen Rothwell 539b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 540b8b572e1SStephen Rothwell clrldi rd,rs,2 541b8b572e1SStephen Rothwell 542b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 543b8b572e1SStephen Rothwell rotldi rd,rs,16; \ 544b8b572e1SStephen Rothwell ori rd,rd,((KERNELBASE>>48)&0xFFFF);\ 545b8b572e1SStephen Rothwell rotldi rd,rd,48 546b8b572e1SStephen Rothwell #else 547b8b572e1SStephen Rothwell #define toreal(rd) tophys(rd,rd) 548b8b572e1SStephen Rothwell #define fromreal(rd) tovirt(rd,rd) 549b8b572e1SStephen Rothwell 550c62ce9efSChristophe Leroy #define tophys(rd, rs) addis rd, rs, -PAGE_OFFSET@h 551c62ce9efSChristophe Leroy #define tovirt(rd, rs) addis rd, rs, PAGE_OFFSET@h 552b8b572e1SStephen Rothwell #endif 553b8b572e1SStephen Rothwell 55444c58cccSBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S_64 555b8b572e1SStephen Rothwell #define MTMSRD(r) mtmsrd r 556b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg) mtmsrd reg,1 557b8b572e1SStephen Rothwell #else 558b8b572e1SStephen Rothwell #define MTMSRD(r) mtmsr r 559b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg) mtmsr reg 560b8b572e1SStephen Rothwell #endif 561b8b572e1SStephen Rothwell 562b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 563b8b572e1SStephen Rothwell 564b8b572e1SStephen Rothwell /* The boring bits... */ 565b8b572e1SStephen Rothwell 566b8b572e1SStephen Rothwell /* Condition Register Bit Fields */ 567b8b572e1SStephen Rothwell 568b8b572e1SStephen Rothwell #define cr0 0 569b8b572e1SStephen Rothwell #define cr1 1 570b8b572e1SStephen Rothwell #define cr2 2 571b8b572e1SStephen Rothwell #define cr3 3 572b8b572e1SStephen Rothwell #define cr4 4 573b8b572e1SStephen Rothwell #define cr5 5 574b8b572e1SStephen Rothwell #define cr6 6 575b8b572e1SStephen Rothwell #define cr7 7 576b8b572e1SStephen Rothwell 577b8b572e1SStephen Rothwell 5789a13a524SMichael Neuling /* 5799a13a524SMichael Neuling * General Purpose Registers (GPRs) 5809a13a524SMichael Neuling * 5819a13a524SMichael Neuling * The lower case r0-r31 should be used in preference to the upper 5829a13a524SMichael Neuling * case R0-R31 as they provide more error checking in the assembler. 5839a13a524SMichael Neuling * Use R0-31 only when really nessesary. 5849a13a524SMichael Neuling */ 585b8b572e1SStephen Rothwell 5869a13a524SMichael Neuling #define r0 %r0 5879a13a524SMichael Neuling #define r1 %r1 5889a13a524SMichael Neuling #define r2 %r2 5899a13a524SMichael Neuling #define r3 %r3 5909a13a524SMichael Neuling #define r4 %r4 5919a13a524SMichael Neuling #define r5 %r5 5929a13a524SMichael Neuling #define r6 %r6 5939a13a524SMichael Neuling #define r7 %r7 5949a13a524SMichael Neuling #define r8 %r8 5959a13a524SMichael Neuling #define r9 %r9 5969a13a524SMichael Neuling #define r10 %r10 5979a13a524SMichael Neuling #define r11 %r11 5989a13a524SMichael Neuling #define r12 %r12 5999a13a524SMichael Neuling #define r13 %r13 6009a13a524SMichael Neuling #define r14 %r14 6019a13a524SMichael Neuling #define r15 %r15 6029a13a524SMichael Neuling #define r16 %r16 6039a13a524SMichael Neuling #define r17 %r17 6049a13a524SMichael Neuling #define r18 %r18 6059a13a524SMichael Neuling #define r19 %r19 6069a13a524SMichael Neuling #define r20 %r20 6079a13a524SMichael Neuling #define r21 %r21 6089a13a524SMichael Neuling #define r22 %r22 6099a13a524SMichael Neuling #define r23 %r23 6109a13a524SMichael Neuling #define r24 %r24 6119a13a524SMichael Neuling #define r25 %r25 6129a13a524SMichael Neuling #define r26 %r26 6139a13a524SMichael Neuling #define r27 %r27 6149a13a524SMichael Neuling #define r28 %r28 6159a13a524SMichael Neuling #define r29 %r29 6169a13a524SMichael Neuling #define r30 %r30 6179a13a524SMichael Neuling #define r31 %r31 618b8b572e1SStephen Rothwell 619b8b572e1SStephen Rothwell 620b8b572e1SStephen Rothwell /* Floating Point Registers (FPRs) */ 621b8b572e1SStephen Rothwell 622b8b572e1SStephen Rothwell #define fr0 0 623b8b572e1SStephen Rothwell #define fr1 1 624b8b572e1SStephen Rothwell #define fr2 2 625b8b572e1SStephen Rothwell #define fr3 3 626b8b572e1SStephen Rothwell #define fr4 4 627b8b572e1SStephen Rothwell #define fr5 5 628b8b572e1SStephen Rothwell #define fr6 6 629b8b572e1SStephen Rothwell #define fr7 7 630b8b572e1SStephen Rothwell #define fr8 8 631b8b572e1SStephen Rothwell #define fr9 9 632b8b572e1SStephen Rothwell #define fr10 10 633b8b572e1SStephen Rothwell #define fr11 11 634b8b572e1SStephen Rothwell #define fr12 12 635b8b572e1SStephen Rothwell #define fr13 13 636b8b572e1SStephen Rothwell #define fr14 14 637b8b572e1SStephen Rothwell #define fr15 15 638b8b572e1SStephen Rothwell #define fr16 16 639b8b572e1SStephen Rothwell #define fr17 17 640b8b572e1SStephen Rothwell #define fr18 18 641b8b572e1SStephen Rothwell #define fr19 19 642b8b572e1SStephen Rothwell #define fr20 20 643b8b572e1SStephen Rothwell #define fr21 21 644b8b572e1SStephen Rothwell #define fr22 22 645b8b572e1SStephen Rothwell #define fr23 23 646b8b572e1SStephen Rothwell #define fr24 24 647b8b572e1SStephen Rothwell #define fr25 25 648b8b572e1SStephen Rothwell #define fr26 26 649b8b572e1SStephen Rothwell #define fr27 27 650b8b572e1SStephen Rothwell #define fr28 28 651b8b572e1SStephen Rothwell #define fr29 29 652b8b572e1SStephen Rothwell #define fr30 30 653b8b572e1SStephen Rothwell #define fr31 31 654b8b572e1SStephen Rothwell 655b8b572e1SStephen Rothwell /* AltiVec Registers (VPRs) */ 656b8b572e1SStephen Rothwell 657c2ce6f9fSAnton Blanchard #define v0 0 658c2ce6f9fSAnton Blanchard #define v1 1 659c2ce6f9fSAnton Blanchard #define v2 2 660c2ce6f9fSAnton Blanchard #define v3 3 661c2ce6f9fSAnton Blanchard #define v4 4 662c2ce6f9fSAnton Blanchard #define v5 5 663c2ce6f9fSAnton Blanchard #define v6 6 664c2ce6f9fSAnton Blanchard #define v7 7 665c2ce6f9fSAnton Blanchard #define v8 8 666c2ce6f9fSAnton Blanchard #define v9 9 667c2ce6f9fSAnton Blanchard #define v10 10 668c2ce6f9fSAnton Blanchard #define v11 11 669c2ce6f9fSAnton Blanchard #define v12 12 670c2ce6f9fSAnton Blanchard #define v13 13 671c2ce6f9fSAnton Blanchard #define v14 14 672c2ce6f9fSAnton Blanchard #define v15 15 673c2ce6f9fSAnton Blanchard #define v16 16 674c2ce6f9fSAnton Blanchard #define v17 17 675c2ce6f9fSAnton Blanchard #define v18 18 676c2ce6f9fSAnton Blanchard #define v19 19 677c2ce6f9fSAnton Blanchard #define v20 20 678c2ce6f9fSAnton Blanchard #define v21 21 679c2ce6f9fSAnton Blanchard #define v22 22 680c2ce6f9fSAnton Blanchard #define v23 23 681c2ce6f9fSAnton Blanchard #define v24 24 682c2ce6f9fSAnton Blanchard #define v25 25 683c2ce6f9fSAnton Blanchard #define v26 26 684c2ce6f9fSAnton Blanchard #define v27 27 685c2ce6f9fSAnton Blanchard #define v28 28 686c2ce6f9fSAnton Blanchard #define v29 29 687c2ce6f9fSAnton Blanchard #define v30 30 688c2ce6f9fSAnton Blanchard #define v31 31 689b8b572e1SStephen Rothwell 690b8b572e1SStephen Rothwell /* VSX Registers (VSRs) */ 691b8b572e1SStephen Rothwell 692df99e6ebSAnton Blanchard #define vs0 0 693df99e6ebSAnton Blanchard #define vs1 1 694df99e6ebSAnton Blanchard #define vs2 2 695df99e6ebSAnton Blanchard #define vs3 3 696df99e6ebSAnton Blanchard #define vs4 4 697df99e6ebSAnton Blanchard #define vs5 5 698df99e6ebSAnton Blanchard #define vs6 6 699df99e6ebSAnton Blanchard #define vs7 7 700df99e6ebSAnton Blanchard #define vs8 8 701df99e6ebSAnton Blanchard #define vs9 9 702df99e6ebSAnton Blanchard #define vs10 10 703df99e6ebSAnton Blanchard #define vs11 11 704df99e6ebSAnton Blanchard #define vs12 12 705df99e6ebSAnton Blanchard #define vs13 13 706df99e6ebSAnton Blanchard #define vs14 14 707df99e6ebSAnton Blanchard #define vs15 15 708df99e6ebSAnton Blanchard #define vs16 16 709df99e6ebSAnton Blanchard #define vs17 17 710df99e6ebSAnton Blanchard #define vs18 18 711df99e6ebSAnton Blanchard #define vs19 19 712df99e6ebSAnton Blanchard #define vs20 20 713df99e6ebSAnton Blanchard #define vs21 21 714df99e6ebSAnton Blanchard #define vs22 22 715df99e6ebSAnton Blanchard #define vs23 23 716df99e6ebSAnton Blanchard #define vs24 24 717df99e6ebSAnton Blanchard #define vs25 25 718df99e6ebSAnton Blanchard #define vs26 26 719df99e6ebSAnton Blanchard #define vs27 27 720df99e6ebSAnton Blanchard #define vs28 28 721df99e6ebSAnton Blanchard #define vs29 29 722df99e6ebSAnton Blanchard #define vs30 30 723df99e6ebSAnton Blanchard #define vs31 31 724df99e6ebSAnton Blanchard #define vs32 32 725df99e6ebSAnton Blanchard #define vs33 33 726df99e6ebSAnton Blanchard #define vs34 34 727df99e6ebSAnton Blanchard #define vs35 35 728df99e6ebSAnton Blanchard #define vs36 36 729df99e6ebSAnton Blanchard #define vs37 37 730df99e6ebSAnton Blanchard #define vs38 38 731df99e6ebSAnton Blanchard #define vs39 39 732df99e6ebSAnton Blanchard #define vs40 40 733df99e6ebSAnton Blanchard #define vs41 41 734df99e6ebSAnton Blanchard #define vs42 42 735df99e6ebSAnton Blanchard #define vs43 43 736df99e6ebSAnton Blanchard #define vs44 44 737df99e6ebSAnton Blanchard #define vs45 45 738df99e6ebSAnton Blanchard #define vs46 46 739df99e6ebSAnton Blanchard #define vs47 47 740df99e6ebSAnton Blanchard #define vs48 48 741df99e6ebSAnton Blanchard #define vs49 49 742df99e6ebSAnton Blanchard #define vs50 50 743df99e6ebSAnton Blanchard #define vs51 51 744df99e6ebSAnton Blanchard #define vs52 52 745df99e6ebSAnton Blanchard #define vs53 53 746df99e6ebSAnton Blanchard #define vs54 54 747df99e6ebSAnton Blanchard #define vs55 55 748df99e6ebSAnton Blanchard #define vs56 56 749df99e6ebSAnton Blanchard #define vs57 57 750df99e6ebSAnton Blanchard #define vs58 58 751df99e6ebSAnton Blanchard #define vs59 59 752df99e6ebSAnton Blanchard #define vs60 60 753df99e6ebSAnton Blanchard #define vs61 61 754df99e6ebSAnton Blanchard #define vs62 62 755df99e6ebSAnton Blanchard #define vs63 63 756b8b572e1SStephen Rothwell 757b8b572e1SStephen Rothwell /* SPE Registers (EVPRs) */ 758b8b572e1SStephen Rothwell 759b8b572e1SStephen Rothwell #define evr0 0 760b8b572e1SStephen Rothwell #define evr1 1 761b8b572e1SStephen Rothwell #define evr2 2 762b8b572e1SStephen Rothwell #define evr3 3 763b8b572e1SStephen Rothwell #define evr4 4 764b8b572e1SStephen Rothwell #define evr5 5 765b8b572e1SStephen Rothwell #define evr6 6 766b8b572e1SStephen Rothwell #define evr7 7 767b8b572e1SStephen Rothwell #define evr8 8 768b8b572e1SStephen Rothwell #define evr9 9 769b8b572e1SStephen Rothwell #define evr10 10 770b8b572e1SStephen Rothwell #define evr11 11 771b8b572e1SStephen Rothwell #define evr12 12 772b8b572e1SStephen Rothwell #define evr13 13 773b8b572e1SStephen Rothwell #define evr14 14 774b8b572e1SStephen Rothwell #define evr15 15 775b8b572e1SStephen Rothwell #define evr16 16 776b8b572e1SStephen Rothwell #define evr17 17 777b8b572e1SStephen Rothwell #define evr18 18 778b8b572e1SStephen Rothwell #define evr19 19 779b8b572e1SStephen Rothwell #define evr20 20 780b8b572e1SStephen Rothwell #define evr21 21 781b8b572e1SStephen Rothwell #define evr22 22 782b8b572e1SStephen Rothwell #define evr23 23 783b8b572e1SStephen Rothwell #define evr24 24 784b8b572e1SStephen Rothwell #define evr25 25 785b8b572e1SStephen Rothwell #define evr26 26 786b8b572e1SStephen Rothwell #define evr27 27 787b8b572e1SStephen Rothwell #define evr28 28 788b8b572e1SStephen Rothwell #define evr29 29 789b8b572e1SStephen Rothwell #define evr30 30 790b8b572e1SStephen Rothwell #define evr31 31 791b8b572e1SStephen Rothwell 7927fa95f9aSNicholas Piggin #define RFSCV .long 0x4c0000a4 7937fa95f9aSNicholas Piggin 7945c0484e2SBenjamin Herrenschmidt /* 7955c0484e2SBenjamin Herrenschmidt * Create an endian fixup trampoline 7965c0484e2SBenjamin Herrenschmidt * 7975c0484e2SBenjamin Herrenschmidt * This starts with a "tdi 0,0,0x48" instruction which is 7985c0484e2SBenjamin Herrenschmidt * essentially a "trap never", and thus akin to a nop. 7995c0484e2SBenjamin Herrenschmidt * 8005c0484e2SBenjamin Herrenschmidt * The opcode for this instruction read with the wrong endian 8015c0484e2SBenjamin Herrenschmidt * however results in a b . + 8 8025c0484e2SBenjamin Herrenschmidt * 8035c0484e2SBenjamin Herrenschmidt * So essentially we use that trick to execute the following 8045c0484e2SBenjamin Herrenschmidt * trampoline in "reverse endian" if we are running with the 8055c0484e2SBenjamin Herrenschmidt * MSR_LE bit set the "wrong" way for whatever endianness the 8065c0484e2SBenjamin Herrenschmidt * kernel is built for. 8075c0484e2SBenjamin Herrenschmidt */ 808b8b572e1SStephen Rothwell 809e0d68273SChristophe Leroy #ifdef CONFIG_PPC_BOOK3E_64 8105c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN 8115c0484e2SBenjamin Herrenschmidt #else 8128ca9c08dSNicholas Piggin /* 813db10f550SRandy Dunlap * This version may be used in HV or non-HV context. 8148ca9c08dSNicholas Piggin * MSR[EE] must be disabled. 8158ca9c08dSNicholas Piggin */ 8165c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN \ 8175c0484e2SBenjamin Herrenschmidt tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ 818f848ea7fSNicholas Piggin b 191f; /* Skip trampoline if endian is good */ \ 8195c0484e2SBenjamin Herrenschmidt .long 0xa600607d; /* mfmsr r11 */ \ 8205c0484e2SBenjamin Herrenschmidt .long 0x01006b69; /* xori r11,r11,1 */ \ 821f1fe5252SNicholas Piggin .long 0x00004039; /* li r10,0 */ \ 822f1fe5252SNicholas Piggin .long 0x6401417d; /* mtmsrd r10,1 */ \ 823f1fe5252SNicholas Piggin .long 0x05009f42; /* bcl 20,31,$+4 */ \ 824f1fe5252SNicholas Piggin .long 0xa602487d; /* mflr r10 */ \ 825f1fe5252SNicholas Piggin .long 0x14004a39; /* addi r10,r10,20 */ \ 8265c0484e2SBenjamin Herrenschmidt .long 0xa6035a7d; /* mtsrr0 r10 */ \ 8275c0484e2SBenjamin Herrenschmidt .long 0xa6037b7d; /* mtsrr1 r11 */ \ 828f848ea7fSNicholas Piggin .long 0x2400004c; /* rfid */ \ 829f848ea7fSNicholas Piggin 191: 830f1fe5252SNicholas Piggin 8318ca9c08dSNicholas Piggin /* 8328ca9c08dSNicholas Piggin * This version that may only be used with MSR[HV]=1 8338ca9c08dSNicholas Piggin * - Does not clear MSR[RI], so more robust. 8348ca9c08dSNicholas Piggin * - Slightly smaller and faster. 8358ca9c08dSNicholas Piggin */ 8368ca9c08dSNicholas Piggin #define FIXUP_ENDIAN_HV \ 8378ca9c08dSNicholas Piggin tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ 8388ca9c08dSNicholas Piggin b 191f; /* Skip trampoline if endian is good */ \ 8398ca9c08dSNicholas Piggin .long 0xa600607d; /* mfmsr r11 */ \ 8408ca9c08dSNicholas Piggin .long 0x01006b69; /* xori r11,r11,1 */ \ 8418ca9c08dSNicholas Piggin .long 0x05009f42; /* bcl 20,31,$+4 */ \ 8428ca9c08dSNicholas Piggin .long 0xa602487d; /* mflr r10 */ \ 8438ca9c08dSNicholas Piggin .long 0x14004a39; /* addi r10,r10,20 */ \ 8448ca9c08dSNicholas Piggin .long 0xa64b5a7d; /* mthsrr0 r10 */ \ 8458ca9c08dSNicholas Piggin .long 0xa64b7b7d; /* mthsrr1 r11 */ \ 8468ca9c08dSNicholas Piggin .long 0x2402004c; /* hrfid */ \ 8478ca9c08dSNicholas Piggin 191: 8488ca9c08dSNicholas Piggin 849e0d68273SChristophe Leroy #endif /* !CONFIG_PPC_BOOK3E_64 */ 850e3f2c6c3SMichael Ellerman 8515c0484e2SBenjamin Herrenschmidt #endif /* __ASSEMBLY__ */ 852e3f2c6c3SMichael Ellerman 853325678fdSNicholas Piggin #define SOFT_MASK_TABLE(_start, _end) \ 854325678fdSNicholas Piggin stringify_in_c(.section __soft_mask_table,"a";)\ 855325678fdSNicholas Piggin stringify_in_c(.balign 8;) \ 856325678fdSNicholas Piggin stringify_in_c(.llong (_start);) \ 857325678fdSNicholas Piggin stringify_in_c(.llong (_end);) \ 858325678fdSNicholas Piggin stringify_in_c(.previous) 859325678fdSNicholas Piggin 860f23699c9SNicholas Piggin #define RESTART_TABLE(_start, _end, _target) \ 861f23699c9SNicholas Piggin stringify_in_c(.section __restart_table,"a";)\ 862f23699c9SNicholas Piggin stringify_in_c(.balign 8;) \ 863f23699c9SNicholas Piggin stringify_in_c(.llong (_start);) \ 864f23699c9SNicholas Piggin stringify_in_c(.llong (_end);) \ 865f23699c9SNicholas Piggin stringify_in_c(.llong (_target);) \ 866f23699c9SNicholas Piggin stringify_in_c(.previous) 867f23699c9SNicholas Piggin 8683e731858SChristophe Leroy #ifdef CONFIG_PPC_E500 8691cbf8990SDiana Craciun #define BTB_FLUSH(reg) \ 8701cbf8990SDiana Craciun lis reg,BUCSR_INIT@h; \ 8711cbf8990SDiana Craciun ori reg,reg,BUCSR_INIT@l; \ 8721cbf8990SDiana Craciun mtspr SPRN_BUCSR,reg; \ 8731cbf8990SDiana Craciun isync; 8741cbf8990SDiana Craciun #else 8751cbf8990SDiana Craciun #define BTB_FLUSH(reg) 8763e731858SChristophe Leroy #endif /* CONFIG_PPC_E500 */ 8771cbf8990SDiana Craciun 878ac9c8901SNicholas Miehlbradt #if defined(CONFIG_PPC64_ELF_ABI_V1) 879ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 48 880ac9c8901SNicholas Miehlbradt #elif defined(CONFIG_PPC64_ELF_ABI_V2) 881ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 32 882ac9c8901SNicholas Miehlbradt #elif defined(CONFIG_PPC32) 883ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 8 884ac9c8901SNicholas Miehlbradt #endif 885ac9c8901SNicholas Miehlbradt 886b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PPC_ASM_H */ 887