entry-armv.S 27 KB

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