system.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * include/asm-v850/system.h -- Low-level interrupt/thread ops
  3. *
  4. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  5. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #ifndef __V850_SYSTEM_H__
  14. #define __V850_SYSTEM_H__
  15. #include <linux/linkage.h>
  16. #include <asm/ptrace.h>
  17. /*
  18. * switch_to(n) should switch tasks to task ptr, first checking that
  19. * ptr isn't the current task, in which case it does nothing.
  20. */
  21. struct thread_struct;
  22. extern void *switch_thread (struct thread_struct *last,
  23. struct thread_struct *next);
  24. #define switch_to(prev,next,last) \
  25. do { \
  26. if (prev != next) { \
  27. (last) = switch_thread (&prev->thread, &next->thread); \
  28. } \
  29. } while (0)
  30. /* Enable/disable interrupts. */
  31. #define local_irq_enable() __asm__ __volatile__ ("ei")
  32. #define local_irq_disable() __asm__ __volatile__ ("di")
  33. #define local_save_flags(flags) \
  34. __asm__ __volatile__ ("stsr %1, %0" : "=r" (flags) : "i" (SR_PSW))
  35. #define local_restore_flags(flags) \
  36. __asm__ __volatile__ ("ldsr %0, %1" :: "r" (flags), "i" (SR_PSW))
  37. /* For spinlocks etc */
  38. #define local_irq_save(flags) \
  39. do { local_save_flags (flags); local_irq_disable (); } while (0)
  40. #define local_irq_restore(flags) \
  41. local_restore_flags (flags);
  42. static inline int irqs_disabled (void)
  43. {
  44. unsigned flags;
  45. local_save_flags (flags);
  46. return !!(flags & 0x20);
  47. }
  48. /*
  49. * Force strict CPU ordering.
  50. * Not really required on v850...
  51. */
  52. #define nop() __asm__ __volatile__ ("nop")
  53. #define mb() __asm__ __volatile__ ("" ::: "memory")
  54. #define rmb() mb ()
  55. #define wmb() mb ()
  56. #define read_barrier_depends() ((void)0)
  57. #define set_rmb(var, value) do { xchg (&var, value); } while (0)
  58. #define set_mb(var, value) set_rmb (var, value)
  59. #define set_wmb(var, value) do { var = value; wmb (); } while (0)
  60. #define smp_mb() mb ()
  61. #define smp_rmb() rmb ()
  62. #define smp_wmb() wmb ()
  63. #define smp_read_barrier_depends() read_barrier_depends()
  64. #define xchg(ptr, with) \
  65. ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr))))
  66. #define tas(ptr) (xchg ((ptr), 1))
  67. static inline unsigned long __xchg (unsigned long with,
  68. __volatile__ void *ptr, int size)
  69. {
  70. unsigned long tmp, flags;
  71. local_irq_save (flags);
  72. switch (size) {
  73. case 1:
  74. tmp = *(unsigned char *)ptr;
  75. *(unsigned char *)ptr = with;
  76. break;
  77. case 2:
  78. tmp = *(unsigned short *)ptr;
  79. *(unsigned short *)ptr = with;
  80. break;
  81. case 4:
  82. tmp = *(unsigned long *)ptr;
  83. *(unsigned long *)ptr = with;
  84. break;
  85. }
  86. local_irq_restore (flags);
  87. return tmp;
  88. }
  89. #define arch_align_stack(x) (x)
  90. #endif /* __V850_SYSTEM_H__ */