entry-armv.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. /*
  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>
  17. #include <asm/glue.h>
  18. #include <asm/vfpmacros.h>
  19. #include <asm/hardware.h> /* should be moved into entry-macro.S */
  20. #include <asm/arch/irqs.h> /* should be moved into entry-macro.S */
  21. #include <asm/arch/entry-macro.S>
  22. #include "entry-header.S"
  23. /*
  24. * Interrupt handling. Preserves r7, r8, r9
  25. */
  26. .macro irq_handler
  27. 1: get_irqnr_and_base r0, r6, r5, lr
  28. movne r1, sp
  29. @
  30. @ routine called with r0 = irq number, r1 = struct pt_regs *
  31. @
  32. adrne lr, 1b
  33. bne asm_do_IRQ
  34. #ifdef CONFIG_SMP
  35. /*
  36. * XXX
  37. *
  38. * this macro assumes that irqstat (r6) and base (r5) are
  39. * preserved from get_irqnr_and_base above
  40. */
  41. test_for_ipi r0, r6, r5, lr
  42. movne r0, sp
  43. adrne lr, 1b
  44. bne do_IPI
  45. #endif
  46. .endm
  47. /*
  48. * Invalid mode handlers
  49. */
  50. .macro inv_entry, sym, reason
  51. sub sp, sp, #S_FRAME_SIZE @ Allocate frame size in one go
  52. stmia sp, {r0 - lr} @ Save XXX r0 - lr
  53. ldr r4, .LC\sym
  54. mov r1, #\reason
  55. .endm
  56. __pabt_invalid:
  57. inv_entry abt, BAD_PREFETCH
  58. b 1f
  59. __dabt_invalid:
  60. inv_entry abt, BAD_DATA
  61. b 1f
  62. __irq_invalid:
  63. inv_entry irq, BAD_IRQ
  64. b 1f
  65. __und_invalid:
  66. inv_entry und, BAD_UNDEFINSTR
  67. 1: zero_fp
  68. ldmia r4, {r5 - r7} @ Get XXX pc, cpsr, old_r0
  69. add r4, sp, #S_PC
  70. stmia r4, {r5 - r7} @ Save XXX pc, cpsr, old_r0
  71. mov r0, sp
  72. and r2, r6, #31 @ int mode
  73. b bad_mode
  74. /*
  75. * SVC mode handlers
  76. */
  77. .macro svc_entry, sym
  78. sub sp, sp, #S_FRAME_SIZE
  79. stmia sp, {r0 - r12} @ save r0 - r12
  80. ldr r2, .LC\sym
  81. add r0, sp, #S_FRAME_SIZE
  82. ldmia r2, {r2 - r4} @ get pc, cpsr
  83. add r5, sp, #S_SP
  84. mov r1, lr
  85. @
  86. @ We are now ready to fill in the remaining blanks on the stack:
  87. @
  88. @ r0 - sp_svc
  89. @ r1 - lr_svc
  90. @ r2 - lr_<exception>, already fixed up for correct return/restart
  91. @ r3 - spsr_<exception>
  92. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  93. @
  94. stmia r5, {r0 - r4}
  95. .endm
  96. .align 5
  97. __dabt_svc:
  98. svc_entry abt
  99. @
  100. @ get ready to re-enable interrupts if appropriate
  101. @
  102. mrs r9, cpsr
  103. tst r3, #PSR_I_BIT
  104. biceq r9, r9, #PSR_I_BIT
  105. @
  106. @ Call the processor-specific abort handler:
  107. @
  108. @ r2 - aborted context pc
  109. @ r3 - aborted context cpsr
  110. @
  111. @ The abort handler must return the aborted address in r0, and
  112. @ the fault status register in r1. r9 must be preserved.
  113. @
  114. #ifdef MULTI_ABORT
  115. ldr r4, .LCprocfns
  116. mov lr, pc
  117. ldr pc, [r4]
  118. #else
  119. bl CPU_ABORT_HANDLER
  120. #endif
  121. @
  122. @ set desired IRQ state, then call main handler
  123. @
  124. msr cpsr_c, r9
  125. mov r2, sp
  126. bl do_DataAbort
  127. @
  128. @ IRQs off again before pulling preserved data off the stack
  129. @
  130. disable_irq
  131. @
  132. @ restore SPSR and restart the instruction
  133. @
  134. ldr r0, [sp, #S_PSR]
  135. msr spsr_cxsf, r0
  136. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  137. .align 5
  138. __irq_svc:
  139. svc_entry irq
  140. #ifdef CONFIG_PREEMPT
  141. get_thread_info tsk
  142. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  143. add r7, r8, #1 @ increment it
  144. str r7, [tsk, #TI_PREEMPT]
  145. #endif
  146. irq_handler
  147. #ifdef CONFIG_PREEMPT
  148. ldr r0, [tsk, #TI_FLAGS] @ get flags
  149. tst r0, #_TIF_NEED_RESCHED
  150. blne svc_preempt
  151. preempt_return:
  152. ldr r0, [tsk, #TI_PREEMPT] @ read preempt value
  153. str r8, [tsk, #TI_PREEMPT] @ restore preempt count
  154. teq r0, r7
  155. strne r0, [r0, -r0] @ bug()
  156. #endif
  157. ldr r0, [sp, #S_PSR] @ irqs are already disabled
  158. msr spsr_cxsf, r0
  159. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  160. .ltorg
  161. #ifdef CONFIG_PREEMPT
  162. svc_preempt:
  163. teq r8, #0 @ was preempt count = 0
  164. ldreq r6, .LCirq_stat
  165. movne pc, lr @ no
  166. ldr r0, [r6, #4] @ local_irq_count
  167. ldr r1, [r6, #8] @ local_bh_count
  168. adds r0, r0, r1
  169. movne pc, lr
  170. mov r7, #0 @ preempt_schedule_irq
  171. str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0
  172. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  173. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  174. tst r0, #_TIF_NEED_RESCHED
  175. beq preempt_return @ go again
  176. b 1b
  177. #endif
  178. .align 5
  179. __und_svc:
  180. svc_entry und
  181. @
  182. @ call emulation code, which returns using r9 if it has emulated
  183. @ the instruction, or the more conventional lr if we are to treat
  184. @ this as a real undefined instruction
  185. @
  186. @ r0 - instruction
  187. @
  188. ldr r0, [r2, #-4]
  189. adr r9, 1f
  190. bl call_fpe
  191. mov r0, sp @ struct pt_regs *regs
  192. bl do_undefinstr
  193. @
  194. @ IRQs off again before pulling preserved data off the stack
  195. @
  196. 1: disable_irq
  197. @
  198. @ restore SPSR and restart the instruction
  199. @
  200. ldr lr, [sp, #S_PSR] @ Get SVC cpsr
  201. msr spsr_cxsf, lr
  202. ldmia sp, {r0 - pc}^ @ Restore SVC registers
  203. .align 5
  204. __pabt_svc:
  205. svc_entry abt
  206. @
  207. @ re-enable interrupts if appropriate
  208. @
  209. mrs r9, cpsr
  210. tst r3, #PSR_I_BIT
  211. biceq r9, r9, #PSR_I_BIT
  212. msr cpsr_c, r9
  213. @
  214. @ set args, then call main handler
  215. @
  216. @ r0 - address of faulting instruction
  217. @ r1 - pointer to registers on stack
  218. @
  219. mov r0, r2 @ address (pc)
  220. mov r1, sp @ regs
  221. bl do_PrefetchAbort @ call abort handler
  222. @
  223. @ IRQs off again before pulling preserved data off the stack
  224. @
  225. disable_irq
  226. @
  227. @ restore SPSR and restart the instruction
  228. @
  229. ldr r0, [sp, #S_PSR]
  230. msr spsr_cxsf, r0
  231. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  232. .align 5
  233. .LCirq:
  234. .word __temp_irq
  235. .LCund:
  236. .word __temp_und
  237. .LCabt:
  238. .word __temp_abt
  239. #ifdef MULTI_ABORT
  240. .LCprocfns:
  241. .word processor
  242. #endif
  243. .LCfp:
  244. .word fp_enter
  245. #ifdef CONFIG_PREEMPT
  246. .LCirq_stat:
  247. .word irq_stat
  248. #endif
  249. /*
  250. * User mode handlers
  251. */
  252. .macro usr_entry, sym
  253. sub sp, sp, #S_FRAME_SIZE @ Allocate frame size in one go
  254. stmia sp, {r0 - r12} @ save r0 - r12
  255. ldr r7, .LC\sym
  256. add r5, sp, #S_PC
  257. ldmia r7, {r2 - r4} @ Get USR pc, cpsr
  258. #if __LINUX_ARM_ARCH__ < 6
  259. @ make sure our user space atomic helper is aborted
  260. cmp r2, #VIRT_OFFSET
  261. bichs r3, r3, #PSR_Z_BIT
  262. #endif
  263. @
  264. @ We are now ready to fill in the remaining blanks on the stack:
  265. @
  266. @ r2 - lr_<exception>, already fixed up for correct return/restart
  267. @ r3 - spsr_<exception>
  268. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  269. @
  270. @ Also, separately save sp_usr and lr_usr
  271. @
  272. stmia r5, {r2 - r4}
  273. stmdb r5, {sp, lr}^
  274. @
  275. @ Enable the alignment trap while in kernel mode
  276. @
  277. alignment_trap r7, r0, __temp_\sym
  278. @
  279. @ Clear FP to mark the first stack frame
  280. @
  281. zero_fp
  282. .endm
  283. .align 5
  284. __dabt_usr:
  285. usr_entry abt
  286. @
  287. @ Call the processor-specific abort handler:
  288. @
  289. @ r2 - aborted context pc
  290. @ r3 - aborted context cpsr
  291. @
  292. @ The abort handler must return the aborted address in r0, and
  293. @ the fault status register in r1.
  294. @
  295. #ifdef MULTI_ABORT
  296. ldr r4, .LCprocfns
  297. mov lr, pc
  298. ldr pc, [r4]
  299. #else
  300. bl CPU_ABORT_HANDLER
  301. #endif
  302. @
  303. @ IRQs on, then call the main handler
  304. @
  305. enable_irq
  306. mov r2, sp
  307. adr lr, ret_from_exception
  308. b do_DataAbort
  309. .align 5
  310. __irq_usr:
  311. usr_entry irq
  312. get_thread_info tsk
  313. #ifdef CONFIG_PREEMPT
  314. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  315. add r7, r8, #1 @ increment it
  316. str r7, [tsk, #TI_PREEMPT]
  317. #endif
  318. irq_handler
  319. #ifdef CONFIG_PREEMPT
  320. ldr r0, [tsk, #TI_PREEMPT]
  321. str r8, [tsk, #TI_PREEMPT]
  322. teq r0, r7
  323. strne r0, [r0, -r0]
  324. #endif
  325. mov why, #0
  326. b ret_to_user
  327. .ltorg
  328. .align 5
  329. __und_usr:
  330. usr_entry und
  331. tst r3, #PSR_T_BIT @ Thumb mode?
  332. bne fpundefinstr @ ignore FP
  333. sub r4, r2, #4
  334. @
  335. @ fall through to the emulation code, which returns using r9 if
  336. @ it has emulated the instruction, or the more conventional lr
  337. @ if we are to treat this as a real undefined instruction
  338. @
  339. @ r0 - instruction
  340. @
  341. 1: ldrt r0, [r4]
  342. adr r9, ret_from_exception
  343. adr lr, fpundefinstr
  344. @
  345. @ fallthrough to call_fpe
  346. @
  347. /*
  348. * The out of line fixup for the ldrt above.
  349. */
  350. .section .fixup, "ax"
  351. 2: mov pc, r9
  352. .previous
  353. .section __ex_table,"a"
  354. .long 1b, 2b
  355. .previous
  356. /*
  357. * Check whether the instruction is a co-processor instruction.
  358. * If yes, we need to call the relevant co-processor handler.
  359. *
  360. * Note that we don't do a full check here for the co-processor
  361. * instructions; all instructions with bit 27 set are well
  362. * defined. The only instructions that should fault are the
  363. * co-processor instructions. However, we have to watch out
  364. * for the ARM6/ARM7 SWI bug.
  365. *
  366. * Emulators may wish to make use of the following registers:
  367. * r0 = instruction opcode.
  368. * r2 = PC+4
  369. * r10 = this threads thread_info structure.
  370. */
  371. call_fpe:
  372. tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
  373. #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
  374. and r8, r0, #0x0f000000 @ mask out op-code bits
  375. teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
  376. #endif
  377. moveq pc, lr
  378. get_thread_info r10 @ get current thread
  379. and r8, r0, #0x00000f00 @ mask out CP number
  380. mov r7, #1
  381. add r6, r10, #TI_USED_CP
  382. strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
  383. #ifdef CONFIG_IWMMXT
  384. @ Test if we need to give access to iWMMXt coprocessors
  385. ldr r5, [r10, #TI_FLAGS]
  386. rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
  387. movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
  388. bcs iwmmxt_task_enable
  389. #endif
  390. enable_irq
  391. add pc, pc, r8, lsr #6
  392. mov r0, r0
  393. mov pc, lr @ CP#0
  394. b do_fpe @ CP#1 (FPE)
  395. b do_fpe @ CP#2 (FPE)
  396. mov pc, lr @ CP#3
  397. mov pc, lr @ CP#4
  398. mov pc, lr @ CP#5
  399. mov pc, lr @ CP#6
  400. mov pc, lr @ CP#7
  401. mov pc, lr @ CP#8
  402. mov pc, lr @ CP#9
  403. #ifdef CONFIG_VFP
  404. b do_vfp @ CP#10 (VFP)
  405. b do_vfp @ CP#11 (VFP)
  406. #else
  407. mov pc, lr @ CP#10 (VFP)
  408. mov pc, lr @ CP#11 (VFP)
  409. #endif
  410. mov pc, lr @ CP#12
  411. mov pc, lr @ CP#13
  412. mov pc, lr @ CP#14 (Debug)
  413. mov pc, lr @ CP#15 (Control)
  414. do_fpe:
  415. ldr r4, .LCfp
  416. add r10, r10, #TI_FPSTATE @ r10 = workspace
  417. ldr pc, [r4] @ Call FP module USR entry point
  418. /*
  419. * The FP module is called with these registers set:
  420. * r0 = instruction
  421. * r2 = PC+4
  422. * r9 = normal "successful" return address
  423. * r10 = FP workspace
  424. * lr = unrecognised FP instruction return address
  425. */
  426. .data
  427. ENTRY(fp_enter)
  428. .word fpundefinstr
  429. .text
  430. fpundefinstr:
  431. mov r0, sp
  432. adr lr, ret_from_exception
  433. b do_undefinstr
  434. .align 5
  435. __pabt_usr:
  436. usr_entry abt
  437. enable_irq @ Enable interrupts
  438. mov r0, r2 @ address (pc)
  439. mov r1, sp @ regs
  440. bl do_PrefetchAbort @ call abort handler
  441. /* fall through */
  442. /*
  443. * This is the return code to user mode for abort handlers
  444. */
  445. ENTRY(ret_from_exception)
  446. get_thread_info tsk
  447. mov why, #0
  448. b ret_to_user
  449. /*
  450. * Register switch for ARMv3 and ARMv4 processors
  451. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  452. * previous and next are guaranteed not to be the same.
  453. */
  454. ENTRY(__switch_to)
  455. add ip, r1, #TI_CPU_SAVE
  456. ldr r3, [r2, #TI_TP_VALUE]
  457. stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
  458. ldr r6, [r2, #TI_CPU_DOMAIN]!
  459. #if defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_IWMMXT)
  460. mra r4, r5, acc0
  461. stmia ip, {r4, r5}
  462. #endif
  463. #if defined(CONFIG_HAS_TLS_REG)
  464. mcr p15, 0, r3, c13, c0, 3 @ set TLS register
  465. #elif !defined(CONFIG_TLS_REG_EMUL)
  466. mov r4, #0xffff0fff
  467. str r3, [r4, #-15] @ TLS val at 0xffff0ff0
  468. #endif
  469. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  470. #ifdef CONFIG_VFP
  471. @ Always disable VFP so we can lazily save/restore the old
  472. @ state. This occurs in the context of the previous thread.
  473. VFPFMRX r4, FPEXC
  474. bic r4, r4, #FPEXC_ENABLE
  475. VFPFMXR FPEXC, r4
  476. #endif
  477. #if defined(CONFIG_IWMMXT)
  478. bl iwmmxt_task_switch
  479. #elif defined(CONFIG_CPU_XSCALE)
  480. add r4, r2, #40 @ cpu_context_save->extra
  481. ldmib r4, {r4, r5}
  482. mar acc0, r4, r5
  483. #endif
  484. ldmib r2, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
  485. __INIT
  486. /*
  487. * User helpers.
  488. *
  489. * These are segment of kernel provided user code reachable from user space
  490. * at a fixed address in kernel memory. This is used to provide user space
  491. * with some operations which require kernel help because of unimplemented
  492. * native feature and/or instructions in many ARM CPUs. The idea is for
  493. * this code to be executed directly in user mode for best efficiency but
  494. * which is too intimate with the kernel counter part to be left to user
  495. * libraries. In fact this code might even differ from one CPU to another
  496. * depending on the available instruction set and restrictions like on
  497. * SMP systems. In other words, the kernel reserves the right to change
  498. * this code as needed without warning. Only the entry points and their
  499. * results are guaranteed to be stable.
  500. *
  501. * Each segment is 32-byte aligned and will be moved to the top of the high
  502. * vector page. New segments (if ever needed) must be added in front of
  503. * existing ones. This mechanism should be used only for things that are
  504. * really small and justified, and not be abused freely.
  505. *
  506. * User space is expected to implement those things inline when optimizing
  507. * for a processor that has the necessary native support, but only if such
  508. * resulting binaries are already to be incompatible with earlier ARM
  509. * processors due to the use of unsupported instructions other than what
  510. * is provided here. In other words don't make binaries unable to run on
  511. * earlier processors just for the sake of not using these kernel helpers
  512. * if your compiled code is not going to use the new instructions for other
  513. * purpose.
  514. */
  515. .align 5
  516. .globl __kuser_helper_start
  517. __kuser_helper_start:
  518. /*
  519. * Reference prototype:
  520. *
  521. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  522. *
  523. * Input:
  524. *
  525. * r0 = oldval
  526. * r1 = newval
  527. * r2 = ptr
  528. * lr = return address
  529. *
  530. * Output:
  531. *
  532. * r0 = returned value (zero or non-zero)
  533. * C flag = set if r0 == 0, clear if r0 != 0
  534. *
  535. * Clobbered:
  536. *
  537. * r3, ip, flags
  538. *
  539. * Definition and user space usage example:
  540. *
  541. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  542. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  543. *
  544. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  545. * Return zero if *ptr was changed or non-zero if no exchange happened.
  546. * The C flag is also set if *ptr was changed to allow for assembly
  547. * optimization in the calling code.
  548. *
  549. * For example, a user space atomic_add implementation could look like this:
  550. *
  551. * #define atomic_add(ptr, val) \
  552. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  553. * register unsigned int __result asm("r1"); \
  554. * asm volatile ( \
  555. * "1: @ atomic_add\n\t" \
  556. * "ldr r0, [r2]\n\t" \
  557. * "mov r3, #0xffff0fff\n\t" \
  558. * "add lr, pc, #4\n\t" \
  559. * "add r1, r0, %2\n\t" \
  560. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  561. * "bcc 1b" \
  562. * : "=&r" (__result) \
  563. * : "r" (__ptr), "rIL" (val) \
  564. * : "r0","r3","ip","lr","cc","memory" ); \
  565. * __result; })
  566. */
  567. __kuser_cmpxchg: @ 0xffff0fc0
  568. #if __LINUX_ARM_ARCH__ < 6
  569. #ifdef CONFIG_SMP /* sanity check */
  570. #error "CONFIG_SMP on a machine supporting pre-ARMv6 processors?"
  571. #endif
  572. /*
  573. * Theory of operation:
  574. *
  575. * We set the Z flag before loading oldval. If ever an exception
  576. * occurs we can not be sure the loaded value will still be the same
  577. * when the exception returns, therefore the user exception handler
  578. * will clear the Z flag whenever the interrupted user code was
  579. * actually from the kernel address space (see the usr_entry macro).
  580. *
  581. * The post-increment on the str is used to prevent a race with an
  582. * exception happening just after the str instruction which would
  583. * clear the Z flag although the exchange was done.
  584. */
  585. teq ip, ip @ set Z flag
  586. ldr ip, [r2] @ load current val
  587. add r3, r2, #1 @ prepare store ptr
  588. teqeq ip, r0 @ compare with oldval if still allowed
  589. streq r1, [r3, #-1]! @ store newval if still allowed
  590. subs r0, r2, r3 @ if r2 == r3 the str occured
  591. mov pc, lr
  592. #else
  593. ldrex r3, [r2]
  594. subs r3, r3, r0
  595. strexeq r3, r1, [r2]
  596. rsbs r0, r3, #0
  597. mov pc, lr
  598. #endif
  599. .align 5
  600. /*
  601. * Reference prototype:
  602. *
  603. * int __kernel_get_tls(void)
  604. *
  605. * Input:
  606. *
  607. * lr = return address
  608. *
  609. * Output:
  610. *
  611. * r0 = TLS value
  612. *
  613. * Clobbered:
  614. *
  615. * the Z flag might be lost
  616. *
  617. * Definition and user space usage example:
  618. *
  619. * typedef int (__kernel_get_tls_t)(void);
  620. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  621. *
  622. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  623. *
  624. * This could be used as follows:
  625. *
  626. * #define __kernel_get_tls() \
  627. * ({ register unsigned int __val asm("r0"); \
  628. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  629. * : "=r" (__val) : : "lr","cc" ); \
  630. * __val; })
  631. */
  632. __kuser_get_tls: @ 0xffff0fe0
  633. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  634. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  635. mov pc, lr
  636. #else
  637. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  638. mov pc, lr
  639. #endif
  640. .rep 5
  641. .word 0 @ pad up to __kuser_helper_version
  642. .endr
  643. /*
  644. * Reference declaration:
  645. *
  646. * extern unsigned int __kernel_helper_version;
  647. *
  648. * Definition and user space usage example:
  649. *
  650. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  651. *
  652. * User space may read this to determine the curent number of helpers
  653. * available.
  654. */
  655. __kuser_helper_version: @ 0xffff0ffc
  656. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  657. .globl __kuser_helper_end
  658. __kuser_helper_end:
  659. /*
  660. * Vector stubs.
  661. *
  662. * This code is copied to 0xffff0200 so we can use branches in the
  663. * vectors, rather than ldr's. Note that this code must not
  664. * exceed 0x300 bytes.
  665. *
  666. * Common stub entry macro:
  667. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  668. */
  669. .macro vector_stub, name, sym, correction=0
  670. .align 5
  671. vector_\name:
  672. ldr r13, .LCs\sym
  673. .if \correction
  674. sub lr, lr, #\correction
  675. .endif
  676. str lr, [r13] @ save lr_IRQ
  677. mrs lr, spsr
  678. str lr, [r13, #4] @ save spsr_IRQ
  679. @
  680. @ now branch to the relevant MODE handling routine
  681. @
  682. mrs r13, cpsr
  683. bic r13, r13, #MODE_MASK
  684. orr r13, r13, #SVC_MODE
  685. msr spsr_cxsf, r13 @ switch to SVC_32 mode
  686. and lr, lr, #15
  687. ldr lr, [pc, lr, lsl #2]
  688. movs pc, lr @ Changes mode and branches
  689. .endm
  690. .globl __stubs_start
  691. __stubs_start:
  692. /*
  693. * Interrupt dispatcher
  694. */
  695. vector_stub irq, irq, 4
  696. .long __irq_usr @ 0 (USR_26 / USR_32)
  697. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  698. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  699. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  700. .long __irq_invalid @ 4
  701. .long __irq_invalid @ 5
  702. .long __irq_invalid @ 6
  703. .long __irq_invalid @ 7
  704. .long __irq_invalid @ 8
  705. .long __irq_invalid @ 9
  706. .long __irq_invalid @ a
  707. .long __irq_invalid @ b
  708. .long __irq_invalid @ c
  709. .long __irq_invalid @ d
  710. .long __irq_invalid @ e
  711. .long __irq_invalid @ f
  712. /*
  713. * Data abort dispatcher
  714. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  715. */
  716. vector_stub dabt, abt, 8
  717. .long __dabt_usr @ 0 (USR_26 / USR_32)
  718. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  719. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  720. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  721. .long __dabt_invalid @ 4
  722. .long __dabt_invalid @ 5
  723. .long __dabt_invalid @ 6
  724. .long __dabt_invalid @ 7
  725. .long __dabt_invalid @ 8
  726. .long __dabt_invalid @ 9
  727. .long __dabt_invalid @ a
  728. .long __dabt_invalid @ b
  729. .long __dabt_invalid @ c
  730. .long __dabt_invalid @ d
  731. .long __dabt_invalid @ e
  732. .long __dabt_invalid @ f
  733. /*
  734. * Prefetch abort dispatcher
  735. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  736. */
  737. vector_stub pabt, abt, 4
  738. .long __pabt_usr @ 0 (USR_26 / USR_32)
  739. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  740. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  741. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  742. .long __pabt_invalid @ 4
  743. .long __pabt_invalid @ 5
  744. .long __pabt_invalid @ 6
  745. .long __pabt_invalid @ 7
  746. .long __pabt_invalid @ 8
  747. .long __pabt_invalid @ 9
  748. .long __pabt_invalid @ a
  749. .long __pabt_invalid @ b
  750. .long __pabt_invalid @ c
  751. .long __pabt_invalid @ d
  752. .long __pabt_invalid @ e
  753. .long __pabt_invalid @ f
  754. /*
  755. * Undef instr entry dispatcher
  756. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  757. */
  758. vector_stub und, und
  759. .long __und_usr @ 0 (USR_26 / USR_32)
  760. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  761. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  762. .long __und_svc @ 3 (SVC_26 / SVC_32)
  763. .long __und_invalid @ 4
  764. .long __und_invalid @ 5
  765. .long __und_invalid @ 6
  766. .long __und_invalid @ 7
  767. .long __und_invalid @ 8
  768. .long __und_invalid @ 9
  769. .long __und_invalid @ a
  770. .long __und_invalid @ b
  771. .long __und_invalid @ c
  772. .long __und_invalid @ d
  773. .long __und_invalid @ e
  774. .long __und_invalid @ f
  775. .align 5
  776. /*=============================================================================
  777. * Undefined FIQs
  778. *-----------------------------------------------------------------------------
  779. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  780. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  781. * Basically to switch modes, we *HAVE* to clobber one register... brain
  782. * damage alert! I don't think that we can execute any code in here in any
  783. * other mode than FIQ... Ok you can switch to another mode, but you can't
  784. * get out of that mode without clobbering one register.
  785. */
  786. vector_fiq:
  787. disable_fiq
  788. subs pc, lr, #4
  789. /*=============================================================================
  790. * Address exception handler
  791. *-----------------------------------------------------------------------------
  792. * These aren't too critical.
  793. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  794. */
  795. vector_addrexcptn:
  796. b vector_addrexcptn
  797. /*
  798. * We group all the following data together to optimise
  799. * for CPUs with separate I & D caches.
  800. */
  801. .align 5
  802. .LCvswi:
  803. .word vector_swi
  804. .LCsirq:
  805. .word __temp_irq
  806. .LCsund:
  807. .word __temp_und
  808. .LCsabt:
  809. .word __temp_abt
  810. .globl __stubs_end
  811. __stubs_end:
  812. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  813. .globl __vectors_start
  814. __vectors_start:
  815. swi SYS_ERROR0
  816. b vector_und + stubs_offset
  817. ldr pc, .LCvswi + stubs_offset
  818. b vector_pabt + stubs_offset
  819. b vector_dabt + stubs_offset
  820. b vector_addrexcptn + stubs_offset
  821. b vector_irq + stubs_offset
  822. b vector_fiq + stubs_offset
  823. .globl __vectors_end
  824. __vectors_end:
  825. .data
  826. /*
  827. * Do not reorder these, and do not insert extra data between...
  828. */
  829. __temp_irq:
  830. .word 0 @ saved lr_irq
  831. .word 0 @ saved spsr_irq
  832. .word -1 @ old_r0
  833. __temp_und:
  834. .word 0 @ Saved lr_und
  835. .word 0 @ Saved spsr_und
  836. .word -1 @ old_r0
  837. __temp_abt:
  838. .word 0 @ Saved lr_abt
  839. .word 0 @ Saved spsr_abt
  840. .word -1 @ old_r0
  841. .globl cr_alignment
  842. .globl cr_no_alignment
  843. cr_alignment:
  844. .space 4
  845. cr_no_alignment:
  846. .space 4