entry-header.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  67. .endm
  68. .macro restore_user_regs, fast = 0, offset = 0
  69. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  70. ldr lr, [sp, #\offset + S_PC]! @ get pc
  71. msr spsr_cxsf, r1 @ save in spsr_svc
  72. .if \fast
  73. ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
  74. .else
  75. ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
  76. .endif
  77. add sp, sp, #S_FRAME_SIZE - S_PC
  78. movs pc, lr @ return & move spsr_svc into cpsr
  79. .endm
  80. .macro get_thread_info, rd
  81. mov \rd, sp, lsr #13
  82. mov \rd, \rd, lsl #13
  83. .endm
  84. #else /* CONFIG_THUMB2_KERNEL */
  85. .macro svc_exit, rpsr
  86. ldr r0, [sp, #S_SP] @ top of the stack
  87. ldr r1, [sp, #S_PC] @ return address
  88. tst r0, #4 @ orig stack 8-byte aligned?
  89. stmdb r0, {r1, \rpsr} @ rfe context
  90. ldmia sp, {r0 - r12}
  91. ldr lr, [sp, #S_LR]
  92. addeq sp, sp, #S_FRAME_SIZE - 8 @ aligned
  93. addne sp, sp, #S_FRAME_SIZE - 4 @ not aligned
  94. rfeia sp!
  95. .endm
  96. .macro restore_user_regs, fast = 0, offset = 0
  97. mov r2, sp
  98. load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
  99. ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
  100. ldr lr, [sp, #\offset + S_PC] @ get pc
  101. add sp, sp, #\offset + S_SP
  102. msr spsr_cxsf, r1 @ save in spsr_svc
  103. .if \fast
  104. ldmdb sp, {r1 - r12} @ get calling r1 - r12
  105. .else
  106. ldmdb sp, {r0 - r12} @ get calling r0 - r12
  107. .endif
  108. add sp, sp, #S_FRAME_SIZE - S_SP
  109. movs pc, lr @ return & move spsr_svc into cpsr
  110. .endm
  111. .macro get_thread_info, rd
  112. mov \rd, sp
  113. lsr \rd, \rd, #13
  114. mov \rd, \rd, lsl #13
  115. .endm
  116. #endif /* !CONFIG_THUMB2_KERNEL */
  117. /*
  118. * These are the registers used in the syscall handler, and allow us to
  119. * have in theory up to 7 arguments to a function - r0 to r6.
  120. *
  121. * r7 is reserved for the system call number for thumb mode.
  122. *
  123. * Note that tbl == why is intentional.
  124. *
  125. * We must set at least "tsk" and "why" when calling ret_with_reschedule.
  126. */
  127. scno .req r7 @ syscall number
  128. tbl .req r8 @ syscall table pointer
  129. why .req r8 @ Linux syscall (!= 0)
  130. tsk .req r9 @ current thread_info