entry-armv.S 27 KB

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