entry.h 5.7 KB

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