entry-armv.S 28 KB

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