entry-armv.S 29 KB

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