processor.h 9.2 KB

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