entry-armv.S 29 KB

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