entry-armv.S 28 KB

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