Merge branch 'uaccess' into fixes
[linux-2.6-block.git] / 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
11 #include <asm/assembler.h>
12 #include <asm/unistd.h>
13 #include <asm/ftrace.h>
14 #include <asm/unwind.h>
15
16 #ifdef CONFIG_NEED_RET_TO_USER
17 #include <mach/entry-macro.S>
18 #else
19         .macro  arch_ret_to_user, tmp1, tmp2
20         .endm
21 #endif
22
23 #include "entry-header.S"
24
25
26         .align  5
27 /*
28  * This is the fast syscall return path.  We do as little as
29  * possible here, and this includes saving r0 back into the SVC
30  * stack.
31  */
32 ret_fast_syscall:
33  UNWIND(.fnstart        )
34  UNWIND(.cantunwind     )
35         disable_irq                             @ disable interrupts
36         ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
37         tst     r1, #_TIF_SYSCALL_WORK
38         bne     __sys_trace_return
39         tst     r1, #_TIF_WORK_MASK
40         bne     fast_work_pending
41         asm_trace_hardirqs_on
42
43         /* perform architecture specific actions before user return */
44         arch_ret_to_user r1, lr
45         ct_user_enter
46
47         restore_user_regs fast = 1, offset = S_OFF
48  UNWIND(.fnend          )
49
50 /*
51  * Ok, we need to do extra processing, enter the slow path.
52  */
53 fast_work_pending:
54         str     r0, [sp, #S_R0+S_OFF]!          @ returned r0
55 work_pending:
56         mov     r0, sp                          @ 'regs'
57         mov     r2, why                         @ 'syscall'
58         bl      do_work_pending
59         cmp     r0, #0
60         beq     no_work_pending
61         movlt   scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
62         ldmia   sp, {r0 - r6}                   @ have to reload r0 - r6
63         b       local_restart                   @ ... and off we go
64 ENDPROC(ret_fast_syscall)
65
66 /*
67  * "slow" syscall return path.  "why" tells us if this was a real syscall.
68  */
69 ENTRY(ret_to_user)
70 ret_slow_syscall:
71         disable_irq                             @ disable interrupts
72 ENTRY(ret_to_user_from_irq)
73         ldr     r1, [tsk, #TI_FLAGS]
74         tst     r1, #_TIF_WORK_MASK
75         bne     work_pending
76 no_work_pending:
77         asm_trace_hardirqs_on
78
79         /* perform architecture specific actions before user return */
80         arch_ret_to_user r1, lr
81         ct_user_enter save = 0
82
83         restore_user_regs fast = 0, offset = 0
84 ENDPROC(ret_to_user_from_irq)
85 ENDPROC(ret_to_user)
86
87 /*
88  * This is how we return from a fork.
89  */
90 ENTRY(ret_from_fork)
91         bl      schedule_tail
92         cmp     r5, #0
93         movne   r0, r4
94         badrne  lr, 1f
95         retne   r5
96 1:      get_thread_info tsk
97         b       ret_slow_syscall
98 ENDPROC(ret_from_fork)
99
100         .equ NR_syscalls,0
101 #define CALL(x) .equ NR_syscalls,NR_syscalls+1
102 #include "calls.S"
103
104 /*
105  * Ensure that the system call table is equal to __NR_syscalls,
106  * which is the value the rest of the system sees
107  */
108 .ifne NR_syscalls - __NR_syscalls
109 .error "__NR_syscalls is not equal to the size of the syscall table"
110 .endif
111
112 #undef CALL
113 #define CALL(x) .long x
114
115 /*=============================================================================
116  * SWI handler
117  *-----------------------------------------------------------------------------
118  */
119
120         .align  5
121 ENTRY(vector_swi)
122 #ifdef CONFIG_CPU_V7M
123         v7m_exception_entry
124 #else
125         sub     sp, sp, #S_FRAME_SIZE
126         stmia   sp, {r0 - r12}                  @ Calling r0 - r12
127  ARM(   add     r8, sp, #S_PC           )
128  ARM(   stmdb   r8, {sp, lr}^           )       @ Calling sp, lr
129  THUMB( mov     r8, sp                  )
130  THUMB( store_user_sp_lr r8, r10, S_SP  )       @ calling sp, lr
131         mrs     r8, spsr                        @ called from non-FIQ mode, so ok.
132         str     lr, [sp, #S_PC]                 @ Save calling PC
133         str     r8, [sp, #S_PSR]                @ Save CPSR
134         str     r0, [sp, #S_OLD_R0]             @ Save OLD_R0
135 #endif
136         zero_fp
137         alignment_trap r10, ip, __cr_alignment
138         enable_irq
139         ct_user_exit
140         get_thread_info tsk
141
142         /*
143          * Get the system call number.
144          */
145
146 #if defined(CONFIG_OABI_COMPAT)
147
148         /*
149          * If we have CONFIG_OABI_COMPAT then we need to look at the swi
150          * value to determine if it is an EABI or an old ABI call.
151          */
152 #ifdef CONFIG_ARM_THUMB
153         tst     r8, #PSR_T_BIT
154         movne   r10, #0                         @ no thumb OABI emulation
155  USER(  ldreq   r10, [lr, #-4]          )       @ get SWI instruction
156 #else
157  USER(  ldr     r10, [lr, #-4]          )       @ get SWI instruction
158 #endif
159  ARM_BE8(rev    r10, r10)                       @ little endian instruction
160
161 #elif defined(CONFIG_AEABI)
162
163         /*
164          * Pure EABI user space always put syscall number into scno (r7).
165          */
166 #elif defined(CONFIG_ARM_THUMB)
167         /* Legacy ABI only, possibly thumb mode. */
168         tst     r8, #PSR_T_BIT                  @ this is SPSR from save_user_regs
169         addne   scno, r7, #__NR_SYSCALL_BASE    @ put OS number in
170  USER(  ldreq   scno, [lr, #-4]         )
171
172 #else
173         /* Legacy ABI only. */
174  USER(  ldr     scno, [lr, #-4]         )       @ get SWI instruction
175 #endif
176
177         uaccess_disable tbl
178
179         adr     tbl, sys_call_table             @ load syscall table pointer
180
181 #if defined(CONFIG_OABI_COMPAT)
182         /*
183          * If the swi argument is zero, this is an EABI call and we do nothing.
184          *
185          * If this is an old ABI call, get the syscall number into scno and
186          * get the old ABI syscall table address.
187          */
188         bics    r10, r10, #0xff000000
189         eorne   scno, r10, #__NR_OABI_SYSCALL_BASE
190         ldrne   tbl, =sys_oabi_call_table
191 #elif !defined(CONFIG_AEABI)
192         bic     scno, scno, #0xff000000         @ mask off SWI op-code
193         eor     scno, scno, #__NR_SYSCALL_BASE  @ check OS number
194 #endif
195
196 local_restart:
197         ldr     r10, [tsk, #TI_FLAGS]           @ check for syscall tracing
198         stmdb   sp!, {r4, r5}                   @ push fifth and sixth args
199
200         tst     r10, #_TIF_SYSCALL_WORK         @ are we tracing syscalls?
201         bne     __sys_trace
202
203         cmp     scno, #NR_syscalls              @ check upper syscall limit
204         badr    lr, ret_fast_syscall            @ return address
205         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
206
207         add     r1, sp, #S_OFF
208 2:      cmp     scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
209         eor     r0, scno, #__NR_SYSCALL_BASE    @ put OS number back
210         bcs     arm_syscall
211         mov     why, #0                         @ no longer a real syscall
212         b       sys_ni_syscall                  @ not private func
213
214 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
215         /*
216          * We failed to handle a fault trying to access the page
217          * containing the swi instruction, but we're not really in a
218          * position to return -EFAULT. Instead, return back to the
219          * instruction and re-enter the user fault handling path trying
220          * to page it in. This will likely result in sending SEGV to the
221          * current task.
222          */
223 9001:
224         sub     lr, lr, #4
225         str     lr, [sp, #S_PC]
226         b       ret_fast_syscall
227 #endif
228 ENDPROC(vector_swi)
229
230         /*
231          * This is the really slow path.  We're going to be doing
232          * context switches, and waiting for our parent to respond.
233          */
234 __sys_trace:
235         mov     r1, scno
236         add     r0, sp, #S_OFF
237         bl      syscall_trace_enter
238
239         badr    lr, __sys_trace_return          @ return address
240         mov     scno, r0                        @ syscall number (possibly new)
241         add     r1, sp, #S_R0 + S_OFF           @ pointer to regs
242         cmp     scno, #NR_syscalls              @ check upper syscall limit
243         ldmccia r1, {r0 - r6}                   @ have to reload r0 - r6
244         stmccia sp, {r4, r5}                    @ and update the stack args
245         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
246         cmp     scno, #-1                       @ skip the syscall?
247         bne     2b
248         add     sp, sp, #S_OFF                  @ restore stack
249         b       ret_slow_syscall
250
251 __sys_trace_return:
252         str     r0, [sp, #S_R0 + S_OFF]!        @ save returned r0
253         mov     r0, sp
254         bl      syscall_trace_exit
255         b       ret_slow_syscall
256
257         .align  5
258 #ifdef CONFIG_ALIGNMENT_TRAP
259         .type   __cr_alignment, #object
260 __cr_alignment:
261         .word   cr_alignment
262 #endif
263         .ltorg
264
265 /*
266  * This is the syscall table declaration for native ABI syscalls.
267  * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
268  */
269 #define ABI(native, compat) native
270 #ifdef CONFIG_AEABI
271 #define OBSOLETE(syscall) sys_ni_syscall
272 #else
273 #define OBSOLETE(syscall) syscall
274 #endif
275
276         .type   sys_call_table, #object
277 ENTRY(sys_call_table)
278 #include "calls.S"
279 #undef ABI
280 #undef OBSOLETE
281
282 /*============================================================================
283  * Special system call wrappers
284  */
285 @ r0 = syscall number
286 @ r8 = syscall table
287 sys_syscall:
288                 bic     scno, r0, #__NR_OABI_SYSCALL_BASE
289                 cmp     scno, #__NR_syscall - __NR_SYSCALL_BASE
290                 cmpne   scno, #NR_syscalls      @ check range
291                 stmloia sp, {r5, r6}            @ shuffle args
292                 movlo   r0, r1
293                 movlo   r1, r2
294                 movlo   r2, r3
295                 movlo   r3, r4
296                 ldrlo   pc, [tbl, scno, lsl #2]
297                 b       sys_ni_syscall
298 ENDPROC(sys_syscall)
299
300 sys_sigreturn_wrapper:
301                 add     r0, sp, #S_OFF
302                 mov     why, #0         @ prevent syscall restart handling
303                 b       sys_sigreturn
304 ENDPROC(sys_sigreturn_wrapper)
305
306 sys_rt_sigreturn_wrapper:
307                 add     r0, sp, #S_OFF
308                 mov     why, #0         @ prevent syscall restart handling
309                 b       sys_rt_sigreturn
310 ENDPROC(sys_rt_sigreturn_wrapper)
311
312 sys_statfs64_wrapper:
313                 teq     r1, #88
314                 moveq   r1, #84
315                 b       sys_statfs64
316 ENDPROC(sys_statfs64_wrapper)
317
318 sys_fstatfs64_wrapper:
319                 teq     r1, #88
320                 moveq   r1, #84
321                 b       sys_fstatfs64
322 ENDPROC(sys_fstatfs64_wrapper)
323
324 /*
325  * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
326  * offset, we return EINVAL.
327  */
328 sys_mmap2:
329 #if PAGE_SHIFT > 12
330                 tst     r5, #PGOFF_MASK
331                 moveq   r5, r5, lsr #PAGE_SHIFT - 12
332                 streq   r5, [sp, #4]
333                 beq     sys_mmap_pgoff
334                 mov     r0, #-EINVAL
335                 ret     lr
336 #else
337                 str     r5, [sp, #4]
338                 b       sys_mmap_pgoff
339 #endif
340 ENDPROC(sys_mmap2)
341
342 #ifdef CONFIG_OABI_COMPAT
343
344 /*
345  * These are syscalls with argument register differences
346  */
347
348 sys_oabi_pread64:
349                 stmia   sp, {r3, r4}
350                 b       sys_pread64
351 ENDPROC(sys_oabi_pread64)
352
353 sys_oabi_pwrite64:
354                 stmia   sp, {r3, r4}
355                 b       sys_pwrite64
356 ENDPROC(sys_oabi_pwrite64)
357
358 sys_oabi_truncate64:
359                 mov     r3, r2
360                 mov     r2, r1
361                 b       sys_truncate64
362 ENDPROC(sys_oabi_truncate64)
363
364 sys_oabi_ftruncate64:
365                 mov     r3, r2
366                 mov     r2, r1
367                 b       sys_ftruncate64
368 ENDPROC(sys_oabi_ftruncate64)
369
370 sys_oabi_readahead:
371                 str     r3, [sp]
372                 mov     r3, r2
373                 mov     r2, r1
374                 b       sys_readahead
375 ENDPROC(sys_oabi_readahead)
376
377 /*
378  * Let's declare a second syscall table for old ABI binaries
379  * using the compatibility syscall entries.
380  */
381 #define ABI(native, compat) compat
382 #define OBSOLETE(syscall) syscall
383
384         .type   sys_oabi_call_table, #object
385 ENTRY(sys_oabi_call_table)
386 #include "calls.S"
387 #undef ABI
388 #undef OBSOLETE
389
390 #endif
391