entry-header.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #ifdef CONFIG_TRACE_IRQFLAGS
  67. @ The parent context IRQs must have been enabled to get here in
  68. @ the first place, so there's no point checking the PSR I bit.
  69. bl trace_hardirqs_on
  70. #endif
  71. .else
  72. #ifdef CONFIG_TRACE_IRQFLAGS
  73. tst \rpsr, #PSR_I_BIT
  74. bleq trace_hardirqs_on
  75. tst \rpsr, #PSR_I_BIT
  76. blne trace_hardirqs_off
  77. #endif
  78. .endif
  79. msr spsr_cxsf, \rpsr
  80. #if defined(CONFIG_CPU_V6)
  81. ldr r0, [sp]
  82. strex r1, r2, [sp] @ clear the exclusive monitor
  83. ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr
  84. #elif defined(CONFIG_CPU_32v6K)
  85. clrex @ clear the exclusive monitor
  86. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  87. #else
  88. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  89. #endif
  90. .endm
  91. .macro restore_user_regs, fast = 0, offset = 0
  92. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  93. ldr lr, [sp, #\offset + S_PC]! @ get pc
  94. msr spsr_cxsf, r1 @ save in spsr_svc
  95. #if defined(CONFIG_CPU_V6)
  96. strex r1, r2, [sp] @ clear the exclusive monitor
  97. #elif defined(CONFIG_CPU_32v6K)
  98. clrex @ clear the exclusive monitor
  99. #endif
  100. .if \fast
  101. ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
  102. .else
  103. ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
  104. .endif
  105. mov r0, r0 @ ARMv5T and earlier require a nop
  106. @ after ldm {}^
  107. add sp, sp, #S_FRAME_SIZE - S_PC
  108. movs pc, lr @ return & move spsr_svc into cpsr
  109. .endm
  110. .macro get_thread_info, rd
  111. mov \rd, sp, lsr #13
  112. mov \rd, \rd, lsl #13
  113. .endm
  114. @
  115. @ 32-bit wide "mov pc, reg"
  116. @
  117. .macro movw_pc, reg
  118. mov pc, \reg
  119. .endm
  120. #else /* CONFIG_THUMB2_KERNEL */
  121. .macro svc_exit, rpsr, irq = 0
  122. .if \irq != 0
  123. #ifdef CONFIG_TRACE_IRQFLAGS
  124. @ The parent context IRQs must have been enabled to get here in
  125. @ the first place, so there's no point checking the PSR I bit.
  126. bl trace_hardirqs_on
  127. #endif
  128. .else
  129. #ifdef CONFIG_TRACE_IRQFLAGS
  130. tst \rpsr, #PSR_I_BIT
  131. bleq trace_hardirqs_on
  132. tst \rpsr, #PSR_I_BIT
  133. blne trace_hardirqs_off
  134. #endif
  135. .endif
  136. ldr lr, [sp, #S_SP] @ top of the stack
  137. ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
  138. clrex @ clear the exclusive monitor
  139. stmdb lr!, {r0, r1, \rpsr} @ calling lr and rfe context
  140. ldmia sp, {r0 - r12}
  141. mov sp, lr
  142. ldr lr, [sp], #4
  143. rfeia sp!
  144. .endm
  145. .macro restore_user_regs, fast = 0, offset = 0
  146. clrex @ clear the exclusive monitor
  147. mov r2, sp
  148. load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
  149. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  150. ldr lr, [sp, #\offset + S_PC] @ get pc
  151. add sp, sp, #\offset + S_SP
  152. msr spsr_cxsf, r1 @ save in spsr_svc
  153. .if \fast
  154. ldmdb sp, {r1 - r12} @ get calling r1 - r12
  155. .else
  156. ldmdb sp, {r0 - r12} @ get calling r0 - r12
  157. .endif
  158. add sp, sp, #S_FRAME_SIZE - S_SP
  159. movs pc, lr @ return & move spsr_svc into cpsr
  160. .endm
  161. .macro get_thread_info, rd
  162. mov \rd, sp
  163. lsr \rd, \rd, #13
  164. mov \rd, \rd, lsl #13
  165. .endm
  166. @
  167. @ 32-bit wide "mov pc, reg"
  168. @
  169. .macro movw_pc, reg
  170. mov pc, \reg
  171. nop
  172. .endm
  173. #endif /* !CONFIG_THUMB2_KERNEL */
  174. /*
  175. * These are the registers used in the syscall handler, and allow us to
  176. * have in theory up to 7 arguments to a function - r0 to r6.
  177. *
  178. * r7 is reserved for the system call number for thumb mode.
  179. *
  180. * Note that tbl == why is intentional.
  181. *
  182. * We must set at least "tsk" and "why" when calling ret_with_reschedule.
  183. */
  184. scno .req r7 @ syscall number
  185. tbl .req r8 @ syscall table pointer
  186. why .req r8 @ Linux syscall (!= 0)
  187. tsk .req r9 @ current thread_info