switch_to_32.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef __ASM_SH_SWITCH_TO_32_H
  2. #define __ASM_SH_SWITCH_TO_32_H
  3. #ifdef CONFIG_SH_DSP
  4. #define is_dsp_enabled(tsk) \
  5. (!!(tsk->thread.dsp_status.status & SR_DSP))
  6. #define __restore_dsp(tsk) \
  7. do { \
  8. register u32 *__ts2 __asm__ ("r2") = \
  9. (u32 *)&tsk->thread.dsp_status; \
  10. __asm__ __volatile__ ( \
  11. ".balign 4\n\t" \
  12. "movs.l @r2+, a0\n\t" \
  13. "movs.l @r2+, a1\n\t" \
  14. "movs.l @r2+, a0g\n\t" \
  15. "movs.l @r2+, a1g\n\t" \
  16. "movs.l @r2+, m0\n\t" \
  17. "movs.l @r2+, m1\n\t" \
  18. "movs.l @r2+, x0\n\t" \
  19. "movs.l @r2+, x1\n\t" \
  20. "movs.l @r2+, y0\n\t" \
  21. "movs.l @r2+, y1\n\t" \
  22. "lds.l @r2+, dsr\n\t" \
  23. "ldc.l @r2+, rs\n\t" \
  24. "ldc.l @r2+, re\n\t" \
  25. "ldc.l @r2+, mod\n\t" \
  26. : : "r" (__ts2)); \
  27. } while (0)
  28. #define __save_dsp(tsk) \
  29. do { \
  30. register u32 *__ts2 __asm__ ("r2") = \
  31. (u32 *)&tsk->thread.dsp_status + 14; \
  32. \
  33. __asm__ __volatile__ ( \
  34. ".balign 4\n\t" \
  35. "stc.l mod, @-r2\n\t" \
  36. "stc.l re, @-r2\n\t" \
  37. "stc.l rs, @-r2\n\t" \
  38. "sts.l dsr, @-r2\n\t" \
  39. "movs.l y1, @-r2\n\t" \
  40. "movs.l y0, @-r2\n\t" \
  41. "movs.l x1, @-r2\n\t" \
  42. "movs.l x0, @-r2\n\t" \
  43. "movs.l m1, @-r2\n\t" \
  44. "movs.l m0, @-r2\n\t" \
  45. "movs.l a1g, @-r2\n\t" \
  46. "movs.l a0g, @-r2\n\t" \
  47. "movs.l a1, @-r2\n\t" \
  48. "movs.l a0, @-r2\n\t" \
  49. : : "r" (__ts2)); \
  50. } while (0)
  51. #else
  52. #define is_dsp_enabled(tsk) (0)
  53. #define __save_dsp(tsk) do { } while (0)
  54. #define __restore_dsp(tsk) do { } while (0)
  55. #endif
  56. struct task_struct *__switch_to(struct task_struct *prev,
  57. struct task_struct *next);
  58. /*
  59. * switch_to() should switch tasks to task nr n, first
  60. */
  61. #define switch_to(prev, next, last) \
  62. do { \
  63. register u32 *__ts1 __asm__ ("r1"); \
  64. register u32 *__ts2 __asm__ ("r2"); \
  65. register u32 *__ts4 __asm__ ("r4"); \
  66. register u32 *__ts5 __asm__ ("r5"); \
  67. register u32 *__ts6 __asm__ ("r6"); \
  68. register u32 __ts7 __asm__ ("r7"); \
  69. struct task_struct *__last; \
  70. \
  71. if (is_dsp_enabled(prev)) \
  72. __save_dsp(prev); \
  73. if (is_dsp_enabled(next)) \
  74. __restore_dsp(next); \
  75. \
  76. __ts1 = (u32 *)&prev->thread.sp; \
  77. __ts2 = (u32 *)&prev->thread.pc; \
  78. __ts4 = (u32 *)prev; \
  79. __ts5 = (u32 *)next; \
  80. __ts6 = (u32 *)&next->thread.sp; \
  81. __ts7 = next->thread.pc; \
  82. \
  83. __asm__ __volatile__ ( \
  84. ".balign 4\n\t" \
  85. "stc.l gbr, @-r15\n\t" \
  86. "sts.l pr, @-r15\n\t" \
  87. "mov.l r8, @-r15\n\t" \
  88. "mov.l r9, @-r15\n\t" \
  89. "mov.l r10, @-r15\n\t" \
  90. "mov.l r11, @-r15\n\t" \
  91. "mov.l r12, @-r15\n\t" \
  92. "mov.l r13, @-r15\n\t" \
  93. "mov.l r14, @-r15\n\t" \
  94. "mov.l r15, @r1\t! save SP\n\t" \
  95. "mov.l @r6, r15\t! change to new stack\n\t" \
  96. "mova 1f, %0\n\t" \
  97. "mov.l %0, @r2\t! save PC\n\t" \
  98. "mov.l 2f, %0\n\t" \
  99. "jmp @%0\t! call __switch_to\n\t" \
  100. " lds r7, pr\t! with return to new PC\n\t" \
  101. ".balign 4\n" \
  102. "2:\n\t" \
  103. ".long __switch_to\n" \
  104. "1:\n\t" \
  105. "mov.l @r15+, r14\n\t" \
  106. "mov.l @r15+, r13\n\t" \
  107. "mov.l @r15+, r12\n\t" \
  108. "mov.l @r15+, r11\n\t" \
  109. "mov.l @r15+, r10\n\t" \
  110. "mov.l @r15+, r9\n\t" \
  111. "mov.l @r15+, r8\n\t" \
  112. "lds.l @r15+, pr\n\t" \
  113. "ldc.l @r15+, gbr\n\t" \
  114. : "=z" (__last) \
  115. : "r" (__ts1), "r" (__ts2), "r" (__ts4), \
  116. "r" (__ts5), "r" (__ts6), "r" (__ts7) \
  117. : "r3", "t"); \
  118. \
  119. last = __last; \
  120. } while (0)
  121. #endif /* __ASM_SH_SWITCH_TO_32_H */