entry-armv.S 28 KB

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