processor.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 1999
  4. * Author(s): Hartmut Penner (hp@de.ibm.com),
  5. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  6. *
  7. * Derived from "include/asm-i386/processor.h"
  8. * Copyright (C) 1994, Linus Torvalds
  9. */
  10. #ifndef __ASM_S390_PROCESSOR_H
  11. #define __ASM_S390_PROCESSOR_H
  12. #ifndef __ASSEMBLY__
  13. #include <linux/linkage.h>
  14. #include <linux/irqflags.h>
  15. #include <asm/cpu.h>
  16. #include <asm/page.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/setup.h>
  19. #include <asm/runtime_instr.h>
  20. /*
  21. * Default implementation of macro that returns current
  22. * instruction pointer ("program counter").
  23. */
  24. #define current_text_addr() ({ void *pc; asm("basr %0,0" : "=a" (pc)); pc; })
  25. static inline void get_cpu_id(struct cpuid *ptr)
  26. {
  27. asm volatile("stidp %0" : "=Q" (*ptr));
  28. }
  29. extern void s390_adjust_jiffies(void);
  30. extern const struct seq_operations cpuinfo_op;
  31. extern int sysctl_ieee_emulation_warnings;
  32. extern void execve_tail(void);
  33. /*
  34. * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
  35. */
  36. #ifndef CONFIG_64BIT
  37. #define TASK_SIZE (1UL << 31)
  38. #define TASK_MAX_SIZE (1UL << 31)
  39. #define TASK_UNMAPPED_BASE (1UL << 30)
  40. #else /* CONFIG_64BIT */
  41. #define TASK_SIZE_OF(tsk) ((tsk)->mm->context.asce_limit)
  42. #define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
  43. (1UL << 30) : (1UL << 41))
  44. #define TASK_SIZE TASK_SIZE_OF(current)
  45. #define TASK_MAX_SIZE (1UL << 53)
  46. #endif /* CONFIG_64BIT */
  47. #ifndef CONFIG_64BIT
  48. #define STACK_TOP (1UL << 31)
  49. #define STACK_TOP_MAX (1UL << 31)
  50. #else /* CONFIG_64BIT */
  51. #define STACK_TOP (1UL << (test_thread_flag(TIF_31BIT) ? 31:42))
  52. #define STACK_TOP_MAX (1UL << 42)
  53. #endif /* CONFIG_64BIT */
  54. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  55. typedef struct {
  56. __u32 ar4;
  57. } mm_segment_t;
  58. /*
  59. * Thread structure
  60. */
  61. struct thread_struct {
  62. s390_fp_regs fp_regs;
  63. unsigned int acrs[NUM_ACRS];
  64. unsigned long ksp; /* kernel stack pointer */
  65. mm_segment_t mm_segment;
  66. unsigned long gmap_addr; /* address of last gmap fault. */
  67. struct per_regs per_user; /* User specified PER registers */
  68. struct per_event per_event; /* Cause of the last PER trap */
  69. unsigned long per_flags; /* Flags to control debug behavior */
  70. /* pfault_wait is used to block the process on a pfault event */
  71. unsigned long pfault_wait;
  72. struct list_head list;
  73. /* cpu runtime instrumentation */
  74. struct runtime_instr_cb *ri_cb;
  75. int ri_signum;
  76. #ifdef CONFIG_64BIT
  77. unsigned char trap_tdb[256]; /* Transaction abort diagnose block */
  78. #endif
  79. };
  80. /* Flag to disable transactions. */
  81. #define PER_FLAG_NO_TE 1UL
  82. /* Flag to enable random transaction aborts. */
  83. #define PER_FLAG_TE_ABORT_RAND 2UL
  84. /* Flag to specify random transaction abort mode:
  85. * - abort each transaction at a random instruction before TEND if set.
  86. * - abort random transactions at a random instruction if cleared.
  87. */
  88. #define PER_FLAG_TE_ABORT_RAND_TEND 4UL
  89. typedef struct thread_struct thread_struct;
  90. /*
  91. * Stack layout of a C stack frame.
  92. */
  93. #ifndef __PACK_STACK
  94. struct stack_frame {
  95. unsigned long back_chain;
  96. unsigned long empty1[5];
  97. unsigned long gprs[10];
  98. unsigned int empty2[8];
  99. };
  100. #else
  101. struct stack_frame {
  102. unsigned long empty1[5];
  103. unsigned int empty2[8];
  104. unsigned long gprs[10];
  105. unsigned long back_chain;
  106. };
  107. #endif
  108. #define ARCH_MIN_TASKALIGN 8
  109. #define INIT_THREAD { \
  110. .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \
  111. }
  112. /*
  113. * Do necessary setup to start up a new thread.
  114. */
  115. #define start_thread(regs, new_psw, new_stackp) do { \
  116. regs->psw.mask = psw_user_bits | PSW_MASK_EA | PSW_MASK_BA; \
  117. regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
  118. regs->gprs[15] = new_stackp; \
  119. execve_tail(); \
  120. } while (0)
  121. #define start_thread31(regs, new_psw, new_stackp) do { \
  122. regs->psw.mask = psw_user_bits | PSW_MASK_BA; \
  123. regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
  124. regs->gprs[15] = new_stackp; \
  125. __tlb_flush_mm(current->mm); \
  126. crst_table_downgrade(current->mm, 1UL << 31); \
  127. update_mm(current->mm, current); \
  128. execve_tail(); \
  129. } while (0)
  130. /* Forward declaration, a strange C thing */
  131. struct task_struct;
  132. struct mm_struct;
  133. struct seq_file;
  134. #ifdef CONFIG_64BIT
  135. extern void show_cacheinfo(struct seq_file *m);
  136. #else
  137. static inline void show_cacheinfo(struct seq_file *m) { }
  138. #endif
  139. /* Free all resources held by a thread. */
  140. extern void release_thread(struct task_struct *);
  141. /*
  142. * Return saved PC of a blocked thread.
  143. */
  144. extern unsigned long thread_saved_pc(struct task_struct *t);
  145. extern void show_code(struct pt_regs *regs);
  146. extern void print_fn_code(unsigned char *code, unsigned long len);
  147. extern int insn_to_mnemonic(unsigned char *instruction, char *buf,
  148. unsigned int len);
  149. unsigned long get_wchan(struct task_struct *p);
  150. #define task_pt_regs(tsk) ((struct pt_regs *) \
  151. (task_stack_page(tsk) + THREAD_SIZE) - 1)
  152. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
  153. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
  154. static inline unsigned short stap(void)
  155. {
  156. unsigned short cpu_address;
  157. asm volatile("stap %0" : "=m" (cpu_address));
  158. return cpu_address;
  159. }
  160. /*
  161. * Give up the time slice of the virtual PU.
  162. */
  163. static inline void cpu_relax(void)
  164. {
  165. if (MACHINE_HAS_DIAG44)
  166. asm volatile("diag 0,0,68");
  167. barrier();
  168. }
  169. #define arch_mutex_cpu_relax() barrier()
  170. static inline void psw_set_key(unsigned int key)
  171. {
  172. asm volatile("spka 0(%0)" : : "d" (key));
  173. }
  174. /*
  175. * Set PSW to specified value.
  176. */
  177. static inline void __load_psw(psw_t psw)
  178. {
  179. #ifndef CONFIG_64BIT
  180. asm volatile("lpsw %0" : : "Q" (psw) : "cc");
  181. #else
  182. asm volatile("lpswe %0" : : "Q" (psw) : "cc");
  183. #endif
  184. }
  185. /*
  186. * Set PSW mask to specified value, while leaving the
  187. * PSW addr pointing to the next instruction.
  188. */
  189. static inline void __load_psw_mask (unsigned long mask)
  190. {
  191. unsigned long addr;
  192. psw_t psw;
  193. psw.mask = mask;
  194. #ifndef CONFIG_64BIT
  195. asm volatile(
  196. " basr %0,0\n"
  197. "0: ahi %0,1f-0b\n"
  198. " st %0,%O1+4(%R1)\n"
  199. " lpsw %1\n"
  200. "1:"
  201. : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc");
  202. #else /* CONFIG_64BIT */
  203. asm volatile(
  204. " larl %0,1f\n"
  205. " stg %0,%O1+8(%R1)\n"
  206. " lpswe %1\n"
  207. "1:"
  208. : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc");
  209. #endif /* CONFIG_64BIT */
  210. }
  211. /*
  212. * Rewind PSW instruction address by specified number of bytes.
  213. */
  214. static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
  215. {
  216. #ifndef CONFIG_64BIT
  217. if (psw.addr & PSW_ADDR_AMODE)
  218. /* 31 bit mode */
  219. return (psw.addr - ilc) | PSW_ADDR_AMODE;
  220. /* 24 bit mode */
  221. return (psw.addr - ilc) & ((1UL << 24) - 1);
  222. #else
  223. unsigned long mask;
  224. mask = (psw.mask & PSW_MASK_EA) ? -1UL :
  225. (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 :
  226. (1UL << 24) - 1;
  227. return (psw.addr - ilc) & mask;
  228. #endif
  229. }
  230. /*
  231. * Function to drop a processor into disabled wait state
  232. */
  233. static inline void __noreturn disabled_wait(unsigned long code)
  234. {
  235. unsigned long ctl_buf;
  236. psw_t dw_psw;
  237. dw_psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA;
  238. dw_psw.addr = code;
  239. /*
  240. * Store status and then load disabled wait psw,
  241. * the processor is dead afterwards
  242. */
  243. #ifndef CONFIG_64BIT
  244. asm volatile(
  245. " stctl 0,0,0(%2)\n"
  246. " ni 0(%2),0xef\n" /* switch off protection */
  247. " lctl 0,0,0(%2)\n"
  248. " stpt 0xd8\n" /* store timer */
  249. " stckc 0xe0\n" /* store clock comparator */
  250. " stpx 0x108\n" /* store prefix register */
  251. " stam 0,15,0x120\n" /* store access registers */
  252. " std 0,0x160\n" /* store f0 */
  253. " std 2,0x168\n" /* store f2 */
  254. " std 4,0x170\n" /* store f4 */
  255. " std 6,0x178\n" /* store f6 */
  256. " stm 0,15,0x180\n" /* store general registers */
  257. " stctl 0,15,0x1c0\n" /* store control registers */
  258. " oi 0x1c0,0x10\n" /* fake protection bit */
  259. " lpsw 0(%1)"
  260. : "=m" (ctl_buf)
  261. : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc");
  262. #else /* CONFIG_64BIT */
  263. asm volatile(
  264. " stctg 0,0,0(%2)\n"
  265. " ni 4(%2),0xef\n" /* switch off protection */
  266. " lctlg 0,0,0(%2)\n"
  267. " lghi 1,0x1000\n"
  268. " stpt 0x328(1)\n" /* store timer */
  269. " stckc 0x330(1)\n" /* store clock comparator */
  270. " stpx 0x318(1)\n" /* store prefix register */
  271. " stam 0,15,0x340(1)\n"/* store access registers */
  272. " stfpc 0x31c(1)\n" /* store fpu control */
  273. " std 0,0x200(1)\n" /* store f0 */
  274. " std 1,0x208(1)\n" /* store f1 */
  275. " std 2,0x210(1)\n" /* store f2 */
  276. " std 3,0x218(1)\n" /* store f3 */
  277. " std 4,0x220(1)\n" /* store f4 */
  278. " std 5,0x228(1)\n" /* store f5 */
  279. " std 6,0x230(1)\n" /* store f6 */
  280. " std 7,0x238(1)\n" /* store f7 */
  281. " std 8,0x240(1)\n" /* store f8 */
  282. " std 9,0x248(1)\n" /* store f9 */
  283. " std 10,0x250(1)\n" /* store f10 */
  284. " std 11,0x258(1)\n" /* store f11 */
  285. " std 12,0x260(1)\n" /* store f12 */
  286. " std 13,0x268(1)\n" /* store f13 */
  287. " std 14,0x270(1)\n" /* store f14 */
  288. " std 15,0x278(1)\n" /* store f15 */
  289. " stmg 0,15,0x280(1)\n"/* store general registers */
  290. " stctg 0,15,0x380(1)\n"/* store control registers */
  291. " oi 0x384(1),0x10\n"/* fake protection bit */
  292. " lpswe 0(%1)"
  293. : "=m" (ctl_buf)
  294. : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc", "0", "1");
  295. #endif /* CONFIG_64BIT */
  296. while (1);
  297. }
  298. /*
  299. * Use to set psw mask except for the first byte which
  300. * won't be changed by this function.
  301. */
  302. static inline void
  303. __set_psw_mask(unsigned long mask)
  304. {
  305. __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8)));
  306. }
  307. #define local_mcck_enable() \
  308. __set_psw_mask(psw_kernel_bits | PSW_MASK_DAT | PSW_MASK_MCHECK)
  309. #define local_mcck_disable() \
  310. __set_psw_mask(psw_kernel_bits | PSW_MASK_DAT)
  311. /*
  312. * Basic Machine Check/Program Check Handler.
  313. */
  314. extern void s390_base_mcck_handler(void);
  315. extern void s390_base_pgm_handler(void);
  316. extern void s390_base_ext_handler(void);
  317. extern void (*s390_base_mcck_handler_fn)(void);
  318. extern void (*s390_base_pgm_handler_fn)(void);
  319. extern void (*s390_base_ext_handler_fn)(void);
  320. #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
  321. extern int memcpy_real(void *, void *, size_t);
  322. extern void memcpy_absolute(void *, void *, size_t);
  323. #define mem_assign_absolute(dest, val) { \
  324. __typeof__(dest) __tmp = (val); \
  325. \
  326. BUILD_BUG_ON(sizeof(__tmp) != sizeof(val)); \
  327. memcpy_absolute(&(dest), &__tmp, sizeof(__tmp)); \
  328. }
  329. /*
  330. * Helper macro for exception table entries
  331. */
  332. #define EX_TABLE(_fault, _target) \
  333. ".section __ex_table,\"a\"\n" \
  334. ".align 4\n" \
  335. ".long (" #_fault ") - .\n" \
  336. ".long (" #_target ") - .\n" \
  337. ".previous\n"
  338. #else /* __ASSEMBLY__ */
  339. #define EX_TABLE(_fault, _target) \
  340. .section __ex_table,"a" ; \
  341. .align 4 ; \
  342. .long (_fault) - . ; \
  343. .long (_target) - . ; \
  344. .previous
  345. #endif /* __ASSEMBLY__ */
  346. #endif /* __ASM_S390_PROCESSOR_H */