processor.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. #ifndef __ASM_PPC64_PROCESSOR_H
  2. #define __ASM_PPC64_PROCESSOR_H
  3. /*
  4. * Copyright (C) 2001 PPC 64 Team, IBM Corp
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/stringify.h>
  12. #ifndef __ASSEMBLY__
  13. #include <linux/config.h>
  14. #include <asm/atomic.h>
  15. #include <asm/ppcdebug.h>
  16. #include <asm/a.out.h>
  17. #endif
  18. #include <asm/ptrace.h>
  19. #include <asm/types.h>
  20. #include <asm/systemcfg.h>
  21. /* Machine State Register (MSR) Fields */
  22. #define MSR_SF_LG 63 /* Enable 64 bit mode */
  23. #define MSR_ISF_LG 61 /* Interrupt 64b mode valid on 630 */
  24. #define MSR_HV_LG 60 /* Hypervisor state */
  25. #define MSR_VEC_LG 25 /* Enable AltiVec */
  26. #define MSR_POW_LG 18 /* Enable Power Management */
  27. #define MSR_WE_LG 18 /* Wait State Enable */
  28. #define MSR_TGPR_LG 17 /* TLB Update registers in use */
  29. #define MSR_CE_LG 17 /* Critical Interrupt Enable */
  30. #define MSR_ILE_LG 16 /* Interrupt Little Endian */
  31. #define MSR_EE_LG 15 /* External Interrupt Enable */
  32. #define MSR_PR_LG 14 /* Problem State / Privilege Level */
  33. #define MSR_FP_LG 13 /* Floating Point enable */
  34. #define MSR_ME_LG 12 /* Machine Check Enable */
  35. #define MSR_FE0_LG 11 /* Floating Exception mode 0 */
  36. #define MSR_SE_LG 10 /* Single Step */
  37. #define MSR_BE_LG 9 /* Branch Trace */
  38. #define MSR_DE_LG 9 /* Debug Exception Enable */
  39. #define MSR_FE1_LG 8 /* Floating Exception mode 1 */
  40. #define MSR_IP_LG 6 /* Exception prefix 0x000/0xFFF */
  41. #define MSR_IR_LG 5 /* Instruction Relocate */
  42. #define MSR_DR_LG 4 /* Data Relocate */
  43. #define MSR_PE_LG 3 /* Protection Enable */
  44. #define MSR_PX_LG 2 /* Protection Exclusive Mode */
  45. #define MSR_PMM_LG 2 /* Performance monitor */
  46. #define MSR_RI_LG 1 /* Recoverable Exception */
  47. #define MSR_LE_LG 0 /* Little Endian */
  48. #ifdef __ASSEMBLY__
  49. #define __MASK(X) (1<<(X))
  50. #else
  51. #define __MASK(X) (1UL<<(X))
  52. #endif
  53. #define MSR_SF __MASK(MSR_SF_LG) /* Enable 64 bit mode */
  54. #define MSR_ISF __MASK(MSR_ISF_LG) /* Interrupt 64b mode valid on 630 */
  55. #define MSR_HV __MASK(MSR_HV_LG) /* Hypervisor state */
  56. #define MSR_VEC __MASK(MSR_VEC_LG) /* Enable AltiVec */
  57. #define MSR_POW __MASK(MSR_POW_LG) /* Enable Power Management */
  58. #define MSR_WE __MASK(MSR_WE_LG) /* Wait State Enable */
  59. #define MSR_TGPR __MASK(MSR_TGPR_LG) /* TLB Update registers in use */
  60. #define MSR_CE __MASK(MSR_CE_LG) /* Critical Interrupt Enable */
  61. #define MSR_ILE __MASK(MSR_ILE_LG) /* Interrupt Little Endian */
  62. #define MSR_EE __MASK(MSR_EE_LG) /* External Interrupt Enable */
  63. #define MSR_PR __MASK(MSR_PR_LG) /* Problem State / Privilege Level */
  64. #define MSR_FP __MASK(MSR_FP_LG) /* Floating Point enable */
  65. #define MSR_ME __MASK(MSR_ME_LG) /* Machine Check Enable */
  66. #define MSR_FE0 __MASK(MSR_FE0_LG) /* Floating Exception mode 0 */
  67. #define MSR_SE __MASK(MSR_SE_LG) /* Single Step */
  68. #define MSR_BE __MASK(MSR_BE_LG) /* Branch Trace */
  69. #define MSR_DE __MASK(MSR_DE_LG) /* Debug Exception Enable */
  70. #define MSR_FE1 __MASK(MSR_FE1_LG) /* Floating Exception mode 1 */
  71. #define MSR_IP __MASK(MSR_IP_LG) /* Exception prefix 0x000/0xFFF */
  72. #define MSR_IR __MASK(MSR_IR_LG) /* Instruction Relocate */
  73. #define MSR_DR __MASK(MSR_DR_LG) /* Data Relocate */
  74. #define MSR_PE __MASK(MSR_PE_LG) /* Protection Enable */
  75. #define MSR_PX __MASK(MSR_PX_LG) /* Protection Exclusive Mode */
  76. #define MSR_PMM __MASK(MSR_PMM_LG) /* Performance monitor */
  77. #define MSR_RI __MASK(MSR_RI_LG) /* Recoverable Exception */
  78. #define MSR_LE __MASK(MSR_LE_LG) /* Little Endian */
  79. #define MSR_ MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF
  80. #define MSR_KERNEL MSR_ | MSR_SF | MSR_HV
  81. #define MSR_USER32 MSR_ | MSR_PR | MSR_EE
  82. #define MSR_USER64 MSR_USER32 | MSR_SF
  83. /* Floating Point Status and Control Register (FPSCR) Fields */
  84. #define FPSCR_FX 0x80000000 /* FPU exception summary */
  85. #define FPSCR_FEX 0x40000000 /* FPU enabled exception summary */
  86. #define FPSCR_VX 0x20000000 /* Invalid operation summary */
  87. #define FPSCR_OX 0x10000000 /* Overflow exception summary */
  88. #define FPSCR_UX 0x08000000 /* Underflow exception summary */
  89. #define FPSCR_ZX 0x04000000 /* Zero-divide exception summary */
  90. #define FPSCR_XX 0x02000000 /* Inexact exception summary */
  91. #define FPSCR_VXSNAN 0x01000000 /* Invalid op for SNaN */
  92. #define FPSCR_VXISI 0x00800000 /* Invalid op for Inv - Inv */
  93. #define FPSCR_VXIDI 0x00400000 /* Invalid op for Inv / Inv */
  94. #define FPSCR_VXZDZ 0x00200000 /* Invalid op for Zero / Zero */
  95. #define FPSCR_VXIMZ 0x00100000 /* Invalid op for Inv * Zero */
  96. #define FPSCR_VXVC 0x00080000 /* Invalid op for Compare */
  97. #define FPSCR_FR 0x00040000 /* Fraction rounded */
  98. #define FPSCR_FI 0x00020000 /* Fraction inexact */
  99. #define FPSCR_FPRF 0x0001f000 /* FPU Result Flags */
  100. #define FPSCR_FPCC 0x0000f000 /* FPU Condition Codes */
  101. #define FPSCR_VXSOFT 0x00000400 /* Invalid op for software request */
  102. #define FPSCR_VXSQRT 0x00000200 /* Invalid op for square root */
  103. #define FPSCR_VXCVI 0x00000100 /* Invalid op for integer convert */
  104. #define FPSCR_VE 0x00000080 /* Invalid op exception enable */
  105. #define FPSCR_OE 0x00000040 /* IEEE overflow exception enable */
  106. #define FPSCR_UE 0x00000020 /* IEEE underflow exception enable */
  107. #define FPSCR_ZE 0x00000010 /* IEEE zero divide exception enable */
  108. #define FPSCR_XE 0x00000008 /* FP inexact exception enable */
  109. #define FPSCR_NI 0x00000004 /* FPU non IEEE-Mode */
  110. #define FPSCR_RN 0x00000003 /* FPU rounding control */
  111. /* Special Purpose Registers (SPRNs)*/
  112. #define SPRN_CTR 0x009 /* Count Register */
  113. #define SPRN_DABR 0x3F5 /* Data Address Breakpoint Register */
  114. #define DABR_TRANSLATION (1UL << 2)
  115. #define SPRN_DAR 0x013 /* Data Address Register */
  116. #define SPRN_DEC 0x016 /* Decrement Register */
  117. #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
  118. #define DSISR_NOHPTE 0x40000000 /* no translation found */
  119. #define DSISR_PROTFAULT 0x08000000 /* protection fault */
  120. #define DSISR_ISSTORE 0x02000000 /* access was a store */
  121. #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
  122. #define DSISR_NOSEGMENT 0x00200000 /* STAB/SLB miss */
  123. #define SPRN_HID0 0x3F0 /* Hardware Implementation Register 0 */
  124. #define SPRN_MSRDORM 0x3F1 /* Hardware Implementation Register 1 */
  125. #define SPRN_HID1 0x3F1 /* Hardware Implementation Register 1 */
  126. #define SPRN_IABR 0x3F2 /* Instruction Address Breakpoint Register */
  127. #define SPRN_NIADORM 0x3F3 /* Hardware Implementation Register 2 */
  128. #define SPRN_HID4 0x3F4 /* 970 HID4 */
  129. #define SPRN_HID5 0x3F6 /* 970 HID5 */
  130. #define SPRN_HID6 0x3F9 /* BE HID 6 */
  131. #define HID6_LB (0x0F<<12) /* Concurrent Large Page Modes */
  132. #define HID6_DLP (1<<20) /* Disable all large page modes (4K only) */
  133. #define SPRN_TSCR 0x399 /* Thread switch control on BE */
  134. #define SPRN_TTR 0x39A /* Thread switch timeout on BE */
  135. #define TSCR_DEC_ENABLE 0x200000 /* Decrementer Interrupt */
  136. #define TSCR_EE_ENABLE 0x100000 /* External Interrupt */
  137. #define TSCR_EE_BOOST 0x080000 /* External Interrupt Boost */
  138. #define SPRN_TSC 0x3FD /* Thread switch control on others */
  139. #define SPRN_TST 0x3FC /* Thread switch timeout on others */
  140. #define SPRN_L2CR 0x3F9 /* Level 2 Cache Control Regsiter */
  141. #define SPRN_LR 0x008 /* Link Register */
  142. #define SPRN_PIR 0x3FF /* Processor Identification Register */
  143. #define SPRN_PIT 0x3DB /* Programmable Interval Timer */
  144. #define SPRN_PURR 0x135 /* Processor Utilization of Resources Register */
  145. #define SPRN_PVR 0x11F /* Processor Version Register */
  146. #define SPRN_RPA 0x3D6 /* Required Physical Address Register */
  147. #define SPRN_SDA 0x3BF /* Sampled Data Address Register */
  148. #define SPRN_SDR1 0x019 /* MMU Hash Base Register */
  149. #define SPRN_SIA 0x3BB /* Sampled Instruction Address Register */
  150. #define SPRN_SPRG0 0x110 /* Special Purpose Register General 0 */
  151. #define SPRN_SPRG1 0x111 /* Special Purpose Register General 1 */
  152. #define SPRN_SPRG2 0x112 /* Special Purpose Register General 2 */
  153. #define SPRN_SPRG3 0x113 /* Special Purpose Register General 3 */
  154. #define SPRN_SRR0 0x01A /* Save/Restore Register 0 */
  155. #define SPRN_SRR1 0x01B /* Save/Restore Register 1 */
  156. #define SPRN_TBRL 0x10C /* Time Base Read Lower Register (user, R/O) */
  157. #define SPRN_TBRU 0x10D /* Time Base Read Upper Register (user, R/O) */
  158. #define SPRN_TBWL 0x11C /* Time Base Lower Register (super, W/O) */
  159. #define SPRN_TBWU 0x11D /* Time Base Write Upper Register (super, W/O) */
  160. #define SPRN_HIOR 0x137 /* 970 Hypervisor interrupt offset */
  161. #define SPRN_USIA 0x3AB /* User Sampled Instruction Address Register */
  162. #define SPRN_XER 0x001 /* Fixed Point Exception Register */
  163. #define SPRN_VRSAVE 0x100 /* Vector save */
  164. #define SPRN_CTRLF 0x088
  165. #define SPRN_CTRLT 0x098
  166. #define CTRL_RUNLATCH 0x1
  167. /* Performance monitor SPRs */
  168. #define SPRN_SIAR 780
  169. #define SPRN_SDAR 781
  170. #define SPRN_MMCRA 786
  171. #define MMCRA_SIHV 0x10000000UL /* state of MSR HV when SIAR set */
  172. #define MMCRA_SIPR 0x08000000UL /* state of MSR PR when SIAR set */
  173. #define MMCRA_SAMPLE_ENABLE 0x00000001UL /* enable sampling */
  174. #define SPRN_PMC1 787
  175. #define SPRN_PMC2 788
  176. #define SPRN_PMC3 789
  177. #define SPRN_PMC4 790
  178. #define SPRN_PMC5 791
  179. #define SPRN_PMC6 792
  180. #define SPRN_PMC7 793
  181. #define SPRN_PMC8 794
  182. #define SPRN_MMCR0 795
  183. #define MMCR0_FC 0x80000000UL /* freeze counters. set to 1 on a perfmon exception */
  184. #define MMCR0_FCS 0x40000000UL /* freeze in supervisor state */
  185. #define MMCR0_KERNEL_DISABLE MMCR0_FCS
  186. #define MMCR0_FCP 0x20000000UL /* freeze in problem state */
  187. #define MMCR0_PROBLEM_DISABLE MMCR0_FCP
  188. #define MMCR0_FCM1 0x10000000UL /* freeze counters while MSR mark = 1 */
  189. #define MMCR0_FCM0 0x08000000UL /* freeze counters while MSR mark = 0 */
  190. #define MMCR0_PMXE 0x04000000UL /* performance monitor exception enable */
  191. #define MMCR0_FCECE 0x02000000UL /* freeze counters on enabled condition or event */
  192. /* time base exception enable */
  193. #define MMCR0_TBEE 0x00400000UL /* time base exception enable */
  194. #define MMCR0_PMC1CE 0x00008000UL /* PMC1 count enable*/
  195. #define MMCR0_PMCjCE 0x00004000UL /* PMCj count enable*/
  196. #define MMCR0_TRIGGER 0x00002000UL /* TRIGGER enable */
  197. #define MMCR0_PMAO 0x00000080UL /* performance monitor alert has occurred, set to 0 after handling exception */
  198. #define MMCR0_SHRFC 0x00000040UL /* SHRre freeze conditions between threads */
  199. #define MMCR0_FCTI 0x00000008UL /* freeze counters in tags inactive mode */
  200. #define MMCR0_FCTA 0x00000004UL /* freeze counters in tags active mode */
  201. #define MMCR0_FCWAIT 0x00000002UL /* freeze counter in WAIT state */
  202. #define MMCR0_FCHV 0x00000001UL /* freeze conditions in hypervisor mode */
  203. #define SPRN_MMCR1 798
  204. /* Short-hand versions for a number of the above SPRNs */
  205. #define CTR SPRN_CTR /* Counter Register */
  206. #define DAR SPRN_DAR /* Data Address Register */
  207. #define DABR SPRN_DABR /* Data Address Breakpoint Register */
  208. #define DEC SPRN_DEC /* Decrement Register */
  209. #define DSISR SPRN_DSISR /* Data Storage Interrupt Status Register */
  210. #define HID0 SPRN_HID0 /* Hardware Implementation Register 0 */
  211. #define MSRDORM SPRN_MSRDORM /* MSR Dormant Register */
  212. #define NIADORM SPRN_NIADORM /* NIA Dormant Register */
  213. #define TSC SPRN_TSC /* Thread switch control */
  214. #define TST SPRN_TST /* Thread switch timeout */
  215. #define IABR SPRN_IABR /* Instruction Address Breakpoint Register */
  216. #define L2CR SPRN_L2CR /* PPC 750 L2 control register */
  217. #define __LR SPRN_LR
  218. #define PVR SPRN_PVR /* Processor Version */
  219. #define PIR SPRN_PIR /* Processor ID */
  220. #define PURR SPRN_PURR /* Processor Utilization of Resource Register */
  221. #define SDR1 SPRN_SDR1 /* MMU hash base register */
  222. #define SPR0 SPRN_SPRG0 /* Supervisor Private Registers */
  223. #define SPR1 SPRN_SPRG1
  224. #define SPR2 SPRN_SPRG2
  225. #define SPR3 SPRN_SPRG3
  226. #define SPRG0 SPRN_SPRG0
  227. #define SPRG1 SPRN_SPRG1
  228. #define SPRG2 SPRN_SPRG2
  229. #define SPRG3 SPRN_SPRG3
  230. #define SRR0 SPRN_SRR0 /* Save and Restore Register 0 */
  231. #define SRR1 SPRN_SRR1 /* Save and Restore Register 1 */
  232. #define TBRL SPRN_TBRL /* Time Base Read Lower Register */
  233. #define TBRU SPRN_TBRU /* Time Base Read Upper Register */
  234. #define TBWL SPRN_TBWL /* Time Base Write Lower Register */
  235. #define TBWU SPRN_TBWU /* Time Base Write Upper Register */
  236. #define XER SPRN_XER
  237. /* Processor Version Register (PVR) field extraction */
  238. #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
  239. #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */
  240. /* Processor Version Numbers */
  241. #define PV_NORTHSTAR 0x0033
  242. #define PV_PULSAR 0x0034
  243. #define PV_POWER4 0x0035
  244. #define PV_ICESTAR 0x0036
  245. #define PV_SSTAR 0x0037
  246. #define PV_POWER4p 0x0038
  247. #define PV_970 0x0039
  248. #define PV_POWER5 0x003A
  249. #define PV_POWER5p 0x003B
  250. #define PV_970FX 0x003C
  251. #define PV_630 0x0040
  252. #define PV_630p 0x0041
  253. #define PV_BE 0x0070
  254. /* Platforms supported by PPC64 */
  255. #define PLATFORM_PSERIES 0x0100
  256. #define PLATFORM_PSERIES_LPAR 0x0101
  257. #define PLATFORM_ISERIES_LPAR 0x0201
  258. #define PLATFORM_LPAR 0x0001
  259. #define PLATFORM_POWERMAC 0x0400
  260. #define PLATFORM_MAPLE 0x0500
  261. #define PLATFORM_BPA 0x1000
  262. /* Compatibility with drivers coming from PPC32 world */
  263. #define _machine (systemcfg->platform)
  264. #define _MACH_Pmac PLATFORM_POWERMAC
  265. /*
  266. * List of interrupt controllers.
  267. */
  268. #define IC_INVALID 0
  269. #define IC_OPEN_PIC 1
  270. #define IC_PPC_XIC 2
  271. #define IC_BPA_IIC 3
  272. #define XGLUE(a,b) a##b
  273. #define GLUE(a,b) XGLUE(a,b)
  274. #ifdef __ASSEMBLY__
  275. #define _GLOBAL(name) \
  276. .section ".text"; \
  277. .align 2 ; \
  278. .globl name; \
  279. .globl GLUE(.,name); \
  280. .section ".opd","aw"; \
  281. name: \
  282. .quad GLUE(.,name); \
  283. .quad .TOC.@tocbase; \
  284. .quad 0; \
  285. .previous; \
  286. .type GLUE(.,name),@function; \
  287. GLUE(.,name):
  288. #define _STATIC(name) \
  289. .section ".text"; \
  290. .align 2 ; \
  291. .section ".opd","aw"; \
  292. name: \
  293. .quad GLUE(.,name); \
  294. .quad .TOC.@tocbase; \
  295. .quad 0; \
  296. .previous; \
  297. .type GLUE(.,name),@function; \
  298. GLUE(.,name):
  299. #else /* __ASSEMBLY__ */
  300. /*
  301. * Default implementation of macro that returns current
  302. * instruction pointer ("program counter").
  303. */
  304. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  305. /* Macros for setting and retrieving special purpose registers */
  306. #define mfmsr() ({unsigned long rval; \
  307. asm volatile("mfmsr %0" : "=r" (rval)); rval;})
  308. #define __mtmsrd(v, l) asm volatile("mtmsrd %0," __stringify(l) \
  309. : : "r" (v))
  310. #define mtmsrd(v) __mtmsrd((v), 0)
  311. #define mfspr(rn) ({unsigned long rval; \
  312. asm volatile("mfspr %0," __stringify(rn) \
  313. : "=r" (rval)); rval;})
  314. #define mtspr(rn, v) asm volatile("mtspr " __stringify(rn) ",%0" : : "r" (v))
  315. #define mftb() ({unsigned long rval; \
  316. asm volatile("mftb %0" : "=r" (rval)); rval;})
  317. #define mttbl(v) asm volatile("mttbl %0":: "r"(v))
  318. #define mttbu(v) asm volatile("mttbu %0":: "r"(v))
  319. #define mfasr() ({unsigned long rval; \
  320. asm volatile("mfasr %0" : "=r" (rval)); rval;})
  321. static inline void set_tb(unsigned int upper, unsigned int lower)
  322. {
  323. mttbl(0);
  324. mttbu(upper);
  325. mttbl(lower);
  326. }
  327. #define __get_SP() ({unsigned long sp; \
  328. asm volatile("mr %0,1": "=r" (sp)); sp;})
  329. #ifdef __KERNEL__
  330. extern int have_of;
  331. extern u64 ppc64_interrupt_controller;
  332. struct task_struct;
  333. void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
  334. void release_thread(struct task_struct *);
  335. /* Prepare to copy thread state - unlazy all lazy status */
  336. extern void prepare_to_copy(struct task_struct *tsk);
  337. /* Create a new kernel thread. */
  338. extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
  339. /* Lazy FPU handling on uni-processor */
  340. extern struct task_struct *last_task_used_math;
  341. extern struct task_struct *last_task_used_altivec;
  342. /* 64-bit user address space is 41-bits (2TBs user VM) */
  343. #define TASK_SIZE_USER64 (0x0000020000000000UL)
  344. /*
  345. * 32-bit user address space is 4GB - 1 page
  346. * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT
  347. */
  348. #define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
  349. #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
  350. TASK_SIZE_USER32 : TASK_SIZE_USER64)
  351. /* This decides where the kernel will search for a free chunk of vm
  352. * space during mmap's.
  353. */
  354. #define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4))
  355. #define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4))
  356. #define TASK_UNMAPPED_BASE ((test_thread_flag(TIF_32BIT)||(ppcdebugset(PPCDBG_BINFMT_32ADDR))) ? \
  357. TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
  358. typedef struct {
  359. unsigned long seg;
  360. } mm_segment_t;
  361. struct thread_struct {
  362. unsigned long ksp; /* Kernel stack pointer */
  363. unsigned long ksp_vsid;
  364. struct pt_regs *regs; /* Pointer to saved register state */
  365. mm_segment_t fs; /* for get_fs() validation */
  366. double fpr[32]; /* Complete floating point set */
  367. unsigned long fpscr; /* Floating point status (plus pad) */
  368. unsigned long fpexc_mode; /* Floating-point exception mode */
  369. unsigned long start_tb; /* Start purr when proc switched in */
  370. unsigned long accum_tb; /* Total accumilated purr for process */
  371. unsigned long vdso_base; /* base of the vDSO library */
  372. #ifdef CONFIG_ALTIVEC
  373. /* Complete AltiVec register set */
  374. vector128 vr[32] __attribute((aligned(16)));
  375. /* AltiVec status */
  376. vector128 vscr __attribute((aligned(16)));
  377. unsigned long vrsave;
  378. int used_vr; /* set if process has used altivec */
  379. #endif /* CONFIG_ALTIVEC */
  380. };
  381. #define ARCH_MIN_TASKALIGN 16
  382. #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
  383. #define INIT_THREAD { \
  384. .ksp = INIT_SP, \
  385. .regs = (struct pt_regs *)INIT_SP - 1, \
  386. .fs = KERNEL_DS, \
  387. .fpr = {0}, \
  388. .fpscr = 0, \
  389. .fpexc_mode = MSR_FE0|MSR_FE1, \
  390. }
  391. /*
  392. * Return saved PC of a blocked thread. For now, this is the "user" PC
  393. */
  394. #define thread_saved_pc(tsk) \
  395. ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  396. unsigned long get_wchan(struct task_struct *p);
  397. #define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  398. #define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
  399. /* Get/set floating-point exception mode */
  400. #define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
  401. #define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
  402. extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
  403. extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
  404. static inline unsigned int __unpack_fe01(unsigned long msr_bits)
  405. {
  406. return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
  407. }
  408. static inline unsigned long __pack_fe01(unsigned int fpmode)
  409. {
  410. return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
  411. }
  412. #define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
  413. /*
  414. * Prefetch macros.
  415. */
  416. #define ARCH_HAS_PREFETCH
  417. #define ARCH_HAS_PREFETCHW
  418. #define ARCH_HAS_SPINLOCK_PREFETCH
  419. static inline void prefetch(const void *x)
  420. {
  421. if (unlikely(!x))
  422. return;
  423. __asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
  424. }
  425. static inline void prefetchw(const void *x)
  426. {
  427. if (unlikely(!x))
  428. return;
  429. __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
  430. }
  431. #define spin_lock_prefetch(x) prefetchw(x)
  432. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  433. static inline void ppc64_runlatch_on(void)
  434. {
  435. unsigned long ctrl;
  436. ctrl = mfspr(SPRN_CTRLF);
  437. ctrl |= CTRL_RUNLATCH;
  438. mtspr(SPRN_CTRLT, ctrl);
  439. }
  440. static inline void ppc64_runlatch_off(void)
  441. {
  442. unsigned long ctrl;
  443. ctrl = mfspr(SPRN_CTRLF);
  444. ctrl &= ~CTRL_RUNLATCH;
  445. mtspr(SPRN_CTRLT, ctrl);
  446. }
  447. #endif /* __KERNEL__ */
  448. #endif /* __ASSEMBLY__ */
  449. /*
  450. * Number of entries in the SLB. If this ever changes we should handle
  451. * it with a use a cpu feature fixup.
  452. */
  453. #define SLB_NUM_ENTRIES 64
  454. #endif /* __ASM_PPC64_PROCESSOR_H */