entry-armv.S 27 KB

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