entry-armv.S 28 KB

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