entry-armv.S 25 KB

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