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