processor.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * include/asm-sh/processor.h
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. * Copyright (C) 2002, 2003 Paul Mundt
  6. */
  7. #ifndef __ASM_SH_PROCESSOR_H
  8. #define __ASM_SH_PROCESSOR_H
  9. #ifdef __KERNEL__
  10. #include <linux/compiler.h>
  11. #include <asm/page.h>
  12. #include <asm/types.h>
  13. #include <asm/cache.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/cpu-features.h>
  16. /*
  17. * Default implementation of macro that returns current
  18. * instruction pointer ("program counter").
  19. */
  20. #define current_text_addr() ({ void *pc; __asm__("mova 1f, %0\n1:":"=z" (pc)); pc; })
  21. /* Core Processor Version Register */
  22. #define CCN_PVR 0xff000030
  23. #define CCN_CVR 0xff000040
  24. #define CCN_PRR 0xff000044
  25. /*
  26. * CPU type and hardware bug flags. Kept separately for each CPU.
  27. *
  28. * Each one of these also needs a CONFIG_CPU_SUBTYPE_xxx entry
  29. * in arch/sh/mm/Kconfig, as well as an entry in arch/sh/kernel/setup.c
  30. * for parsing the subtype in get_cpu_subtype().
  31. */
  32. enum cpu_type {
  33. /* SH-2 types */
  34. CPU_SH7604, CPU_SH7619,
  35. /* SH-2A types */
  36. CPU_SH7206,
  37. /* SH-3 types */
  38. CPU_SH7705, CPU_SH7706, CPU_SH7707,
  39. CPU_SH7708, CPU_SH7708S, CPU_SH7708R,
  40. CPU_SH7709, CPU_SH7709A, CPU_SH7710,
  41. CPU_SH7729, CPU_SH7300,
  42. /* SH-4 types */
  43. CPU_SH7750, CPU_SH7750S, CPU_SH7750R, CPU_SH7751, CPU_SH7751R,
  44. CPU_SH7760, CPU_ST40RA, CPU_ST40GX1, CPU_SH4_202, CPU_SH4_501,
  45. /* SH-4A types */
  46. CPU_SH73180, CPU_SH7343, CPU_SH7770, CPU_SH7780, CPU_SH7781,
  47. CPU_SH7785,
  48. /* Unknown subtype */
  49. CPU_SH_NONE
  50. };
  51. struct sh_cpuinfo {
  52. unsigned int type;
  53. unsigned long loops_per_jiffy;
  54. struct cache_info icache; /* Primary I-cache */
  55. struct cache_info dcache; /* Primary D-cache */
  56. struct cache_info scache; /* Secondary cache */
  57. unsigned long flags;
  58. } __attribute__ ((aligned(SMP_CACHE_BYTES)));
  59. extern struct sh_cpuinfo boot_cpu_data;
  60. #ifdef CONFIG_SMP
  61. extern struct sh_cpuinfo cpu_data[];
  62. #define current_cpu_data cpu_data[smp_processor_id()]
  63. #else
  64. #define cpu_data (&boot_cpu_data)
  65. #define current_cpu_data boot_cpu_data
  66. #endif
  67. /*
  68. * User space process size: 2GB.
  69. *
  70. * Since SH7709 and SH7750 have "area 7", we can't use 0x7c000000--0x7fffffff
  71. */
  72. #define TASK_SIZE 0x7c000000UL
  73. /* This decides where the kernel will search for a free chunk of vm
  74. * space during mmap's.
  75. */
  76. #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
  77. /*
  78. * Bit of SR register
  79. *
  80. * FD-bit:
  81. * When it's set, it means the processor doesn't have right to use FPU,
  82. * and it results exception when the floating operation is executed.
  83. *
  84. * IMASK-bit:
  85. * Interrupt level mask
  86. */
  87. #define SR_FD 0x00008000
  88. #define SR_DSP 0x00001000
  89. #define SR_IMASK 0x000000f0
  90. /*
  91. * FPU structure and data
  92. */
  93. struct sh_fpu_hard_struct {
  94. unsigned long fp_regs[16];
  95. unsigned long xfp_regs[16];
  96. unsigned long fpscr;
  97. unsigned long fpul;
  98. long status; /* software status information */
  99. };
  100. /* Dummy fpu emulator */
  101. struct sh_fpu_soft_struct {
  102. unsigned long fp_regs[16];
  103. unsigned long xfp_regs[16];
  104. unsigned long fpscr;
  105. unsigned long fpul;
  106. unsigned char lookahead;
  107. unsigned long entry_pc;
  108. };
  109. union sh_fpu_union {
  110. struct sh_fpu_hard_struct hard;
  111. struct sh_fpu_soft_struct soft;
  112. };
  113. struct thread_struct {
  114. /* Saved registers when thread is descheduled */
  115. unsigned long sp;
  116. unsigned long pc;
  117. /* Hardware debugging registers */
  118. unsigned long ubc_pc;
  119. /* floating point info */
  120. union sh_fpu_union fpu;
  121. };
  122. typedef struct {
  123. unsigned long seg;
  124. } mm_segment_t;
  125. /* Count of active tasks with UBC settings */
  126. extern int ubc_usercnt;
  127. #define INIT_THREAD { \
  128. .sp = sizeof(init_stack) + (long) &init_stack, \
  129. }
  130. /*
  131. * Do necessary setup to start up a newly executed thread.
  132. */
  133. #define start_thread(regs, new_pc, new_sp) \
  134. set_fs(USER_DS); \
  135. regs->pr = 0; \
  136. regs->sr = SR_FD; /* User mode. */ \
  137. regs->pc = new_pc; \
  138. regs->regs[15] = new_sp
  139. /* Forward declaration, a strange C thing */
  140. struct task_struct;
  141. struct mm_struct;
  142. /* Free all resources held by a thread. */
  143. extern void release_thread(struct task_struct *);
  144. /* Prepare to copy thread state - unlazy all lazy status */
  145. #define prepare_to_copy(tsk) do { } while (0)
  146. /*
  147. * create a kernel thread without removing it from tasklists
  148. */
  149. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  150. /* Copy and release all segment info associated with a VM */
  151. #define copy_segments(p, mm) do { } while(0)
  152. #define release_segments(mm) do { } while(0)
  153. /*
  154. * FPU lazy state save handling.
  155. */
  156. static __inline__ void disable_fpu(void)
  157. {
  158. unsigned long __dummy;
  159. /* Set FD flag in SR */
  160. __asm__ __volatile__("stc sr, %0\n\t"
  161. "or %1, %0\n\t"
  162. "ldc %0, sr"
  163. : "=&r" (__dummy)
  164. : "r" (SR_FD));
  165. }
  166. static __inline__ void enable_fpu(void)
  167. {
  168. unsigned long __dummy;
  169. /* Clear out FD flag in SR */
  170. __asm__ __volatile__("stc sr, %0\n\t"
  171. "and %1, %0\n\t"
  172. "ldc %0, sr"
  173. : "=&r" (__dummy)
  174. : "r" (~SR_FD));
  175. }
  176. static __inline__ void release_fpu(struct pt_regs *regs)
  177. {
  178. regs->sr |= SR_FD;
  179. }
  180. static __inline__ void grab_fpu(struct pt_regs *regs)
  181. {
  182. regs->sr &= ~SR_FD;
  183. }
  184. #ifdef CONFIG_CPU_SH4
  185. extern void save_fpu(struct task_struct *__tsk, struct pt_regs *regs);
  186. #else
  187. #define save_fpu(tsk) do { } while (0)
  188. #endif
  189. #define unlazy_fpu(tsk, regs) do { \
  190. if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { \
  191. save_fpu(tsk, regs); \
  192. } \
  193. } while (0)
  194. #define clear_fpu(tsk, regs) do { \
  195. if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { \
  196. clear_tsk_thread_flag(tsk, TIF_USEDFPU); \
  197. release_fpu(regs); \
  198. } \
  199. } while (0)
  200. /* Double presision, NANS as NANS, rounding to nearest, no exceptions */
  201. #define FPSCR_INIT 0x00080000
  202. #define FPSCR_CAUSE_MASK 0x0001f000 /* Cause bits */
  203. #define FPSCR_FLAG_MASK 0x0000007c /* Flag bits */
  204. /*
  205. * Return saved PC of a blocked thread.
  206. */
  207. #define thread_saved_pc(tsk) (tsk->thread.pc)
  208. void show_trace(struct task_struct *tsk, unsigned long *sp,
  209. struct pt_regs *regs);
  210. extern unsigned long get_wchan(struct task_struct *p);
  211. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
  212. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[15])
  213. #define cpu_sleep() __asm__ __volatile__ ("sleep" : : : "memory")
  214. #define cpu_relax() barrier()
  215. #if defined(CONFIG_CPU_SH2A) || defined(CONFIG_CPU_SH3) || \
  216. defined(CONFIG_CPU_SH4)
  217. #define PREFETCH_STRIDE L1_CACHE_BYTES
  218. #define ARCH_HAS_PREFETCH
  219. #define ARCH_HAS_PREFETCHW
  220. static inline void prefetch(void *x)
  221. {
  222. __asm__ __volatile__ ("pref @%0\n\t" : : "r" (x) : "memory");
  223. }
  224. #define prefetchw(x) prefetch(x)
  225. #endif
  226. #ifdef CONFIG_VSYSCALL
  227. extern int vsyscall_init(void);
  228. #else
  229. #define vsyscall_init() do { } while (0)
  230. #endif
  231. #endif /* __KERNEL__ */
  232. #endif /* __ASM_SH_PROCESSOR_H */