processor.h 6.3 KB

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