system.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #ifndef __ASM_SH_SYSTEM_H
  2. #define __ASM_SH_SYSTEM_H
  3. /*
  4. * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  5. * Copyright (C) 2002 Paul Mundt
  6. */
  7. #include <linux/irqflags.h>
  8. #include <linux/compiler.h>
  9. #include <linux/linkage.h>
  10. #include <asm/types.h>
  11. #include <asm/ptrace.h>
  12. struct task_struct *__switch_to(struct task_struct *prev,
  13. struct task_struct *next);
  14. /*
  15. * switch_to() should switch tasks to task nr n, first
  16. */
  17. #define switch_to(prev, next, last) do { \
  18. struct task_struct *__last; \
  19. register unsigned long *__ts1 __asm__ ("r1") = &prev->thread.sp; \
  20. register unsigned long *__ts2 __asm__ ("r2") = &prev->thread.pc; \
  21. register unsigned long *__ts4 __asm__ ("r4") = (unsigned long *)prev; \
  22. register unsigned long *__ts5 __asm__ ("r5") = (unsigned long *)next; \
  23. register unsigned long *__ts6 __asm__ ("r6") = &next->thread.sp; \
  24. register unsigned long __ts7 __asm__ ("r7") = next->thread.pc; \
  25. __asm__ __volatile__ (".balign 4\n\t" \
  26. "stc.l gbr, @-r15\n\t" \
  27. "sts.l pr, @-r15\n\t" \
  28. "mov.l r8, @-r15\n\t" \
  29. "mov.l r9, @-r15\n\t" \
  30. "mov.l r10, @-r15\n\t" \
  31. "mov.l r11, @-r15\n\t" \
  32. "mov.l r12, @-r15\n\t" \
  33. "mov.l r13, @-r15\n\t" \
  34. "mov.l r14, @-r15\n\t" \
  35. "mov.l r15, @r1 ! save SP\n\t" \
  36. "mov.l @r6, r15 ! change to new stack\n\t" \
  37. "mova 1f, %0\n\t" \
  38. "mov.l %0, @r2 ! save PC\n\t" \
  39. "mov.l 2f, %0\n\t" \
  40. "jmp @%0 ! call __switch_to\n\t" \
  41. " lds r7, pr ! with return to new PC\n\t" \
  42. ".balign 4\n" \
  43. "2:\n\t" \
  44. ".long __switch_to\n" \
  45. "1:\n\t" \
  46. "mov.l @r15+, r14\n\t" \
  47. "mov.l @r15+, r13\n\t" \
  48. "mov.l @r15+, r12\n\t" \
  49. "mov.l @r15+, r11\n\t" \
  50. "mov.l @r15+, r10\n\t" \
  51. "mov.l @r15+, r9\n\t" \
  52. "mov.l @r15+, r8\n\t" \
  53. "lds.l @r15+, pr\n\t" \
  54. "ldc.l @r15+, gbr\n\t" \
  55. : "=z" (__last) \
  56. : "r" (__ts1), "r" (__ts2), "r" (__ts4), \
  57. "r" (__ts5), "r" (__ts6), "r" (__ts7) \
  58. : "r3", "t"); \
  59. last = __last; \
  60. } while (0)
  61. /*
  62. * On SMP systems, when the scheduler does migration-cost autodetection,
  63. * it needs a way to flush as much of the CPU's caches as possible.
  64. *
  65. * TODO: fill this in!
  66. */
  67. static inline void sched_cacheflush(void)
  68. {
  69. }
  70. #ifdef CONFIG_CPU_SH4A
  71. #define __icbi() \
  72. { \
  73. unsigned long __addr; \
  74. __addr = 0xa8000000; \
  75. __asm__ __volatile__( \
  76. "icbi %0\n\t" \
  77. : /* no output */ \
  78. : "m" (__m(__addr))); \
  79. }
  80. #endif
  81. /*
  82. * A brief note on ctrl_barrier(), the control register write barrier.
  83. *
  84. * Legacy SH cores typically require a sequence of 8 nops after
  85. * modification of a control register in order for the changes to take
  86. * effect. On newer cores (like the sh4a and sh5) this is accomplished
  87. * with icbi.
  88. *
  89. * Also note that on sh4a in the icbi case we can forego a synco for the
  90. * write barrier, as it's not necessary for control registers.
  91. *
  92. * Historically we have only done this type of barrier for the MMUCR, but
  93. * it's also necessary for the CCR, so we make it generic here instead.
  94. */
  95. #ifdef CONFIG_CPU_SH4A
  96. #define mb() __asm__ __volatile__ ("synco": : :"memory")
  97. #define rmb() mb()
  98. #define wmb() __asm__ __volatile__ ("synco": : :"memory")
  99. #define ctrl_barrier() __icbi()
  100. #define read_barrier_depends() do { } while(0)
  101. #else
  102. #define mb() __asm__ __volatile__ ("": : :"memory")
  103. #define rmb() mb()
  104. #define wmb() __asm__ __volatile__ ("": : :"memory")
  105. #define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
  106. #define read_barrier_depends() do { } while(0)
  107. #endif
  108. #ifdef CONFIG_SMP
  109. #define smp_mb() mb()
  110. #define smp_rmb() rmb()
  111. #define smp_wmb() wmb()
  112. #define smp_read_barrier_depends() read_barrier_depends()
  113. #else
  114. #define smp_mb() barrier()
  115. #define smp_rmb() barrier()
  116. #define smp_wmb() barrier()
  117. #define smp_read_barrier_depends() do { } while(0)
  118. #endif
  119. #define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
  120. /*
  121. * Jump to P2 area.
  122. * When handling TLB or caches, we need to do it from P2 area.
  123. */
  124. #define jump_to_P2() \
  125. do { \
  126. unsigned long __dummy; \
  127. __asm__ __volatile__( \
  128. "mov.l 1f, %0\n\t" \
  129. "or %1, %0\n\t" \
  130. "jmp @%0\n\t" \
  131. " nop\n\t" \
  132. ".balign 4\n" \
  133. "1: .long 2f\n" \
  134. "2:" \
  135. : "=&r" (__dummy) \
  136. : "r" (0x20000000)); \
  137. } while (0)
  138. /*
  139. * Back to P1 area.
  140. */
  141. #define back_to_P1() \
  142. do { \
  143. unsigned long __dummy; \
  144. ctrl_barrier(); \
  145. __asm__ __volatile__( \
  146. "mov.l 1f, %0\n\t" \
  147. "jmp @%0\n\t" \
  148. " nop\n\t" \
  149. ".balign 4\n" \
  150. "1: .long 2f\n" \
  151. "2:" \
  152. : "=&r" (__dummy)); \
  153. } while (0)
  154. static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
  155. {
  156. unsigned long flags, retval;
  157. local_irq_save(flags);
  158. retval = *m;
  159. *m = val;
  160. local_irq_restore(flags);
  161. return retval;
  162. }
  163. static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
  164. {
  165. unsigned long flags, retval;
  166. local_irq_save(flags);
  167. retval = *m;
  168. *m = val & 0xff;
  169. local_irq_restore(flags);
  170. return retval;
  171. }
  172. extern void __xchg_called_with_bad_pointer(void);
  173. #define __xchg(ptr, x, size) \
  174. ({ \
  175. unsigned long __xchg__res; \
  176. volatile void *__xchg_ptr = (ptr); \
  177. switch (size) { \
  178. case 4: \
  179. __xchg__res = xchg_u32(__xchg_ptr, x); \
  180. break; \
  181. case 1: \
  182. __xchg__res = xchg_u8(__xchg_ptr, x); \
  183. break; \
  184. default: \
  185. __xchg_called_with_bad_pointer(); \
  186. __xchg__res = x; \
  187. break; \
  188. } \
  189. \
  190. __xchg__res; \
  191. })
  192. #define xchg(ptr,x) \
  193. ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
  194. static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
  195. unsigned long new)
  196. {
  197. __u32 retval;
  198. unsigned long flags;
  199. local_irq_save(flags);
  200. retval = *m;
  201. if (retval == old)
  202. *m = new;
  203. local_irq_restore(flags); /* implies memory barrier */
  204. return retval;
  205. }
  206. /* This function doesn't exist, so you'll get a linker error
  207. * if something tries to do an invalid cmpxchg(). */
  208. extern void __cmpxchg_called_with_bad_pointer(void);
  209. #define __HAVE_ARCH_CMPXCHG 1
  210. static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
  211. unsigned long new, int size)
  212. {
  213. switch (size) {
  214. case 4:
  215. return __cmpxchg_u32(ptr, old, new);
  216. }
  217. __cmpxchg_called_with_bad_pointer();
  218. return old;
  219. }
  220. #define cmpxchg(ptr,o,n) \
  221. ({ \
  222. __typeof__(*(ptr)) _o_ = (o); \
  223. __typeof__(*(ptr)) _n_ = (n); \
  224. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  225. (unsigned long)_n_, sizeof(*(ptr))); \
  226. })
  227. extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
  228. extern void *set_exception_table_vec(unsigned int vec, void *handler);
  229. static inline void *set_exception_table_evt(unsigned int evt, void *handler)
  230. {
  231. return set_exception_table_vec(evt >> 5, handler);
  232. }
  233. /*
  234. * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
  235. */
  236. #ifdef CONFIG_CPU_SH2A
  237. extern unsigned int instruction_size(unsigned int insn);
  238. #else
  239. #define instruction_size(insn) (2)
  240. #endif
  241. /* XXX
  242. * disable hlt during certain critical i/o operations
  243. */
  244. #define HAVE_DISABLE_HLT
  245. void disable_hlt(void);
  246. void enable_hlt(void);
  247. void default_idle(void);
  248. asmlinkage void break_point_trap(void);
  249. asmlinkage void debug_trap_handler(unsigned long r4, unsigned long r5,
  250. unsigned long r6, unsigned long r7,
  251. struct pt_regs __regs);
  252. asmlinkage void bug_trap_handler(unsigned long r4, unsigned long r5,
  253. unsigned long r6, unsigned long r7,
  254. struct pt_regs __regs);
  255. #define arch_align_stack(x) (x)
  256. #endif