processor.h 9.5 KB

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