entry.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef __ASM_ARC_ENTRY_H
  10. #define __ASM_ARC_ENTRY_H
  11. #include <asm/unistd.h> /* For NR_syscalls defination */
  12. #include <asm/arcregs.h>
  13. #include <asm/ptrace.h>
  14. #include <asm/processor.h> /* For VMALLOC_START */
  15. #include <asm/mmu.h>
  16. #ifdef CONFIG_ISA_ARCOMPACT
  17. #include <asm/entry-compact.h> /* ISA specific bits */
  18. #else
  19. #include <asm/entry-arcv2.h>
  20. #endif
  21. /* Note on the LD/ST addr modes with addr reg wback
  22. *
  23. * LD.a same as LD.aw
  24. *
  25. * LD.a reg1, [reg2, x] => Pre Incr
  26. * Eff Addr for load = [reg2 + x]
  27. *
  28. * LD.ab reg1, [reg2, x] => Post Incr
  29. * Eff Addr for load = [reg2]
  30. */
  31. .macro PUSH reg
  32. st.a \reg, [sp, -4]
  33. .endm
  34. .macro PUSHAX aux
  35. lr r9, [\aux]
  36. PUSH r9
  37. .endm
  38. .macro POP reg
  39. ld.ab \reg, [sp, 4]
  40. .endm
  41. .macro POPAX aux
  42. POP r9
  43. sr r9, [\aux]
  44. .endm
  45. /*--------------------------------------------------------------
  46. * Helpers to save/restore Scratch Regs:
  47. * used by Interrupt/Exception Prologue/Epilogue
  48. *-------------------------------------------------------------*/
  49. .macro SAVE_R0_TO_R12
  50. PUSH r0
  51. PUSH r1
  52. PUSH r2
  53. PUSH r3
  54. PUSH r4
  55. PUSH r5
  56. PUSH r6
  57. PUSH r7
  58. PUSH r8
  59. PUSH r9
  60. PUSH r10
  61. PUSH r11
  62. PUSH r12
  63. .endm
  64. .macro RESTORE_R12_TO_R0
  65. POP r12
  66. POP r11
  67. POP r10
  68. POP r9
  69. POP r8
  70. POP r7
  71. POP r6
  72. POP r5
  73. POP r4
  74. POP r3
  75. POP r2
  76. POP r1
  77. POP r0
  78. .endm
  79. /*--------------------------------------------------------------
  80. * Helpers to save/restore callee-saved regs:
  81. * used by several macros below
  82. *-------------------------------------------------------------*/
  83. .macro SAVE_R13_TO_R24
  84. PUSH r13
  85. PUSH r14
  86. PUSH r15
  87. PUSH r16
  88. PUSH r17
  89. PUSH r18
  90. PUSH r19
  91. PUSH r20
  92. PUSH r21
  93. PUSH r22
  94. PUSH r23
  95. PUSH r24
  96. .endm
  97. .macro RESTORE_R24_TO_R13
  98. POP r24
  99. POP r23
  100. POP r22
  101. POP r21
  102. POP r20
  103. POP r19
  104. POP r18
  105. POP r17
  106. POP r16
  107. POP r15
  108. POP r14
  109. POP r13
  110. .endm
  111. /*--------------------------------------------------------------
  112. * Collect User Mode callee regs as struct callee_regs - needed by
  113. * fork/do_signal/unaligned-access-emulation.
  114. * (By default only scratch regs are saved on entry to kernel)
  115. *
  116. * Special handling for r25 if used for caching Task Pointer.
  117. * It would have been saved in task->thread.user_r25 already, but to keep
  118. * the interface same it is copied into regular r25 placeholder in
  119. * struct callee_regs.
  120. *-------------------------------------------------------------*/
  121. .macro SAVE_CALLEE_SAVED_USER
  122. mov r12, sp ; save SP as ref to pt_regs
  123. SAVE_R13_TO_R24
  124. #ifdef CONFIG_ARC_CURR_IN_REG
  125. ; Retrieve orig r25 and save it with rest of callee_regs
  126. ld r12, [r12, PT_user_r25]
  127. PUSH r12
  128. #else
  129. PUSH r25
  130. #endif
  131. .endm
  132. /*--------------------------------------------------------------
  133. * Save kernel Mode callee regs at the time of Contect Switch.
  134. *
  135. * Special handling for r25 if used for caching Task Pointer.
  136. * Kernel simply skips saving it since it will be loaded with
  137. * incoming task pointer anyways
  138. *-------------------------------------------------------------*/
  139. .macro SAVE_CALLEE_SAVED_KERNEL
  140. SAVE_R13_TO_R24
  141. #ifdef CONFIG_ARC_CURR_IN_REG
  142. sub sp, sp, 4
  143. #else
  144. PUSH r25
  145. #endif
  146. .endm
  147. /*--------------------------------------------------------------
  148. * Opposite of SAVE_CALLEE_SAVED_KERNEL
  149. *-------------------------------------------------------------*/
  150. .macro RESTORE_CALLEE_SAVED_KERNEL
  151. #ifdef CONFIG_ARC_CURR_IN_REG
  152. add sp, sp, 4 /* skip usual r25 placeholder */
  153. #else
  154. POP r25
  155. #endif
  156. RESTORE_R24_TO_R13
  157. .endm
  158. /*--------------------------------------------------------------
  159. * Opposite of SAVE_CALLEE_SAVED_USER
  160. *
  161. * ptrace tracer or unaligned-access fixup might have changed a user mode
  162. * callee reg which is saved back to usual r25 storage location
  163. *-------------------------------------------------------------*/
  164. .macro RESTORE_CALLEE_SAVED_USER
  165. #ifdef CONFIG_ARC_CURR_IN_REG
  166. POP r12
  167. #else
  168. POP r25
  169. #endif
  170. RESTORE_R24_TO_R13
  171. ; SP is back to start of pt_regs
  172. #ifdef CONFIG_ARC_CURR_IN_REG
  173. st r12, [sp, PT_user_r25]
  174. #endif
  175. .endm
  176. /*--------------------------------------------------------------
  177. * Super FAST Restore callee saved regs by simply re-adjusting SP
  178. *-------------------------------------------------------------*/
  179. .macro DISCARD_CALLEE_SAVED_USER
  180. add sp, sp, SZ_CALLEE_REGS
  181. .endm
  182. /*-------------------------------------------------------------
  183. * given a tsk struct, get to the base of it's kernel mode stack
  184. * tsk->thread_info is really a PAGE, whose bottom hoists stack
  185. * which grows upwards towards thread_info
  186. *------------------------------------------------------------*/
  187. .macro GET_TSK_STACK_BASE tsk, out
  188. /* Get task->thread_info (this is essentially start of a PAGE) */
  189. ld \out, [\tsk, TASK_THREAD_INFO]
  190. /* Go to end of page where stack begins (grows upwards) */
  191. add2 \out, \out, (THREAD_SIZE)/4
  192. .endm
  193. /*
  194. * @reg [OUT] thread_info->flags of "current"
  195. */
  196. .macro GET_CURR_THR_INFO_FLAGS reg
  197. GET_CURR_THR_INFO_FROM_SP \reg
  198. ld \reg, [\reg, THREAD_INFO_FLAGS]
  199. .endm
  200. #ifdef CONFIG_SMP
  201. /*-------------------------------------------------
  202. * Retrieve the current running task on this CPU
  203. * 1. Determine curr CPU id.
  204. * 2. Use it to index into _current_task[ ]
  205. */
  206. .macro GET_CURR_TASK_ON_CPU reg
  207. GET_CPU_ID \reg
  208. ld.as \reg, [@_current_task, \reg]
  209. .endm
  210. /*-------------------------------------------------
  211. * Save a new task as the "current" task on this CPU
  212. * 1. Determine curr CPU id.
  213. * 2. Use it to index into _current_task[ ]
  214. *
  215. * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
  216. * because ST r0, [r1, offset] can ONLY have s9 @offset
  217. * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
  218. */
  219. .macro SET_CURR_TASK_ON_CPU tsk, tmp
  220. GET_CPU_ID \tmp
  221. add2 \tmp, @_current_task, \tmp
  222. st \tsk, [\tmp]
  223. #ifdef CONFIG_ARC_CURR_IN_REG
  224. mov r25, \tsk
  225. #endif
  226. .endm
  227. #else /* Uniprocessor implementation of macros */
  228. .macro GET_CURR_TASK_ON_CPU reg
  229. ld \reg, [@_current_task]
  230. .endm
  231. .macro SET_CURR_TASK_ON_CPU tsk, tmp
  232. st \tsk, [@_current_task]
  233. #ifdef CONFIG_ARC_CURR_IN_REG
  234. mov r25, \tsk
  235. #endif
  236. .endm
  237. #endif /* SMP / UNI */
  238. /* ------------------------------------------------------------------
  239. * Get the ptr to some field of Current Task at @off in task struct
  240. * -Uses r25 for Current task ptr if that is enabled
  241. */
  242. #ifdef CONFIG_ARC_CURR_IN_REG
  243. .macro GET_CURR_TASK_FIELD_PTR off, reg
  244. add \reg, r25, \off
  245. .endm
  246. #else
  247. .macro GET_CURR_TASK_FIELD_PTR off, reg
  248. GET_CURR_TASK_ON_CPU \reg
  249. add \reg, \reg, \off
  250. .endm
  251. #endif /* CONFIG_ARC_CURR_IN_REG */
  252. #endif /* __ASM_ARC_ENTRY_H */