system.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef _H8300_SYSTEM_H
  2. #define _H8300_SYSTEM_H
  3. #include <linux/linkage.h>
  4. /*
  5. * switch_to(n) should switch tasks to task ptr, first checking that
  6. * ptr isn't the current task, in which case it does nothing. This
  7. * also clears the TS-flag if the task we switched to has used the
  8. * math co-processor latest.
  9. */
  10. /*
  11. * switch_to() saves the extra registers, that are not saved
  12. * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
  13. * a0-a1. Some of these are used by schedule() and its predecessors
  14. * and so we might get see unexpected behaviors when a task returns
  15. * with unexpected register values.
  16. *
  17. * syscall stores these registers itself and none of them are used
  18. * by syscall after the function in the syscall has been called.
  19. *
  20. * Beware that resume now expects *next to be in d1 and the offset of
  21. * tss to be in a1. This saves a few instructions as we no longer have
  22. * to push them onto the stack and read them back right after.
  23. *
  24. * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
  25. *
  26. * Changed 96/09/19 by Andreas Schwab
  27. * pass prev in a0, next in a1, offset of tss in d1, and whether
  28. * the mm structures are shared in d2 (to avoid atc flushing).
  29. *
  30. * H8/300 Porting 2002/09/04 Yoshinori Sato
  31. */
  32. asmlinkage void resume(void);
  33. #define switch_to(prev,next,last) { \
  34. void *_last; \
  35. __asm__ __volatile__( \
  36. "mov.l %1, er0\n\t" \
  37. "mov.l %2, er1\n\t" \
  38. "mov.l %3, er2\n\t" \
  39. "jsr @_resume\n\t" \
  40. "mov.l er2,%0\n\t" \
  41. : "=r" (_last) \
  42. : "r" (&(prev->thread)), \
  43. "r" (&(next->thread)), \
  44. "g" (prev) \
  45. : "cc", "er0", "er1", "er2", "er3"); \
  46. (last) = _last; \
  47. }
  48. #define __sti() asm volatile ("andc #0x7f,ccr")
  49. #define __cli() asm volatile ("orc #0x80,ccr")
  50. #define __save_flags(x) \
  51. asm volatile ("stc ccr,%w0":"=r" (x))
  52. #define __restore_flags(x) \
  53. asm volatile ("ldc %w0,ccr": :"r" (x))
  54. #define irqs_disabled() \
  55. ({ \
  56. unsigned char flags; \
  57. __save_flags(flags); \
  58. ((flags & 0x80) == 0x80); \
  59. })
  60. #define iret() __asm__ __volatile__ ("rte": : :"memory", "sp", "cc")
  61. /* For spinlocks etc */
  62. #define local_irq_disable() __cli()
  63. #define local_irq_enable() __sti()
  64. #define local_irq_save(x) ({ __save_flags(x); local_irq_disable(); })
  65. #define local_irq_restore(x) __restore_flags(x)
  66. #define local_save_flags(x) __save_flags(x)
  67. /*
  68. * Force strict CPU ordering.
  69. * Not really required on H8...
  70. */
  71. #define nop() asm volatile ("nop"::)
  72. #define mb() asm volatile ("" : : :"memory")
  73. #define rmb() asm volatile ("" : : :"memory")
  74. #define wmb() asm volatile ("" : : :"memory")
  75. #define set_rmb(var, value) do { xchg(&var, value); } while (0)
  76. #define set_mb(var, value) set_rmb(var, value)
  77. #ifdef CONFIG_SMP
  78. #define smp_mb() mb()
  79. #define smp_rmb() rmb()
  80. #define smp_wmb() wmb()
  81. #define smp_read_barrier_depends() read_barrier_depends()
  82. #else
  83. #define smp_mb() barrier()
  84. #define smp_rmb() barrier()
  85. #define smp_wmb() barrier()
  86. #define smp_read_barrier_depends() do { } while(0)
  87. #endif
  88. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  89. #define tas(ptr) (xchg((ptr),1))
  90. struct __xchg_dummy { unsigned long a[100]; };
  91. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  92. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  93. {
  94. unsigned long tmp, flags;
  95. local_irq_save(flags);
  96. switch (size) {
  97. case 1:
  98. __asm__ __volatile__
  99. ("mov.b %2,%0\n\t"
  100. "mov.b %1,%2"
  101. : "=&r" (tmp) : "r" (x), "m" (*__xg(ptr)) : "memory");
  102. break;
  103. case 2:
  104. __asm__ __volatile__
  105. ("mov.w %2,%0\n\t"
  106. "mov.w %1,%2"
  107. : "=&r" (tmp) : "r" (x), "m" (*__xg(ptr)) : "memory");
  108. break;
  109. case 4:
  110. __asm__ __volatile__
  111. ("mov.l %2,%0\n\t"
  112. "mov.l %1,%2"
  113. : "=&r" (tmp) : "r" (x), "m" (*__xg(ptr)) : "memory");
  114. break;
  115. default:
  116. tmp = 0;
  117. }
  118. local_irq_restore(flags);
  119. return tmp;
  120. }
  121. #define HARD_RESET_NOW() ({ \
  122. local_irq_disable(); \
  123. asm("jmp @@0"); \
  124. })
  125. #define arch_align_stack(x) (x)
  126. #endif /* _H8300_SYSTEM_H */