entry-armv.S 23 KB

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