entry-armv.S 29 KB

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