entry-armv.S 22 KB

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