processor.h 9.2 KB

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