entry-armv.S 25 KB

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