entry-armv.S 27 KB

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