entry-armv.S 29 KB

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