blob: 379b2878ee3059917ccb8cf41a3d8e3577e39491 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * linux/arch/arm/kernel/entry-armv.S
3 *
4 * Copyright (C) 1996,1997,1998 Russell King.
5 * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk)
6 * nommu support by Hyok S. Choi (hyok.choi@samsung.com)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Low-level vector interface routines
13 *
14 * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction
15 * that causes it to save wrong values... Be aware!
16 */
17
18#include <asm/assembler.h>
19#include <asm/memory.h>
20#include <asm/glue-df.h>
21#include <asm/glue-pf.h>
22#include <asm/vfpmacros.h>
23#ifndef CONFIG_MULTI_IRQ_HANDLER
24#include <mach/entry-macro.S>
25#endif
26#include <asm/thread_notify.h>
27#include <asm/unwind.h>
28#include <asm/unistd.h>
29#include <asm/tls.h>
30#include <asm/system_info.h>
31
32#include "entry-header.S"
33#include <asm/entry-macro-multi.S>
34
35#ifdef CONFIG_IRQ_STACK
36.globl irq_handler_stack_top
37#endif
38
39/*
40 * Interrupt handling.
41 */
42 .macro irq_handler
43#ifdef CONFIG_MULTI_IRQ_HANDLER
44 ldr r1, =handle_arch_irq
45 mov r0, sp
46 adr lr, BSYM(9997f)
47 ldr pc, [r1]
48#else
49 arch_irq_handler_default
50#endif
519997:
52 .endm
53
54 .macro pabt_helper
55 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
56#ifdef MULTI_PABORT
57 ldr ip, .LCprocfns
58 mov lr, pc
59 ldr pc, [ip, #PROCESSOR_PABT_FUNC]
60#else
61 bl CPU_PABORT_HANDLER
62#endif
63 .endm
64
65 .macro dabt_helper
66
67 @
68 @ Call the processor-specific abort handler:
69 @
70 @ r2 - pt_regs
71 @ r4 - aborted context pc
72 @ r5 - aborted context psr
73 @
74 @ The abort handler must return the aborted address in r0, and
75 @ the fault status register in r1. r9 must be preserved.
76 @
77#ifdef MULTI_DABORT
78 ldr ip, .LCprocfns
79 mov lr, pc
80 ldr pc, [ip, #PROCESSOR_DABT_FUNC]
81#else
82 bl CPU_DABORT_HANDLER
83#endif
84 .endm
85
86#ifdef CONFIG_KPROBES
87 .section .kprobes.text,"ax",%progbits
88#else
89 .text
90#endif
91
92/*
93 * Invalid mode handlers
94 */
95 .macro inv_entry, reason
96 sub sp, sp, #S_FRAME_SIZE
97 ARM( stmib sp, {r1 - lr} )
98 THUMB( stmia sp, {r0 - r12} )
99 THUMB( str sp, [sp, #S_SP] )
100 THUMB( str lr, [sp, #S_LR] )
101 mov r1, #\reason
102 .endm
103
104__pabt_invalid:
105 inv_entry BAD_PREFETCH
106 b common_invalid
107ENDPROC(__pabt_invalid)
108
109__dabt_invalid:
110 inv_entry BAD_DATA
111 b common_invalid
112ENDPROC(__dabt_invalid)
113
114__irq_invalid:
115 inv_entry BAD_IRQ
116 b common_invalid
117ENDPROC(__irq_invalid)
118
119__und_invalid:
120 inv_entry BAD_UNDEFINSTR
121
122 @
123 @ XXX fall through to common_invalid
124 @
125
126@
127@ common_invalid - generic code for failed exception (re-entrant version of handlers)
128@
129common_invalid:
130 zero_fp
131
132 ldmia r0, {r4 - r6}
133 add r0, sp, #S_PC @ here for interlock avoidance
134 mov r7, #-1 @ "" "" "" ""
135 str r4, [sp] @ save preserved r0
136 stmia r0, {r5 - r7} @ lr_<exception>,
137 @ cpsr_<exception>, "old_r0"
138
139 mov r0, sp
140 b bad_mode
141ENDPROC(__und_invalid)
142
143/*
144 * SVC mode handlers
145 */
146
147#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
148#define SPFIX(code...) code
149#else
150#define SPFIX(code...)
151#endif
152
153 .macro svc_entry, stack_hole=0
154 UNWIND(.fnstart )
155 UNWIND(.save {r0 - pc} )
156 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
157#ifdef CONFIG_THUMB2_KERNEL
158 SPFIX( str r0, [sp] ) @ temporarily saved
159 SPFIX( mov r0, sp )
160 SPFIX( tst r0, #4 ) @ test original stack alignment
161 SPFIX( ldr r0, [sp] ) @ restored
162#else
163 SPFIX( tst sp, #4 )
164#endif
165 SPFIX( subeq sp, sp, #4 )
166 stmia sp, {r1 - r12}
167
168 ldmia r0, {r3 - r5}
169 add r7, sp, #S_SP - 4 @ here for interlock avoidance
170 mov r6, #-1 @ "" "" "" ""
171 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
172 SPFIX( addeq r2, r2, #4 )
173 str r3, [sp, #-4]! @ save the "real" r0 copied
174 @ from the exception stack
175
176 mov r3, lr
177
178 @
179 @ We are now ready to fill in the remaining blanks on the stack:
180 @
181 @ r2 - sp_svc
182 @ r3 - lr_svc
183 @ r4 - lr_<exception>, already fixed up for correct return/restart
184 @ r5 - spsr_<exception>
185 @ r6 - orig_r0 (see pt_regs definition in ptrace.h)
186 @
187 stmia r7, {r2 - r6}
188
189#ifdef CONFIG_TRACE_IRQFLAGS
190 bl trace_hardirqs_off
191#endif
192 .endm
193
194 .align 5
195__dabt_svc:
196 svc_entry
197 mov r2, sp
198 dabt_helper
199
200 @
201 @ IRQs off again before pulling preserved data off the stack
202 @
203 disable_irq_notrace
204
205#ifdef CONFIG_TRACE_IRQFLAGS
206 tst r5, #PSR_I_BIT
207 bleq trace_hardirqs_on
208 tst r5, #PSR_I_BIT
209 blne trace_hardirqs_off
210#endif
211 svc_exit r5 @ return from exception
212 UNWIND(.fnend )
213ENDPROC(__dabt_svc)
214
215 .align 5
216__irq_svc:
217 svc_entry
218#ifdef CONFIG_IRQ_STACK
219 mov r6, sp
220 ldr sp, =irq_handler_stack_top
221#endif
222 irq_handler
223#ifdef CONFIG_IRQ_STACK
224 mov sp, r6
225#endif
226
227#ifdef CONFIG_PREEMPT
228 get_thread_info tsk
229 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
230 ldr r0, [tsk, #TI_FLAGS] @ get flags
231 teq r8, #0 @ if preempt count != 0
232 movne r0, #0 @ force flags to 0
233 tst r0, #_TIF_NEED_RESCHED
234 blne svc_preempt
235#endif
236
237#ifdef CONFIG_TRACE_IRQFLAGS
238 @ The parent context IRQs must have been enabled to get here in
239 @ the first place, so there's no point checking the PSR I bit.
240 bl trace_hardirqs_on
241#endif
242 svc_exit r5 @ return from exception
243 UNWIND(.fnend )
244ENDPROC(__irq_svc)
245
246 .ltorg
247
248#ifdef CONFIG_PREEMPT
249svc_preempt:
250 mov r8, lr
2511: bl preempt_schedule_irq @ irq en/disable is done inside
252 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
253 tst r0, #_TIF_NEED_RESCHED
254 moveq pc, r8 @ go again
255 b 1b
256#endif
257
258__und_fault:
259 @ Correct the PC such that it is pointing at the instruction
260 @ which caused the fault. If the faulting instruction was ARM
261 @ the PC will be pointing at the next instruction, and have to
262 @ subtract 4. Otherwise, it is Thumb, and the PC will be
263 @ pointing at the second half of the Thumb instruction. We
264 @ have to subtract 2.
265 ldr r2, [r0, #S_PC]
266 sub r2, r2, r1
267 str r2, [r0, #S_PC]
268 b do_undefinstr
269ENDPROC(__und_fault)
270
271 .align 5
272__und_svc:
273#ifdef CONFIG_KPROBES
274 @ If a kprobe is about to simulate a "stmdb sp..." instruction,
275 @ it obviously needs free stack space which then will belong to
276 @ the saved context.
277 svc_entry 64
278#else
279 svc_entry
280#endif
281 @
282 @ call emulation code, which returns using r9 if it has emulated
283 @ the instruction, or the more conventional lr if we are to treat
284 @ this as a real undefined instruction
285 @
286 @ r0 - instruction
287 @
288#ifndef CONFIG_THUMB2_KERNEL
289 ldr r0, [r4, #-4]
290#else
291 mov r1, #2
292 ldrh r0, [r4, #-2] @ Thumb instruction at LR - 2
293 cmp r0, #0xe800 @ 32-bit instruction if xx >= 0
294 blo __und_svc_fault
295 ldrh r9, [r4] @ bottom 16 bits
296 add r4, r4, #2
297 str r4, [sp, #S_PC]
298 orr r0, r9, r0, lsl #16
299#endif
300 adr r9, BSYM(__und_svc_finish)
301 mov r2, r4
302 bl call_fpe
303
304 mov r1, #4 @ PC correction to apply
305__und_svc_fault:
306 mov r0, sp @ struct pt_regs *regs
307 bl __und_fault
308
309 @
310 @ IRQs off again before pulling preserved data off the stack
311 @
312__und_svc_finish:
313 disable_irq_notrace
314
315 @
316 @ restore SPSR and restart the instruction
317 @
318 ldr r5, [sp, #S_PSR] @ Get SVC cpsr
319#ifdef CONFIG_TRACE_IRQFLAGS
320 tst r5, #PSR_I_BIT
321 bleq trace_hardirqs_on
322 tst r5, #PSR_I_BIT
323 blne trace_hardirqs_off
324#endif
325 svc_exit r5 @ return from exception
326 UNWIND(.fnend )
327ENDPROC(__und_svc)
328
329 .align 5
330__pabt_svc:
331 svc_entry
332 mov r2, sp @ regs
333 pabt_helper
334
335 @
336 @ IRQs off again before pulling preserved data off the stack
337 @
338 disable_irq_notrace
339
340#ifdef CONFIG_TRACE_IRQFLAGS
341 tst r5, #PSR_I_BIT
342 bleq trace_hardirqs_on
343 tst r5, #PSR_I_BIT
344 blne trace_hardirqs_off
345#endif
346 svc_exit r5 @ return from exception
347 UNWIND(.fnend )
348ENDPROC(__pabt_svc)
349
350 .align 5
351.LCcralign:
352 .word cr_alignment
353#ifdef MULTI_DABORT
354.LCprocfns:
355 .word processor
356#endif
357.LCfp:
358 .word fp_enter
359
360/*
361 * User mode handlers
362 *
363 * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
364 */
365
366#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
367#error "sizeof(struct pt_regs) must be a multiple of 8"
368#endif
369
370 .macro usr_entry
371 UNWIND(.fnstart )
372 UNWIND(.cantunwind ) @ don't unwind the user space
373 sub sp, sp, #S_FRAME_SIZE
374 ARM( stmib sp, {r1 - r12} )
375 THUMB( stmia sp, {r0 - r12} )
376
377 ldmia r0, {r3 - r5}
378 add r0, sp, #S_PC @ here for interlock avoidance
379 mov r6, #-1 @ "" "" "" ""
380
381 str r3, [sp] @ save the "real" r0 copied
382 @ from the exception stack
383
384 @
385 @ We are now ready to fill in the remaining blanks on the stack:
386 @
387 @ r4 - lr_<exception>, already fixed up for correct return/restart
388 @ r5 - spsr_<exception>
389 @ r6 - orig_r0 (see pt_regs definition in ptrace.h)
390 @
391 @ Also, separately save sp_usr and lr_usr
392 @
393 stmia r0, {r4 - r6}
394 ARM( stmdb r0, {sp, lr}^ )
395 THUMB( store_user_sp_lr r0, r1, S_SP - S_PC )
396
397 @
398 @ Enable the alignment trap while in kernel mode
399 @
400 alignment_trap r0
401
402 @
403 @ Clear FP to mark the first stack frame
404 @
405 zero_fp
406
407#ifdef CONFIG_IRQSOFF_TRACER
408 bl trace_hardirqs_off
409#endif
410 .endm
411
412 .macro kuser_cmpxchg_check
413#if !defined(CONFIG_CPU_32v6K) && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
414#ifndef CONFIG_MMU
415#warning "NPTL on non MMU needs fixing"
416#else
417 @ Make sure our user space atomic helper is restarted
418 @ if it was interrupted in a critical region. Here we
419 @ perform a quick test inline since it should be false
420 @ 99.9999% of the time. The rest is done out of line.
421 cmp r4, #TASK_SIZE
422 blhs kuser_cmpxchg64_fixup
423#endif
424#endif
425 .endm
426
427 .align 5
428__dabt_usr:
429 usr_entry
430 kuser_cmpxchg_check
431 mov r2, sp
432 dabt_helper
433 b ret_from_exception
434 UNWIND(.fnend )
435ENDPROC(__dabt_usr)
436
437 .align 5
438__irq_usr:
439 usr_entry
440 kuser_cmpxchg_check
441#ifdef CONFIG_IRQ_STACK
442 mov r6, sp
443 ldr sp, =irq_handler_stack_top
444#endif
445 irq_handler
446#ifdef CONFIG_IRQ_STACK
447 mov sp, r6
448#endif
449
450 get_thread_info tsk
451 mov why, #0
452 b ret_to_user_from_irq
453 UNWIND(.fnend )
454ENDPROC(__irq_usr)
455
456 .ltorg
457
458 .align 5
459__und_usr:
460 usr_entry
461
462 mov r2, r4
463 mov r3, r5
464
465 @ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the
466 @ faulting instruction depending on Thumb mode.
467 @ r3 = regs->ARM_cpsr
468 @
469 @ The emulation code returns using r9 if it has emulated the
470 @ instruction, or the more conventional lr if we are to treat
471 @ this as a real undefined instruction
472 @
473 adr r9, BSYM(ret_from_exception)
474
475 tst r3, #PSR_T_BIT @ Thumb mode?
476 bne __und_usr_thumb
477 sub r4, r2, #4 @ ARM instr at LR - 4
4781: ldrt r0, [r4]
479#ifdef CONFIG_CPU_ENDIAN_BE8
480 rev r0, r0 @ little endian instruction
481#endif
482 @ r0 = 32-bit ARM instruction which caused the exception
483 @ r2 = PC value for the following instruction (:= regs->ARM_pc)
484 @ r4 = PC value for the faulting instruction
485 @ lr = 32-bit undefined instruction function
486 adr lr, BSYM(__und_usr_fault_32)
487 b call_fpe
488
489__und_usr_thumb:
490 @ Thumb instruction
491 sub r4, r2, #2 @ First half of thumb instr at LR - 2
492#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
493/*
494 * Thumb-2 instruction handling. Note that because pre-v6 and >= v6 platforms
495 * can never be supported in a single kernel, this code is not applicable at
496 * all when __LINUX_ARM_ARCH__ < 6. This allows simplifying assumptions to be
497 * made about .arch directives.
498 */
499#if __LINUX_ARM_ARCH__ < 7
500/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */
501#define NEED_CPU_ARCHITECTURE
502 ldr r5, .LCcpu_architecture
503 ldr r5, [r5]
504 cmp r5, #CPU_ARCH_ARMv7
505 blo __und_usr_fault_16 @ 16bit undefined instruction
506/*
507 * The following code won't get run unless the running CPU really is v7, so
508 * coding round the lack of ldrht on older arches is pointless. Temporarily
509 * override the assembler target arch with the minimum required instead:
510 */
511 .arch armv6t2
512#endif
5132: ldrht r5, [r4]
514 cmp r5, #0xe800 @ 32bit instruction if xx != 0
515 blo __und_usr_fault_16 @ 16bit undefined instruction
5163: ldrht r0, [r2]
517 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
518 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
519 orr r0, r0, r5, lsl #16
520 adr lr, BSYM(__und_usr_fault_32)
521 @ r0 = the two 16-bit Thumb instructions which caused the exception
522 @ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc)
523 @ r4 = PC value for the first 16-bit Thumb instruction
524 @ lr = 32bit undefined instruction function
525
526#if __LINUX_ARM_ARCH__ < 7
527/* If the target arch was overridden, change it back: */
528#ifdef CONFIG_CPU_32v6K
529 .arch armv6k
530#else
531 .arch armv6
532#endif
533#endif /* __LINUX_ARM_ARCH__ < 7 */
534#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */
535 b __und_usr_fault_16
536#endif
537 UNWIND(.fnend)
538ENDPROC(__und_usr)
539
540/*
541 * The out of line fixup for the ldrt instructions above.
542 */
543 .pushsection .fixup, "ax"
5444: mov pc, r9
545 .popsection
546 .pushsection __ex_table,"a"
547 .long 1b, 4b
548#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
549 .long 2b, 4b
550 .long 3b, 4b
551#endif
552 .popsection
553
554/*
555 * Check whether the instruction is a co-processor instruction.
556 * If yes, we need to call the relevant co-processor handler.
557 *
558 * Note that we don't do a full check here for the co-processor
559 * instructions; all instructions with bit 27 set are well
560 * defined. The only instructions that should fault are the
561 * co-processor instructions. However, we have to watch out
562 * for the ARM6/ARM7 SWI bug.
563 *
564 * NEON is a special case that has to be handled here. Not all
565 * NEON instructions are co-processor instructions, so we have
566 * to make a special case of checking for them. Plus, there's
567 * five groups of them, so we have a table of mask/opcode pairs
568 * to check against, and if any match then we branch off into the
569 * NEON handler code.
570 *
571 * Emulators may wish to make use of the following registers:
572 * r0 = instruction opcode (32-bit ARM or two 16-bit Thumb)
573 * r2 = PC value to resume execution after successful emulation
574 * r9 = normal "successful" return address
575 * r10 = this threads thread_info structure
576 * lr = unrecognised instruction return address
577 * IRQs disabled, FIQs enabled.
578 */
579 @
580 @ Fall-through from Thumb-2 __und_usr
581 @
582#ifdef CONFIG_NEON
583 adr r6, .LCneon_thumb_opcodes
584 b 2f
585#endif
586call_fpe:
587#ifdef CONFIG_NEON
588 adr r6, .LCneon_arm_opcodes
5892:
590 ldr r7, [r6], #4 @ mask value
591 cmp r7, #0 @ end mask?
592 beq 1f
593 and r8, r0, r7
594 ldr r7, [r6], #4 @ opcode bits matching in mask
595 cmp r8, r7 @ NEON instruction?
596 bne 2b
597 get_thread_info r10
598 mov r7, #1
599 strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
600 strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
601 b do_vfp @ let VFP handler handle this
6021:
603#endif
604 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
605 tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
606#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
607 and r8, r0, #0x0f000000 @ mask out op-code bits
608 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
609#endif
610 moveq pc, lr
611 get_thread_info r10 @ get current thread
612 and r8, r0, #0x00000f00 @ mask out CP number
613 THUMB( lsr r8, r8, #8 )
614 mov r7, #1
615 add r6, r10, #TI_USED_CP
616 ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[]
617 THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[]
618#ifdef CONFIG_IWMMXT
619 @ Test if we need to give access to iWMMXt coprocessors
620 ldr r5, [r10, #TI_FLAGS]
621 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
622 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
623 bcs iwmmxt_task_enable
624#endif
625 ARM( add pc, pc, r8, lsr #6 )
626 THUMB( lsl r8, r8, #2 )
627 THUMB( add pc, r8 )
628 nop
629
630 movw_pc lr @ CP#0
631 W(b) do_fpe @ CP#1 (FPE)
632 W(b) do_fpe @ CP#2 (FPE)
633 movw_pc lr @ CP#3
634#ifdef CONFIG_CRUNCH
635 b crunch_task_enable @ CP#4 (MaverickCrunch)
636 b crunch_task_enable @ CP#5 (MaverickCrunch)
637 b crunch_task_enable @ CP#6 (MaverickCrunch)
638#else
639 movw_pc lr @ CP#4
640 movw_pc lr @ CP#5
641 movw_pc lr @ CP#6
642#endif
643 movw_pc lr @ CP#7
644 movw_pc lr @ CP#8
645 movw_pc lr @ CP#9
646#ifdef CONFIG_VFP
647 W(b) do_vfp @ CP#10 (VFP)
648 W(b) do_vfp @ CP#11 (VFP)
649#else
650 movw_pc lr @ CP#10 (VFP)
651 movw_pc lr @ CP#11 (VFP)
652#endif
653 movw_pc lr @ CP#12
654 movw_pc lr @ CP#13
655 movw_pc lr @ CP#14 (Debug)
656 movw_pc lr @ CP#15 (Control)
657
658#ifdef NEED_CPU_ARCHITECTURE
659 .align 2
660.LCcpu_architecture:
661 .word __cpu_architecture
662#endif
663
664#ifdef CONFIG_NEON
665 .align 6
666
667.LCneon_arm_opcodes:
668 .word 0xfe000000 @ mask
669 .word 0xf2000000 @ opcode
670
671 .word 0xff100000 @ mask
672 .word 0xf4000000 @ opcode
673
674 .word 0x00000000 @ mask
675 .word 0x00000000 @ opcode
676
677.LCneon_thumb_opcodes:
678 .word 0xef000000 @ mask
679 .word 0xef000000 @ opcode
680
681 .word 0xff100000 @ mask
682 .word 0xf9000000 @ opcode
683
684 .word 0x00000000 @ mask
685 .word 0x00000000 @ opcode
686#endif
687
688do_fpe:
689 enable_irq
690 ldr r4, .LCfp
691 add r10, r10, #TI_FPSTATE @ r10 = workspace
692 ldr pc, [r4] @ Call FP module USR entry point
693
694/*
695 * The FP module is called with these registers set:
696 * r0 = instruction
697 * r2 = PC+4
698 * r9 = normal "successful" return address
699 * r10 = FP workspace
700 * lr = unrecognised FP instruction return address
701 */
702
703 .pushsection .data
704ENTRY(fp_enter)
705 .word no_fp
706 .popsection
707
708ENTRY(no_fp)
709 mov pc, lr
710ENDPROC(no_fp)
711
712__und_usr_fault_32:
713 mov r1, #4
714 b 1f
715__und_usr_fault_16:
716 mov r1, #2
7171: enable_irq
718 mov r0, sp
719 adr lr, BSYM(ret_from_exception)
720 b __und_fault
721ENDPROC(__und_usr_fault_32)
722ENDPROC(__und_usr_fault_16)
723
724 .align 5
725__pabt_usr:
726 usr_entry
727 mov r2, sp @ regs
728 pabt_helper
729 UNWIND(.fnend )
730 /* fall through */
731/*
732 * This is the return code to user mode for abort handlers
733 */
734ENTRY(ret_from_exception)
735 UNWIND(.fnstart )
736 UNWIND(.cantunwind )
737 get_thread_info tsk
738 mov why, #0
739 b ret_to_user
740 UNWIND(.fnend )
741ENDPROC(__pabt_usr)
742ENDPROC(ret_from_exception)
743
744/*
745 * Register switch for ARMv3 and ARMv4 processors
746 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
747 * previous and next are guaranteed not to be the same.
748 */
749ENTRY(__switch_to)
750 UNWIND(.fnstart )
751 UNWIND(.cantunwind )
752 add ip, r1, #TI_CPU_SAVE
753 ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack
754 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
755 THUMB( str sp, [ip], #4 )
756 THUMB( str lr, [ip], #4 )
757 ldr r4, [r2, #TI_TP_VALUE]
758 ldr r5, [r2, #TI_TP_VALUE + 4]
759#ifdef CONFIG_CPU_USE_DOMAINS
760 ldr r6, [r2, #TI_CPU_DOMAIN]
761#endif
762 switch_tls r1, r4, r5, r3, r7
763#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
764 ldr r7, [r2, #TI_TASK]
765 ldr r8, =__stack_chk_guard
766 ldr r7, [r7, #TSK_STACK_CANARY]
767#endif
768#ifdef CONFIG_CPU_USE_DOMAINS
769 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
770#endif
771 mov r5, r0
772 add r4, r2, #TI_CPU_SAVE
773 ldr r0, =thread_notify_head
774 mov r1, #THREAD_NOTIFY_SWITCH
775 bl atomic_notifier_call_chain
776#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
777 str r7, [r8]
778#endif
779 THUMB( mov ip, r4 )
780 mov r0, r5
781 ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously
782 THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously
783 THUMB( ldr sp, [ip], #4 )
784 THUMB( ldr pc, [ip] )
785 UNWIND(.fnend )
786ENDPROC(__switch_to)
787
788 __INIT
789
790/*
791 * User helpers.
792 *
793 * Each segment is 32-byte aligned and will be moved to the top of the high
794 * vector page. New segments (if ever needed) must be added in front of
795 * existing ones. This mechanism should be used only for things that are
796 * really small and justified, and not be abused freely.
797 *
798 * See Documentation/arm/kernel_user_helpers.txt for formal definitions.
799 */
800 THUMB( .arm )
801
802 .macro usr_ret, reg
803#ifdef CONFIG_ARM_THUMB
804 bx \reg
805#else
806 mov pc, \reg
807#endif
808 .endm
809
810 .align 5
811 .globl __kuser_helper_start
812__kuser_helper_start:
813
814/*
815 * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular
816 * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point.
817 */
818
819__kuser_cmpxchg64: @ 0xffff0f60
820
821#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
822
823 /*
824 * Poor you. No fast solution possible...
825 * The kernel itself must perform the operation.
826 * A special ghost syscall is used for that (see traps.c).
827 */
828 stmfd sp!, {r7, lr}
829 ldr r7, 1f @ it's 20 bits
830 swi __ARM_NR_cmpxchg64
831 ldmfd sp!, {r7, pc}
8321: .word __ARM_NR_cmpxchg64
833
834#elif defined(CONFIG_CPU_32v6K)
835
836 stmfd sp!, {r4, r5, r6, r7}
837 ldrd r4, r5, [r0] @ load old val
838 ldrd r6, r7, [r1] @ load new val
839 smp_dmb arm
8401: ldrexd r0, r1, [r2] @ load current val
841 eors r3, r0, r4 @ compare with oldval (1)
842 eoreqs r3, r1, r5 @ compare with oldval (2)
843 strexdeq r3, r6, r7, [r2] @ store newval if eq
844 teqeq r3, #1 @ success?
845 beq 1b @ if no then retry
846 smp_dmb arm
847 rsbs r0, r3, #0 @ set returned val and C flag
848 ldmfd sp!, {r4, r5, r6, r7}
849 usr_ret lr
850
851#elif !defined(CONFIG_SMP)
852
853#ifdef CONFIG_MMU
854
855 /*
856 * The only thing that can break atomicity in this cmpxchg64
857 * implementation is either an IRQ or a data abort exception
858 * causing another process/thread to be scheduled in the middle of
859 * the critical sequence. The same strategy as for cmpxchg is used.
860 */
861 stmfd sp!, {r4, r5, r6, lr}
862 ldmia r0, {r4, r5} @ load old val
863 ldmia r1, {r6, lr} @ load new val
8641: ldmia r2, {r0, r1} @ load current val
865 eors r3, r0, r4 @ compare with oldval (1)
866 eoreqs r3, r1, r5 @ compare with oldval (2)
8672: stmeqia r2, {r6, lr} @ store newval if eq
868 rsbs r0, r3, #0 @ set return val and C flag
869 ldmfd sp!, {r4, r5, r6, pc}
870
871 .text
872kuser_cmpxchg64_fixup:
873 @ Called from kuser_cmpxchg_fixup.
874 @ r4 = address of interrupted insn (must be preserved).
875 @ sp = saved regs. r7 and r8 are clobbered.
876 @ 1b = first critical insn, 2b = last critical insn.
877 @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
878 mov r7, #0xffff0fff
879 sub r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64)))
880 subs r8, r4, r7
881 rsbcss r8, r8, #(2b - 1b)
882 strcs r7, [sp, #S_PC]
883#if __LINUX_ARM_ARCH__ < 6
884 bcc kuser_cmpxchg32_fixup
885#endif
886 mov pc, lr
887 .previous
888
889#else
890#warning "NPTL on non MMU needs fixing"
891 mov r0, #-1
892 adds r0, r0, #0
893 usr_ret lr
894#endif
895
896#else
897#error "incoherent kernel configuration"
898#endif
899
900 /* pad to next slot */
901 .rept (16 - (. - __kuser_cmpxchg64)/4)
902 .word 0
903 .endr
904
905 .align 5
906
907__kuser_memory_barrier: @ 0xffff0fa0
908 smp_dmb arm
909 usr_ret lr
910
911 .align 5
912
913__kuser_cmpxchg: @ 0xffff0fc0
914
915#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
916
917 /*
918 * Poor you. No fast solution possible...
919 * The kernel itself must perform the operation.
920 * A special ghost syscall is used for that (see traps.c).
921 */
922 stmfd sp!, {r7, lr}
923 ldr r7, 1f @ it's 20 bits
924 swi __ARM_NR_cmpxchg
925 ldmfd sp!, {r7, pc}
9261: .word __ARM_NR_cmpxchg
927
928#elif __LINUX_ARM_ARCH__ < 6
929
930#ifdef CONFIG_MMU
931
932 /*
933 * The only thing that can break atomicity in this cmpxchg
934 * implementation is either an IRQ or a data abort exception
935 * causing another process/thread to be scheduled in the middle
936 * of the critical sequence. To prevent this, code is added to
937 * the IRQ and data abort exception handlers to set the pc back
938 * to the beginning of the critical section if it is found to be
939 * within that critical section (see kuser_cmpxchg_fixup).
940 */
9411: ldr r3, [r2] @ load current val
942 subs r3, r3, r0 @ compare with oldval
9432: streq r1, [r2] @ store newval if eq
944 rsbs r0, r3, #0 @ set return val and C flag
945 usr_ret lr
946
947 .text
948kuser_cmpxchg32_fixup:
949 @ Called from kuser_cmpxchg_check macro.
950 @ r4 = address of interrupted insn (must be preserved).
951 @ sp = saved regs. r7 and r8 are clobbered.
952 @ 1b = first critical insn, 2b = last critical insn.
953 @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
954 mov r7, #0xffff0fff
955 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
956 subs r8, r4, r7
957 rsbcss r8, r8, #(2b - 1b)
958 strcs r7, [sp, #S_PC]
959 mov pc, lr
960 .previous
961
962#else
963#warning "NPTL on non MMU needs fixing"
964 mov r0, #-1
965 adds r0, r0, #0
966 usr_ret lr
967#endif
968
969#else
970
971 smp_dmb arm
9721: ldrex r3, [r2]
973 subs r3, r3, r0
974 strexeq r3, r1, [r2]
975 teqeq r3, #1
976 beq 1b
977 rsbs r0, r3, #0
978 /* beware -- each __kuser slot must be 8 instructions max */
979 ALT_SMP(b __kuser_memory_barrier)
980 ALT_UP(usr_ret lr)
981
982#endif
983
984 .align 5
985
986__kuser_get_tls: @ 0xffff0fe0
987 ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init
988 usr_ret lr
989 mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code
990 .rep 4
991 .word 0 @ 0xffff0ff0 software TLS value, then
992 .endr @ pad up to __kuser_helper_version
993
994__kuser_helper_version: @ 0xffff0ffc
995 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
996
997 .globl __kuser_helper_end
998__kuser_helper_end:
999
1000 THUMB( .thumb )
1001
1002/*
1003 * Vector stubs.
1004 *
1005 * This code is copied to 0xffff0200 so we can use branches in the
1006 * vectors, rather than ldr's. Note that this code must not
1007 * exceed 0x300 bytes.
1008 *
1009 * Common stub entry macro:
1010 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1011 *
1012 * SP points to a minimal amount of processor-private memory, the address
1013 * of which is copied into r0 for the mode specific abort handler.
1014 */
1015 .macro vector_stub, name, mode, correction=0
1016 .align 5
1017
1018vector_\name:
1019 .if \correction
1020 sub lr, lr, #\correction
1021 .endif
1022
1023 @
1024 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1025 @ (parent CPSR)
1026 @
1027 stmia sp, {r0, lr} @ save r0, lr
1028 mrs lr, spsr
1029 str lr, [sp, #8] @ save spsr
1030
1031 @
1032 @ Prepare for SVC32 mode. IRQs remain disabled.
1033 @
1034 mrs r0, cpsr
1035 eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
1036 msr spsr_cxsf, r0
1037
1038 @
1039 @ the branch table must immediately follow this code
1040 @
1041 and lr, lr, #0x0f
1042 THUMB( adr r0, 1f )
1043 THUMB( ldr lr, [r0, lr, lsl #2] )
1044 mov r0, sp
1045 ARM( ldr lr, [pc, lr, lsl #2] )
1046 movs pc, lr @ branch to handler in SVC mode
1047ENDPROC(vector_\name)
1048
1049 .align 2
1050 @ handler addresses follow this label
10511:
1052 .endm
1053
1054 .globl __stubs_start
1055__stubs_start:
1056/*
1057 * Interrupt dispatcher
1058 */
1059 vector_stub irq, IRQ_MODE, 4
1060
1061 .long __irq_usr @ 0 (USR_26 / USR_32)
1062 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
1063 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
1064 .long __irq_svc @ 3 (SVC_26 / SVC_32)
1065 .long __irq_invalid @ 4
1066 .long __irq_invalid @ 5
1067 .long __irq_invalid @ 6
1068 .long __irq_invalid @ 7
1069 .long __irq_invalid @ 8
1070 .long __irq_invalid @ 9
1071 .long __irq_invalid @ a
1072 .long __irq_invalid @ b
1073 .long __irq_invalid @ c
1074 .long __irq_invalid @ d
1075 .long __irq_invalid @ e
1076 .long __irq_invalid @ f
1077
1078/*
1079 * Data abort dispatcher
1080 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1081 */
1082 vector_stub dabt, ABT_MODE, 8
1083
1084 .long __dabt_usr @ 0 (USR_26 / USR_32)
1085 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
1086 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
1087 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
1088 .long __dabt_invalid @ 4
1089 .long __dabt_invalid @ 5
1090 .long __dabt_invalid @ 6
1091 .long __dabt_invalid @ 7
1092 .long __dabt_invalid @ 8
1093 .long __dabt_invalid @ 9
1094 .long __dabt_invalid @ a
1095 .long __dabt_invalid @ b
1096 .long __dabt_invalid @ c
1097 .long __dabt_invalid @ d
1098 .long __dabt_invalid @ e
1099 .long __dabt_invalid @ f
1100
1101/*
1102 * Prefetch abort dispatcher
1103 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1104 */
1105 vector_stub pabt, ABT_MODE, 4
1106
1107 .long __pabt_usr @ 0 (USR_26 / USR_32)
1108 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
1109 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
1110 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
1111 .long __pabt_invalid @ 4
1112 .long __pabt_invalid @ 5
1113 .long __pabt_invalid @ 6
1114 .long __pabt_invalid @ 7
1115 .long __pabt_invalid @ 8
1116 .long __pabt_invalid @ 9
1117 .long __pabt_invalid @ a
1118 .long __pabt_invalid @ b
1119 .long __pabt_invalid @ c
1120 .long __pabt_invalid @ d
1121 .long __pabt_invalid @ e
1122 .long __pabt_invalid @ f
1123
1124/*
1125 * Undef instr entry dispatcher
1126 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1127 */
1128 vector_stub und, UND_MODE
1129
1130 .long __und_usr @ 0 (USR_26 / USR_32)
1131 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
1132 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
1133 .long __und_svc @ 3 (SVC_26 / SVC_32)
1134 .long __und_invalid @ 4
1135 .long __und_invalid @ 5
1136 .long __und_invalid @ 6
1137 .long __und_invalid @ 7
1138 .long __und_invalid @ 8
1139 .long __und_invalid @ 9
1140 .long __und_invalid @ a
1141 .long __und_invalid @ b
1142 .long __und_invalid @ c
1143 .long __und_invalid @ d
1144 .long __und_invalid @ e
1145 .long __und_invalid @ f
1146
1147 .align 5
1148
1149/*=============================================================================
1150 * Undefined FIQs
1151 *-----------------------------------------------------------------------------
1152 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
1153 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
1154 * Basically to switch modes, we *HAVE* to clobber one register... brain
1155 * damage alert! I don't think that we can execute any code in here in any
1156 * other mode than FIQ... Ok you can switch to another mode, but you can't
1157 * get out of that mode without clobbering one register.
1158 */
1159vector_fiq:
1160 subs pc, lr, #4
1161
1162/*=============================================================================
1163 * Address exception handler
1164 *-----------------------------------------------------------------------------
1165 * These aren't too critical.
1166 * (they're not supposed to happen, and won't happen in 32-bit data mode).
1167 */
1168
1169vector_addrexcptn:
1170 b vector_addrexcptn
1171
1172/*
1173 * We group all the following data together to optimise
1174 * for CPUs with separate I & D caches.
1175 */
1176 .align 5
1177
1178.LCvswi:
1179 .word vector_swi
1180
1181 .globl __stubs_end
1182__stubs_end:
1183
1184 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
1185
1186 .globl __vectors_start
1187__vectors_start:
1188 ARM( swi SYS_ERROR0 )
1189 THUMB( svc #0 )
1190 THUMB( nop )
1191 W(b) vector_und + stubs_offset
1192 W(ldr) pc, .LCvswi + stubs_offset
1193 W(b) vector_pabt + stubs_offset
1194 W(b) vector_dabt + stubs_offset
1195 W(b) vector_addrexcptn + stubs_offset
1196 W(b) vector_irq + stubs_offset
1197 W(b) vector_fiq + stubs_offset
1198
1199 .globl __vectors_end
1200__vectors_end:
1201
1202 .data
1203
1204 .globl cr_alignment
1205 .globl cr_no_alignment
1206cr_alignment:
1207 .space 4
1208cr_no_alignment:
1209 .space 4
1210
1211#ifdef CONFIG_MULTI_IRQ_HANDLER
1212 .globl handle_arch_irq
1213handle_arch_irq:
1214 .space 4
1215#endif
1216
1217#ifdef CONFIG_IRQ_STACK
1218irq_handler_stack_bottom:
1219 .rept 1024
1220 .long 0
1221 .endr
1222irq_handler_stack_top:
1223#endif
1224