processor.h 6.6 KB

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