65c58b34db97b9de20c918f2d6c14de95a38e9db
[safe/jmp/linux-2.6] / arch / arm / kernel / entry-common.S
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
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:
26         disable_irq                             @ disable interrupts
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
45         disable_irq                             @ disable interrupts
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:
55         disable_irq                             @ disable interrupts
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
115         /*
116          * Get the system call number.
117          */
118 #ifdef CONFIG_ARM_THUMB
119         tst     r8, #PSR_T_BIT                  @ this is SPSR from save_user_regs
120         addne   scno, r7, #__NR_SYSCALL_BASE    @ put OS number in
121         ldreq   scno, [lr, #-4]
122 #else
123         ldr     scno, [lr, #-4]                 @ get SWI instruction
124 #endif
125         arm710_bug_check scno, ip
126
127 #ifdef CONFIG_ALIGNMENT_TRAP
128         ldr     ip, __cr_alignment
129         ldr     ip, [ip]
130         mcr     p15, 0, ip, c1, c0              @ update control register
131 #endif
132         enable_irq
133
134         str     r4, [sp, #-S_OFF]!              @ push fifth arg
135
136         get_thread_info tsk
137         ldr     ip, [tsk, #TI_FLAGS]            @ check for syscall tracing
138         bic     scno, scno, #0xff000000         @ mask off SWI op-code
139         eor     scno, scno, #__NR_SYSCALL_BASE  @ check OS number
140         adr     tbl, sys_call_table             @ load syscall table pointer
141         tst     ip, #_TIF_SYSCALL_TRACE         @ are we tracing syscalls?
142         bne     __sys_trace
143
144         adr     lr, ret_fast_syscall            @ return address
145         cmp     scno, #NR_syscalls              @ check upper syscall limit
146         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
147
148         add     r1, sp, #S_OFF
149 2:      mov     why, #0                         @ no longer a real syscall
150         cmp     scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
151         eor     r0, scno, #__NR_SYSCALL_BASE    @ put OS number back
152         bcs     arm_syscall     
153         b       sys_ni_syscall                  @ not private func
154
155         /*
156          * This is the really slow path.  We're going to be doing
157          * context switches, and waiting for our parent to respond.
158          */
159 __sys_trace:
160         add     r1, sp, #S_OFF
161         mov     r0, #0                          @ trace entry [IP = 0]
162         bl      syscall_trace
163
164         adr     lr, __sys_trace_return          @ return address
165         add     r1, sp, #S_R0 + S_OFF           @ pointer to regs
166         cmp     scno, #NR_syscalls              @ check upper syscall limit
167         ldmccia r1, {r0 - r3}                   @ have to reload r0 - r3
168         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
169         b       2b
170
171 __sys_trace_return:
172         str     r0, [sp, #S_R0 + S_OFF]!        @ save returned r0
173         mov     r1, sp
174         mov     r0, #1                          @ trace exit [IP = 1]
175         bl      syscall_trace
176         b       ret_slow_syscall
177
178         .align  5
179 #ifdef CONFIG_ALIGNMENT_TRAP
180         .type   __cr_alignment, #object
181 __cr_alignment:
182         .word   cr_alignment
183 #endif
184
185         .type   sys_call_table, #object
186 ENTRY(sys_call_table)
187 #include "calls.S"
188
189 /*============================================================================
190  * Special system call wrappers
191  */
192 @ r0 = syscall number
193 @ r5 = syscall table
194                 .type   sys_syscall, #function
195 sys_syscall:
196                 eor     scno, r0, #__NR_SYSCALL_BASE
197                 cmp     scno, #__NR_syscall - __NR_SYSCALL_BASE
198                 cmpne   scno, #NR_syscalls      @ check range
199                 stmloia sp, {r5, r6}            @ shuffle args
200                 movlo   r0, r1
201                 movlo   r1, r2
202                 movlo   r2, r3
203                 movlo   r3, r4
204                 ldrlo   pc, [tbl, scno, lsl #2]
205                 b       sys_ni_syscall
206
207 sys_fork_wrapper:
208                 add     r0, sp, #S_OFF
209                 b       sys_fork
210
211 sys_vfork_wrapper:
212                 add     r0, sp, #S_OFF
213                 b       sys_vfork
214
215 sys_execve_wrapper:
216                 add     r3, sp, #S_OFF
217                 b       sys_execve
218
219 sys_clone_wrapper:
220                 add     ip, sp, #S_OFF
221                 str     ip, [sp, #4]
222                 b       sys_clone
223
224 sys_sigsuspend_wrapper:
225                 add     r3, sp, #S_OFF
226                 b       sys_sigsuspend
227
228 sys_rt_sigsuspend_wrapper:
229                 add     r2, sp, #S_OFF
230                 b       sys_rt_sigsuspend
231
232 sys_sigreturn_wrapper:
233                 add     r0, sp, #S_OFF
234                 b       sys_sigreturn
235
236 sys_rt_sigreturn_wrapper:
237                 add     r0, sp, #S_OFF
238                 b       sys_rt_sigreturn
239
240 sys_sigaltstack_wrapper:
241                 ldr     r2, [sp, #S_OFF + S_SP]
242                 b       do_sigaltstack
243
244 sys_futex_wrapper:
245                 str     r5, [sp, #4]            @ push sixth arg
246                 b       sys_futex
247
248 /*
249  * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
250  * offset, we return EINVAL.
251  */
252 sys_mmap2:
253 #if PAGE_SHIFT > 12
254                 tst     r5, #PGOFF_MASK
255                 moveq   r5, r5, lsr #PAGE_SHIFT - 12
256                 streq   r5, [sp, #4]
257                 beq     do_mmap2
258                 mov     r0, #-EINVAL
259                 RETINSTR(mov,pc, lr)
260 #else
261                 str     r5, [sp, #4]
262                 b       do_mmap2
263 #endif