entry-armv.S 28 KB

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