entry-armv.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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
  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 __LINUX_ARM_ARCH__ < 6
  560. #ifdef CONFIG_SMP /* sanity check */
  561. #error "CONFIG_SMP on a machine supporting pre-ARMv6 processors?"
  562. #endif
  563. /*
  564. * Theory of operation:
  565. *
  566. * We set the Z flag before loading oldval. If ever an exception
  567. * occurs we can not be sure the loaded value will still be the same
  568. * when the exception returns, therefore the user exception handler
  569. * will clear the Z flag whenever the interrupted user code was
  570. * actually from the kernel address space (see the usr_entry macro).
  571. *
  572. * The post-increment on the str is used to prevent a race with an
  573. * exception happening just after the str instruction which would
  574. * clear the Z flag although the exchange was done.
  575. */
  576. teq ip, ip @ set Z flag
  577. ldr ip, [r2] @ load current val
  578. add r3, r2, #1 @ prepare store ptr
  579. teqeq ip, r0 @ compare with oldval if still allowed
  580. streq r1, [r3, #-1]! @ store newval if still allowed
  581. subs r0, r2, r3 @ if r2 == r3 the str occured
  582. mov pc, lr
  583. #else
  584. ldrex r3, [r2]
  585. subs r3, r3, r0
  586. strexeq r3, r1, [r2]
  587. rsbs r0, r3, #0
  588. mov pc, lr
  589. #endif
  590. .align 5
  591. /*
  592. * Reference prototype:
  593. *
  594. * int __kernel_get_tls(void)
  595. *
  596. * Input:
  597. *
  598. * lr = return address
  599. *
  600. * Output:
  601. *
  602. * r0 = TLS value
  603. *
  604. * Clobbered:
  605. *
  606. * the Z flag might be lost
  607. *
  608. * Definition and user space usage example:
  609. *
  610. * typedef int (__kernel_get_tls_t)(void);
  611. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  612. *
  613. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  614. *
  615. * This could be used as follows:
  616. *
  617. * #define __kernel_get_tls() \
  618. * ({ register unsigned int __val asm("r0"); \
  619. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  620. * : "=r" (__val) : : "lr","cc" ); \
  621. * __val; })
  622. */
  623. __kuser_get_tls: @ 0xffff0fe0
  624. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  625. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  626. mov pc, lr
  627. #else
  628. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  629. mov pc, lr
  630. #endif
  631. .rep 5
  632. .word 0 @ pad up to __kuser_helper_version
  633. .endr
  634. /*
  635. * Reference declaration:
  636. *
  637. * extern unsigned int __kernel_helper_version;
  638. *
  639. * Definition and user space usage example:
  640. *
  641. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  642. *
  643. * User space may read this to determine the curent number of helpers
  644. * available.
  645. */
  646. __kuser_helper_version: @ 0xffff0ffc
  647. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  648. .globl __kuser_helper_end
  649. __kuser_helper_end:
  650. /*
  651. * Vector stubs.
  652. *
  653. * This code is copied to 0xffff0200 so we can use branches in the
  654. * vectors, rather than ldr's. Note that this code must not
  655. * exceed 0x300 bytes.
  656. *
  657. * Common stub entry macro:
  658. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  659. */
  660. .macro vector_stub, name, sym, correction=0
  661. .align 5
  662. vector_\name:
  663. ldr r13, .LCs\sym
  664. .if \correction
  665. sub lr, lr, #\correction
  666. .endif
  667. str lr, [r13] @ save lr_IRQ
  668. mrs lr, spsr
  669. str lr, [r13, #4] @ save spsr_IRQ
  670. @
  671. @ now branch to the relevant MODE handling routine
  672. @
  673. mrs r13, cpsr
  674. bic r13, r13, #MODE_MASK
  675. orr r13, r13, #SVC_MODE
  676. msr spsr_cxsf, r13 @ switch to SVC_32 mode
  677. and lr, lr, #15
  678. ldr lr, [pc, lr, lsl #2]
  679. movs pc, lr @ Changes mode and branches
  680. .endm
  681. .globl __stubs_start
  682. __stubs_start:
  683. /*
  684. * Interrupt dispatcher
  685. */
  686. vector_stub irq, irq, 4
  687. .long __irq_usr @ 0 (USR_26 / USR_32)
  688. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  689. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  690. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  691. .long __irq_invalid @ 4
  692. .long __irq_invalid @ 5
  693. .long __irq_invalid @ 6
  694. .long __irq_invalid @ 7
  695. .long __irq_invalid @ 8
  696. .long __irq_invalid @ 9
  697. .long __irq_invalid @ a
  698. .long __irq_invalid @ b
  699. .long __irq_invalid @ c
  700. .long __irq_invalid @ d
  701. .long __irq_invalid @ e
  702. .long __irq_invalid @ f
  703. /*
  704. * Data abort dispatcher
  705. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  706. */
  707. vector_stub dabt, abt, 8
  708. .long __dabt_usr @ 0 (USR_26 / USR_32)
  709. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  710. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  711. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  712. .long __dabt_invalid @ 4
  713. .long __dabt_invalid @ 5
  714. .long __dabt_invalid @ 6
  715. .long __dabt_invalid @ 7
  716. .long __dabt_invalid @ 8
  717. .long __dabt_invalid @ 9
  718. .long __dabt_invalid @ a
  719. .long __dabt_invalid @ b
  720. .long __dabt_invalid @ c
  721. .long __dabt_invalid @ d
  722. .long __dabt_invalid @ e
  723. .long __dabt_invalid @ f
  724. /*
  725. * Prefetch abort dispatcher
  726. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  727. */
  728. vector_stub pabt, abt, 4
  729. .long __pabt_usr @ 0 (USR_26 / USR_32)
  730. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  731. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  732. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  733. .long __pabt_invalid @ 4
  734. .long __pabt_invalid @ 5
  735. .long __pabt_invalid @ 6
  736. .long __pabt_invalid @ 7
  737. .long __pabt_invalid @ 8
  738. .long __pabt_invalid @ 9
  739. .long __pabt_invalid @ a
  740. .long __pabt_invalid @ b
  741. .long __pabt_invalid @ c
  742. .long __pabt_invalid @ d
  743. .long __pabt_invalid @ e
  744. .long __pabt_invalid @ f
  745. /*
  746. * Undef instr entry dispatcher
  747. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  748. */
  749. vector_stub und, und
  750. .long __und_usr @ 0 (USR_26 / USR_32)
  751. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  752. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  753. .long __und_svc @ 3 (SVC_26 / SVC_32)
  754. .long __und_invalid @ 4
  755. .long __und_invalid @ 5
  756. .long __und_invalid @ 6
  757. .long __und_invalid @ 7
  758. .long __und_invalid @ 8
  759. .long __und_invalid @ 9
  760. .long __und_invalid @ a
  761. .long __und_invalid @ b
  762. .long __und_invalid @ c
  763. .long __und_invalid @ d
  764. .long __und_invalid @ e
  765. .long __und_invalid @ f
  766. .align 5
  767. /*=============================================================================
  768. * Undefined FIQs
  769. *-----------------------------------------------------------------------------
  770. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  771. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  772. * Basically to switch modes, we *HAVE* to clobber one register... brain
  773. * damage alert! I don't think that we can execute any code in here in any
  774. * other mode than FIQ... Ok you can switch to another mode, but you can't
  775. * get out of that mode without clobbering one register.
  776. */
  777. vector_fiq:
  778. disable_fiq
  779. subs pc, lr, #4
  780. /*=============================================================================
  781. * Address exception handler
  782. *-----------------------------------------------------------------------------
  783. * These aren't too critical.
  784. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  785. */
  786. vector_addrexcptn:
  787. b vector_addrexcptn
  788. /*
  789. * We group all the following data together to optimise
  790. * for CPUs with separate I & D caches.
  791. */
  792. .align 5
  793. .LCvswi:
  794. .word vector_swi
  795. .LCsirq:
  796. .word __temp_irq
  797. .LCsund:
  798. .word __temp_und
  799. .LCsabt:
  800. .word __temp_abt
  801. .globl __stubs_end
  802. __stubs_end:
  803. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  804. .globl __vectors_start
  805. __vectors_start:
  806. swi SYS_ERROR0
  807. b vector_und + stubs_offset
  808. ldr pc, .LCvswi + stubs_offset
  809. b vector_pabt + stubs_offset
  810. b vector_dabt + stubs_offset
  811. b vector_addrexcptn + stubs_offset
  812. b vector_irq + stubs_offset
  813. b vector_fiq + stubs_offset
  814. .globl __vectors_end
  815. __vectors_end:
  816. .data
  817. /*
  818. * Do not reorder these, and do not insert extra data between...
  819. */
  820. __temp_irq:
  821. .word 0 @ saved lr_irq
  822. .word 0 @ saved spsr_irq
  823. .word -1 @ old_r0
  824. __temp_und:
  825. .word 0 @ Saved lr_und
  826. .word 0 @ Saved spsr_und
  827. .word -1 @ old_r0
  828. __temp_abt:
  829. .word 0 @ Saved lr_abt
  830. .word 0 @ Saved spsr_abt
  831. .word -1 @ old_r0
  832. .globl cr_alignment
  833. .globl cr_no_alignment
  834. cr_alignment:
  835. .space 4
  836. cr_no_alignment:
  837. .space 4