assembler.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #ifndef _ASM_M32R_ASSEMBLER_H
  2. #define _ASM_M32R_ASSEMBLER_H
  3. /*
  4. * linux/asm-m32r/assembler.h
  5. *
  6. * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org>
  7. *
  8. * This file contains M32R architecture specific macro definitions.
  9. */
  10. #include <linux/stringify.h>
  11. #undef __STR
  12. #ifdef __ASSEMBLY__
  13. #define __STR(x) x
  14. #else
  15. #define __STR(x) __stringify(x)
  16. #endif
  17. #ifdef CONFIG_SMP
  18. #define M32R_LOCK __STR(lock)
  19. #define M32R_UNLOCK __STR(unlock)
  20. #else
  21. #define M32R_LOCK __STR(ld)
  22. #define M32R_UNLOCK __STR(st)
  23. #endif
  24. #ifdef __ASSEMBLY__
  25. #undef ENTRY
  26. #define ENTRY(name) ENTRY_M name
  27. .macro ENTRY_M name
  28. .global \name
  29. ALIGN
  30. \name:
  31. .endm
  32. #endif
  33. /**
  34. * LDIMM - load immediate value
  35. * STI - enable interruption
  36. * CLI - disable interruption
  37. */
  38. #ifdef __ASSEMBLY__
  39. #define LDIMM(reg,x) LDIMM reg x
  40. .macro LDIMM reg x
  41. seth \reg, #high(\x)
  42. or3 \reg, \reg, #low(\x)
  43. .endm
  44. #if !(defined(CONFIG_CHIP_M32102) || defined(CONFIG_CHIP_M32104))
  45. #define ENABLE_INTERRUPTS(reg) ENABLE_INTERRUPTS reg
  46. .macro ENABLE_INTERRUPTS reg
  47. setpsw #0x40 -> nop
  48. ; WORKAROUND: "-> nop" is a workaround for the M32700(TS1).
  49. .endm
  50. #define DISABLE_INTERRUPTS(reg) DISABLE_INTERRUPTS reg
  51. .macro DISABLE_INTERRUPTS reg
  52. clrpsw #0x40 -> nop
  53. ; WORKAROUND: "-> nop" is a workaround for the M32700(TS1).
  54. .endm
  55. #else /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
  56. #define ENABLE_INTERRUPTS(reg) ENABLE_INTERRUPTS reg
  57. .macro ENABLE_INTERRUPTS reg
  58. mvfc \reg, psw
  59. or3 \reg, \reg, #0x0040
  60. mvtc \reg, psw
  61. .endm
  62. #define DISABLE_INTERRUPTS(reg) DISABLE_INTERRUPTS reg
  63. .macro DISABLE_INTERRUPTS reg
  64. mvfc \reg, psw
  65. and3 \reg, \reg, #0xffbf
  66. mvtc \reg, psw
  67. .endm
  68. #endif /* CONFIG_CHIP_M32102 */
  69. .macro SAVE_ALL
  70. push r0 ; orig_r0
  71. push sp ; spi (r15)
  72. push lr ; r14
  73. push r13
  74. mvfc r13, cr3 ; spu
  75. push r13
  76. mvfc r13, bbpc
  77. push r13
  78. mvfc r13, bbpsw
  79. push r13
  80. mvfc r13, bpc
  81. push r13
  82. mvfc r13, psw
  83. push r13
  84. #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
  85. mvfaclo r13, a1
  86. push r13
  87. mvfachi r13, a1
  88. push r13
  89. mvfaclo r13, a0
  90. push r13
  91. mvfachi r13, a0
  92. push r13
  93. #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
  94. mvfaclo r13
  95. push r13
  96. mvfachi r13
  97. push r13
  98. ldi r13, #0
  99. push r13 ; dummy push acc1h
  100. push r13 ; dummy push acc1l
  101. #else
  102. #error unknown isa configuration
  103. #endif
  104. ldi r13, #-1
  105. push r13 ; syscall_nr (default: -1)
  106. push r12
  107. push r11
  108. push r10
  109. push r9
  110. push r8
  111. push r7
  112. push r3
  113. push r2
  114. push r1
  115. push r0
  116. addi sp, #-4 ; room for implicit pt_regs parameter
  117. push r6
  118. push r5
  119. push r4
  120. .endm
  121. .macro RESTORE_ALL
  122. pop r4
  123. pop r5
  124. pop r6
  125. addi sp, #4
  126. pop r0
  127. pop r1
  128. pop r2
  129. pop r3
  130. pop r7
  131. pop r8
  132. pop r9
  133. pop r10
  134. pop r11
  135. pop r12
  136. addi r15, #4 ; Skip syscall number
  137. #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
  138. pop r13
  139. mvtachi r13, a0
  140. pop r13
  141. mvtaclo r13, a0
  142. pop r13
  143. mvtachi r13, a1
  144. pop r13
  145. mvtaclo r13, a1
  146. #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
  147. pop r13 ; dummy pop acc1h
  148. pop r13 ; dummy pop acc1l
  149. pop r13
  150. mvtachi r13
  151. pop r13
  152. mvtaclo r13
  153. #else
  154. #error unknown isa configuration
  155. #endif
  156. pop r14
  157. mvtc r14, psw
  158. pop r14
  159. mvtc r14, bpc
  160. addi sp, #8 ; Skip bbpsw, bbpc
  161. pop r14
  162. mvtc r14, cr3 ; spu
  163. pop r13
  164. pop lr ; r14
  165. pop sp ; spi (r15)
  166. addi sp, #4 ; Skip orig_r0
  167. .fillinsn
  168. 1: rte
  169. .section .fixup,"ax"
  170. 2: bl do_exit
  171. .previous
  172. .section __ex_table,"a"
  173. ALIGN
  174. .long 1b, 2b
  175. .previous
  176. .endm
  177. #define GET_CURRENT(reg) get_current reg
  178. .macro get_current reg
  179. ldi \reg, #-8192
  180. and \reg, sp
  181. .endm
  182. #if !(defined(CONFIG_CHIP_M32102) || defined(CONFIG_CHIP_M32104))
  183. .macro SWITCH_TO_KERNEL_STACK
  184. ; switch to kernel stack (spi)
  185. clrpsw #0x80 -> nop
  186. .endm
  187. #else /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
  188. .macro SWITCH_TO_KERNEL_STACK
  189. push r0 ; save r0 for working
  190. mvfc r0, psw
  191. and3 r0, r0, #0x00ff7f
  192. mvtc r0, psw
  193. slli r0, #16
  194. bltz r0, 1f ; check BSM-bit
  195. ;
  196. ;; called from kernel context: previous stack = spi
  197. pop r0 ; retrieve r0
  198. bra 2f
  199. .fillinsn
  200. 1:
  201. ;; called from user context: previous stack = spu
  202. mvfc r0, cr3 ; spu
  203. addi r0, #4
  204. mvtc r0, cr3 ; spu
  205. ld r0, @(-4,r0) ; retrieve r0
  206. .fillinsn
  207. 2:
  208. .endm
  209. #endif /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
  210. #endif /* __ASSEMBLY__ */
  211. #endif /* _ASM_M32R_ASSEMBLER_H */