entry-armv.S 27 KB

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