system.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:10k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* $Id: system.h,v 1.68 2001/11/18 00:12:56 davem Exp $ */
  2. #ifndef __SPARC64_SYSTEM_H
  3. #define __SPARC64_SYSTEM_H
  4. #include <linux/config.h>
  5. #include <asm/ptrace.h>
  6. #include <asm/processor.h>
  7. #include <asm/asm_offsets.h>
  8. #include <asm/visasm.h>
  9. #ifndef __ASSEMBLY__
  10. /*
  11.  * Sparc (general) CPU types
  12.  */
  13. enum sparc_cpu {
  14.   sun4        = 0x00,
  15.   sun4c       = 0x01,
  16.   sun4m       = 0x02,
  17.   sun4d       = 0x03,
  18.   sun4e       = 0x04,
  19.   sun4u       = 0x05, /* V8 ploos ploos */
  20.   sun_unknown = 0x06,
  21.   ap1000      = 0x07, /* almost a sun4m */
  22. };
  23.                   
  24. #define sparc_cpu_model sun4u
  25. /* This cannot ever be a sun4c nor sun4 :) That's just history. */
  26. #define ARCH_SUN4C_SUN4 0
  27. #define ARCH_SUN4 0
  28. #endif
  29. #define setipl(__new_ipl) 
  30. __asm__ __volatile__("wrpr %0, %%pil"  : : "r" (__new_ipl) : "memory")
  31. #define __cli() 
  32. __asm__ __volatile__("wrpr 15, %%pil" : : : "memory")
  33. #define __sti() 
  34. __asm__ __volatile__("wrpr 0, %%pil" : : : "memory")
  35. #define getipl() 
  36. ({ unsigned long retval; __asm__ __volatile__("rdpr %%pil, %0" : "=r" (retval)); retval; })
  37. #define swap_pil(__new_pil) 
  38. ({ unsigned long retval; 
  39. __asm__ __volatile__("rdpr %%pil, %0nt" 
  40.      "wrpr %1, %%pil" 
  41.      : "=&r" (retval) 
  42.      : "r" (__new_pil) 
  43.      : "memory"); 
  44. retval; 
  45. })
  46. #define read_pil_and_cli() 
  47. ({ unsigned long retval; 
  48. __asm__ __volatile__("rdpr %%pil, %0nt" 
  49.      "wrpr 15, %%pil" 
  50.      : "=r" (retval) 
  51.      : : "memory"); 
  52. retval; 
  53. })
  54. #define __save_flags(flags) ((flags) = getipl())
  55. #define __save_and_cli(flags) ((flags) = read_pil_and_cli())
  56. #define __restore_flags(flags) setipl((flags))
  57. #define local_irq_disable() __cli()
  58. #define local_irq_enable() __sti()
  59. #define local_irq_save(flags) __save_and_cli(flags)
  60. #define local_irq_restore(flags) __restore_flags(flags)
  61. #ifndef CONFIG_SMP
  62. #define cli() __cli()
  63. #define sti() __sti()
  64. #define save_flags(x) __save_flags(x)
  65. #define restore_flags(x) __restore_flags(x)
  66. #define save_and_cli(x) __save_and_cli(x)
  67. #else
  68. #ifndef __ASSEMBLY__
  69. extern void __global_cli(void);
  70. extern void __global_sti(void);
  71. extern unsigned long __global_save_flags(void);
  72. extern void __global_restore_flags(unsigned long flags);
  73. #endif
  74. #define cli() __global_cli()
  75. #define sti() __global_sti()
  76. #define save_flags(x) ((x) = __global_save_flags())
  77. #define restore_flags(flags) __global_restore_flags(flags)
  78. #define save_and_cli(flags) do { save_flags(flags); cli(); } while(0)
  79. #endif
  80. #define nop()  __asm__ __volatile__ ("nop")
  81. #define membar(type) __asm__ __volatile__ ("membar " type : : : "memory");
  82. #define mb()
  83. membar("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad");
  84. #define rmb() membar("#LoadLoad")
  85. #define wmb() membar("#StoreStore")
  86. #define set_mb(__var, __value) 
  87. do { __var = __value; membar("#StoreLoad | #StoreStore"); } while(0)
  88. #define set_wmb(__var, __value) 
  89. do { __var = __value; membar("#StoreStore"); } while(0)
  90. #ifdef CONFIG_SMP
  91. #define smp_mb() mb()
  92. #define smp_rmb() rmb()
  93. #define smp_wmb() wmb()
  94. #else
  95. #define smp_mb() __asm__ __volatile__("":::"memory");
  96. #define smp_rmb() __asm__ __volatile__("":::"memory");
  97. #define smp_wmb() __asm__ __volatile__("":::"memory");
  98. #endif
  99. #define flushi(addr) __asm__ __volatile__ ("flush %0" : : "r" (addr) : "memory")
  100. #define flushw_all() __asm__ __volatile__("flushw")
  101. /* Performance counter register access. */
  102. #define read_pcr(__p)  __asm__ __volatile__("rd %%pcr, %0" : "=r" (__p))
  103. #define write_pcr(__p) __asm__ __volatile__("wr %0, 0x0, %%pcr" : : "r" (__p));
  104. #define read_pic(__p)  __asm__ __volatile__("rd %%pic, %0" : "=r" (__p))
  105. /* Blackbird errata workaround.  See commentary in
  106.  * arch/sparc64/kernel/smp.c:smp_percpu_timer_interrupt()
  107.  * for more information.
  108.  */
  109. #define reset_pic()    
  110. __asm__ __volatile__("ba,pt %xcc, 99fnt"
  111.      ".align 64n"
  112.   "99:wr %g0, 0x0, %picnt"
  113.      "rd %pic, %g0")
  114. #ifndef __ASSEMBLY__
  115. extern void synchronize_user_stack(void);
  116. extern void __flushw_user(void);
  117. #define flushw_user() __flushw_user()
  118. #define flush_user_windows flushw_user
  119. #define flush_register_windows flushw_all
  120. #define prepare_to_switch flushw_all
  121. #ifndef CONFIG_DEBUG_SPINLOCk
  122. #define CHECK_LOCKS(PREV) do { } while(0)
  123. #else /* CONFIG_DEBUG_SPINLOCk */
  124. #define CHECK_LOCKS(PREV)
  125. if ((PREV)->thread.smp_lock_count) {
  126. unsigned long rpc;
  127. __asm__ __volatile__("mov %%i7, %0" : "=r" (rpc));
  128. printk(KERN_CRIT "(%s)[%d]: Sleeping with %d locks held!n",
  129.        (PREV)->comm, (PREV)->pid,
  130.        (PREV)->thread.smp_lock_count);
  131. printk(KERN_CRIT "(%s)[%d]: Last lock at %08xn",
  132.        (PREV)->comm, (PREV)->pid,
  133.        (PREV)->thread.smp_lock_pc);
  134. printk(KERN_CRIT "(%s)[%d]: Sched caller %016lxn",
  135.        (PREV)->comm, (PREV)->pid, rpc);
  136. }
  137. #endif /* !(CONFIG_DEBUG_SPINLOCk) */
  138. /* See what happens when you design the chip correctly?
  139.  *
  140.  * We tell gcc we clobber all non-fixed-usage registers except
  141.  * for l0/l1.  It will use one for 'next' and the other to hold
  142.  * the output value of 'last'.  'next' is not referenced again
  143.  * past the invocation of switch_to in the scheduler, so we need
  144.  * not preserve it's value.  Hairy, but it lets us remove 2 loads
  145.  * and 2 stores in this critical code path.  -DaveM
  146.  */
  147. #define switch_to(prev, next, last)
  148. do { CHECK_LOCKS(prev);
  149. if (current->thread.flags & SPARC_FLAG_PERFCTR) {
  150. unsigned long __tmp;
  151. read_pcr(__tmp);
  152. current->thread.pcr_reg = __tmp;
  153. read_pic(__tmp);
  154. current->thread.kernel_cntd0 += (unsigned int)(__tmp);
  155. current->thread.kernel_cntd1 += ((__tmp) >> 32);
  156. }
  157. save_and_clear_fpu();
  158. /* If you are tempted to conditionalize the following */
  159. /* so that ASI is only written if it changes, think again. */
  160. __asm__ __volatile__("wr %%g0, %0, %%asi"
  161.      : : "r" (next->thread.current_ds.seg));
  162. __asm__ __volatile__(
  163. "mov %%g6, %%g5nt"
  164. "wrpr %%g0, 0x95, %%pstatent"
  165. "stx %%i6, [%%sp + 2047 + 0x70]nt"
  166. "stx %%i7, [%%sp + 2047 + 0x78]nt"
  167. "rdpr %%wstate, %%o5nt"
  168. "stx %%o6, [%%g6 + %3]nt"
  169. "stb %%o5, [%%g6 + %2]nt"
  170. "rdpr %%cwp, %%o5nt"
  171. "stb %%o5, [%%g6 + %5]nt"
  172. "mov %1, %%g6nt"
  173. "ldub [%1 + %5], %%g1nt"
  174. "wrpr %%g1, %%cwpnt"
  175. "ldx [%%g6 + %3], %%o6nt"
  176. "ldub [%%g6 + %2], %%o5nt"
  177. "ldub [%%g6 + %4], %%o7nt"
  178. "mov %%g6, %%l2nt"
  179. "wrpr %%o5, 0x0, %%wstatent"
  180. "ldx [%%sp + 2047 + 0x70], %%i6nt"
  181. "ldx [%%sp + 2047 + 0x78], %%i7nt"
  182. "wrpr %%g0, 0x94, %%pstatent"
  183. "mov %%l2, %%g6nt"
  184. "wrpr %%g0, 0x96, %%pstatent"
  185. "andcc %%o7, %6, %%g0nt"
  186. "bne,pn %%icc, ret_from_syscallnt"
  187. " mov %%g5, %0nt"
  188. : "=&r" (last)
  189. : "r" (next),
  190.   "i" ((const unsigned long)(&((struct task_struct *)0)->thread.wstate)),
  191.   "i" ((const unsigned long)(&((struct task_struct *)0)->thread.ksp)),
  192.   "i" ((const unsigned long)(&((struct task_struct *)0)->thread.flags)),
  193.   "i" ((const unsigned long)(&((struct task_struct *)0)->thread.cwp)),
  194.   "i" (SPARC_FLAG_NEWCHILD)
  195. : "cc", "g1", "g2", "g3", "g5", "g7",
  196.   "l2", "l3", "l4", "l5", "l6", "l7",
  197.   "i0", "i1", "i2", "i3", "i4", "i5",
  198.   "o0", "o1", "o2", "o3", "o4", "o5", "o7");
  199. /* If you fuck with this, update ret_from_syscall code too. */
  200. if (current->thread.flags & SPARC_FLAG_PERFCTR) {
  201. write_pcr(current->thread.pcr_reg);
  202. reset_pic();
  203. }
  204. } while(0)
  205. extern __inline__ unsigned long xchg32(__volatile__ unsigned int *m, unsigned int val)
  206. {
  207. __asm__ __volatile__(
  208. " mov %0, %%g5n"
  209. "1: lduw [%2], %%g7n"
  210. " cas [%2], %%g7, %0n"
  211. " cmp %%g7, %0n"
  212. " bne,a,pn %%icc, 1bn"
  213. "  mov %%g5, %0n"
  214. " membar #StoreLoad | #StoreStoren"
  215. : "=&r" (val)
  216. : "0" (val), "r" (m)
  217. : "g5", "g7", "cc", "memory");
  218. return val;
  219. }
  220. extern __inline__ unsigned long xchg64(__volatile__ unsigned long *m, unsigned long val)
  221. {
  222. __asm__ __volatile__(
  223. " mov %0, %%g5n"
  224. "1: ldx [%2], %%g7n"
  225. " casx [%2], %%g7, %0n"
  226. " cmp %%g7, %0n"
  227. " bne,a,pn %%xcc, 1bn"
  228. "  mov %%g5, %0n"
  229. " membar #StoreLoad | #StoreStoren"
  230. : "=&r" (val)
  231. : "0" (val), "r" (m)
  232. : "g5", "g7", "cc", "memory");
  233. return val;
  234. }
  235. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  236. #define tas(ptr) (xchg((ptr),1))
  237. extern void __xchg_called_with_bad_pointer(void);
  238. static __inline__ unsigned long __xchg(unsigned long x, __volatile__ void * ptr,
  239.        int size)
  240. {
  241. switch (size) {
  242. case 4:
  243. return xchg32(ptr, x);
  244. case 8:
  245. return xchg64(ptr, x);
  246. };
  247. __xchg_called_with_bad_pointer();
  248. return x;
  249. }
  250. extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
  251. /* 
  252.  * Atomic compare and exchange.  Compare OLD with MEM, if identical,
  253.  * store NEW in MEM.  Return the initial value in MEM.  Success is
  254.  * indicated by comparing RETURN with OLD.
  255.  */
  256. #define __HAVE_ARCH_CMPXCHG 1
  257. extern __inline__ unsigned long
  258. __cmpxchg_u32(volatile int *m, int old, int new)
  259. {
  260. __asm__ __volatile__("cas [%2], %3, %0nt"
  261.      "membar #StoreLoad | #StoreStore"
  262.      : "=&r" (new)
  263.      : "0" (new), "r" (m), "r" (old)
  264.      : "memory");
  265. return new;
  266. }
  267. extern __inline__ unsigned long
  268. __cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
  269. {
  270. __asm__ __volatile__("casx [%2], %3, %0nt"
  271.      "membar #StoreLoad | #StoreStore"
  272.      : "=&r" (new)
  273.      : "0" (new), "r" (m), "r" (old)
  274.      : "memory");
  275. return new;
  276. }
  277. /* This function doesn't exist, so you'll get a linker error
  278.    if something tries to do an invalid cmpxchg().  */
  279. extern void __cmpxchg_called_with_bad_pointer(void);
  280. static __inline__ unsigned long
  281. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  282. {
  283. switch (size) {
  284. case 4:
  285. return __cmpxchg_u32(ptr, old, new);
  286. case 8:
  287. return __cmpxchg_u64(ptr, old, new);
  288. }
  289. __cmpxchg_called_with_bad_pointer();
  290. return old;
  291. }
  292. #define cmpxchg(ptr,o,n)  
  293.   ({  
  294.      __typeof__(*(ptr)) _o_ = (o);  
  295.      __typeof__(*(ptr)) _n_ = (n);  
  296.      (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,  
  297.     (unsigned long)_n_, sizeof(*(ptr))); 
  298.   })
  299. #endif /* !(__ASSEMBLY__) */
  300. #endif /* !(__SPARC64_SYSTEM_H) */