entry-armv.S 23 KB

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