Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * sigreturn_codes.S - code sinpets for sigreturn syscalls
0004  *
0005  * Created by:  Victor Kamensky, 2013-08-13
0006  * Copyright:   (C) 2013  Linaro Limited
0007  */
0008 
0009 #include <asm/assembler.h>
0010 #include <asm/asm-offsets.h>
0011 #include <asm/unistd.h>
0012 
0013 /*
0014  * For ARM syscalls, we encode the syscall number into the instruction.
0015  * With EABI, the syscall number has to be loaded into r7. As result
0016  * ARM syscall sequence snippet will have move and svc in .arm encoding
0017  *
0018  * For Thumb syscalls, we pass the syscall number via r7.  We therefore
0019  * need two 16-bit instructions in .thumb encoding
0020  *
0021  * Please note sigreturn_codes code are not executed in place. Instead
0022  * they just copied by kernel into appropriate places. Code inside of
0023  * arch/arm/kernel/signal.c is very sensitive to layout of these code
0024  * snippets.
0025  */
0026 
0027 /*
0028  * In CPU_THUMBONLY case kernel arm opcodes are not allowed.
0029  * Note in this case codes skips those instructions but it uses .org
0030  * directive to keep correct layout of sigreturn_codes array.
0031  */
0032 #ifndef CONFIG_CPU_THUMBONLY
0033 #define ARM_OK(code...) code
0034 #else
0035 #define ARM_OK(code...)
0036 #endif
0037 
0038     .macro arm_slot n
0039     .org    sigreturn_codes + 12 * (\n)
0040 ARM_OK( .arm    )
0041     .endm
0042 
0043     .macro thumb_slot n
0044     .org    sigreturn_codes + 12 * (\n) + 8
0045     .thumb
0046     .endm
0047 
0048     .macro arm_fdpic_slot n
0049     .org    sigreturn_codes + 24 + 20 * (\n)
0050 ARM_OK( .arm    )
0051     .endm
0052 
0053     .macro thumb_fdpic_slot n
0054     .org    sigreturn_codes + 24 + 20 * (\n) + 12
0055     .thumb
0056     .endm
0057 
0058 
0059 #if __LINUX_ARM_ARCH__ <= 4
0060     /*
0061      * Note we manually set minimally required arch that supports
0062      * required thumb opcodes for early arch versions. It is OK
0063      * for this file to be used in combination with other
0064      * lower arch variants, since these code snippets are only
0065      * used as input data.
0066      */
0067     .arch armv4t
0068 #endif
0069 
0070     .section .rodata
0071     .global sigreturn_codes
0072     .type   sigreturn_codes, #object
0073 
0074     .align
0075 
0076 sigreturn_codes:
0077 
0078     /* ARM sigreturn syscall code snippet */
0079     arm_slot 0
0080 ARM_OK( mov r7, #(__NR_sigreturn - __NR_SYSCALL_BASE)   )
0081 ARM_OK( swi #(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE)  )
0082 
0083     /* Thumb sigreturn syscall code snippet */
0084     thumb_slot 0
0085     movs    r7, #(__NR_sigreturn - __NR_SYSCALL_BASE)
0086     swi #0
0087 
0088     /* ARM sigreturn_rt syscall code snippet */
0089     arm_slot 1
0090 ARM_OK( mov r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE)    )
0091 ARM_OK( swi #(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE)   )
0092 
0093     /* Thumb sigreturn_rt syscall code snippet */
0094     thumb_slot 1
0095     movs    r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE)
0096     swi #0
0097 
0098     /* ARM sigreturn restorer FDPIC bounce code snippet */
0099     arm_fdpic_slot 0
0100 ARM_OK( ldr r3, [sp, #SIGFRAME_RC3_OFFSET] )
0101 ARM_OK( ldmia   r3, {r3, r9} )
0102 #ifdef CONFIG_ARM_THUMB
0103 ARM_OK( bx  r3 )
0104 #else
0105 ARM_OK( ret r3 )
0106 #endif
0107 
0108     /* Thumb sigreturn restorer FDPIC bounce code snippet */
0109     thumb_fdpic_slot 0
0110     ldr r3, [sp, #SIGFRAME_RC3_OFFSET]
0111     ldmia   r3, {r2, r3}
0112     mov r9, r3
0113     bx  r2
0114 
0115     /* ARM sigreturn_rt restorer FDPIC bounce code snippet */
0116     arm_fdpic_slot 1
0117 ARM_OK( ldr r3, [sp, #RT_SIGFRAME_RC3_OFFSET] )
0118 ARM_OK( ldmia   r3, {r3, r9} )
0119 #ifdef CONFIG_ARM_THUMB
0120 ARM_OK( bx  r3 )
0121 #else
0122 ARM_OK( ret r3 )
0123 #endif
0124 
0125     /* Thumb sigreturn_rt restorer FDPIC bounce code snippet */
0126     thumb_fdpic_slot 1
0127     ldr r3, [sp, #RT_SIGFRAME_RC3_OFFSET]
0128     ldmia   r3, {r2, r3}
0129     mov r9, r3
0130     bx  r2
0131 
0132     /*
0133      * Note on additional space: setup_return in signal.c
0134      * always copies the same number of words regardless whether
0135      * it is thumb case or not, so we need one additional padding
0136      * word after the last entry.
0137      */
0138     .space  4
0139 
0140     .size   sigreturn_codes, . - sigreturn_codes