sigreturn_codes.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * sigreturn_codes.S - code sinpets for sigreturn syscalls
  3. *
  4. * Created by: Victor Kamensky, 2013-08-13
  5. * Copyright: (C) 2013 Linaro Limited
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <asm/assembler.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/unistd.h>
  19. /*
  20. * For ARM syscalls, we encode the syscall number into the instruction.
  21. * With EABI, the syscall number has to be loaded into r7. As result
  22. * ARM syscall sequence snippet will have move and svc in .arm encoding
  23. *
  24. * For Thumb syscalls, we pass the syscall number via r7. We therefore
  25. * need two 16-bit instructions in .thumb encoding
  26. *
  27. * Please note sigreturn_codes code are not executed in place. Instead
  28. * they just copied by kernel into appropriate places. Code inside of
  29. * arch/arm/kernel/signal.c is very sensitive to layout of these code
  30. * snippets.
  31. */
  32. /*
  33. * In CPU_THUMBONLY case kernel arm opcodes are not allowed.
  34. * Note in this case codes skips those instructions but it uses .org
  35. * directive to keep correct layout of sigreturn_codes array.
  36. */
  37. #ifndef CONFIG_CPU_THUMBONLY
  38. #define ARM_OK(code...) code
  39. #else
  40. #define ARM_OK(code...)
  41. #endif
  42. .macro arm_slot n
  43. .org sigreturn_codes + 12 * (\n)
  44. ARM_OK( .arm )
  45. .endm
  46. .macro thumb_slot n
  47. .org sigreturn_codes + 12 * (\n) + 8
  48. .thumb
  49. .endm
  50. .macro arm_fdpic_slot n
  51. .org sigreturn_codes + 24 + 20 * (\n)
  52. ARM_OK( .arm )
  53. .endm
  54. .macro thumb_fdpic_slot n
  55. .org sigreturn_codes + 24 + 20 * (\n) + 12
  56. .thumb
  57. .endm
  58. #if __LINUX_ARM_ARCH__ <= 4
  59. /*
  60. * Note we manually set minimally required arch that supports
  61. * required thumb opcodes for early arch versions. It is OK
  62. * for this file to be used in combination with other
  63. * lower arch variants, since these code snippets are only
  64. * used as input data.
  65. */
  66. .arch armv4t
  67. #endif
  68. .section .rodata
  69. .global sigreturn_codes
  70. .type sigreturn_codes, #object
  71. .align
  72. sigreturn_codes:
  73. /* ARM sigreturn syscall code snippet */
  74. arm_slot 0
  75. ARM_OK( mov r7, #(__NR_sigreturn - __NR_SYSCALL_BASE) )
  76. ARM_OK( swi #(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE) )
  77. /* Thumb sigreturn syscall code snippet */
  78. thumb_slot 0
  79. movs r7, #(__NR_sigreturn - __NR_SYSCALL_BASE)
  80. swi #0
  81. /* ARM sigreturn_rt syscall code snippet */
  82. arm_slot 1
  83. ARM_OK( mov r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE) )
  84. ARM_OK( swi #(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE) )
  85. /* Thumb sigreturn_rt syscall code snippet */
  86. thumb_slot 1
  87. movs r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE)
  88. swi #0
  89. /* ARM sigreturn restorer FDPIC bounce code snippet */
  90. arm_fdpic_slot 0
  91. ARM_OK( ldr r3, [sp, #SIGFRAME_RC3_OFFSET] )
  92. ARM_OK( ldmia r3, {r3, r9} )
  93. #ifdef CONFIG_ARM_THUMB
  94. ARM_OK( bx r3 )
  95. #else
  96. ARM_OK( ret r3 )
  97. #endif
  98. /* Thumb sigreturn restorer FDPIC bounce code snippet */
  99. thumb_fdpic_slot 0
  100. ldr r3, [sp, #SIGFRAME_RC3_OFFSET]
  101. ldmia r3, {r2, r3}
  102. mov r9, r3
  103. bx r2
  104. /* ARM sigreturn_rt restorer FDPIC bounce code snippet */
  105. arm_fdpic_slot 1
  106. ARM_OK( ldr r3, [sp, #RT_SIGFRAME_RC3_OFFSET] )
  107. ARM_OK( ldmia r3, {r3, r9} )
  108. #ifdef CONFIG_ARM_THUMB
  109. ARM_OK( bx r3 )
  110. #else
  111. ARM_OK( ret r3 )
  112. #endif
  113. /* Thumb sigreturn_rt restorer FDPIC bounce code snippet */
  114. thumb_fdpic_slot 1
  115. ldr r3, [sp, #RT_SIGFRAME_RC3_OFFSET]
  116. ldmia r3, {r2, r3}
  117. mov r9, r3
  118. bx r2
  119. /*
  120. * Note on additional space: setup_return in signal.c
  121. * always copies the same number of words regardless whether
  122. * it is thumb case or not, so we need one additional padding
  123. * word after the last entry.
  124. */
  125. .space 4
  126. .size sigreturn_codes, . - sigreturn_codes