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