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