entry-armv.S 27 KB

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