processor.h 10 KB

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