entry-armv.S 29 KB

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