system.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #define AT_VECTOR_SIZE_ARCH 5 /* entries in ARCH_DLINFO */
  13. #if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
  14. #define __icbi() \
  15. { \
  16. unsigned long __addr; \
  17. __addr = 0xa8000000; \
  18. __asm__ __volatile__( \
  19. "icbi %0\n\t" \
  20. : /* no output */ \
  21. : "m" (__m(__addr))); \
  22. }
  23. #endif
  24. /*
  25. * A brief note on ctrl_barrier(), the control register write barrier.
  26. *
  27. * Legacy SH cores typically require a sequence of 8 nops after
  28. * modification of a control register in order for the changes to take
  29. * effect. On newer cores (like the sh4a and sh5) this is accomplished
  30. * with icbi.
  31. *
  32. * Also note that on sh4a in the icbi case we can forego a synco for the
  33. * write barrier, as it's not necessary for control registers.
  34. *
  35. * Historically we have only done this type of barrier for the MMUCR, but
  36. * it's also necessary for the CCR, so we make it generic here instead.
  37. */
  38. #if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
  39. #define mb() __asm__ __volatile__ ("synco": : :"memory")
  40. #define rmb() mb()
  41. #define wmb() __asm__ __volatile__ ("synco": : :"memory")
  42. #define ctrl_barrier() __icbi()
  43. #define read_barrier_depends() do { } while(0)
  44. #else
  45. #define mb() __asm__ __volatile__ ("": : :"memory")
  46. #define rmb() mb()
  47. #define wmb() __asm__ __volatile__ ("": : :"memory")
  48. #define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
  49. #define read_barrier_depends() do { } while(0)
  50. #endif
  51. #ifdef CONFIG_SMP
  52. #define smp_mb() mb()
  53. #define smp_rmb() rmb()
  54. #define smp_wmb() wmb()
  55. #define smp_read_barrier_depends() read_barrier_depends()
  56. #else
  57. #define smp_mb() barrier()
  58. #define smp_rmb() barrier()
  59. #define smp_wmb() barrier()
  60. #define smp_read_barrier_depends() do { } while(0)
  61. #endif
  62. #define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
  63. #ifdef CONFIG_GUSA_RB
  64. #include <asm/cmpxchg-grb.h>
  65. #else
  66. #include <asm/cmpxchg-irq.h>
  67. #endif
  68. extern void __xchg_called_with_bad_pointer(void);
  69. #define __xchg(ptr, x, size) \
  70. ({ \
  71. unsigned long __xchg__res; \
  72. volatile void *__xchg_ptr = (ptr); \
  73. switch (size) { \
  74. case 4: \
  75. __xchg__res = xchg_u32(__xchg_ptr, x); \
  76. break; \
  77. case 1: \
  78. __xchg__res = xchg_u8(__xchg_ptr, x); \
  79. break; \
  80. default: \
  81. __xchg_called_with_bad_pointer(); \
  82. __xchg__res = x; \
  83. break; \
  84. } \
  85. \
  86. __xchg__res; \
  87. })
  88. #define xchg(ptr,x) \
  89. ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
  90. /* This function doesn't exist, so you'll get a linker error
  91. * if something tries to do an invalid cmpxchg(). */
  92. extern void __cmpxchg_called_with_bad_pointer(void);
  93. #define __HAVE_ARCH_CMPXCHG 1
  94. static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
  95. unsigned long new, int size)
  96. {
  97. switch (size) {
  98. case 4:
  99. return __cmpxchg_u32(ptr, old, new);
  100. }
  101. __cmpxchg_called_with_bad_pointer();
  102. return old;
  103. }
  104. #define cmpxchg(ptr,o,n) \
  105. ({ \
  106. __typeof__(*(ptr)) _o_ = (o); \
  107. __typeof__(*(ptr)) _n_ = (n); \
  108. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  109. (unsigned long)_n_, sizeof(*(ptr))); \
  110. })
  111. extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
  112. extern void *set_exception_table_vec(unsigned int vec, void *handler);
  113. static inline void *set_exception_table_evt(unsigned int evt, void *handler)
  114. {
  115. return set_exception_table_vec(evt >> 5, handler);
  116. }
  117. /*
  118. * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
  119. */
  120. #ifdef CONFIG_CPU_SH2A
  121. extern unsigned int instruction_size(unsigned int insn);
  122. #elif defined(CONFIG_SUPERH32)
  123. #define instruction_size(insn) (2)
  124. #else
  125. #define instruction_size(insn) (4)
  126. #endif
  127. extern unsigned long cached_to_uncached;
  128. extern struct dentry *sh_debugfs_root;
  129. void per_cpu_trap_init(void);
  130. asmlinkage void break_point_trap(void);
  131. #ifdef CONFIG_SUPERH32
  132. #define BUILD_TRAP_HANDLER(name) \
  133. asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5, \
  134. unsigned long r6, unsigned long r7, \
  135. struct pt_regs __regs)
  136. #define TRAP_HANDLER_DECL \
  137. struct pt_regs *regs = RELOC_HIDE(&__regs, 0); \
  138. unsigned int vec = regs->tra; \
  139. (void)vec;
  140. #else
  141. #define BUILD_TRAP_HANDLER(name) \
  142. asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs)
  143. #define TRAP_HANDLER_DECL
  144. #endif
  145. BUILD_TRAP_HANDLER(address_error);
  146. BUILD_TRAP_HANDLER(debug);
  147. BUILD_TRAP_HANDLER(bug);
  148. BUILD_TRAP_HANDLER(fpu_error);
  149. BUILD_TRAP_HANDLER(fpu_state_restore);
  150. #define arch_align_stack(x) (x)
  151. struct mem_access {
  152. unsigned long (*from)(void *dst, const void *src, unsigned long cnt);
  153. unsigned long (*to)(void *dst, const void *src, unsigned long cnt);
  154. };
  155. #ifdef CONFIG_SUPERH32
  156. # include "system_32.h"
  157. #else
  158. # include "system_64.h"
  159. #endif
  160. #endif