entry-armv.S 27 KB

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