OSDN Git Service

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