system.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* system.h: FR-V CPU control definitions
  2. *
  3. * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_SYSTEM_H
  12. #define _ASM_SYSTEM_H
  13. #include <linux/config.h> /* get configuration macros */
  14. #include <linux/linkage.h>
  15. #include <asm/atomic.h>
  16. struct thread_struct;
  17. /*
  18. * switch_to(prev, next) should switch from task `prev' to `next'
  19. * `prev' will never be the same as `next'.
  20. * The `mb' is to tell GCC not to cache `current' across this call.
  21. */
  22. extern asmlinkage
  23. struct task_struct *__switch_to(struct thread_struct *prev_thread,
  24. struct thread_struct *next_thread,
  25. struct task_struct *prev);
  26. #define switch_to(prev, next, last) \
  27. do { \
  28. (prev)->thread.sched_lr = \
  29. (unsigned long) __builtin_return_address(0); \
  30. (last) = __switch_to(&(prev)->thread, &(next)->thread, (prev)); \
  31. mb(); \
  32. } while(0)
  33. /*
  34. * interrupt flag manipulation
  35. * - use virtual interrupt management since touching the PSR is slow
  36. * - ICC2.Z: T if interrupts virtually disabled
  37. * - ICC2.C: F if interrupts really disabled
  38. * - if Z==1 upon interrupt:
  39. * - C is set to 0
  40. * - interrupts are really disabled
  41. * - entry.S returns immediately
  42. * - uses TIHI (TRAP if Z==0 && C==0) #2 to really reenable interrupts
  43. * - if taken, the trap:
  44. * - sets ICC2.C
  45. * - enables interrupts
  46. */
  47. #define local_irq_disable() \
  48. do { \
  49. /* set Z flag, but don't change the C flag */ \
  50. asm volatile(" andcc gr0,gr0,gr0,icc2 \n" \
  51. : \
  52. : \
  53. : "memory", "icc2" \
  54. ); \
  55. } while(0)
  56. #define local_irq_enable() \
  57. do { \
  58. /* clear Z flag and then test the C flag */ \
  59. asm volatile(" oricc gr0,#1,gr0,icc2 \n" \
  60. " tihi icc2,gr0,#2 \n" \
  61. : \
  62. : \
  63. : "memory", "icc2" \
  64. ); \
  65. } while(0)
  66. #define local_save_flags(flags) \
  67. do { \
  68. typecheck(unsigned long, flags); \
  69. asm volatile("movsg ccr,%0" \
  70. : "=r"(flags) \
  71. : \
  72. : "memory"); \
  73. \
  74. /* shift ICC2.Z to bit 0 */ \
  75. flags >>= 26; \
  76. \
  77. /* make flags 1 if interrupts disabled, 0 otherwise */ \
  78. flags &= 1UL; \
  79. } while(0)
  80. #define irqs_disabled() \
  81. ({unsigned long flags; local_save_flags(flags); flags; })
  82. #define local_irq_save(flags) \
  83. do { \
  84. typecheck(unsigned long, flags); \
  85. local_save_flags(flags); \
  86. local_irq_disable(); \
  87. } while(0)
  88. #define local_irq_restore(flags) \
  89. do { \
  90. typecheck(unsigned long, flags); \
  91. \
  92. /* load the Z flag by turning 1 if disabled into 0 if disabled \
  93. * and thus setting the Z flag but not the C flag */ \
  94. asm volatile(" xoricc %0,#1,gr0,icc2 \n" \
  95. /* then test Z=0 and C=0 */ \
  96. " tihi icc2,gr0,#2 \n" \
  97. : \
  98. : "r"(flags) \
  99. : "memory", "icc2" \
  100. ); \
  101. \
  102. } while(0)
  103. /*
  104. * real interrupt flag manipulation
  105. */
  106. #define __local_irq_disable() \
  107. do { \
  108. unsigned long psr; \
  109. asm volatile(" movsg psr,%0 \n" \
  110. " andi %0,%2,%0 \n" \
  111. " ori %0,%1,%0 \n" \
  112. " movgs %0,psr \n" \
  113. : "=r"(psr) \
  114. : "i" (PSR_PIL_14), "i" (~PSR_PIL) \
  115. : "memory"); \
  116. } while(0)
  117. #define __local_irq_enable() \
  118. do { \
  119. unsigned long psr; \
  120. asm volatile(" movsg psr,%0 \n" \
  121. " andi %0,%1,%0 \n" \
  122. " movgs %0,psr \n" \
  123. : "=r"(psr) \
  124. : "i" (~PSR_PIL) \
  125. : "memory"); \
  126. } while(0)
  127. #define __local_save_flags(flags) \
  128. do { \
  129. typecheck(unsigned long, flags); \
  130. asm("movsg psr,%0" \
  131. : "=r"(flags) \
  132. : \
  133. : "memory"); \
  134. } while(0)
  135. #define __local_irq_save(flags) \
  136. do { \
  137. unsigned long npsr; \
  138. typecheck(unsigned long, flags); \
  139. asm volatile(" movsg psr,%0 \n" \
  140. " andi %0,%3,%1 \n" \
  141. " ori %1,%2,%1 \n" \
  142. " movgs %1,psr \n" \
  143. : "=r"(flags), "=r"(npsr) \
  144. : "i" (PSR_PIL_14), "i" (~PSR_PIL) \
  145. : "memory"); \
  146. } while(0)
  147. #define __local_irq_restore(flags) \
  148. do { \
  149. typecheck(unsigned long, flags); \
  150. asm volatile(" movgs %0,psr \n" \
  151. : \
  152. : "r" (flags) \
  153. : "memory"); \
  154. } while(0)
  155. #define __irqs_disabled() \
  156. ((__get_PSR() & PSR_PIL) >= PSR_PIL_14)
  157. /*
  158. * Force strict CPU ordering.
  159. */
  160. #define nop() asm volatile ("nop"::)
  161. #define mb() asm volatile ("membar" : : :"memory")
  162. #define rmb() asm volatile ("membar" : : :"memory")
  163. #define wmb() asm volatile ("membar" : : :"memory")
  164. #define set_mb(var, value) do { var = value; mb(); } while (0)
  165. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  166. #define smp_mb() mb()
  167. #define smp_rmb() rmb()
  168. #define smp_wmb() wmb()
  169. #define read_barrier_depends() do {} while(0)
  170. #define smp_read_barrier_depends() read_barrier_depends()
  171. #define HARD_RESET_NOW() \
  172. do { \
  173. cli(); \
  174. } while(1)
  175. extern void die_if_kernel(const char *, ...) __attribute__((format(printf, 1, 2)));
  176. extern void free_initmem(void);
  177. #define arch_align_stack(x) (x)
  178. #endif /* _ASM_SYSTEM_H */