Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/entry-common.S |
| 3 | * |
| 4 | * Copyright (C) 2000 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/config.h> |
| 11 | |
| 12 | #include <asm/thread_info.h> |
| 13 | #include <asm/ptrace.h> |
| 14 | #include <asm/unistd.h> |
| 15 | |
| 16 | #include "entry-header.S" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | .align 5 |
| 20 | /* |
| 21 | * This is the fast syscall return path. We do as little as |
| 22 | * possible here, and this includes saving r0 back into the SVC |
| 23 | * stack. |
| 24 | */ |
| 25 | ret_fast_syscall: |
Russell King | 1ec42c0 | 2005-04-26 15:18:26 +0100 | [diff] [blame] | 26 | disable_irq @ disable interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | ldr r1, [tsk, #TI_FLAGS] |
| 28 | tst r1, #_TIF_WORK_MASK |
| 29 | bne fast_work_pending |
| 30 | fast_restore_user_regs |
| 31 | |
| 32 | /* |
| 33 | * Ok, we need to do extra processing, enter the slow path. |
| 34 | */ |
| 35 | fast_work_pending: |
| 36 | str r0, [sp, #S_R0+S_OFF]! @ returned r0 |
| 37 | work_pending: |
| 38 | tst r1, #_TIF_NEED_RESCHED |
| 39 | bne work_resched |
| 40 | tst r1, #_TIF_NOTIFY_RESUME | _TIF_SIGPENDING |
| 41 | beq no_work_pending |
| 42 | mov r0, sp @ 'regs' |
| 43 | mov r2, why @ 'syscall' |
| 44 | bl do_notify_resume |
Russell King | 1ec42c0 | 2005-04-26 15:18:26 +0100 | [diff] [blame] | 45 | disable_irq @ disable interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | b no_work_pending |
| 47 | |
| 48 | work_resched: |
| 49 | bl schedule |
| 50 | /* |
| 51 | * "slow" syscall return path. "why" tells us if this was a real syscall. |
| 52 | */ |
| 53 | ENTRY(ret_to_user) |
| 54 | ret_slow_syscall: |
Russell King | 1ec42c0 | 2005-04-26 15:18:26 +0100 | [diff] [blame] | 55 | disable_irq @ disable interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | ldr r1, [tsk, #TI_FLAGS] |
| 57 | tst r1, #_TIF_WORK_MASK |
| 58 | bne work_pending |
| 59 | no_work_pending: |
| 60 | slow_restore_user_regs |
| 61 | |
| 62 | /* |
| 63 | * This is how we return from a fork. |
| 64 | */ |
| 65 | ENTRY(ret_from_fork) |
| 66 | bl schedule_tail |
| 67 | get_thread_info tsk |
| 68 | ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing |
| 69 | mov why, #1 |
| 70 | tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls? |
| 71 | beq ret_slow_syscall |
| 72 | mov r1, sp |
| 73 | mov r0, #1 @ trace exit [IP = 1] |
| 74 | bl syscall_trace |
| 75 | b ret_slow_syscall |
| 76 | |
| 77 | |
| 78 | #include "calls.S" |
| 79 | |
| 80 | /*============================================================================= |
| 81 | * SWI handler |
| 82 | *----------------------------------------------------------------------------- |
| 83 | */ |
| 84 | |
| 85 | /* If we're optimising for StrongARM the resulting code won't |
| 86 | run on an ARM7 and we can save a couple of instructions. |
| 87 | --pb */ |
| 88 | #ifdef CONFIG_CPU_ARM710 |
| 89 | .macro arm710_bug_check, instr, temp |
| 90 | and \temp, \instr, #0x0f000000 @ check for SWI |
| 91 | teq \temp, #0x0f000000 |
| 92 | bne .Larm700bug |
| 93 | .endm |
| 94 | |
| 95 | .Larm700bug: |
| 96 | ldr r0, [sp, #S_PSR] @ Get calling cpsr |
| 97 | sub lr, lr, #4 |
| 98 | str lr, [r8] |
| 99 | msr spsr_cxsf, r0 |
| 100 | ldmia sp, {r0 - lr}^ @ Get calling r0 - lr |
| 101 | mov r0, r0 |
| 102 | ldr lr, [sp, #S_PC] @ Get PC |
| 103 | add sp, sp, #S_FRAME_SIZE |
| 104 | movs pc, lr |
| 105 | #else |
| 106 | .macro arm710_bug_check, instr, temp |
| 107 | .endm |
| 108 | #endif |
| 109 | |
| 110 | .align 5 |
| 111 | ENTRY(vector_swi) |
| 112 | save_user_regs |
| 113 | zero_fp |
| 114 | get_scno |
| 115 | arm710_bug_check scno, ip |
| 116 | |
| 117 | #ifdef CONFIG_ALIGNMENT_TRAP |
| 118 | ldr ip, __cr_alignment |
| 119 | ldr ip, [ip] |
| 120 | mcr p15, 0, ip, c1, c0 @ update control register |
| 121 | #endif |
Russell King | 1ec42c0 | 2005-04-26 15:18:26 +0100 | [diff] [blame] | 122 | enable_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | str r4, [sp, #-S_OFF]! @ push fifth arg |
| 125 | |
| 126 | get_thread_info tsk |
| 127 | ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing |
| 128 | bic scno, scno, #0xff000000 @ mask off SWI op-code |
| 129 | eor scno, scno, #OS_NUMBER << 20 @ check OS number |
| 130 | adr tbl, sys_call_table @ load syscall table pointer |
| 131 | tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls? |
| 132 | bne __sys_trace |
| 133 | |
| 134 | adr lr, ret_fast_syscall @ return address |
| 135 | cmp scno, #NR_syscalls @ check upper syscall limit |
| 136 | ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine |
| 137 | |
| 138 | add r1, sp, #S_OFF |
| 139 | 2: mov why, #0 @ no longer a real syscall |
| 140 | cmp scno, #ARMSWI_OFFSET |
| 141 | eor r0, scno, #OS_NUMBER << 20 @ put OS number back |
| 142 | bcs arm_syscall |
| 143 | b sys_ni_syscall @ not private func |
| 144 | |
| 145 | /* |
| 146 | * This is the really slow path. We're going to be doing |
| 147 | * context switches, and waiting for our parent to respond. |
| 148 | */ |
| 149 | __sys_trace: |
| 150 | add r1, sp, #S_OFF |
| 151 | mov r0, #0 @ trace entry [IP = 0] |
| 152 | bl syscall_trace |
| 153 | |
| 154 | adr lr, __sys_trace_return @ return address |
| 155 | add r1, sp, #S_R0 + S_OFF @ pointer to regs |
| 156 | cmp scno, #NR_syscalls @ check upper syscall limit |
| 157 | ldmccia r1, {r0 - r3} @ have to reload r0 - r3 |
| 158 | ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine |
| 159 | b 2b |
| 160 | |
| 161 | __sys_trace_return: |
| 162 | str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 |
| 163 | mov r1, sp |
| 164 | mov r0, #1 @ trace exit [IP = 1] |
| 165 | bl syscall_trace |
| 166 | b ret_slow_syscall |
| 167 | |
| 168 | .align 5 |
| 169 | #ifdef CONFIG_ALIGNMENT_TRAP |
| 170 | .type __cr_alignment, #object |
| 171 | __cr_alignment: |
| 172 | .word cr_alignment |
| 173 | #endif |
| 174 | |
| 175 | .type sys_call_table, #object |
| 176 | ENTRY(sys_call_table) |
| 177 | #include "calls.S" |
| 178 | |
| 179 | /*============================================================================ |
| 180 | * Special system call wrappers |
| 181 | */ |
| 182 | @ r0 = syscall number |
| 183 | @ r5 = syscall table |
| 184 | .type sys_syscall, #function |
| 185 | sys_syscall: |
| 186 | eor scno, r0, #OS_NUMBER << 20 |
| 187 | cmp scno, #__NR_syscall - __NR_SYSCALL_BASE |
| 188 | cmpne scno, #NR_syscalls @ check range |
| 189 | stmloia sp, {r5, r6} @ shuffle args |
| 190 | movlo r0, r1 |
| 191 | movlo r1, r2 |
| 192 | movlo r2, r3 |
| 193 | movlo r3, r4 |
| 194 | ldrlo pc, [tbl, scno, lsl #2] |
| 195 | b sys_ni_syscall |
| 196 | |
| 197 | sys_fork_wrapper: |
| 198 | add r0, sp, #S_OFF |
| 199 | b sys_fork |
| 200 | |
| 201 | sys_vfork_wrapper: |
| 202 | add r0, sp, #S_OFF |
| 203 | b sys_vfork |
| 204 | |
| 205 | sys_execve_wrapper: |
| 206 | add r3, sp, #S_OFF |
| 207 | b sys_execve |
| 208 | |
| 209 | sys_clone_wrapper: |
| 210 | add ip, sp, #S_OFF |
| 211 | str ip, [sp, #4] |
| 212 | b sys_clone |
| 213 | |
| 214 | sys_sigsuspend_wrapper: |
| 215 | add r3, sp, #S_OFF |
| 216 | b sys_sigsuspend |
| 217 | |
| 218 | sys_rt_sigsuspend_wrapper: |
| 219 | add r2, sp, #S_OFF |
| 220 | b sys_rt_sigsuspend |
| 221 | |
| 222 | sys_sigreturn_wrapper: |
| 223 | add r0, sp, #S_OFF |
| 224 | b sys_sigreturn |
| 225 | |
| 226 | sys_rt_sigreturn_wrapper: |
| 227 | add r0, sp, #S_OFF |
| 228 | b sys_rt_sigreturn |
| 229 | |
| 230 | sys_sigaltstack_wrapper: |
| 231 | ldr r2, [sp, #S_OFF + S_SP] |
| 232 | b do_sigaltstack |
| 233 | |
| 234 | sys_futex_wrapper: |
| 235 | str r5, [sp, #4] @ push sixth arg |
| 236 | b sys_futex |
| 237 | |
| 238 | /* |
| 239 | * Note: off_4k (r5) is always units of 4K. If we can't do the requested |
| 240 | * offset, we return EINVAL. |
| 241 | */ |
| 242 | sys_mmap2: |
| 243 | #if PAGE_SHIFT > 12 |
| 244 | tst r5, #PGOFF_MASK |
| 245 | moveq r5, r5, lsr #PAGE_SHIFT - 12 |
| 246 | streq r5, [sp, #4] |
| 247 | beq do_mmap2 |
| 248 | mov r0, #-EINVAL |
| 249 | RETINSTR(mov,pc, lr) |
| 250 | #else |
| 251 | str r5, [sp, #4] |
| 252 | b do_mmap2 |
| 253 | #endif |