entry-armv.S 25 KB

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