entry.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. #ifdef CONFIG_ARC_CURR_IN_REG
  79. ld r25, [sp, 12]
  80. #endif
  81. .endm
  82. /*--------------------------------------------------------------
  83. * Helpers to save/restore callee-saved regs:
  84. * used by several macros below
  85. *-------------------------------------------------------------*/
  86. .macro SAVE_R13_TO_R24
  87. PUSH r13
  88. PUSH r14
  89. PUSH r15
  90. PUSH r16
  91. PUSH r17
  92. PUSH r18
  93. PUSH r19
  94. PUSH r20
  95. PUSH r21
  96. PUSH r22
  97. PUSH r23
  98. PUSH r24
  99. .endm
  100. .macro RESTORE_R24_TO_R13
  101. POP r24
  102. POP r23
  103. POP r22
  104. POP r21
  105. POP r20
  106. POP r19
  107. POP r18
  108. POP r17
  109. POP r16
  110. POP r15
  111. POP r14
  112. POP r13
  113. .endm
  114. /*--------------------------------------------------------------
  115. * Collect User Mode callee regs as struct callee_regs - needed by
  116. * fork/do_signal/unaligned-access-emulation.
  117. * (By default only scratch regs are saved on entry to kernel)
  118. *
  119. * Special handling for r25 if used for caching Task Pointer.
  120. * It would have been saved in task->thread.user_r25 already, but to keep
  121. * the interface same it is copied into regular r25 placeholder in
  122. * struct callee_regs.
  123. *-------------------------------------------------------------*/
  124. .macro SAVE_CALLEE_SAVED_USER
  125. mov r12, sp ; save SP as ref to pt_regs
  126. SAVE_R13_TO_R24
  127. #ifdef CONFIG_ARC_CURR_IN_REG
  128. ; Retrieve orig r25 and save it with rest of callee_regs
  129. ld r12, [r12, PT_user_r25]
  130. PUSH r12
  131. #else
  132. PUSH r25
  133. #endif
  134. .endm
  135. /*--------------------------------------------------------------
  136. * Save kernel Mode callee regs at the time of Contect Switch.
  137. *
  138. * Special handling for r25 if used for caching Task Pointer.
  139. * Kernel simply skips saving it since it will be loaded with
  140. * incoming task pointer anyways
  141. *-------------------------------------------------------------*/
  142. .macro SAVE_CALLEE_SAVED_KERNEL
  143. SAVE_R13_TO_R24
  144. #ifdef CONFIG_ARC_CURR_IN_REG
  145. sub sp, sp, 4
  146. #else
  147. PUSH r25
  148. #endif
  149. .endm
  150. /*--------------------------------------------------------------
  151. * Opposite of SAVE_CALLEE_SAVED_KERNEL
  152. *-------------------------------------------------------------*/
  153. .macro RESTORE_CALLEE_SAVED_KERNEL
  154. #ifdef CONFIG_ARC_CURR_IN_REG
  155. add sp, sp, 4 /* skip usual r25 placeholder */
  156. #else
  157. POP r25
  158. #endif
  159. RESTORE_R24_TO_R13
  160. .endm
  161. /*--------------------------------------------------------------
  162. * Opposite of SAVE_CALLEE_SAVED_USER
  163. *
  164. * ptrace tracer or unaligned-access fixup might have changed a user mode
  165. * callee reg which is saved back to usual r25 storage location
  166. *-------------------------------------------------------------*/
  167. .macro RESTORE_CALLEE_SAVED_USER
  168. #ifdef CONFIG_ARC_CURR_IN_REG
  169. POP r12
  170. #else
  171. POP r25
  172. #endif
  173. RESTORE_R24_TO_R13
  174. ; SP is back to start of pt_regs
  175. #ifdef CONFIG_ARC_CURR_IN_REG
  176. st r12, [sp, PT_user_r25]
  177. #endif
  178. .endm
  179. /*--------------------------------------------------------------
  180. * Super FAST Restore callee saved regs by simply re-adjusting SP
  181. *-------------------------------------------------------------*/
  182. .macro DISCARD_CALLEE_SAVED_USER
  183. add sp, sp, SZ_CALLEE_REGS
  184. .endm
  185. /*-------------------------------------------------------------
  186. * given a tsk struct, get to the base of it's kernel mode stack
  187. * tsk->thread_info is really a PAGE, whose bottom hoists stack
  188. * which grows upwards towards thread_info
  189. *------------------------------------------------------------*/
  190. .macro GET_TSK_STACK_BASE tsk, out
  191. /* Get task->thread_info (this is essentially start of a PAGE) */
  192. ld \out, [\tsk, TASK_THREAD_INFO]
  193. /* Go to end of page where stack begins (grows upwards) */
  194. add2 \out, \out, (THREAD_SIZE)/4
  195. .endm
  196. /*
  197. * @reg [OUT] thread_info->flags of "current"
  198. */
  199. .macro GET_CURR_THR_INFO_FLAGS reg
  200. GET_CURR_THR_INFO_FROM_SP \reg
  201. ld \reg, [\reg, THREAD_INFO_FLAGS]
  202. .endm
  203. #ifdef CONFIG_SMP
  204. /*-------------------------------------------------
  205. * Retrieve the current running task on this CPU
  206. * 1. Determine curr CPU id.
  207. * 2. Use it to index into _current_task[ ]
  208. */
  209. .macro GET_CURR_TASK_ON_CPU reg
  210. GET_CPU_ID \reg
  211. ld.as \reg, [@_current_task, \reg]
  212. .endm
  213. /*-------------------------------------------------
  214. * Save a new task as the "current" task on this CPU
  215. * 1. Determine curr CPU id.
  216. * 2. Use it to index into _current_task[ ]
  217. *
  218. * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
  219. * because ST r0, [r1, offset] can ONLY have s9 @offset
  220. * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
  221. */
  222. .macro SET_CURR_TASK_ON_CPU tsk, tmp
  223. GET_CPU_ID \tmp
  224. add2 \tmp, @_current_task, \tmp
  225. st \tsk, [\tmp]
  226. #ifdef CONFIG_ARC_CURR_IN_REG
  227. mov r25, \tsk
  228. #endif
  229. .endm
  230. #else /* Uniprocessor implementation of macros */
  231. .macro GET_CURR_TASK_ON_CPU reg
  232. ld \reg, [@_current_task]
  233. .endm
  234. .macro SET_CURR_TASK_ON_CPU tsk, tmp
  235. st \tsk, [@_current_task]
  236. #ifdef CONFIG_ARC_CURR_IN_REG
  237. mov r25, \tsk
  238. #endif
  239. .endm
  240. #endif /* SMP / UNI */
  241. /* ------------------------------------------------------------------
  242. * Get the ptr to some field of Current Task at @off in task struct
  243. * -Uses r25 for Current task ptr if that is enabled
  244. */
  245. #ifdef CONFIG_ARC_CURR_IN_REG
  246. .macro GET_CURR_TASK_FIELD_PTR off, reg
  247. add \reg, r25, \off
  248. .endm
  249. #else
  250. .macro GET_CURR_TASK_FIELD_PTR off, reg
  251. GET_CURR_TASK_ON_CPU \reg
  252. add \reg, \reg, \off
  253. .endm
  254. #endif /* CONFIG_ARC_CURR_IN_REG */
  255. #endif /* __ASM_ARC_ENTRY_H */