ppc_asm.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
  3. */
  4. #ifndef _ASM_POWERPC_PPC_ASM_H
  5. #define _ASM_POWERPC_PPC_ASM_H
  6. #include <linux/stringify.h>
  7. #include <asm/asm-compat.h>
  8. #include <asm/processor.h>
  9. #include <asm/ppc-opcode.h>
  10. #include <asm/firmware.h>
  11. #ifndef __ASSEMBLY__
  12. #error __FILE__ should only be used in assembler files
  13. #else
  14. #define SZL (BITS_PER_LONG/8)
  15. /*
  16. * Stuff for accurate CPU time accounting.
  17. * These macros handle transitions between user and system state
  18. * in exception entry and exit and accumulate time to the
  19. * user_time and system_time fields in the paca.
  20. */
  21. #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  22. #define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb)
  23. #define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb)
  24. #define ACCOUNT_STOLEN_TIME
  25. #else
  26. #define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb) \
  27. MFTB(ra); /* get timebase */ \
  28. PPC_LL rb, ACCOUNT_STARTTIME_USER(ptr); \
  29. PPC_STL ra, ACCOUNT_STARTTIME(ptr); \
  30. subf rb,rb,ra; /* subtract start value */ \
  31. PPC_LL ra, ACCOUNT_USER_TIME(ptr); \
  32. add ra,ra,rb; /* add on to user time */ \
  33. PPC_STL ra, ACCOUNT_USER_TIME(ptr); \
  34. #define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb) \
  35. MFTB(ra); /* get timebase */ \
  36. PPC_LL rb, ACCOUNT_STARTTIME(ptr); \
  37. PPC_STL ra, ACCOUNT_STARTTIME_USER(ptr); \
  38. subf rb,rb,ra; /* subtract start value */ \
  39. PPC_LL ra, ACCOUNT_SYSTEM_TIME(ptr); \
  40. add ra,ra,rb; /* add on to system time */ \
  41. PPC_STL ra, ACCOUNT_SYSTEM_TIME(ptr)
  42. #ifdef CONFIG_PPC_SPLPAR
  43. #define ACCOUNT_STOLEN_TIME \
  44. BEGIN_FW_FTR_SECTION; \
  45. beq 33f; \
  46. /* from user - see if there are any DTL entries to process */ \
  47. ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \
  48. ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \
  49. addi r10,r10,LPPACA_DTLIDX; \
  50. LDX_BE r10,0,r10; /* get log write index */ \
  51. cmpd cr1,r11,r10; \
  52. beq+ cr1,33f; \
  53. bl accumulate_stolen_time; \
  54. ld r12,_MSR(r1); \
  55. andi. r10,r12,MSR_PR; /* Restore cr0 (coming from user) */ \
  56. 33: \
  57. END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
  58. #else /* CONFIG_PPC_SPLPAR */
  59. #define ACCOUNT_STOLEN_TIME
  60. #endif /* CONFIG_PPC_SPLPAR */
  61. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  62. /*
  63. * Macros for storing registers into and loading registers from
  64. * exception frames.
  65. */
  66. #ifdef __powerpc64__
  67. #define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
  68. #define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
  69. #define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
  70. #define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
  71. #else
  72. #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
  73. #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
  74. #define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
  75. SAVE_10GPRS(22, base)
  76. #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
  77. REST_10GPRS(22, base)
  78. #endif
  79. #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
  80. #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
  81. #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
  82. #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
  83. #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
  84. #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
  85. #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
  86. #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
  87. #define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base)
  88. #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
  89. #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
  90. #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
  91. #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
  92. #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
  93. #define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base)
  94. #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
  95. #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
  96. #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
  97. #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
  98. #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
  99. #define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b
  100. #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
  101. #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
  102. #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
  103. #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
  104. #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
  105. #define REST_VR(n,b,base) li b,16*(n); lvx n,base,b
  106. #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
  107. #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
  108. #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
  109. #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
  110. #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
  111. #ifdef __BIG_ENDIAN__
  112. #define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base)
  113. #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base)
  114. #else
  115. #define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \
  116. STXVD2X(n,b,base); \
  117. XXSWAPD(n,n)
  118. #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \
  119. XXSWAPD(n,n)
  120. #endif
  121. /* Save the lower 32 VSRs in the thread VSR region */
  122. #define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b)
  123. #define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
  124. #define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
  125. #define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
  126. #define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
  127. #define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
  128. #define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
  129. #define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
  130. #define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
  131. #define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
  132. #define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
  133. #define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
  134. /*
  135. * b = base register for addressing, o = base offset from register of 1st EVR
  136. * n = first EVR, s = scratch
  137. */
  138. #define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b)
  139. #define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
  140. #define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
  141. #define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
  142. #define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
  143. #define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
  144. #define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n
  145. #define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
  146. #define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
  147. #define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
  148. #define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
  149. #define REST_32EVRS(n,s,b,o) REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
  150. /* Macros to adjust thread priority for hardware multithreading */
  151. #define HMT_VERY_LOW or 31,31,31 # very low priority
  152. #define HMT_LOW or 1,1,1
  153. #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
  154. #define HMT_MEDIUM or 2,2,2
  155. #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
  156. #define HMT_HIGH or 3,3,3
  157. #define HMT_EXTRA_HIGH or 7,7,7 # power7 only
  158. #ifdef CONFIG_PPC64
  159. #define ULONG_SIZE 8
  160. #else
  161. #define ULONG_SIZE 4
  162. #endif
  163. #define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
  164. #define VCPU_GPR(n) __VCPU_GPR(__REG_##n)
  165. #ifdef __KERNEL__
  166. #ifdef CONFIG_PPC64
  167. #define STACKFRAMESIZE 256
  168. #define __STK_REG(i) (112 + ((i)-14)*8)
  169. #define STK_REG(i) __STK_REG(__REG_##i)
  170. #ifdef PPC64_ELF_ABI_v2
  171. #define STK_GOT 24
  172. #define __STK_PARAM(i) (32 + ((i)-3)*8)
  173. #else
  174. #define STK_GOT 40
  175. #define __STK_PARAM(i) (48 + ((i)-3)*8)
  176. #endif
  177. #define STK_PARAM(i) __STK_PARAM(__REG_##i)
  178. #ifdef PPC64_ELF_ABI_v2
  179. #define _GLOBAL(name) \
  180. .align 2 ; \
  181. .type name,@function; \
  182. .globl name; \
  183. name:
  184. #define _GLOBAL_TOC(name) \
  185. .align 2 ; \
  186. .type name,@function; \
  187. .globl name; \
  188. name: \
  189. 0: addis r2,r12,(.TOC.-0b)@ha; \
  190. addi r2,r2,(.TOC.-0b)@l; \
  191. .localentry name,.-name
  192. #define DOTSYM(a) a
  193. #else
  194. #define XGLUE(a,b) a##b
  195. #define GLUE(a,b) XGLUE(a,b)
  196. #define _GLOBAL(name) \
  197. .align 2 ; \
  198. .globl name; \
  199. .globl GLUE(.,name); \
  200. .pushsection ".opd","aw"; \
  201. name: \
  202. .quad GLUE(.,name); \
  203. .quad .TOC.@tocbase; \
  204. .quad 0; \
  205. .popsection; \
  206. .type GLUE(.,name),@function; \
  207. GLUE(.,name):
  208. #define _GLOBAL_TOC(name) _GLOBAL(name)
  209. #define DOTSYM(a) GLUE(.,a)
  210. #endif
  211. #else /* 32-bit */
  212. #define _ENTRY(n) \
  213. .globl n; \
  214. n:
  215. #define _GLOBAL(n) \
  216. .stabs __stringify(n:F-1),N_FUN,0,0,n;\
  217. .globl n; \
  218. n:
  219. #define _GLOBAL_TOC(name) _GLOBAL(name)
  220. #endif
  221. /*
  222. * __kprobes (the C annotation) puts the symbol into the .kprobes.text
  223. * section, which gets emitted at the end of regular text.
  224. *
  225. * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
  226. * a blacklist. The former is for core kprobe functions/data, the
  227. * latter is for those that incdentially must be excluded from probing
  228. * and allows them to be linked at more optimal location within text.
  229. */
  230. #define _ASM_NOKPROBE_SYMBOL(entry) \
  231. .pushsection "_kprobe_blacklist","aw"; \
  232. PPC_LONG (entry) ; \
  233. .popsection
  234. #define FUNC_START(name) _GLOBAL(name)
  235. #define FUNC_END(name)
  236. /*
  237. * LOAD_REG_IMMEDIATE(rn, expr)
  238. * Loads the value of the constant expression 'expr' into register 'rn'
  239. * using immediate instructions only. Use this when it's important not
  240. * to reference other data (i.e. on ppc64 when the TOC pointer is not
  241. * valid) and when 'expr' is a constant or absolute address.
  242. *
  243. * LOAD_REG_ADDR(rn, name)
  244. * Loads the address of label 'name' into register 'rn'. Use this when
  245. * you don't particularly need immediate instructions only, but you need
  246. * the whole address in one register (e.g. it's a structure address and
  247. * you want to access various offsets within it). On ppc32 this is
  248. * identical to LOAD_REG_IMMEDIATE.
  249. *
  250. * LOAD_REG_ADDR_PIC(rn, name)
  251. * Loads the address of label 'name' into register 'run'. Use this when
  252. * the kernel doesn't run at the linked or relocated address. Please
  253. * note that this macro will clobber the lr register.
  254. *
  255. * LOAD_REG_ADDRBASE(rn, name)
  256. * ADDROFF(name)
  257. * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
  258. * register 'rn'. ADDROFF(name) returns the remainder of the address as
  259. * a constant expression. ADDROFF(name) is a signed expression < 16 bits
  260. * in size, so is suitable for use directly as an offset in load and store
  261. * instructions. Use this when loading/storing a single word or less as:
  262. * LOAD_REG_ADDRBASE(rX, name)
  263. * ld rY,ADDROFF(name)(rX)
  264. */
  265. /* Be careful, this will clobber the lr register. */
  266. #define LOAD_REG_ADDR_PIC(reg, name) \
  267. bl 0f; \
  268. 0: mflr reg; \
  269. addis reg,reg,(name - 0b)@ha; \
  270. addi reg,reg,(name - 0b)@l;
  271. #ifdef __powerpc64__
  272. #ifdef HAVE_AS_ATHIGH
  273. #define __AS_ATHIGH high
  274. #else
  275. #define __AS_ATHIGH h
  276. #endif
  277. #define LOAD_REG_IMMEDIATE(reg,expr) \
  278. lis reg,(expr)@highest; \
  279. ori reg,reg,(expr)@higher; \
  280. rldicr reg,reg,32,31; \
  281. oris reg,reg,(expr)@__AS_ATHIGH; \
  282. ori reg,reg,(expr)@l;
  283. #define LOAD_REG_ADDR(reg,name) \
  284. ld reg,name@got(r2)
  285. #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
  286. #define ADDROFF(name) 0
  287. /* offsets for stack frame layout */
  288. #define LRSAVE 16
  289. #else /* 32-bit */
  290. #define LOAD_REG_IMMEDIATE(reg,expr) \
  291. lis reg,(expr)@ha; \
  292. addi reg,reg,(expr)@l;
  293. #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
  294. #define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha
  295. #define ADDROFF(name) name@l
  296. /* offsets for stack frame layout */
  297. #define LRSAVE 4
  298. #endif
  299. /* various errata or part fixups */
  300. #ifdef CONFIG_PPC601_SYNC_FIX
  301. #define SYNC \
  302. BEGIN_FTR_SECTION \
  303. sync; \
  304. isync; \
  305. END_FTR_SECTION_IFSET(CPU_FTR_601)
  306. #define SYNC_601 \
  307. BEGIN_FTR_SECTION \
  308. sync; \
  309. END_FTR_SECTION_IFSET(CPU_FTR_601)
  310. #define ISYNC_601 \
  311. BEGIN_FTR_SECTION \
  312. isync; \
  313. END_FTR_SECTION_IFSET(CPU_FTR_601)
  314. #else
  315. #define SYNC
  316. #define SYNC_601
  317. #define ISYNC_601
  318. #endif
  319. #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
  320. #define MFTB(dest) \
  321. 90: mfspr dest, SPRN_TBRL; \
  322. BEGIN_FTR_SECTION_NESTED(96); \
  323. cmpwi dest,0; \
  324. beq- 90b; \
  325. END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
  326. #elif defined(CONFIG_8xx)
  327. #define MFTB(dest) mftb dest
  328. #else
  329. #define MFTB(dest) mfspr dest, SPRN_TBRL
  330. #endif
  331. #ifndef CONFIG_SMP
  332. #define TLBSYNC
  333. #else /* CONFIG_SMP */
  334. /* tlbsync is not implemented on 601 */
  335. #define TLBSYNC \
  336. BEGIN_FTR_SECTION \
  337. tlbsync; \
  338. sync; \
  339. END_FTR_SECTION_IFCLR(CPU_FTR_601)
  340. #endif
  341. #ifdef CONFIG_PPC64
  342. #define MTOCRF(FXM, RS) \
  343. BEGIN_FTR_SECTION_NESTED(848); \
  344. mtcrf (FXM), RS; \
  345. FTR_SECTION_ELSE_NESTED(848); \
  346. mtocrf (FXM), RS; \
  347. ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
  348. #endif
  349. /*
  350. * This instruction is not implemented on the PPC 603 or 601; however, on
  351. * the 403GCX and 405GP tlbia IS defined and tlbie is not.
  352. * All of these instructions exist in the 8xx, they have magical powers,
  353. * and they must be used.
  354. */
  355. #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
  356. #define tlbia \
  357. li r4,1024; \
  358. mtctr r4; \
  359. lis r4,KERNELBASE@h; \
  360. .machine push; \
  361. .machine "power4"; \
  362. 0: tlbie r4; \
  363. .machine pop; \
  364. addi r4,r4,0x1000; \
  365. bdnz 0b
  366. #endif
  367. #ifdef CONFIG_IBM440EP_ERR42
  368. #define PPC440EP_ERR42 isync
  369. #else
  370. #define PPC440EP_ERR42
  371. #endif
  372. /* The following stops all load and store data streams associated with stream
  373. * ID (ie. streams created explicitly). The embedded and server mnemonics for
  374. * dcbt are different so we use machine "power4" here explicitly.
  375. */
  376. #define DCBT_STOP_ALL_STREAM_IDS(scratch) \
  377. .machine push ; \
  378. .machine "power4" ; \
  379. lis scratch,0x60000000@h; \
  380. dcbt r0,scratch,0b01010; \
  381. .machine pop
  382. /*
  383. * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
  384. * keep the address intact to be compatible with code shared with
  385. * 32-bit classic.
  386. *
  387. * On the other hand, I find it useful to have them behave as expected
  388. * by their name (ie always do the addition) on 64-bit BookE
  389. */
  390. #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
  391. #define toreal(rd)
  392. #define fromreal(rd)
  393. /*
  394. * We use addis to ensure compatibility with the "classic" ppc versions of
  395. * these macros, which use rs = 0 to get the tophys offset in rd, rather than
  396. * converting the address in r0, and so this version has to do that too
  397. * (i.e. set register rd to 0 when rs == 0).
  398. */
  399. #define tophys(rd,rs) \
  400. addis rd,rs,0
  401. #define tovirt(rd,rs) \
  402. addis rd,rs,0
  403. #elif defined(CONFIG_PPC64)
  404. #define toreal(rd) /* we can access c000... in real mode */
  405. #define fromreal(rd)
  406. #define tophys(rd,rs) \
  407. clrldi rd,rs,2
  408. #define tovirt(rd,rs) \
  409. rotldi rd,rs,16; \
  410. ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
  411. rotldi rd,rd,48
  412. #else
  413. /*
  414. * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
  415. * physical base address of RAM at compile time.
  416. */
  417. #define toreal(rd) tophys(rd,rd)
  418. #define fromreal(rd) tovirt(rd,rd)
  419. #define tophys(rd,rs) \
  420. 0: addis rd,rs,-PAGE_OFFSET@h; \
  421. .section ".vtop_fixup","aw"; \
  422. .align 1; \
  423. .long 0b; \
  424. .previous
  425. #define tovirt(rd,rs) \
  426. 0: addis rd,rs,PAGE_OFFSET@h; \
  427. .section ".ptov_fixup","aw"; \
  428. .align 1; \
  429. .long 0b; \
  430. .previous
  431. #endif
  432. #ifdef CONFIG_PPC_BOOK3S_64
  433. #define RFI rfid
  434. #define MTMSRD(r) mtmsrd r
  435. #define MTMSR_EERI(reg) mtmsrd reg,1
  436. #else
  437. #define FIX_SRR1(ra, rb)
  438. #ifndef CONFIG_40x
  439. #define RFI rfi
  440. #else
  441. #define RFI rfi; b . /* Prevent prefetch past rfi */
  442. #endif
  443. #define MTMSRD(r) mtmsr r
  444. #define MTMSR_EERI(reg) mtmsr reg
  445. #endif
  446. #endif /* __KERNEL__ */
  447. /* The boring bits... */
  448. /* Condition Register Bit Fields */
  449. #define cr0 0
  450. #define cr1 1
  451. #define cr2 2
  452. #define cr3 3
  453. #define cr4 4
  454. #define cr5 5
  455. #define cr6 6
  456. #define cr7 7
  457. /*
  458. * General Purpose Registers (GPRs)
  459. *
  460. * The lower case r0-r31 should be used in preference to the upper
  461. * case R0-R31 as they provide more error checking in the assembler.
  462. * Use R0-31 only when really nessesary.
  463. */
  464. #define r0 %r0
  465. #define r1 %r1
  466. #define r2 %r2
  467. #define r3 %r3
  468. #define r4 %r4
  469. #define r5 %r5
  470. #define r6 %r6
  471. #define r7 %r7
  472. #define r8 %r8
  473. #define r9 %r9
  474. #define r10 %r10
  475. #define r11 %r11
  476. #define r12 %r12
  477. #define r13 %r13
  478. #define r14 %r14
  479. #define r15 %r15
  480. #define r16 %r16
  481. #define r17 %r17
  482. #define r18 %r18
  483. #define r19 %r19
  484. #define r20 %r20
  485. #define r21 %r21
  486. #define r22 %r22
  487. #define r23 %r23
  488. #define r24 %r24
  489. #define r25 %r25
  490. #define r26 %r26
  491. #define r27 %r27
  492. #define r28 %r28
  493. #define r29 %r29
  494. #define r30 %r30
  495. #define r31 %r31
  496. /* Floating Point Registers (FPRs) */
  497. #define fr0 0
  498. #define fr1 1
  499. #define fr2 2
  500. #define fr3 3
  501. #define fr4 4
  502. #define fr5 5
  503. #define fr6 6
  504. #define fr7 7
  505. #define fr8 8
  506. #define fr9 9
  507. #define fr10 10
  508. #define fr11 11
  509. #define fr12 12
  510. #define fr13 13
  511. #define fr14 14
  512. #define fr15 15
  513. #define fr16 16
  514. #define fr17 17
  515. #define fr18 18
  516. #define fr19 19
  517. #define fr20 20
  518. #define fr21 21
  519. #define fr22 22
  520. #define fr23 23
  521. #define fr24 24
  522. #define fr25 25
  523. #define fr26 26
  524. #define fr27 27
  525. #define fr28 28
  526. #define fr29 29
  527. #define fr30 30
  528. #define fr31 31
  529. /* AltiVec Registers (VPRs) */
  530. #define v0 0
  531. #define v1 1
  532. #define v2 2
  533. #define v3 3
  534. #define v4 4
  535. #define v5 5
  536. #define v6 6
  537. #define v7 7
  538. #define v8 8
  539. #define v9 9
  540. #define v10 10
  541. #define v11 11
  542. #define v12 12
  543. #define v13 13
  544. #define v14 14
  545. #define v15 15
  546. #define v16 16
  547. #define v17 17
  548. #define v18 18
  549. #define v19 19
  550. #define v20 20
  551. #define v21 21
  552. #define v22 22
  553. #define v23 23
  554. #define v24 24
  555. #define v25 25
  556. #define v26 26
  557. #define v27 27
  558. #define v28 28
  559. #define v29 29
  560. #define v30 30
  561. #define v31 31
  562. /* VSX Registers (VSRs) */
  563. #define vs0 0
  564. #define vs1 1
  565. #define vs2 2
  566. #define vs3 3
  567. #define vs4 4
  568. #define vs5 5
  569. #define vs6 6
  570. #define vs7 7
  571. #define vs8 8
  572. #define vs9 9
  573. #define vs10 10
  574. #define vs11 11
  575. #define vs12 12
  576. #define vs13 13
  577. #define vs14 14
  578. #define vs15 15
  579. #define vs16 16
  580. #define vs17 17
  581. #define vs18 18
  582. #define vs19 19
  583. #define vs20 20
  584. #define vs21 21
  585. #define vs22 22
  586. #define vs23 23
  587. #define vs24 24
  588. #define vs25 25
  589. #define vs26 26
  590. #define vs27 27
  591. #define vs28 28
  592. #define vs29 29
  593. #define vs30 30
  594. #define vs31 31
  595. #define vs32 32
  596. #define vs33 33
  597. #define vs34 34
  598. #define vs35 35
  599. #define vs36 36
  600. #define vs37 37
  601. #define vs38 38
  602. #define vs39 39
  603. #define vs40 40
  604. #define vs41 41
  605. #define vs42 42
  606. #define vs43 43
  607. #define vs44 44
  608. #define vs45 45
  609. #define vs46 46
  610. #define vs47 47
  611. #define vs48 48
  612. #define vs49 49
  613. #define vs50 50
  614. #define vs51 51
  615. #define vs52 52
  616. #define vs53 53
  617. #define vs54 54
  618. #define vs55 55
  619. #define vs56 56
  620. #define vs57 57
  621. #define vs58 58
  622. #define vs59 59
  623. #define vs60 60
  624. #define vs61 61
  625. #define vs62 62
  626. #define vs63 63
  627. /* SPE Registers (EVPRs) */
  628. #define evr0 0
  629. #define evr1 1
  630. #define evr2 2
  631. #define evr3 3
  632. #define evr4 4
  633. #define evr5 5
  634. #define evr6 6
  635. #define evr7 7
  636. #define evr8 8
  637. #define evr9 9
  638. #define evr10 10
  639. #define evr11 11
  640. #define evr12 12
  641. #define evr13 13
  642. #define evr14 14
  643. #define evr15 15
  644. #define evr16 16
  645. #define evr17 17
  646. #define evr18 18
  647. #define evr19 19
  648. #define evr20 20
  649. #define evr21 21
  650. #define evr22 22
  651. #define evr23 23
  652. #define evr24 24
  653. #define evr25 25
  654. #define evr26 26
  655. #define evr27 27
  656. #define evr28 28
  657. #define evr29 29
  658. #define evr30 30
  659. #define evr31 31
  660. /* some stab codes */
  661. #define N_FUN 36
  662. #define N_RSYM 64
  663. #define N_SLINE 68
  664. #define N_SO 100
  665. /*
  666. * Create an endian fixup trampoline
  667. *
  668. * This starts with a "tdi 0,0,0x48" instruction which is
  669. * essentially a "trap never", and thus akin to a nop.
  670. *
  671. * The opcode for this instruction read with the wrong endian
  672. * however results in a b . + 8
  673. *
  674. * So essentially we use that trick to execute the following
  675. * trampoline in "reverse endian" if we are running with the
  676. * MSR_LE bit set the "wrong" way for whatever endianness the
  677. * kernel is built for.
  678. */
  679. #ifdef CONFIG_PPC_BOOK3E
  680. #define FIXUP_ENDIAN
  681. #else
  682. #define FIXUP_ENDIAN \
  683. tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
  684. b $+36; /* Skip trampoline if endian is good */ \
  685. .long 0x05009f42; /* bcl 20,31,$+4 */ \
  686. .long 0xa602487d; /* mflr r10 */ \
  687. .long 0x1c004a39; /* addi r10,r10,28 */ \
  688. .long 0xa600607d; /* mfmsr r11 */ \
  689. .long 0x01006b69; /* xori r11,r11,1 */ \
  690. .long 0xa6035a7d; /* mtsrr0 r10 */ \
  691. .long 0xa6037b7d; /* mtsrr1 r11 */ \
  692. .long 0x2400004c /* rfid */
  693. #endif /* !CONFIG_PPC_BOOK3E */
  694. #endif /* __ASSEMBLY__ */
  695. #endif /* _ASM_POWERPC_PPC_ASM_H */