processor.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 <asm/cpuid.h>
  16. #include <asm/page.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/setup.h>
  19. #ifdef __KERNEL__
  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(cpuid_t *ptr)
  26. {
  27. asm volatile("stidp 0(%1)" : "=m" (*ptr) : "a" (ptr));
  28. }
  29. extern void s390_adjust_jiffies(void);
  30. extern void print_cpu_info(void);
  31. extern int get_cpu_capability(unsigned int *);
  32. /*
  33. * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
  34. */
  35. #ifndef __s390x__
  36. #define TASK_SIZE (1UL << 31)
  37. #define TASK_UNMAPPED_BASE (1UL << 30)
  38. #else /* __s390x__ */
  39. #define TASK_SIZE_OF(tsk) ((tsk)->mm->context.asce_limit)
  40. #define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
  41. (1UL << 30) : (1UL << 41))
  42. #define TASK_SIZE TASK_SIZE_OF(current)
  43. #endif /* __s390x__ */
  44. #ifdef __KERNEL__
  45. #ifndef __s390x__
  46. #define STACK_TOP (1UL << 31)
  47. #define STACK_TOP_MAX (1UL << 31)
  48. #else /* __s390x__ */
  49. #define STACK_TOP (1UL << (test_thread_flag(TIF_31BIT) ? 31:42))
  50. #define STACK_TOP_MAX (1UL << 42)
  51. #endif /* __s390x__ */
  52. #endif
  53. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  54. typedef struct {
  55. __u32 ar4;
  56. } mm_segment_t;
  57. /*
  58. * Thread structure
  59. */
  60. struct thread_struct {
  61. s390_fp_regs fp_regs;
  62. unsigned int acrs[NUM_ACRS];
  63. unsigned long ksp; /* kernel stack pointer */
  64. mm_segment_t mm_segment;
  65. unsigned long prot_addr; /* address of protection-excep. */
  66. unsigned int trap_no;
  67. per_struct per_info;
  68. /* Used to give failing instruction back to user for ieee exceptions */
  69. unsigned long ieee_instruction_pointer;
  70. /* pfault_wait is used to block the process on a pfault event */
  71. unsigned long pfault_wait;
  72. };
  73. typedef struct thread_struct thread_struct;
  74. /*
  75. * Stack layout of a C stack frame.
  76. */
  77. #ifndef __PACK_STACK
  78. struct stack_frame {
  79. unsigned long back_chain;
  80. unsigned long empty1[5];
  81. unsigned long gprs[10];
  82. unsigned int empty2[8];
  83. };
  84. #else
  85. struct stack_frame {
  86. unsigned long empty1[5];
  87. unsigned int empty2[8];
  88. unsigned long gprs[10];
  89. unsigned long back_chain;
  90. };
  91. #endif
  92. #define ARCH_MIN_TASKALIGN 8
  93. #define INIT_THREAD { \
  94. .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \
  95. }
  96. /*
  97. * Do necessary setup to start up a new thread.
  98. */
  99. #define start_thread(regs, new_psw, new_stackp) do { \
  100. set_fs(USER_DS); \
  101. regs->psw.mask = psw_user_bits; \
  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. set_fs(USER_DS); \
  107. regs->psw.mask = psw_user32_bits; \
  108. regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
  109. regs->gprs[15] = new_stackp; \
  110. crst_table_downgrade(current->mm, 1UL << 31); \
  111. } while (0)
  112. /* Forward declaration, a strange C thing */
  113. struct task_struct;
  114. struct mm_struct;
  115. struct seq_file;
  116. /* Free all resources held by a thread. */
  117. extern void release_thread(struct task_struct *);
  118. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  119. /* Prepare to copy thread state - unlazy all lazy status */
  120. #define prepare_to_copy(tsk) do { } while (0)
  121. /*
  122. * Return saved PC of a blocked thread.
  123. */
  124. extern unsigned long thread_saved_pc(struct task_struct *t);
  125. /*
  126. * Print register of task into buffer. Used in fs/proc/array.c.
  127. */
  128. extern void task_show_regs(struct seq_file *m, struct task_struct *task);
  129. extern void show_code(struct pt_regs *regs);
  130. unsigned long get_wchan(struct task_struct *p);
  131. #define task_pt_regs(tsk) ((struct pt_regs *) \
  132. (task_stack_page(tsk) + THREAD_SIZE) - 1)
  133. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
  134. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
  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 __s390x__
  154. asm volatile("lpsw 0(%0)" : : "a" (&psw), "m" (psw) : "cc");
  155. #else
  156. asm volatile("lpswe 0(%0)" : : "a" (&psw), "m" (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 __s390x__
  169. asm volatile(
  170. " basr %0,0\n"
  171. "0: ahi %0,1f-0b\n"
  172. " st %0,4(%1)\n"
  173. " lpsw 0(%1)\n"
  174. "1:"
  175. : "=&d" (addr) : "a" (&psw), "m" (psw) : "memory", "cc");
  176. #else /* __s390x__ */
  177. asm volatile(
  178. " larl %0,1f\n"
  179. " stg %0,8(%1)\n"
  180. " lpswe 0(%1)\n"
  181. "1:"
  182. : "=&d" (addr) : "a" (&psw), "m" (psw) : "memory", "cc");
  183. #endif /* __s390x__ */
  184. }
  185. /*
  186. * Function to stop a processor until an interruption occurred
  187. */
  188. static inline void enabled_wait(void)
  189. {
  190. __load_psw_mask(PSW_BASE_BITS | PSW_MASK_IO | PSW_MASK_EXT |
  191. PSW_MASK_MCHECK | PSW_MASK_WAIT | PSW_DEFAULT_KEY);
  192. }
  193. /*
  194. * Function to drop a processor into disabled wait state
  195. */
  196. static inline void ATTRIB_NORET disabled_wait(unsigned long code)
  197. {
  198. unsigned long ctl_buf;
  199. psw_t dw_psw;
  200. dw_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
  201. dw_psw.addr = code;
  202. /*
  203. * Store status and then load disabled wait psw,
  204. * the processor is dead afterwards
  205. */
  206. #ifndef __s390x__
  207. asm volatile(
  208. " stctl 0,0,0(%2)\n"
  209. " ni 0(%2),0xef\n" /* switch off protection */
  210. " lctl 0,0,0(%2)\n"
  211. " stpt 0xd8\n" /* store timer */
  212. " stckc 0xe0\n" /* store clock comparator */
  213. " stpx 0x108\n" /* store prefix register */
  214. " stam 0,15,0x120\n" /* store access registers */
  215. " std 0,0x160\n" /* store f0 */
  216. " std 2,0x168\n" /* store f2 */
  217. " std 4,0x170\n" /* store f4 */
  218. " std 6,0x178\n" /* store f6 */
  219. " stm 0,15,0x180\n" /* store general registers */
  220. " stctl 0,15,0x1c0\n" /* store control registers */
  221. " oi 0x1c0,0x10\n" /* fake protection bit */
  222. " lpsw 0(%1)"
  223. : "=m" (ctl_buf)
  224. : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc");
  225. #else /* __s390x__ */
  226. asm volatile(
  227. " stctg 0,0,0(%2)\n"
  228. " ni 4(%2),0xef\n" /* switch off protection */
  229. " lctlg 0,0,0(%2)\n"
  230. " lghi 1,0x1000\n"
  231. " stpt 0x328(1)\n" /* store timer */
  232. " stckc 0x330(1)\n" /* store clock comparator */
  233. " stpx 0x318(1)\n" /* store prefix register */
  234. " stam 0,15,0x340(1)\n"/* store access registers */
  235. " stfpc 0x31c(1)\n" /* store fpu control */
  236. " std 0,0x200(1)\n" /* store f0 */
  237. " std 1,0x208(1)\n" /* store f1 */
  238. " std 2,0x210(1)\n" /* store f2 */
  239. " std 3,0x218(1)\n" /* store f3 */
  240. " std 4,0x220(1)\n" /* store f4 */
  241. " std 5,0x228(1)\n" /* store f5 */
  242. " std 6,0x230(1)\n" /* store f6 */
  243. " std 7,0x238(1)\n" /* store f7 */
  244. " std 8,0x240(1)\n" /* store f8 */
  245. " std 9,0x248(1)\n" /* store f9 */
  246. " std 10,0x250(1)\n" /* store f10 */
  247. " std 11,0x258(1)\n" /* store f11 */
  248. " std 12,0x260(1)\n" /* store f12 */
  249. " std 13,0x268(1)\n" /* store f13 */
  250. " std 14,0x270(1)\n" /* store f14 */
  251. " std 15,0x278(1)\n" /* store f15 */
  252. " stmg 0,15,0x280(1)\n"/* store general registers */
  253. " stctg 0,15,0x380(1)\n"/* store control registers */
  254. " oi 0x384(1),0x10\n"/* fake protection bit */
  255. " lpswe 0(%1)"
  256. : "=m" (ctl_buf)
  257. : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc", "0");
  258. #endif /* __s390x__ */
  259. while (1);
  260. }
  261. /*
  262. * Basic Machine Check/Program Check Handler.
  263. */
  264. extern void s390_base_mcck_handler(void);
  265. extern void s390_base_pgm_handler(void);
  266. extern void s390_base_ext_handler(void);
  267. extern void (*s390_base_mcck_handler_fn)(void);
  268. extern void (*s390_base_pgm_handler_fn)(void);
  269. extern void (*s390_base_ext_handler_fn)(void);
  270. #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
  271. #endif
  272. /*
  273. * Helper macro for exception table entries
  274. */
  275. #ifndef __s390x__
  276. #define EX_TABLE(_fault,_target) \
  277. ".section __ex_table,\"a\"\n" \
  278. " .align 4\n" \
  279. " .long " #_fault "," #_target "\n" \
  280. ".previous\n"
  281. #else
  282. #define EX_TABLE(_fault,_target) \
  283. ".section __ex_table,\"a\"\n" \
  284. " .align 8\n" \
  285. " .quad " #_fault "," #_target "\n" \
  286. ".previous\n"
  287. #endif
  288. #endif /* __ASM_S390_PROCESSOR_H */