entry-header.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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
  65. msr spsr_cxsf, \rpsr
  66. #if defined(CONFIG_CPU_V6)
  67. ldr r0, [sp]
  68. strex r1, r2, [sp] @ clear the exclusive monitor
  69. ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr
  70. #elif defined(CONFIG_CPU_32v6K)
  71. clrex @ clear the exclusive monitor
  72. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  73. #else
  74. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  75. #endif
  76. .endm
  77. .macro restore_user_regs, fast = 0, offset = 0
  78. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  79. ldr lr, [sp, #\offset + S_PC]! @ get pc
  80. msr spsr_cxsf, r1 @ save in spsr_svc
  81. #if defined(CONFIG_CPU_V6)
  82. strex r1, r2, [sp] @ clear the exclusive monitor
  83. #elif defined(CONFIG_CPU_32v6K)
  84. clrex @ clear the exclusive monitor
  85. #endif
  86. .if \fast
  87. ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
  88. .else
  89. ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
  90. .endif
  91. mov r0, r0 @ ARMv5T and earlier require a nop
  92. @ after ldm {}^
  93. add sp, sp, #S_FRAME_SIZE - S_PC
  94. movs pc, lr @ return & move spsr_svc into cpsr
  95. .endm
  96. .macro get_thread_info, rd
  97. mov \rd, sp, lsr #13
  98. mov \rd, \rd, lsl #13
  99. .endm
  100. @
  101. @ 32-bit wide "mov pc, reg"
  102. @
  103. .macro movw_pc, reg
  104. mov pc, \reg
  105. .endm
  106. #else /* CONFIG_THUMB2_KERNEL */
  107. .macro svc_exit, rpsr
  108. clrex @ clear the exclusive monitor
  109. ldr r0, [sp, #S_SP] @ top of the stack
  110. ldr r1, [sp, #S_PC] @ return address
  111. tst r0, #4 @ orig stack 8-byte aligned?
  112. stmdb r0, {r1, \rpsr} @ rfe context
  113. ldmia sp, {r0 - r12}
  114. ldr lr, [sp, #S_LR]
  115. addeq sp, sp, #S_FRAME_SIZE - 8 @ aligned
  116. addne sp, sp, #S_FRAME_SIZE - 4 @ not aligned
  117. rfeia sp!
  118. .endm
  119. .macro restore_user_regs, fast = 0, offset = 0
  120. clrex @ clear the exclusive monitor
  121. mov r2, sp
  122. load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
  123. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  124. ldr lr, [sp, #\offset + S_PC] @ get pc
  125. add sp, sp, #\offset + S_SP
  126. msr spsr_cxsf, r1 @ save in spsr_svc
  127. .if \fast
  128. ldmdb sp, {r1 - r12} @ get calling r1 - r12
  129. .else
  130. ldmdb sp, {r0 - r12} @ get calling r0 - r12
  131. .endif
  132. add sp, sp, #S_FRAME_SIZE - S_SP
  133. movs pc, lr @ return & move spsr_svc into cpsr
  134. .endm
  135. .macro get_thread_info, rd
  136. mov \rd, sp
  137. lsr \rd, \rd, #13
  138. mov \rd, \rd, lsl #13
  139. .endm
  140. @
  141. @ 32-bit wide "mov pc, reg"
  142. @
  143. .macro movw_pc, reg
  144. mov pc, \reg
  145. nop
  146. .endm
  147. #endif /* !CONFIG_THUMB2_KERNEL */
  148. @
  149. @ Debug exceptions are taken as prefetch or data aborts.
  150. @ We must disable preemption during the handler so that
  151. @ we can access the debug registers safely.
  152. @
  153. .macro debug_entry, fsr
  154. #if defined(CONFIG_HAVE_HW_BREAKPOINT) && defined(CONFIG_PREEMPT)
  155. ldr r4, =0x40f @ mask out fsr.fs
  156. and r5, r4, \fsr
  157. cmp r5, #2 @ debug exception
  158. bne 1f
  159. get_thread_info r10
  160. ldr r6, [r10, #TI_PREEMPT] @ get preempt count
  161. add r11, r6, #1 @ increment it
  162. str r11, [r10, #TI_PREEMPT]
  163. 1:
  164. #endif
  165. .endm
  166. /*
  167. * These are the registers used in the syscall handler, and allow us to
  168. * have in theory up to 7 arguments to a function - r0 to r6.
  169. *
  170. * r7 is reserved for the system call number for thumb mode.
  171. *
  172. * Note that tbl == why is intentional.
  173. *
  174. * We must set at least "tsk" and "why" when calling ret_with_reschedule.
  175. */
  176. scno .req r7 @ syscall number
  177. tbl .req r8 @ syscall table pointer
  178. why .req r8 @ Linux syscall (!= 0)
  179. tsk .req r9 @ current thread_info