MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / arm / kernel / entry-common.S
blob25641c658886688ef8f9c350659c491756e3715d
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  */
11 #include <asm/unistd.h>
12 #include <asm/arch/entry-macro.S>
14 #include "entry-header.S"
16 #if !defined(CONFIG_MMU)
17 #define sys_madvise             sys_ni_syscall
18 #define sys_readahead           sys_ni_syscall
19 #define sys_mprotect            sys_ni_syscall
20 #define sys_msync               sys_ni_syscall
21 #define sys_mlock               sys_ni_syscall
22 #define sys_munlock             sys_ni_syscall
23 #define sys_mlockall            sys_ni_syscall
24 #define sys_munlockall          sys_ni_syscall
25 #define sys_mremap              sys_ni_syscall
26 #define sys_mincore             sys_ni_syscall
27 #define sys_remap_file_pages    sys_ni_syscall
28 #endif /* CONFIG_MMU */
30         .align  5
32  * This is the fast syscall return path.  We do as little as
33  * possible here, and this includes saving r0 back into the SVC
34  * stack.
35  */
36 ret_fast_syscall:
37         disable_irq                             @ disable interrupts
38         ldr     r1, [tsk, #TI_FLAGS]
39         tst     r1, #_TIF_WORK_MASK
40         bne     fast_work_pending
42         @ fast_restore_user_regs
43         ldr     r1, [sp, #S_OFF + S_PSR]        @ get calling cpsr
44         ldr     lr, [sp, #S_OFF + S_PC]!        @ get pc
45         msr     spsr_cxsf, r1                   @ save in spsr_svc
46         ldmdb   sp, {r1 - lr}^                  @ get calling r1 - lr
47         mov     r0, r0
48         add     sp, sp, #S_FRAME_SIZE - S_PC
49         movs    pc, lr                          @ return & move spsr_svc into cpsr
52  * Ok, we need to do extra processing, enter the slow path.
53  */
54 fast_work_pending:
55         str     r0, [sp, #S_R0+S_OFF]!          @ returned r0
56 work_pending:
57         tst     r1, #_TIF_NEED_RESCHED
58         bne     work_resched
59         tst     r1, #_TIF_NOTIFY_RESUME | _TIF_SIGPENDING
60         beq     no_work_pending
61         mov     r0, sp                          @ 'regs'
62         mov     r2, why                         @ 'syscall'
63         bl      do_notify_resume
64         b       ret_slow_syscall                @ Check work again
66 work_resched:
67         bl      schedule
69  * "slow" syscall return path.  "why" tells us if this was a real syscall.
70  */
71 ENTRY(ret_to_user)
72 ret_slow_syscall:
73         disable_irq                             @ disable interrupts
74         ldr     r1, [tsk, #TI_FLAGS]
75         tst     r1, #_TIF_WORK_MASK
76         bne     work_pending
77 no_work_pending:
78         @ slow_restore_user_regs
79         ldr     r1, [sp, #S_PSR]                @ get calling cpsr
80         ldr     lr, [sp, #S_PC]!                @ get pc
81         msr     spsr_cxsf, r1                   @ save in spsr_svc
82         ldmdb   sp, {r0 - lr}^                  @ get calling r1 - lr
83         mov     r0, r0
84         add     sp, sp, #S_FRAME_SIZE - S_PC
85         movs    pc, lr                          @ return & move spsr_svc into cpsr
88  * This is how we return from a fork.
89  */
90 ENTRY(ret_from_fork)
91         bl      schedule_tail
92         get_thread_info tsk
93         ldr     r1, [tsk, #TI_FLAGS]            @ check for syscall tracing
94         mov     why, #1
95         tst     r1, #_TIF_SYSCALL_TRACE         @ are we tracing syscalls?
96         beq     ret_slow_syscall
97         mov     r1, sp
98         mov     r0, #1                          @ trace exit [IP = 1]
99         bl      syscall_trace
100         b       ret_slow_syscall
101         
103         .equ NR_syscalls,0
104 #define CALL(x) .equ NR_syscalls,NR_syscalls+1
105 #include "calls.S"
106 #undef CALL
107 #define CALL(x) .long x
109 /*=============================================================================
110  * SWI handler
111  *-----------------------------------------------------------------------------
112  */
114         /* If we're optimising for StrongARM the resulting code won't 
115            run on an ARM7 and we can save a couple of instructions.  
116                                                                 --pb */
117 #ifdef CONFIG_CPU_ARM710
118 #define A710(code...) code
119 .Larm710bug:
120         ldmia   sp, {r0 - lr}^                  @ Get calling r0 - lr
121         mov     r0, r0
122         add     sp, sp, #S_FRAME_SIZE
123         subs    pc, lr, #4
124 #else
125 #define A710(code...)
126 #endif
128         .align  5
129 ENTRY(vector_swi)
130         sub     sp, sp, #S_FRAME_SIZE
131         stmia   sp, {r0 - r12}                  @ Calling r0 - r12
132         add     r8, sp, #S_PC
133         stmdb   r8, {sp, lr}^                   @ Calling sp, lr
134         mrs     r8, spsr                        @ called from non-FIQ mode, so ok.
135         str     lr, [sp, #S_PC]                 @ Save calling PC
136         str     r8, [sp, #S_PSR]                @ Save CPSR
137         str     r0, [sp, #S_OLD_R0]             @ Save OLD_R0
138         zero_fp
140         /*
141          * Get the system call number.
142          */
144 #if defined(CONFIG_OABI_COMPAT)
146         /*
147          * If we have CONFIG_OABI_COMPAT then we need to look at the swi
148          * value to determine if it is an EABI or an old ABI call.
149          */
150 #ifdef CONFIG_ARM_THUMB
151         tst     r8, #PSR_T_BIT
152         movne   r10, #0                         @ no thumb OABI emulation
153         ldreq   r10, [lr, #-4]                  @ get SWI instruction
154 #else
155         ldr     r10, [lr, #-4]                  @ get SWI instruction
156   A710( and     ip, r10, #0x0f000000            @ check for SWI         )
157   A710( teq     ip, #0x0f000000                                         )
158   A710( bne     .Larm710bug                                             )
159 #endif
161 #elif defined(CONFIG_AEABI)
163         /*
164          * Pure EABI user space always put syscall number into scno (r7).
165          */
166   A710( ldr     ip, [lr, #-4]                   @ get SWI instruction   )
167   A710( and     ip, ip, #0x0f000000             @ check for SWI         )
168   A710( teq     ip, #0x0f000000                                         )
169   A710( bne     .Larm710bug                                             )
171 #elif defined(CONFIG_ARM_THUMB)
173         /* Legacy ABI only, possibly thumb mode. */
174         tst     r8, #PSR_T_BIT                  @ this is SPSR from save_user_regs
175         addne   scno, r7, #__NR_SYSCALL_BASE    @ put OS number in
176         ldreq   scno, [lr, #-4]
178 #else
180         /* Legacy ABI only. */
181         ldr     scno, [lr, #-4]                 @ get SWI instruction
182   A710( and     ip, scno, #0x0f000000           @ check for SWI         )
183   A710( teq     ip, #0x0f000000                                         )
184   A710( bne     .Larm710bug                                             )
186 #endif
188 #ifdef CONFIG_ALIGNMENT_TRAP
189         ldr     ip, __cr_alignment
190         ldr     ip, [ip]
191         mcr     p15, 0, ip, c1, c0              @ update control register
192 #endif
193         enable_irq
195         get_thread_info tsk
196         adr     tbl, sys_call_table             @ load syscall table pointer
197         ldr     ip, [tsk, #TI_FLAGS]            @ check for syscall tracing
199 #if defined(CONFIG_OABI_COMPAT)
200         /*
201          * If the swi argument is zero, this is an EABI call and we do nothing.
202          *
203          * If this is an old ABI call, get the syscall number into scno and
204          * get the old ABI syscall table address.
205          */
206         bics    r10, r10, #0xff000000
207         eorne   scno, r10, #__NR_OABI_SYSCALL_BASE
208         ldrne   tbl, =sys_oabi_call_table
209 #elif !defined(CONFIG_AEABI)
210         bic     scno, scno, #0xff000000         @ mask off SWI op-code
211         eor     scno, scno, #__NR_SYSCALL_BASE  @ check OS number
212 #endif
214         stmdb   sp!, {r4, r5}                   @ push fifth and sixth args
215         tst     ip, #_TIF_SYSCALL_TRACE         @ are we tracing syscalls?
216         bne     __sys_trace
218         cmp     scno, #NR_syscalls              @ check upper syscall limit
219         adr     lr, ret_fast_syscall            @ return address
220         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
222         add     r1, sp, #S_OFF
223 2:      mov     why, #0                         @ no longer a real syscall
224         cmp     scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
225         eor     r0, scno, #__NR_SYSCALL_BASE    @ put OS number back
226         bcs     arm_syscall     
227         b       sys_ni_syscall                  @ not private func
229         /*
230          * This is the really slow path.  We're going to be doing
231          * context switches, and waiting for our parent to respond.
232          */
233 __sys_trace:
234         mov     r2, scno
235         add     r1, sp, #S_OFF
236         mov     r0, #0                          @ trace entry [IP = 0]
237         bl      syscall_trace
239         adr     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 - r3}                   @ have to reload r0 - r3
244         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
245         b       2b
247 __sys_trace_return:
248         str     r0, [sp, #S_R0 + S_OFF]!        @ save returned r0
249         mov     r2, scno
250         mov     r1, sp
251         mov     r0, #1                          @ trace exit [IP = 1]
252         bl      syscall_trace
253         b       ret_slow_syscall
255         .align  5
256 #ifdef CONFIG_ALIGNMENT_TRAP
257         .type   __cr_alignment, #object
258 __cr_alignment:
259         .word   cr_alignment
260 #endif
261         .ltorg
264  * This is the syscall table declaration for native ABI syscalls.
265  * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
266  */
267 #define ABI(native, compat) native
268 #ifdef CONFIG_AEABI
269 #define OBSOLETE(syscall) sys_ni_syscall
270 #else
271 #define OBSOLETE(syscall) syscall
272 #endif
274         .type   sys_call_table, #object
275 ENTRY(sys_call_table)
276 #include "calls.S"
277 #undef ABI
278 #undef OBSOLETE
280 /*============================================================================
281  * Special system call wrappers
282  */
283 @ r0 = syscall number
284 @ r8 = syscall table
285                 .type   sys_syscall, #function
286 sys_syscall:
287                 bic     scno, r0, #__NR_OABI_SYSCALL_BASE
288                 cmp     scno, #__NR_syscall - __NR_SYSCALL_BASE
289                 cmpne   scno, #NR_syscalls      @ check range
290                 stmloia sp, {r5, r6}            @ shuffle args
291                 movlo   r0, r1
292                 movlo   r1, r2
293                 movlo   r2, r3
294                 movlo   r3, r4
295                 ldrlo   pc, [tbl, scno, lsl #2]
296                 b       sys_ni_syscall
298 sys_fork_wrapper:
299                 add     r0, sp, #S_OFF
300                 b       sys_fork
302 sys_vfork_wrapper:
303                 add     r0, sp, #S_OFF
304                 b       sys_vfork
306 sys_execve_wrapper:
307                 add     r3, sp, #S_OFF
308                 b       sys_execve
310 sys_clone_wrapper:
311                 add     ip, sp, #S_OFF
312                 str     ip, [sp, #4]
313                 b       sys_clone
315 sys_sigsuspend_wrapper:
316                 add     r3, sp, #S_OFF
317                 b       sys_sigsuspend
319 sys_rt_sigsuspend_wrapper:
320                 add     r2, sp, #S_OFF
321                 b       sys_rt_sigsuspend
323 sys_sigreturn_wrapper:
324                 add     r0, sp, #S_OFF
325                 b       sys_sigreturn
327 sys_rt_sigreturn_wrapper:
328                 add     r0, sp, #S_OFF
329                 b       sys_rt_sigreturn
331 sys_sigaltstack_wrapper:
332                 ldr     r2, [sp, #S_OFF + S_SP]
333                 b       do_sigaltstack
335 sys_statfs64_wrapper:
336                 teq     r1, #88
337                 moveq   r1, #84
338                 b       sys_statfs64
340 sys_fstatfs64_wrapper:
341                 teq     r1, #88
342                 moveq   r1, #84
343                 b       sys_fstatfs64
346  * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
347  * offset, we return EINVAL.
348  */
349 sys_mmap2:
350 #if PAGE_SHIFT > 12
351                 tst     r5, #PGOFF_MASK
352                 moveq   r5, r5, lsr #PAGE_SHIFT - 12
353                 streq   r5, [sp, #4]
354                 beq     do_mmap2
355                 mov     r0, #-EINVAL
356                 mov     pc, lr
357 #else
358                 str     r5, [sp, #4]
359                 b       do_mmap2
360 #endif
362 #ifdef CONFIG_OABI_COMPAT
365  * These are syscalls with argument register differences
366  */
368 sys_oabi_pread64:
369                 stmia   sp, {r3, r4}
370                 b       sys_pread64
372 sys_oabi_pwrite64:
373                 stmia   sp, {r3, r4}
374                 b       sys_pwrite64
376 sys_oabi_truncate64:
377                 mov     r3, r2
378                 mov     r2, r1
379                 b       sys_truncate64
381 sys_oabi_ftruncate64:
382                 mov     r3, r2
383                 mov     r2, r1
384                 b       sys_ftruncate64
386 sys_oabi_readahead:
387                 str     r3, [sp]
388                 mov     r3, r2
389                 mov     r2, r1
390                 b       sys_readahead
393  * Let's declare a second syscall table for old ABI binaries
394  * using the compatibility syscall entries.
395  */
396 #define ABI(native, compat) compat
397 #define OBSOLETE(syscall) syscall
399         .type   sys_oabi_call_table, #object
400 ENTRY(sys_oabi_call_table)
401 #include "calls.S"
402 #undef ABI
403 #undef OBSOLETE
405 #endif