entry-armv.S 28 KB

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