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 17#include <asm/assembler.h> 18#include <asm/asm-offsets.h> 19#include <asm/unistd.h> 20 21/* 22 * For ARM syscalls, we encode the syscall number into the instruction. 23 * With EABI, the syscall number has to be loaded into r7. As result 24 * ARM syscall sequence snippet will have move and svc in .arm encoding 25 * 26 * For Thumb syscalls, we pass the syscall number via r7. We therefore 27 * need two 16-bit instructions in .thumb encoding 28 * 29 * Please note sigreturn_codes code are not executed in place. Instead 30 * they just copied by kernel into appropriate places. Code inside of 31 * arch/arm/kernel/signal.c is very sensitive to layout of these code 32 * snippets. 33 */ 34 35/* 36 * In CPU_THUMBONLY case kernel arm opcodes are not allowed. 37 * Note in this case codes skips those instructions but it uses .org 38 * directive to keep correct layout of sigreturn_codes array. 39 */ 40#ifndef CONFIG_CPU_THUMBONLY 41#define ARM_OK(code...) code 42#else 43#define ARM_OK(code...) 44#endif 45 46 .macro arm_slot n 47 .org sigreturn_codes + 12 * (\n) 48ARM_OK( .arm ) 49 .endm 50 51 .macro thumb_slot n 52 .org sigreturn_codes + 12 * (\n) + 8 53 .thumb 54 .endm 55 56 .macro arm_fdpic_slot n 57 .org sigreturn_codes + 24 + 20 * (\n) 58ARM_OK( .arm ) 59 .endm 60 61 .macro thumb_fdpic_slot n 62 .org sigreturn_codes + 24 + 20 * (\n) + 12 63 .thumb 64 .endm 65 66 67#if __LINUX_ARM_ARCH__ <= 4 68 /* 69 * Note we manually set minimally required arch that supports 70 * required thumb opcodes for early arch versions. It is OK 71 * for this file to be used in combination with other 72 * lower arch variants, since these code snippets are only 73 * used as input data. 74 */ 75 .arch armv4t 76#endif 77 78 .section .rodata 79 .global sigreturn_codes 80 .type sigreturn_codes, #object 81 82 .align 83 84sigreturn_codes: 85 86 /* ARM sigreturn syscall code snippet */ 87 arm_slot 0 88ARM_OK( mov r7, #(__NR_sigreturn - __NR_SYSCALL_BASE) ) 89ARM_OK( swi #(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE) ) 90 91 /* Thumb sigreturn syscall code snippet */ 92 thumb_slot 0 93 movs r7, #(__NR_sigreturn - __NR_SYSCALL_BASE) 94 swi #0 95 96 /* ARM sigreturn_rt syscall code snippet */ 97 arm_slot 1 98ARM_OK( mov r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE) ) 99ARM_OK( swi #(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE) ) 100 101 /* Thumb sigreturn_rt syscall code snippet */ 102 thumb_slot 1 103 movs r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE) 104 swi #0 105 106 /* ARM sigreturn restorer FDPIC bounce code snippet */ 107 arm_fdpic_slot 0 108ARM_OK( ldr r3, [sp, #SIGFRAME_RC3_OFFSET] ) 109ARM_OK( ldmia r3, {r3, r9} ) 110#ifdef CONFIG_ARM_THUMB 111ARM_OK( bx r3 ) 112#else 113ARM_OK( ret r3 ) 114#endif 115 116 /* Thumb sigreturn restorer FDPIC bounce code snippet */ 117 thumb_fdpic_slot 0 118 ldr r3, [sp, #SIGFRAME_RC3_OFFSET] 119 ldmia r3, {r2, r3} 120 mov r9, r3 121 bx r2 122 123 /* ARM sigreturn_rt restorer FDPIC bounce code snippet */ 124 arm_fdpic_slot 1 125ARM_OK( ldr r3, [sp, #RT_SIGFRAME_RC3_OFFSET] ) 126ARM_OK( ldmia r3, {r3, r9} ) 127#ifdef CONFIG_ARM_THUMB 128ARM_OK( bx r3 ) 129#else 130ARM_OK( ret r3 ) 131#endif 132 133 /* Thumb sigreturn_rt restorer FDPIC bounce code snippet */ 134 thumb_fdpic_slot 1 135 ldr r3, [sp, #RT_SIGFRAME_RC3_OFFSET] 136 ldmia r3, {r2, r3} 137 mov r9, r3 138 bx r2 139 140 /* 141 * Note on additional space: setup_return in signal.c 142 * always copies the same number of words regardless whether 143 * it is thumb case or not, so we need one additional padding 144 * word after the last entry. 145 */ 146 .space 4 147 148 .size sigreturn_codes, . - sigreturn_codes 149