entry-header.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #include <linux/init.h>
  2. #include <linux/linkage.h>
  3. #include <asm/assembler.h>
  4. #include <asm/asm-offsets.h>
  5. #include <asm/errno.h>
  6. #include <asm/thread_info.h>
  7. @ Bad Abort numbers
  8. @ -----------------
  9. @
  10. #define BAD_PREFETCH 0
  11. #define BAD_DATA 1
  12. #define BAD_ADDREXCPTN 2
  13. #define BAD_IRQ 3
  14. #define BAD_UNDEFINSTR 4
  15. @
  16. @ Most of the stack format comes from struct pt_regs, but with
  17. @ the addition of 8 bytes for storing syscall args 5 and 6.
  18. @ This _must_ remain a multiple of 8 for EABI.
  19. @
  20. #define S_OFF 8
  21. /*
  22. * The SWI code relies on the fact that R0 is at the bottom of the stack
  23. * (due to slow/fast restore user regs).
  24. */
  25. #if S_R0 != 0
  26. #error "Please fix"
  27. #endif
  28. .macro zero_fp
  29. #ifdef CONFIG_FRAME_POINTER
  30. mov fp, #0
  31. #endif
  32. .endm
  33. .macro alignment_trap, rtemp
  34. #ifdef CONFIG_ALIGNMENT_TRAP
  35. ldr \rtemp, .LCcralign
  36. ldr \rtemp, [\rtemp]
  37. mcr p15, 0, \rtemp, c1, c0
  38. #endif
  39. .endm
  40. @
  41. @ Store/load the USER SP and LR registers by switching to the SYS
  42. @ mode. Useful in Thumb-2 mode where "stm/ldm rd, {sp, lr}^" is not
  43. @ available. Should only be called from SVC mode
  44. @
  45. .macro store_user_sp_lr, rd, rtemp, offset = 0
  46. mrs \rtemp, cpsr
  47. eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
  48. msr cpsr_c, \rtemp @ switch to the SYS mode
  49. str sp, [\rd, #\offset] @ save sp_usr
  50. str lr, [\rd, #\offset + 4] @ save lr_usr
  51. eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
  52. msr cpsr_c, \rtemp @ switch back to the SVC mode
  53. .endm
  54. .macro load_user_sp_lr, rd, rtemp, offset = 0
  55. mrs \rtemp, cpsr
  56. eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
  57. msr cpsr_c, \rtemp @ switch to the SYS mode
  58. ldr sp, [\rd, #\offset] @ load sp_usr
  59. ldr lr, [\rd, #\offset + 4] @ load lr_usr
  60. eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
  61. msr cpsr_c, \rtemp @ switch back to the SVC mode
  62. .endm
  63. #ifndef CONFIG_THUMB2_KERNEL
  64. .macro svc_exit, rpsr, irq = 0
  65. .if \irq != 0
  66. @ IRQs already off
  67. #ifdef CONFIG_TRACE_IRQFLAGS
  68. @ The parent context IRQs must have been enabled to get here in
  69. @ the first place, so there's no point checking the PSR I bit.
  70. bl trace_hardirqs_on
  71. #endif
  72. .else
  73. @ IRQs off again before pulling preserved data off the stack
  74. disable_irq_notrace
  75. #ifdef CONFIG_TRACE_IRQFLAGS
  76. tst \rpsr, #PSR_I_BIT
  77. bleq trace_hardirqs_on
  78. tst \rpsr, #PSR_I_BIT
  79. blne trace_hardirqs_off
  80. #endif
  81. .endif
  82. msr spsr_cxsf, \rpsr
  83. #if defined(CONFIG_CPU_V6)
  84. ldr r0, [sp]
  85. strex r1, r2, [sp] @ clear the exclusive monitor
  86. ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr
  87. #elif defined(CONFIG_CPU_32v6K)
  88. clrex @ clear the exclusive monitor
  89. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  90. #else
  91. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  92. #endif
  93. .endm
  94. .macro restore_user_regs, fast = 0, offset = 0
  95. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  96. ldr lr, [sp, #\offset + S_PC]! @ get pc
  97. msr spsr_cxsf, r1 @ save in spsr_svc
  98. #if defined(CONFIG_CPU_V6)
  99. strex r1, r2, [sp] @ clear the exclusive monitor
  100. #elif defined(CONFIG_CPU_32v6K)
  101. clrex @ clear the exclusive monitor
  102. #endif
  103. .if \fast
  104. ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
  105. .else
  106. ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
  107. .endif
  108. mov r0, r0 @ ARMv5T and earlier require a nop
  109. @ after ldm {}^
  110. add sp, sp, #S_FRAME_SIZE - S_PC
  111. movs pc, lr @ return & move spsr_svc into cpsr
  112. .endm
  113. .macro get_thread_info, rd
  114. mov \rd, sp, lsr #13
  115. mov \rd, \rd, lsl #13
  116. .endm
  117. @
  118. @ 32-bit wide "mov pc, reg"
  119. @
  120. .macro movw_pc, reg
  121. mov pc, \reg
  122. .endm
  123. #else /* CONFIG_THUMB2_KERNEL */
  124. .macro svc_exit, rpsr, irq = 0
  125. .if \irq != 0
  126. @ IRQs already off
  127. #ifdef CONFIG_TRACE_IRQFLAGS
  128. @ The parent context IRQs must have been enabled to get here in
  129. @ the first place, so there's no point checking the PSR I bit.
  130. bl trace_hardirqs_on
  131. #endif
  132. .else
  133. @ IRQs off again before pulling preserved data off the stack
  134. disable_irq_notrace
  135. #ifdef CONFIG_TRACE_IRQFLAGS
  136. tst \rpsr, #PSR_I_BIT
  137. bleq trace_hardirqs_on
  138. tst \rpsr, #PSR_I_BIT
  139. blne trace_hardirqs_off
  140. #endif
  141. .endif
  142. ldr lr, [sp, #S_SP] @ top of the stack
  143. ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
  144. clrex @ clear the exclusive monitor
  145. stmdb lr!, {r0, r1, \rpsr} @ calling lr and rfe context
  146. ldmia sp, {r0 - r12}
  147. mov sp, lr
  148. ldr lr, [sp], #4
  149. rfeia sp!
  150. .endm
  151. .macro restore_user_regs, fast = 0, offset = 0
  152. clrex @ clear the exclusive monitor
  153. mov r2, sp
  154. load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
  155. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  156. ldr lr, [sp, #\offset + S_PC] @ get pc
  157. add sp, sp, #\offset + S_SP
  158. msr spsr_cxsf, r1 @ save in spsr_svc
  159. .if \fast
  160. ldmdb sp, {r1 - r12} @ get calling r1 - r12
  161. .else
  162. ldmdb sp, {r0 - r12} @ get calling r0 - r12
  163. .endif
  164. add sp, sp, #S_FRAME_SIZE - S_SP
  165. movs pc, lr @ return & move spsr_svc into cpsr
  166. .endm
  167. .macro get_thread_info, rd
  168. mov \rd, sp
  169. lsr \rd, \rd, #13
  170. mov \rd, \rd, lsl #13
  171. .endm
  172. @
  173. @ 32-bit wide "mov pc, reg"
  174. @
  175. .macro movw_pc, reg
  176. mov pc, \reg
  177. nop
  178. .endm
  179. #endif /* !CONFIG_THUMB2_KERNEL */
  180. /*
  181. * Context tracking subsystem. Used to instrument transitions
  182. * between user and kernel mode.
  183. */
  184. .macro ct_user_exit, save = 1
  185. #ifdef CONFIG_CONTEXT_TRACKING
  186. .if \save
  187. stmdb sp!, {r0-r3, ip, lr}
  188. bl user_exit
  189. ldmia sp!, {r0-r3, ip, lr}
  190. .else
  191. bl user_exit
  192. .endif
  193. #endif
  194. .endm
  195. .macro ct_user_enter, save = 1
  196. #ifdef CONFIG_CONTEXT_TRACKING
  197. .if \save
  198. stmdb sp!, {r0-r3, ip, lr}
  199. bl user_enter
  200. ldmia sp!, {r0-r3, ip, lr}
  201. .else
  202. bl user_enter
  203. .endif
  204. #endif
  205. .endm
  206. /*
  207. * These are the registers used in the syscall handler, and allow us to
  208. * have in theory up to 7 arguments to a function - r0 to r6.
  209. *
  210. * r7 is reserved for the system call number for thumb mode.
  211. *
  212. * Note that tbl == why is intentional.
  213. *
  214. * We must set at least "tsk" and "why" when calling ret_with_reschedule.
  215. */
  216. scno .req r7 @ syscall number
  217. tbl .req r8 @ syscall table pointer
  218. why .req r8 @ Linux syscall (!= 0)
  219. tsk .req r9 @ current thread_info