entry-armv.S 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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. * void __kernel_memory_barrier(void)
  545. *
  546. * Input:
  547. *
  548. * lr = return address
  549. *
  550. * Output:
  551. *
  552. * none
  553. *
  554. * Clobbered:
  555. *
  556. * the Z flag might be lost
  557. *
  558. * Definition and user space usage example:
  559. *
  560. * typedef void (__kernel_dmb_t)(void);
  561. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  562. *
  563. * Apply any needed memory barrier to preserve consistency with data modified
  564. * manually and __kuser_cmpxchg usage.
  565. *
  566. * This could be used as follows:
  567. *
  568. * #define __kernel_dmb() \
  569. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  570. * : : : "lr","cc" )
  571. */
  572. __kuser_memory_barrier: @ 0xffff0fa0
  573. #if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
  574. mcr p15, 0, r0, c7, c10, 5 @ dmb
  575. #endif
  576. mov pc, lr
  577. .align 5
  578. /*
  579. * Reference prototype:
  580. *
  581. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  582. *
  583. * Input:
  584. *
  585. * r0 = oldval
  586. * r1 = newval
  587. * r2 = ptr
  588. * lr = return address
  589. *
  590. * Output:
  591. *
  592. * r0 = returned value (zero or non-zero)
  593. * C flag = set if r0 == 0, clear if r0 != 0
  594. *
  595. * Clobbered:
  596. *
  597. * r3, ip, flags
  598. *
  599. * Definition and user space usage example:
  600. *
  601. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  602. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  603. *
  604. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  605. * Return zero if *ptr was changed or non-zero if no exchange happened.
  606. * The C flag is also set if *ptr was changed to allow for assembly
  607. * optimization in the calling code.
  608. *
  609. * Note: this routine already includes memory barriers as needed.
  610. *
  611. * For example, a user space atomic_add implementation could look like this:
  612. *
  613. * #define atomic_add(ptr, val) \
  614. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  615. * register unsigned int __result asm("r1"); \
  616. * asm volatile ( \
  617. * "1: @ atomic_add\n\t" \
  618. * "ldr r0, [r2]\n\t" \
  619. * "mov r3, #0xffff0fff\n\t" \
  620. * "add lr, pc, #4\n\t" \
  621. * "add r1, r0, %2\n\t" \
  622. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  623. * "bcc 1b" \
  624. * : "=&r" (__result) \
  625. * : "r" (__ptr), "rIL" (val) \
  626. * : "r0","r3","ip","lr","cc","memory" ); \
  627. * __result; })
  628. */
  629. __kuser_cmpxchg: @ 0xffff0fc0
  630. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  631. /*
  632. * Poor you. No fast solution possible...
  633. * The kernel itself must perform the operation.
  634. * A special ghost syscall is used for that (see traps.c).
  635. */
  636. swi #0x9ffff0
  637. mov pc, lr
  638. #elif __LINUX_ARM_ARCH__ < 6
  639. /*
  640. * Theory of operation:
  641. *
  642. * We set the Z flag before loading oldval. If ever an exception
  643. * occurs we can not be sure the loaded value will still be the same
  644. * when the exception returns, therefore the user exception handler
  645. * will clear the Z flag whenever the interrupted user code was
  646. * actually from the kernel address space (see the usr_entry macro).
  647. *
  648. * The post-increment on the str is used to prevent a race with an
  649. * exception happening just after the str instruction which would
  650. * clear the Z flag although the exchange was done.
  651. */
  652. teq ip, ip @ set Z flag
  653. ldr ip, [r2] @ load current val
  654. add r3, r2, #1 @ prepare store ptr
  655. teqeq ip, r0 @ compare with oldval if still allowed
  656. streq r1, [r3, #-1]! @ store newval if still allowed
  657. subs r0, r2, r3 @ if r2 == r3 the str occured
  658. mov pc, lr
  659. #else
  660. #ifdef CONFIG_SMP
  661. mcr p15, 0, r0, c7, c10, 5 @ dmb
  662. #endif
  663. ldrex r3, [r2]
  664. subs r3, r3, r0
  665. strexeq r3, r1, [r2]
  666. rsbs r0, r3, #0
  667. #ifdef CONFIG_SMP
  668. mcr p15, 0, r0, c7, c10, 5 @ dmb
  669. #endif
  670. mov pc, lr
  671. #endif
  672. .align 5
  673. /*
  674. * Reference prototype:
  675. *
  676. * int __kernel_get_tls(void)
  677. *
  678. * Input:
  679. *
  680. * lr = return address
  681. *
  682. * Output:
  683. *
  684. * r0 = TLS value
  685. *
  686. * Clobbered:
  687. *
  688. * the Z flag might be lost
  689. *
  690. * Definition and user space usage example:
  691. *
  692. * typedef int (__kernel_get_tls_t)(void);
  693. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  694. *
  695. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  696. *
  697. * This could be used as follows:
  698. *
  699. * #define __kernel_get_tls() \
  700. * ({ register unsigned int __val asm("r0"); \
  701. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  702. * : "=r" (__val) : : "lr","cc" ); \
  703. * __val; })
  704. */
  705. __kuser_get_tls: @ 0xffff0fe0
  706. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  707. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  708. mov pc, lr
  709. #else
  710. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  711. mov pc, lr
  712. #endif
  713. .rep 5
  714. .word 0 @ pad up to __kuser_helper_version
  715. .endr
  716. /*
  717. * Reference declaration:
  718. *
  719. * extern unsigned int __kernel_helper_version;
  720. *
  721. * Definition and user space usage example:
  722. *
  723. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  724. *
  725. * User space may read this to determine the curent number of helpers
  726. * available.
  727. */
  728. __kuser_helper_version: @ 0xffff0ffc
  729. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  730. .globl __kuser_helper_end
  731. __kuser_helper_end:
  732. /*
  733. * Vector stubs.
  734. *
  735. * This code is copied to 0xffff0200 so we can use branches in the
  736. * vectors, rather than ldr's. Note that this code must not
  737. * exceed 0x300 bytes.
  738. *
  739. * Common stub entry macro:
  740. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  741. *
  742. * SP points to a minimal amount of processor-private memory, the address
  743. * of which is copied into r0 for the mode specific abort handler.
  744. */
  745. .macro vector_stub, name, mode, correction=0
  746. .align 5
  747. vector_\name:
  748. .if \correction
  749. sub lr, lr, #\correction
  750. .endif
  751. @
  752. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  753. @ (parent CPSR)
  754. @
  755. stmia sp, {r0, lr} @ save r0, lr
  756. mrs lr, spsr
  757. str lr, [sp, #8] @ save spsr
  758. @
  759. @ Prepare for SVC32 mode. IRQs remain disabled.
  760. @
  761. mrs r0, cpsr
  762. eor r0, r0, #(\mode ^ SVC_MODE)
  763. msr spsr_cxsf, r0
  764. @
  765. @ the branch table must immediately follow this code
  766. @
  767. and lr, lr, #0x0f
  768. mov r0, sp
  769. ldr lr, [pc, lr, lsl #2]
  770. movs pc, lr @ branch to handler in SVC mode
  771. .endm
  772. .globl __stubs_start
  773. __stubs_start:
  774. /*
  775. * Interrupt dispatcher
  776. */
  777. vector_stub irq, IRQ_MODE, 4
  778. .long __irq_usr @ 0 (USR_26 / USR_32)
  779. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  780. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  781. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  782. .long __irq_invalid @ 4
  783. .long __irq_invalid @ 5
  784. .long __irq_invalid @ 6
  785. .long __irq_invalid @ 7
  786. .long __irq_invalid @ 8
  787. .long __irq_invalid @ 9
  788. .long __irq_invalid @ a
  789. .long __irq_invalid @ b
  790. .long __irq_invalid @ c
  791. .long __irq_invalid @ d
  792. .long __irq_invalid @ e
  793. .long __irq_invalid @ f
  794. /*
  795. * Data abort dispatcher
  796. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  797. */
  798. vector_stub dabt, ABT_MODE, 8
  799. .long __dabt_usr @ 0 (USR_26 / USR_32)
  800. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  801. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  802. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  803. .long __dabt_invalid @ 4
  804. .long __dabt_invalid @ 5
  805. .long __dabt_invalid @ 6
  806. .long __dabt_invalid @ 7
  807. .long __dabt_invalid @ 8
  808. .long __dabt_invalid @ 9
  809. .long __dabt_invalid @ a
  810. .long __dabt_invalid @ b
  811. .long __dabt_invalid @ c
  812. .long __dabt_invalid @ d
  813. .long __dabt_invalid @ e
  814. .long __dabt_invalid @ f
  815. /*
  816. * Prefetch abort dispatcher
  817. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  818. */
  819. vector_stub pabt, ABT_MODE, 4
  820. .long __pabt_usr @ 0 (USR_26 / USR_32)
  821. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  822. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  823. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  824. .long __pabt_invalid @ 4
  825. .long __pabt_invalid @ 5
  826. .long __pabt_invalid @ 6
  827. .long __pabt_invalid @ 7
  828. .long __pabt_invalid @ 8
  829. .long __pabt_invalid @ 9
  830. .long __pabt_invalid @ a
  831. .long __pabt_invalid @ b
  832. .long __pabt_invalid @ c
  833. .long __pabt_invalid @ d
  834. .long __pabt_invalid @ e
  835. .long __pabt_invalid @ f
  836. /*
  837. * Undef instr entry dispatcher
  838. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  839. */
  840. vector_stub und, UND_MODE
  841. .long __und_usr @ 0 (USR_26 / USR_32)
  842. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  843. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  844. .long __und_svc @ 3 (SVC_26 / SVC_32)
  845. .long __und_invalid @ 4
  846. .long __und_invalid @ 5
  847. .long __und_invalid @ 6
  848. .long __und_invalid @ 7
  849. .long __und_invalid @ 8
  850. .long __und_invalid @ 9
  851. .long __und_invalid @ a
  852. .long __und_invalid @ b
  853. .long __und_invalid @ c
  854. .long __und_invalid @ d
  855. .long __und_invalid @ e
  856. .long __und_invalid @ f
  857. .align 5
  858. /*=============================================================================
  859. * Undefined FIQs
  860. *-----------------------------------------------------------------------------
  861. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  862. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  863. * Basically to switch modes, we *HAVE* to clobber one register... brain
  864. * damage alert! I don't think that we can execute any code in here in any
  865. * other mode than FIQ... Ok you can switch to another mode, but you can't
  866. * get out of that mode without clobbering one register.
  867. */
  868. vector_fiq:
  869. disable_fiq
  870. subs pc, lr, #4
  871. /*=============================================================================
  872. * Address exception handler
  873. *-----------------------------------------------------------------------------
  874. * These aren't too critical.
  875. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  876. */
  877. vector_addrexcptn:
  878. b vector_addrexcptn
  879. /*
  880. * We group all the following data together to optimise
  881. * for CPUs with separate I & D caches.
  882. */
  883. .align 5
  884. .LCvswi:
  885. .word vector_swi
  886. .globl __stubs_end
  887. __stubs_end:
  888. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  889. .globl __vectors_start
  890. __vectors_start:
  891. swi SYS_ERROR0
  892. b vector_und + stubs_offset
  893. ldr pc, .LCvswi + stubs_offset
  894. b vector_pabt + stubs_offset
  895. b vector_dabt + stubs_offset
  896. b vector_addrexcptn + stubs_offset
  897. b vector_irq + stubs_offset
  898. b vector_fiq + stubs_offset
  899. .globl __vectors_end
  900. __vectors_end:
  901. .data
  902. .globl cr_alignment
  903. .globl cr_no_alignment
  904. cr_alignment:
  905. .space 4
  906. cr_no_alignment:
  907. .space 4