entry-armv.S 22 KB

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