http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / 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
15 #include "entry-header.S"
16
17 /* 
18  * We rely on the fact that R0 is at the bottom of the stack (due to
19  * slow/fast restore user regs).
20  */
21 #if S_R0 != 0
22 #error "Please fix"
23 #endif
24
25         .align  5
26 /*
27  * This is the fast syscall return path.  We do as little as
28  * possible here, and this includes saving r0 back into the SVC
29  * stack.
30  */
31 ret_fast_syscall:
32         disable_irq r1                          @ disable interrupts
33         ldr     r1, [tsk, #TI_FLAGS]
34         tst     r1, #_TIF_WORK_MASK
35         bne     fast_work_pending
36         fast_restore_user_regs
37
38 /*
39  * Ok, we need to do extra processing, enter the slow path.
40  */
41 fast_work_pending:
42         str     r0, [sp, #S_R0+S_OFF]!          @ returned r0
43 work_pending:
44         tst     r1, #_TIF_NEED_RESCHED
45         bne     work_resched
46         tst     r1, #_TIF_NOTIFY_RESUME | _TIF_SIGPENDING
47         beq     no_work_pending
48         mov     r0, sp                          @ 'regs'
49         mov     r2, why                         @ 'syscall'
50         bl      do_notify_resume
51         disable_irq r1                          @ disable interrupts
52         b       no_work_pending
53
54 work_resched:
55         bl      schedule
56 /*
57  * "slow" syscall return path.  "why" tells us if this was a real syscall.
58  */
59 ENTRY(ret_to_user)
60 ret_slow_syscall:
61         disable_irq r1                          @ disable interrupts
62         ldr     r1, [tsk, #TI_FLAGS]
63         tst     r1, #_TIF_WORK_MASK
64         bne     work_pending
65 no_work_pending:
66         slow_restore_user_regs
67
68 /*
69  * This is how we return from a fork.
70  */
71 ENTRY(ret_from_fork)
72         bl      schedule_tail
73         get_thread_info tsk
74         ldr     r1, [tsk, #TI_FLAGS]            @ check for syscall tracing
75         mov     why, #1
76         tst     r1, #_TIF_SYSCALL_TRACE         @ are we tracing syscalls?
77         beq     ret_slow_syscall
78         mov     r1, sp
79         mov     r0, #1                          @ trace exit [IP = 1]
80         bl      syscall_trace
81         b       ret_slow_syscall
82         
83
84 #include "calls.S"
85
86 /*=============================================================================
87  * SWI handler
88  *-----------------------------------------------------------------------------
89  */
90
91         /* If we're optimising for StrongARM the resulting code won't 
92            run on an ARM7 and we can save a couple of instructions.  
93                                                                 --pb */
94 #ifdef CONFIG_CPU_ARM710
95         .macro  arm710_bug_check, instr, temp
96         and     \temp, \instr, #0x0f000000      @ check for SWI
97         teq     \temp, #0x0f000000
98         bne     .Larm700bug
99         .endm
100
101 .Larm700bug:
102         ldr     r0, [sp, #S_PSR]                @ Get calling cpsr
103         sub     lr, lr, #4
104         str     lr, [r8]
105         msr     spsr_cxsf, r0
106         ldmia   sp, {r0 - lr}^                  @ Get calling r0 - lr
107         mov     r0, r0
108         ldr     lr, [sp, #S_PC]                 @ Get PC
109         add     sp, sp, #S_FRAME_SIZE
110         movs    pc, lr
111 #else
112         .macro  arm710_bug_check, instr, temp
113         .endm
114 #endif
115
116         .align  5
117 ENTRY(vector_swi)
118         save_user_regs
119         zero_fp
120         get_scno
121         arm710_bug_check scno, ip
122
123 #ifdef CONFIG_ALIGNMENT_TRAP
124         ldr     ip, __cr_alignment
125         ldr     ip, [ip]
126         mcr     p15, 0, ip, c1, c0              @ update control register
127 #endif
128         enable_irq ip
129
130         str     r4, [sp, #-S_OFF]!              @ push fifth arg
131
132         get_thread_info tsk
133         ldr     ip, [tsk, #TI_FLAGS]            @ check for syscall tracing
134         bic     scno, scno, #0xff000000         @ mask off SWI op-code
135         eor     scno, scno, #OS_NUMBER << 20    @ check OS number
136         adr     tbl, sys_call_table             @ load syscall table pointer
137         tst     ip, #_TIF_SYSCALL_TRACE         @ are we tracing syscalls?
138         bne     __sys_trace
139
140         adrsvc  al, lr, ret_fast_syscall        @ return address
141         cmp     scno, #NR_syscalls              @ check upper syscall limit
142         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
143
144         add     r1, sp, #S_OFF
145 2:      mov     why, #0                         @ no longer a real syscall
146         cmp     scno, #ARMSWI_OFFSET
147         eor     r0, scno, #OS_NUMBER << 20      @ put OS number back
148         bcs     arm_syscall     
149         b       sys_ni_syscall                  @ not private func
150
151         /*
152          * This is the really slow path.  We're going to be doing
153          * context switches, and waiting for our parent to respond.
154          */
155 __sys_trace:
156         add     r1, sp, #S_OFF
157         mov     r0, #0                          @ trace entry [IP = 0]
158         bl      syscall_trace
159
160         adrsvc  al, lr, __sys_trace_return      @ return address
161         add     r1, sp, #S_R0 + S_OFF           @ pointer to regs
162         cmp     scno, #NR_syscalls              @ check upper syscall limit
163         ldmccia r1, {r0 - r3}                   @ have to reload r0 - r3
164         ldrcc   pc, [tbl, scno, lsl #2]         @ call sys_* routine
165         b       2b
166
167 __sys_trace_return:
168         str     r0, [sp, #S_R0 + S_OFF]!        @ save returned r0
169         mov     r1, sp
170         mov     r0, #1                          @ trace exit [IP = 1]
171         bl      syscall_trace
172         b       ret_slow_syscall
173
174         .align  5
175 #ifdef CONFIG_ALIGNMENT_TRAP
176         .type   __cr_alignment, #object
177 __cr_alignment:
178         .word   cr_alignment
179 #endif
180
181         .type   sys_call_table, #object
182 ENTRY(sys_call_table)
183 #include "calls.S"
184
185 /*============================================================================
186  * Special system call wrappers
187  */
188 @ r0 = syscall number
189 @ r5 = syscall table
190                 .type   sys_syscall, #function
191 sys_syscall:
192                 eor     scno, r0, #OS_NUMBER << 20
193                 cmp     scno, #NR_syscalls      @ check range
194                 stmleia sp, {r5, r6}            @ shuffle args
195                 movle   r0, r1
196                 movle   r1, r2
197                 movle   r2, r3
198                 movle   r3, r4
199                 ldrle   pc, [tbl, scno, lsl #2]
200                 b       sys_ni_syscall
201
202 sys_fork_wrapper:
203                 add     r0, sp, #S_OFF
204                 b       sys_fork
205
206 sys_vfork_wrapper:
207                 add     r0, sp, #S_OFF
208                 b       sys_vfork
209
210 sys_execve_wrapper:
211                 add     r3, sp, #S_OFF
212                 b       sys_execve
213
214 sys_clone_wapper:
215                 add     r2, sp, #S_OFF
216                 b       sys_clone
217
218 sys_sigsuspend_wrapper:
219                 add     r3, sp, #S_OFF
220                 b       sys_sigsuspend
221
222 sys_rt_sigsuspend_wrapper:
223                 add     r2, sp, #S_OFF
224                 b       sys_rt_sigsuspend
225
226 sys_sigreturn_wrapper:
227                 add     r0, sp, #S_OFF
228                 b       sys_sigreturn
229
230 sys_rt_sigreturn_wrapper:
231                 add     r0, sp, #S_OFF
232                 b       sys_rt_sigreturn
233
234 sys_sigaltstack_wrapper:
235                 ldr     r2, [sp, #S_OFF + S_SP]
236                 b       do_sigaltstack
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