entry-armv.S 24 KB

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