entry.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __M68K_ENTRY_H
  3. #define __M68K_ENTRY_H
  4. #include <asm/setup.h>
  5. #include <asm/page.h>
  6. #ifdef __ASSEMBLY__
  7. #include <asm/thread_info.h>
  8. #endif
  9. /*
  10. * Stack layout in 'ret_from_exception':
  11. *
  12. * This allows access to the syscall arguments in registers d1-d5
  13. *
  14. * 0(sp) - d1
  15. * 4(sp) - d2
  16. * 8(sp) - d3
  17. * C(sp) - d4
  18. * 10(sp) - d5
  19. * 14(sp) - a0
  20. * 18(sp) - a1
  21. * 1C(sp) - a2
  22. * 20(sp) - d0
  23. * 24(sp) - orig_d0
  24. * 28(sp) - stack adjustment
  25. * 2C(sp) - [ sr ] [ format & vector ]
  26. * 2E(sp) - [ pc-hiword ] [ sr ]
  27. * 30(sp) - [ pc-loword ] [ pc-hiword ]
  28. * 32(sp) - [ format & vector ] [ pc-loword ]
  29. * ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
  30. * M68K COLDFIRE
  31. */
  32. /* the following macro is used when enabling interrupts */
  33. #if defined(MACH_ATARI_ONLY)
  34. /* block out HSYNC = ipl 2 on the atari */
  35. #define ALLOWINT (~0x500)
  36. #else
  37. /* portable version */
  38. #define ALLOWINT (~0x700)
  39. #endif /* machine compilation types */
  40. #ifdef __ASSEMBLY__
  41. /*
  42. * This defines the normal kernel pt-regs layout.
  43. *
  44. * regs a3-a6 and d6-d7 are preserved by C code
  45. * the kernel doesn't mess with usp unless it needs to
  46. */
  47. #define SWITCH_STACK_SIZE (6*4+4) /* includes return address */
  48. #ifdef CONFIG_COLDFIRE
  49. #ifdef CONFIG_COLDFIRE_SW_A7
  50. /*
  51. * This is made a little more tricky on older ColdFires. There is no
  52. * separate supervisor and user stack pointers. Need to artificially
  53. * construct a usp in software... When doing this we need to disable
  54. * interrupts, otherwise bad things will happen.
  55. */
  56. .globl sw_usp
  57. .globl sw_ksp
  58. .macro SAVE_ALL_SYS
  59. move #0x2700,%sr /* disable intrs */
  60. btst #5,%sp@(2) /* from user? */
  61. bnes 6f /* no, skip */
  62. movel %sp,sw_usp /* save user sp */
  63. addql #8,sw_usp /* remove exception */
  64. movel sw_ksp,%sp /* kernel sp */
  65. subql #8,%sp /* room for exception */
  66. clrl %sp@- /* stkadj */
  67. movel %d0,%sp@- /* orig d0 */
  68. movel %d0,%sp@- /* d0 */
  69. lea %sp@(-32),%sp /* space for 8 regs */
  70. moveml %d1-%d5/%a0-%a2,%sp@
  71. movel sw_usp,%a0 /* get usp */
  72. movel %a0@-,%sp@(PT_OFF_PC) /* copy exception program counter */
  73. movel %a0@-,%sp@(PT_OFF_FORMATVEC)/*copy exception format/vector/sr */
  74. bra 7f
  75. 6:
  76. clrl %sp@- /* stkadj */
  77. movel %d0,%sp@- /* orig d0 */
  78. movel %d0,%sp@- /* d0 */
  79. lea %sp@(-32),%sp /* space for 8 regs */
  80. moveml %d1-%d5/%a0-%a2,%sp@
  81. 7:
  82. .endm
  83. .macro SAVE_ALL_INT
  84. SAVE_ALL_SYS
  85. moveq #-1,%d0 /* not system call entry */
  86. movel %d0,%sp@(PT_OFF_ORIG_D0)
  87. .endm
  88. .macro RESTORE_USER
  89. move #0x2700,%sr /* disable intrs */
  90. movel sw_usp,%a0 /* get usp */
  91. movel %sp@(PT_OFF_PC),%a0@- /* copy exception program counter */
  92. movel %sp@(PT_OFF_FORMATVEC),%a0@-/*copy exception format/vector/sr */
  93. moveml %sp@,%d1-%d5/%a0-%a2
  94. lea %sp@(32),%sp /* space for 8 regs */
  95. movel %sp@+,%d0
  96. addql #4,%sp /* orig d0 */
  97. addl %sp@+,%sp /* stkadj */
  98. addql #8,%sp /* remove exception */
  99. movel %sp,sw_ksp /* save ksp */
  100. subql #8,sw_usp /* set exception */
  101. movel sw_usp,%sp /* restore usp */
  102. rte
  103. .endm
  104. .macro RDUSP
  105. movel sw_usp,%a3
  106. .endm
  107. .macro WRUSP
  108. movel %a3,sw_usp
  109. .endm
  110. #else /* !CONFIG_COLDFIRE_SW_A7 */
  111. /*
  112. * Modern ColdFire parts have separate supervisor and user stack
  113. * pointers. Simple load and restore macros for this case.
  114. */
  115. .macro SAVE_ALL_SYS
  116. move #0x2700,%sr /* disable intrs */
  117. clrl %sp@- /* stkadj */
  118. movel %d0,%sp@- /* orig d0 */
  119. movel %d0,%sp@- /* d0 */
  120. lea %sp@(-32),%sp /* space for 8 regs */
  121. moveml %d1-%d5/%a0-%a2,%sp@
  122. .endm
  123. .macro SAVE_ALL_INT
  124. move #0x2700,%sr /* disable intrs */
  125. clrl %sp@- /* stkadj */
  126. pea -1:w /* orig d0 */
  127. movel %d0,%sp@- /* d0 */
  128. lea %sp@(-32),%sp /* space for 8 regs */
  129. moveml %d1-%d5/%a0-%a2,%sp@
  130. .endm
  131. .macro RESTORE_USER
  132. moveml %sp@,%d1-%d5/%a0-%a2
  133. lea %sp@(32),%sp /* space for 8 regs */
  134. movel %sp@+,%d0
  135. addql #4,%sp /* orig d0 */
  136. addl %sp@+,%sp /* stkadj */
  137. rte
  138. .endm
  139. .macro RDUSP
  140. /*move %usp,%a3*/
  141. .word 0x4e6b
  142. .endm
  143. .macro WRUSP
  144. /*move %a3,%usp*/
  145. .word 0x4e63
  146. .endm
  147. #endif /* !CONFIG_COLDFIRE_SW_A7 */
  148. .macro SAVE_SWITCH_STACK
  149. lea %sp@(-24),%sp /* 6 regs */
  150. moveml %a3-%a6/%d6-%d7,%sp@
  151. .endm
  152. .macro RESTORE_SWITCH_STACK
  153. moveml %sp@,%a3-%a6/%d6-%d7
  154. lea %sp@(24),%sp /* 6 regs */
  155. .endm
  156. #else /* !CONFIG_COLDFIRE */
  157. /*
  158. * All other types of m68k parts (68000, 680x0, CPU32) have the same
  159. * entry and exit code.
  160. */
  161. /*
  162. * a -1 in the orig_d0 field signifies
  163. * that the stack frame is NOT for syscall
  164. */
  165. .macro SAVE_ALL_INT
  166. clrl %sp@- /* stk_adj */
  167. pea -1:w /* orig d0 */
  168. movel %d0,%sp@- /* d0 */
  169. moveml %d1-%d5/%a0-%a2,%sp@-
  170. .endm
  171. .macro SAVE_ALL_SYS
  172. clrl %sp@- /* stk_adj */
  173. movel %d0,%sp@- /* orig d0 */
  174. movel %d0,%sp@- /* d0 */
  175. moveml %d1-%d5/%a0-%a2,%sp@-
  176. .endm
  177. .macro RESTORE_ALL
  178. moveml %sp@+,%a0-%a2/%d1-%d5
  179. movel %sp@+,%d0
  180. addql #4,%sp /* orig d0 */
  181. addl %sp@+,%sp /* stk adj */
  182. rte
  183. .endm
  184. .macro SAVE_SWITCH_STACK
  185. moveml %a3-%a6/%d6-%d7,%sp@-
  186. .endm
  187. .macro RESTORE_SWITCH_STACK
  188. moveml %sp@+,%a3-%a6/%d6-%d7
  189. .endm
  190. #endif /* !CONFIG_COLDFIRE */
  191. /*
  192. * Register %a2 is reserved and set to current task on MMU enabled systems.
  193. * Non-MMU systems do not reserve %a2 in this way, and this definition is
  194. * not used for them.
  195. */
  196. #ifdef CONFIG_MMU
  197. #define curptr a2
  198. #define GET_CURRENT(tmp) get_current tmp
  199. .macro get_current reg=%d0
  200. movel %sp,\reg
  201. andl #-THREAD_SIZE,\reg
  202. movel \reg,%curptr
  203. movel %curptr@,%curptr
  204. .endm
  205. #else
  206. #define GET_CURRENT(tmp)
  207. #endif /* CONFIG_MMU */
  208. #else /* C source */
  209. #define STR(X) STR1(X)
  210. #define STR1(X) #X
  211. #define SAVE_ALL_INT \
  212. "clrl %%sp@-;" /* stk_adj */ \
  213. "pea -1:w;" /* orig d0 = -1 */ \
  214. "movel %%d0,%%sp@-;" /* d0 */ \
  215. "moveml %%d1-%%d5/%%a0-%%a2,%%sp@-"
  216. #define GET_CURRENT(tmp) \
  217. "movel %%sp,"#tmp"\n\t" \
  218. "andw #-"STR(THREAD_SIZE)","#tmp"\n\t" \
  219. "movel "#tmp",%%a2\n\t" \
  220. "movel %%a2@,%%a2"
  221. #endif
  222. #endif /* __M68K_ENTRY_H */