entry-armv.S 22 KB

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