system.h 5.3 KB

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