blob: 39a6c1b0b9a32db8f578bab2d9f4156acc5d4054 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Low-level vector interface routines
12 *
13 * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction that causes
14 * it to save wrong values... Be aware!
15 */
16#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/glue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/vfpmacros.h>
Nicolas Pitre41e46d62005-05-05 23:24:45 +010020#include <asm/hardware.h> /* should be moved into entry-macro.S */
21#include <asm/arch/irqs.h> /* should be moved into entry-macro.S */
Russell Kingbce495d2005-04-26 15:21:02 +010022#include <asm/arch/entry-macro.S>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include "entry-header.S"
25
26/*
Russell King187a51a2005-05-21 18:14:44 +010027 * Interrupt handling. Preserves r7, r8, r9
28 */
29 .macro irq_handler
301: get_irqnr_and_base r0, r6, r5, lr
31 movne r1, sp
32 @
33 @ routine called with r0 = irq number, r1 = struct pt_regs *
34 @
35 adrne lr, 1b
36 bne asm_do_IRQ
Russell King791be9b2005-05-21 18:16:44 +010037
38#ifdef CONFIG_SMP
39 /*
40 * XXX
41 *
42 * this macro assumes that irqstat (r6) and base (r5) are
43 * preserved from get_irqnr_and_base above
44 */
45 test_for_ipi r0, r6, r5, lr
46 movne r0, sp
47 adrne lr, 1b
48 bne do_IPI
49#endif
50
Russell King187a51a2005-05-21 18:14:44 +010051 .endm
52
53/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * Invalid mode handlers
55 */
Russell Kingccea7a12005-05-31 22:22:32 +010056 .macro inv_entry, reason
57 sub sp, sp, #S_FRAME_SIZE
58 stmib sp, {r1 - lr}
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 mov r1, #\reason
60 .endm
61
62__pabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010063 inv_entry BAD_PREFETCH
64 b common_invalid
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66__dabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010067 inv_entry BAD_DATA
68 b common_invalid
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70__irq_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010071 inv_entry BAD_IRQ
72 b common_invalid
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74__und_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010075 inv_entry BAD_UNDEFINSTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Russell Kingccea7a12005-05-31 22:22:32 +010077 @
78 @ XXX fall through to common_invalid
79 @
80
81@
82@ common_invalid - generic code for failed exception (re-entrant version of handlers)
83@
84common_invalid:
85 zero_fp
86
87 ldmia r0, {r4 - r6}
88 add r0, sp, #S_PC @ here for interlock avoidance
89 mov r7, #-1 @ "" "" "" ""
90 str r4, [sp] @ save preserved r0
91 stmia r0, {r5 - r7} @ lr_<exception>,
92 @ cpsr_<exception>, "old_r0"
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 mov r0, sp
Russell Kingccea7a12005-05-31 22:22:32 +010095 and r2, r6, #0x1f
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 b bad_mode
97
98/*
99 * SVC mode handlers
100 */
Russell Kingccea7a12005-05-31 22:22:32 +0100101 .macro svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 sub sp, sp, #S_FRAME_SIZE
Russell Kingccea7a12005-05-31 22:22:32 +0100103 stmib sp, {r1 - r12}
104
105 ldmia r0, {r1 - r3}
106 add r5, sp, #S_SP @ here for interlock avoidance
107 mov r4, #-1 @ "" "" "" ""
108 add r0, sp, #S_FRAME_SIZE @ "" "" "" ""
109 str r1, [sp] @ save the "real" r0 copied
110 @ from the exception stack
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 mov r1, lr
113
114 @
115 @ We are now ready to fill in the remaining blanks on the stack:
116 @
117 @ r0 - sp_svc
118 @ r1 - lr_svc
119 @ r2 - lr_<exception>, already fixed up for correct return/restart
120 @ r3 - spsr_<exception>
121 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
122 @
123 stmia r5, {r0 - r4}
124 .endm
125
126 .align 5
127__dabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100128 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 @
131 @ get ready to re-enable interrupts if appropriate
132 @
133 mrs r9, cpsr
134 tst r3, #PSR_I_BIT
135 biceq r9, r9, #PSR_I_BIT
136
137 @
138 @ Call the processor-specific abort handler:
139 @
140 @ r2 - aborted context pc
141 @ r3 - aborted context cpsr
142 @
143 @ The abort handler must return the aborted address in r0, and
144 @ the fault status register in r1. r9 must be preserved.
145 @
146#ifdef MULTI_ABORT
147 ldr r4, .LCprocfns
148 mov lr, pc
149 ldr pc, [r4]
150#else
151 bl CPU_ABORT_HANDLER
152#endif
153
154 @
155 @ set desired IRQ state, then call main handler
156 @
157 msr cpsr_c, r9
158 mov r2, sp
159 bl do_DataAbort
160
161 @
162 @ IRQs off again before pulling preserved data off the stack
163 @
Russell King1ec42c02005-04-26 15:18:26 +0100164 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 @
167 @ restore SPSR and restart the instruction
168 @
169 ldr r0, [sp, #S_PSR]
170 msr spsr_cxsf, r0
171 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
172
173 .align 5
174__irq_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100175 svc_entry
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100178 get_thread_info tsk
179 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
180 add r7, r8, #1 @ increment it
181 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100183
Russell King187a51a2005-05-21 18:14:44 +0100184 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100186 ldr r0, [tsk, #TI_FLAGS] @ get flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 tst r0, #_TIF_NEED_RESCHED
188 blne svc_preempt
189preempt_return:
Russell King706fdd92005-05-21 18:15:45 +0100190 ldr r0, [tsk, #TI_PREEMPT] @ read preempt value
191 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 strne r0, [r0, -r0] @ bug()
194#endif
195 ldr r0, [sp, #S_PSR] @ irqs are already disabled
196 msr spsr_cxsf, r0
197 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
198
199 .ltorg
200
201#ifdef CONFIG_PREEMPT
202svc_preempt:
Russell King706fdd92005-05-21 18:15:45 +0100203 teq r8, #0 @ was preempt count = 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 ldreq r6, .LCirq_stat
205 movne pc, lr @ no
206 ldr r0, [r6, #4] @ local_irq_count
207 ldr r1, [r6, #8] @ local_bh_count
208 adds r0, r0, r1
209 movne pc, lr
210 mov r7, #0 @ preempt_schedule_irq
Russell King706fdd92005-05-21 18:15:45 +0100211 str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121: bl preempt_schedule_irq @ irq en/disable is done inside
Russell King706fdd92005-05-21 18:15:45 +0100213 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 tst r0, #_TIF_NEED_RESCHED
215 beq preempt_return @ go again
216 b 1b
217#endif
218
219 .align 5
220__und_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100221 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 @
224 @ call emulation code, which returns using r9 if it has emulated
225 @ the instruction, or the more conventional lr if we are to treat
226 @ this as a real undefined instruction
227 @
228 @ r0 - instruction
229 @
230 ldr r0, [r2, #-4]
231 adr r9, 1f
232 bl call_fpe
233
234 mov r0, sp @ struct pt_regs *regs
235 bl do_undefinstr
236
237 @
238 @ IRQs off again before pulling preserved data off the stack
239 @
Russell King1ec42c02005-04-26 15:18:26 +01002401: disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 @
243 @ restore SPSR and restart the instruction
244 @
245 ldr lr, [sp, #S_PSR] @ Get SVC cpsr
246 msr spsr_cxsf, lr
247 ldmia sp, {r0 - pc}^ @ Restore SVC registers
248
249 .align 5
250__pabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100251 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 @
254 @ re-enable interrupts if appropriate
255 @
256 mrs r9, cpsr
257 tst r3, #PSR_I_BIT
258 biceq r9, r9, #PSR_I_BIT
259 msr cpsr_c, r9
260
261 @
262 @ set args, then call main handler
263 @
264 @ r0 - address of faulting instruction
265 @ r1 - pointer to registers on stack
266 @
267 mov r0, r2 @ address (pc)
268 mov r1, sp @ regs
269 bl do_PrefetchAbort @ call abort handler
270
271 @
272 @ IRQs off again before pulling preserved data off the stack
273 @
Russell King1ec42c02005-04-26 15:18:26 +0100274 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 @
277 @ restore SPSR and restart the instruction
278 @
279 ldr r0, [sp, #S_PSR]
280 msr spsr_cxsf, r0
281 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
282
283 .align 5
Russell King49f680e2005-05-31 18:02:00 +0100284.LCcralign:
285 .word cr_alignment
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286#ifdef MULTI_ABORT
287.LCprocfns:
288 .word processor
289#endif
290.LCfp:
291 .word fp_enter
292#ifdef CONFIG_PREEMPT
293.LCirq_stat:
294 .word irq_stat
295#endif
296
297/*
298 * User mode handlers
299 */
Russell Kingccea7a12005-05-31 22:22:32 +0100300 .macro usr_entry
301 sub sp, sp, #S_FRAME_SIZE
302 stmib sp, {r1 - r12}
303
304 ldmia r0, {r1 - r3}
305 add r0, sp, #S_PC @ here for interlock avoidance
306 mov r4, #-1 @ "" "" "" ""
307
308 str r1, [sp] @ save the "real" r0 copied
309 @ from the exception stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100311#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100312 @ make sure our user space atomic helper is aborted
313 cmp r2, #VIRT_OFFSET
314 bichs r3, r3, #PSR_Z_BIT
315#endif
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 @
318 @ We are now ready to fill in the remaining blanks on the stack:
319 @
320 @ r2 - lr_<exception>, already fixed up for correct return/restart
321 @ r3 - spsr_<exception>
322 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
323 @
324 @ Also, separately save sp_usr and lr_usr
325 @
Russell Kingccea7a12005-05-31 22:22:32 +0100326 stmia r0, {r2 - r4}
327 stmdb r0, {sp, lr}^
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 @
330 @ Enable the alignment trap while in kernel mode
331 @
Russell King49f680e2005-05-31 18:02:00 +0100332 alignment_trap r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 @
335 @ Clear FP to mark the first stack frame
336 @
337 zero_fp
338 .endm
339
340 .align 5
341__dabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100342 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 @
345 @ Call the processor-specific abort handler:
346 @
347 @ r2 - aborted context pc
348 @ r3 - aborted context cpsr
349 @
350 @ The abort handler must return the aborted address in r0, and
351 @ the fault status register in r1.
352 @
353#ifdef MULTI_ABORT
354 ldr r4, .LCprocfns
355 mov lr, pc
356 ldr pc, [r4]
357#else
358 bl CPU_ABORT_HANDLER
359#endif
360
361 @
362 @ IRQs on, then call the main handler
363 @
Russell King1ec42c02005-04-26 15:18:26 +0100364 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 mov r2, sp
366 adr lr, ret_from_exception
367 b do_DataAbort
368
369 .align 5
370__irq_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100371 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100375 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
376 add r7, r8, #1 @ increment it
377 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100379
Russell King187a51a2005-05-21 18:14:44 +0100380 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100382 ldr r0, [tsk, #TI_PREEMPT]
383 str r8, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 strne r0, [r0, -r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 mov why, #0
389 b ret_to_user
390
391 .ltorg
392
393 .align 5
394__und_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100395 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 tst r3, #PSR_T_BIT @ Thumb mode?
398 bne fpundefinstr @ ignore FP
399 sub r4, r2, #4
400
401 @
402 @ fall through to the emulation code, which returns using r9 if
403 @ it has emulated the instruction, or the more conventional lr
404 @ if we are to treat this as a real undefined instruction
405 @
406 @ r0 - instruction
407 @
4081: ldrt r0, [r4]
409 adr r9, ret_from_exception
410 adr lr, fpundefinstr
411 @
412 @ fallthrough to call_fpe
413 @
414
415/*
416 * The out of line fixup for the ldrt above.
417 */
418 .section .fixup, "ax"
4192: mov pc, r9
420 .previous
421 .section __ex_table,"a"
422 .long 1b, 2b
423 .previous
424
425/*
426 * Check whether the instruction is a co-processor instruction.
427 * If yes, we need to call the relevant co-processor handler.
428 *
429 * Note that we don't do a full check here for the co-processor
430 * instructions; all instructions with bit 27 set are well
431 * defined. The only instructions that should fault are the
432 * co-processor instructions. However, we have to watch out
433 * for the ARM6/ARM7 SWI bug.
434 *
435 * Emulators may wish to make use of the following registers:
436 * r0 = instruction opcode.
437 * r2 = PC+4
438 * r10 = this threads thread_info structure.
439 */
440call_fpe:
441 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
442#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
443 and r8, r0, #0x0f000000 @ mask out op-code bits
444 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
445#endif
446 moveq pc, lr
447 get_thread_info r10 @ get current thread
448 and r8, r0, #0x00000f00 @ mask out CP number
449 mov r7, #1
450 add r6, r10, #TI_USED_CP
451 strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
452#ifdef CONFIG_IWMMXT
453 @ Test if we need to give access to iWMMXt coprocessors
454 ldr r5, [r10, #TI_FLAGS]
455 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
456 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
457 bcs iwmmxt_task_enable
458#endif
Russell King1ec42c02005-04-26 15:18:26 +0100459 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 add pc, pc, r8, lsr #6
461 mov r0, r0
462
463 mov pc, lr @ CP#0
464 b do_fpe @ CP#1 (FPE)
465 b do_fpe @ CP#2 (FPE)
466 mov pc, lr @ CP#3
467 mov pc, lr @ CP#4
468 mov pc, lr @ CP#5
469 mov pc, lr @ CP#6
470 mov pc, lr @ CP#7
471 mov pc, lr @ CP#8
472 mov pc, lr @ CP#9
473#ifdef CONFIG_VFP
474 b do_vfp @ CP#10 (VFP)
475 b do_vfp @ CP#11 (VFP)
476#else
477 mov pc, lr @ CP#10 (VFP)
478 mov pc, lr @ CP#11 (VFP)
479#endif
480 mov pc, lr @ CP#12
481 mov pc, lr @ CP#13
482 mov pc, lr @ CP#14 (Debug)
483 mov pc, lr @ CP#15 (Control)
484
485do_fpe:
486 ldr r4, .LCfp
487 add r10, r10, #TI_FPSTATE @ r10 = workspace
488 ldr pc, [r4] @ Call FP module USR entry point
489
490/*
491 * The FP module is called with these registers set:
492 * r0 = instruction
493 * r2 = PC+4
494 * r9 = normal "successful" return address
495 * r10 = FP workspace
496 * lr = unrecognised FP instruction return address
497 */
498
499 .data
500ENTRY(fp_enter)
501 .word fpundefinstr
502 .text
503
504fpundefinstr:
505 mov r0, sp
506 adr lr, ret_from_exception
507 b do_undefinstr
508
509 .align 5
510__pabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100511 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Russell King1ec42c02005-04-26 15:18:26 +0100513 enable_irq @ Enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 mov r0, r2 @ address (pc)
515 mov r1, sp @ regs
516 bl do_PrefetchAbort @ call abort handler
517 /* fall through */
518/*
519 * This is the return code to user mode for abort handlers
520 */
521ENTRY(ret_from_exception)
522 get_thread_info tsk
523 mov why, #0
524 b ret_to_user
525
526/*
527 * Register switch for ARMv3 and ARMv4 processors
528 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
529 * previous and next are guaranteed not to be the same.
530 */
531ENTRY(__switch_to)
532 add ip, r1, #TI_CPU_SAVE
533 ldr r3, [r2, #TI_TP_VALUE]
534 stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
535 ldr r6, [r2, #TI_CPU_DOMAIN]!
536#if defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_IWMMXT)
537 mra r4, r5, acc0
538 stmia ip, {r4, r5}
539#endif
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100540#if defined(CONFIG_HAS_TLS_REG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100541 mcr p15, 0, r3, c13, c0, 3 @ set TLS register
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100542#elif !defined(CONFIG_TLS_REG_EMUL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 mov r4, #0xffff0fff
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100544 str r3, [r4, #-15] @ TLS val at 0xffff0ff0
545#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
547#ifdef CONFIG_VFP
548 @ Always disable VFP so we can lazily save/restore the old
549 @ state. This occurs in the context of the previous thread.
550 VFPFMRX r4, FPEXC
551 bic r4, r4, #FPEXC_ENABLE
552 VFPFMXR FPEXC, r4
553#endif
554#if defined(CONFIG_IWMMXT)
555 bl iwmmxt_task_switch
556#elif defined(CONFIG_CPU_XSCALE)
557 add r4, r2, #40 @ cpu_context_save->extra
558 ldmib r4, {r4, r5}
559 mar acc0, r4, r5
560#endif
561 ldmib r2, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
562
563 __INIT
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100564
565/*
566 * User helpers.
567 *
568 * These are segment of kernel provided user code reachable from user space
569 * at a fixed address in kernel memory. This is used to provide user space
570 * with some operations which require kernel help because of unimplemented
571 * native feature and/or instructions in many ARM CPUs. The idea is for
572 * this code to be executed directly in user mode for best efficiency but
573 * which is too intimate with the kernel counter part to be left to user
574 * libraries. In fact this code might even differ from one CPU to another
575 * depending on the available instruction set and restrictions like on
576 * SMP systems. In other words, the kernel reserves the right to change
577 * this code as needed without warning. Only the entry points and their
578 * results are guaranteed to be stable.
579 *
580 * Each segment is 32-byte aligned and will be moved to the top of the high
581 * vector page. New segments (if ever needed) must be added in front of
582 * existing ones. This mechanism should be used only for things that are
583 * really small and justified, and not be abused freely.
584 *
585 * User space is expected to implement those things inline when optimizing
586 * for a processor that has the necessary native support, but only if such
587 * resulting binaries are already to be incompatible with earlier ARM
588 * processors due to the use of unsupported instructions other than what
589 * is provided here. In other words don't make binaries unable to run on
590 * earlier processors just for the sake of not using these kernel helpers
591 * if your compiled code is not going to use the new instructions for other
592 * purpose.
593 */
594
595 .align 5
596 .globl __kuser_helper_start
597__kuser_helper_start:
598
599/*
600 * Reference prototype:
601 *
602 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
603 *
604 * Input:
605 *
606 * r0 = oldval
607 * r1 = newval
608 * r2 = ptr
609 * lr = return address
610 *
611 * Output:
612 *
613 * r0 = returned value (zero or non-zero)
614 * C flag = set if r0 == 0, clear if r0 != 0
615 *
616 * Clobbered:
617 *
618 * r3, ip, flags
619 *
620 * Definition and user space usage example:
621 *
622 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
623 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
624 *
625 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
626 * Return zero if *ptr was changed or non-zero if no exchange happened.
627 * The C flag is also set if *ptr was changed to allow for assembly
628 * optimization in the calling code.
629 *
630 * For example, a user space atomic_add implementation could look like this:
631 *
632 * #define atomic_add(ptr, val) \
633 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
634 * register unsigned int __result asm("r1"); \
635 * asm volatile ( \
636 * "1: @ atomic_add\n\t" \
637 * "ldr r0, [r2]\n\t" \
638 * "mov r3, #0xffff0fff\n\t" \
639 * "add lr, pc, #4\n\t" \
640 * "add r1, r0, %2\n\t" \
641 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
642 * "bcc 1b" \
643 * : "=&r" (__result) \
644 * : "r" (__ptr), "rIL" (val) \
645 * : "r0","r3","ip","lr","cc","memory" ); \
646 * __result; })
647 */
648
649__kuser_cmpxchg: @ 0xffff0fc0
650
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100651#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100652
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100653 /*
654 * Poor you. No fast solution possible...
655 * The kernel itself must perform the operation.
656 * A special ghost syscall is used for that (see traps.c).
657 */
658 swi #0x9ffff0
659 mov pc, lr
660
661#elif __LINUX_ARM_ARCH__ < 6
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100662
663 /*
664 * Theory of operation:
665 *
666 * We set the Z flag before loading oldval. If ever an exception
667 * occurs we can not be sure the loaded value will still be the same
668 * when the exception returns, therefore the user exception handler
669 * will clear the Z flag whenever the interrupted user code was
670 * actually from the kernel address space (see the usr_entry macro).
671 *
672 * The post-increment on the str is used to prevent a race with an
673 * exception happening just after the str instruction which would
674 * clear the Z flag although the exchange was done.
675 */
676 teq ip, ip @ set Z flag
677 ldr ip, [r2] @ load current val
678 add r3, r2, #1 @ prepare store ptr
679 teqeq ip, r0 @ compare with oldval if still allowed
680 streq r1, [r3, #-1]! @ store newval if still allowed
681 subs r0, r2, r3 @ if r2 == r3 the str occured
682 mov pc, lr
683
684#else
685
686 ldrex r3, [r2]
687 subs r3, r3, r0
688 strexeq r3, r1, [r2]
689 rsbs r0, r3, #0
690 mov pc, lr
691
692#endif
693
694 .align 5
695
696/*
697 * Reference prototype:
698 *
699 * int __kernel_get_tls(void)
700 *
701 * Input:
702 *
703 * lr = return address
704 *
705 * Output:
706 *
707 * r0 = TLS value
708 *
709 * Clobbered:
710 *
711 * the Z flag might be lost
712 *
713 * Definition and user space usage example:
714 *
715 * typedef int (__kernel_get_tls_t)(void);
716 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
717 *
718 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
719 *
720 * This could be used as follows:
721 *
722 * #define __kernel_get_tls() \
723 * ({ register unsigned int __val asm("r0"); \
724 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
725 * : "=r" (__val) : : "lr","cc" ); \
726 * __val; })
727 */
728
729__kuser_get_tls: @ 0xffff0fe0
730
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100731#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100732
733 ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
734 mov pc, lr
735
736#else
737
738 mrc p15, 0, r0, c13, c0, 3 @ read TLS register
739 mov pc, lr
740
741#endif
742
743 .rep 5
744 .word 0 @ pad up to __kuser_helper_version
745 .endr
746
747/*
748 * Reference declaration:
749 *
750 * extern unsigned int __kernel_helper_version;
751 *
752 * Definition and user space usage example:
753 *
754 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
755 *
756 * User space may read this to determine the curent number of helpers
757 * available.
758 */
759
760__kuser_helper_version: @ 0xffff0ffc
761 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
762
763 .globl __kuser_helper_end
764__kuser_helper_end:
765
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767/*
768 * Vector stubs.
769 *
Russell King79335232005-04-26 15:17:42 +0100770 * This code is copied to 0xffff0200 so we can use branches in the
771 * vectors, rather than ldr's. Note that this code must not
772 * exceed 0x300 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 *
774 * Common stub entry macro:
775 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
Russell Kingccea7a12005-05-31 22:22:32 +0100776 *
777 * SP points to a minimal amount of processor-private memory, the address
778 * of which is copied into r0 for the mode specific abort handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 */
Russell Kingccea7a12005-05-31 22:22:32 +0100780 .macro vector_stub, name, correction=0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 .align 5
782
783vector_\name:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .if \correction
785 sub lr, lr, #\correction
786 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Russell Kingccea7a12005-05-31 22:22:32 +0100788 @
789 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
790 @ (parent CPSR)
791 @
792 stmia sp, {r0, lr} @ save r0, lr
793 mrs lr, spsr
794 str lr, [sp, #8] @ save spsr
795
796 @
797 @ Prepare for SVC32 mode. IRQs remain disabled.
798 @
799 mrs r0, cpsr
800 bic r0, r0, #MODE_MASK
801 orr r0, r0, #SVC_MODE
802 msr spsr_cxsf, r0
803
804 @
805 @ the branch table must immediately follow this code
806 @
807 mov r0, sp
808 and lr, lr, #0x0f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 ldr lr, [pc, lr, lsl #2]
Russell Kingccea7a12005-05-31 22:22:32 +0100810 movs pc, lr @ branch to handler in SVC mode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .endm
812
Russell King79335232005-04-26 15:17:42 +0100813 .globl __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814__stubs_start:
815/*
816 * Interrupt dispatcher
817 */
Russell Kingccea7a12005-05-31 22:22:32 +0100818 vector_stub irq, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 .long __irq_usr @ 0 (USR_26 / USR_32)
821 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
822 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
823 .long __irq_svc @ 3 (SVC_26 / SVC_32)
824 .long __irq_invalid @ 4
825 .long __irq_invalid @ 5
826 .long __irq_invalid @ 6
827 .long __irq_invalid @ 7
828 .long __irq_invalid @ 8
829 .long __irq_invalid @ 9
830 .long __irq_invalid @ a
831 .long __irq_invalid @ b
832 .long __irq_invalid @ c
833 .long __irq_invalid @ d
834 .long __irq_invalid @ e
835 .long __irq_invalid @ f
836
837/*
838 * Data abort dispatcher
839 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
840 */
Russell Kingccea7a12005-05-31 22:22:32 +0100841 vector_stub dabt, 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 .long __dabt_usr @ 0 (USR_26 / USR_32)
844 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
845 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
846 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
847 .long __dabt_invalid @ 4
848 .long __dabt_invalid @ 5
849 .long __dabt_invalid @ 6
850 .long __dabt_invalid @ 7
851 .long __dabt_invalid @ 8
852 .long __dabt_invalid @ 9
853 .long __dabt_invalid @ a
854 .long __dabt_invalid @ b
855 .long __dabt_invalid @ c
856 .long __dabt_invalid @ d
857 .long __dabt_invalid @ e
858 .long __dabt_invalid @ f
859
860/*
861 * Prefetch abort dispatcher
862 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
863 */
Russell Kingccea7a12005-05-31 22:22:32 +0100864 vector_stub pabt, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 .long __pabt_usr @ 0 (USR_26 / USR_32)
867 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
868 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
869 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
870 .long __pabt_invalid @ 4
871 .long __pabt_invalid @ 5
872 .long __pabt_invalid @ 6
873 .long __pabt_invalid @ 7
874 .long __pabt_invalid @ 8
875 .long __pabt_invalid @ 9
876 .long __pabt_invalid @ a
877 .long __pabt_invalid @ b
878 .long __pabt_invalid @ c
879 .long __pabt_invalid @ d
880 .long __pabt_invalid @ e
881 .long __pabt_invalid @ f
882
883/*
884 * Undef instr entry dispatcher
885 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
886 */
Russell Kingccea7a12005-05-31 22:22:32 +0100887 vector_stub und
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 .long __und_usr @ 0 (USR_26 / USR_32)
890 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
891 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
892 .long __und_svc @ 3 (SVC_26 / SVC_32)
893 .long __und_invalid @ 4
894 .long __und_invalid @ 5
895 .long __und_invalid @ 6
896 .long __und_invalid @ 7
897 .long __und_invalid @ 8
898 .long __und_invalid @ 9
899 .long __und_invalid @ a
900 .long __und_invalid @ b
901 .long __und_invalid @ c
902 .long __und_invalid @ d
903 .long __und_invalid @ e
904 .long __und_invalid @ f
905
906 .align 5
907
908/*=============================================================================
909 * Undefined FIQs
910 *-----------------------------------------------------------------------------
911 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
912 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
913 * Basically to switch modes, we *HAVE* to clobber one register... brain
914 * damage alert! I don't think that we can execute any code in here in any
915 * other mode than FIQ... Ok you can switch to another mode, but you can't
916 * get out of that mode without clobbering one register.
917 */
918vector_fiq:
919 disable_fiq
920 subs pc, lr, #4
921
922/*=============================================================================
923 * Address exception handler
924 *-----------------------------------------------------------------------------
925 * These aren't too critical.
926 * (they're not supposed to happen, and won't happen in 32-bit data mode).
927 */
928
929vector_addrexcptn:
930 b vector_addrexcptn
931
932/*
933 * We group all the following data together to optimise
934 * for CPUs with separate I & D caches.
935 */
936 .align 5
937
938.LCvswi:
939 .word vector_swi
940
Russell King79335232005-04-26 15:17:42 +0100941 .globl __stubs_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942__stubs_end:
943
Russell King79335232005-04-26 15:17:42 +0100944 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Russell King79335232005-04-26 15:17:42 +0100946 .globl __vectors_start
947__vectors_start:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 swi SYS_ERROR0
Russell King79335232005-04-26 15:17:42 +0100949 b vector_und + stubs_offset
950 ldr pc, .LCvswi + stubs_offset
951 b vector_pabt + stubs_offset
952 b vector_dabt + stubs_offset
953 b vector_addrexcptn + stubs_offset
954 b vector_irq + stubs_offset
955 b vector_fiq + stubs_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Russell King79335232005-04-26 15:17:42 +0100957 .globl __vectors_end
958__vectors_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 .data
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .globl cr_alignment
963 .globl cr_no_alignment
964cr_alignment:
965 .space 4
966cr_no_alignment:
967 .space 4