entry-armv.S 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  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 __LINUX_ARM_ARCH__ < 6 && !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_cmpxchg_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. get_thread_info tsk
  384. #ifdef CONFIG_PREEMPT
  385. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  386. add r7, r8, #1 @ increment it
  387. str r7, [tsk, #TI_PREEMPT]
  388. #endif
  389. irq_handler
  390. #ifdef CONFIG_PREEMPT
  391. ldr r0, [tsk, #TI_PREEMPT]
  392. str r8, [tsk, #TI_PREEMPT]
  393. teq r0, r7
  394. ARM( strne r0, [r0, -r0] )
  395. THUMB( movne r0, #0 )
  396. THUMB( strne r0, [r0] )
  397. #endif
  398. mov why, #0
  399. b ret_to_user
  400. UNWIND(.fnend )
  401. ENDPROC(__irq_usr)
  402. .ltorg
  403. .align 5
  404. __und_usr:
  405. usr_entry
  406. @
  407. @ fall through to the emulation code, which returns using r9 if
  408. @ it has emulated the instruction, or the more conventional lr
  409. @ if we are to treat this as a real undefined instruction
  410. @
  411. @ r0 - instruction
  412. @
  413. adr r9, BSYM(ret_from_exception)
  414. adr lr, BSYM(__und_usr_unknown)
  415. tst r3, #PSR_T_BIT @ Thumb mode?
  416. itet eq @ explicit IT needed for the 1f label
  417. subeq r4, r2, #4 @ ARM instr at LR - 4
  418. subne r4, r2, #2 @ Thumb instr at LR - 2
  419. 1: ldreqt r0, [r4]
  420. #ifdef CONFIG_CPU_ENDIAN_BE8
  421. reveq r0, r0 @ little endian instruction
  422. #endif
  423. beq call_fpe
  424. @ Thumb instruction
  425. #if __LINUX_ARM_ARCH__ >= 7
  426. 2:
  427. ARM( ldrht r5, [r4], #2 )
  428. THUMB( ldrht r5, [r4] )
  429. THUMB( add r4, r4, #2 )
  430. and r0, r5, #0xf800 @ mask bits 111x x... .... ....
  431. cmp r0, #0xe800 @ 32bit instruction if xx != 0
  432. blo __und_usr_unknown
  433. 3: ldrht r0, [r4]
  434. add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
  435. orr r0, r0, r5, lsl #16
  436. #else
  437. b __und_usr_unknown
  438. #endif
  439. UNWIND(.fnend )
  440. ENDPROC(__und_usr)
  441. @
  442. @ fallthrough to call_fpe
  443. @
  444. /*
  445. * The out of line fixup for the ldrt above.
  446. */
  447. .pushsection .fixup, "ax"
  448. 4: mov pc, r9
  449. .popsection
  450. .pushsection __ex_table,"a"
  451. .long 1b, 4b
  452. #if __LINUX_ARM_ARCH__ >= 7
  453. .long 2b, 4b
  454. .long 3b, 4b
  455. #endif
  456. .popsection
  457. /*
  458. * Check whether the instruction is a co-processor instruction.
  459. * If yes, we need to call the relevant co-processor handler.
  460. *
  461. * Note that we don't do a full check here for the co-processor
  462. * instructions; all instructions with bit 27 set are well
  463. * defined. The only instructions that should fault are the
  464. * co-processor instructions. However, we have to watch out
  465. * for the ARM6/ARM7 SWI bug.
  466. *
  467. * NEON is a special case that has to be handled here. Not all
  468. * NEON instructions are co-processor instructions, so we have
  469. * to make a special case of checking for them. Plus, there's
  470. * five groups of them, so we have a table of mask/opcode pairs
  471. * to check against, and if any match then we branch off into the
  472. * NEON handler code.
  473. *
  474. * Emulators may wish to make use of the following registers:
  475. * r0 = instruction opcode.
  476. * r2 = PC+4
  477. * r9 = normal "successful" return address
  478. * r10 = this threads thread_info structure.
  479. * lr = unrecognised instruction return address
  480. */
  481. @
  482. @ Fall-through from Thumb-2 __und_usr
  483. @
  484. #ifdef CONFIG_NEON
  485. adr r6, .LCneon_thumb_opcodes
  486. b 2f
  487. #endif
  488. call_fpe:
  489. #ifdef CONFIG_NEON
  490. adr r6, .LCneon_arm_opcodes
  491. 2:
  492. ldr r7, [r6], #4 @ mask value
  493. cmp r7, #0 @ end mask?
  494. beq 1f
  495. and r8, r0, r7
  496. ldr r7, [r6], #4 @ opcode bits matching in mask
  497. cmp r8, r7 @ NEON instruction?
  498. bne 2b
  499. get_thread_info r10
  500. mov r7, #1
  501. strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
  502. strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
  503. b do_vfp @ let VFP handler handle this
  504. 1:
  505. #endif
  506. tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
  507. tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
  508. #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
  509. and r8, r0, #0x0f000000 @ mask out op-code bits
  510. teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
  511. #endif
  512. moveq pc, lr
  513. get_thread_info r10 @ get current thread
  514. and r8, r0, #0x00000f00 @ mask out CP number
  515. THUMB( lsr r8, r8, #8 )
  516. mov r7, #1
  517. add r6, r10, #TI_USED_CP
  518. ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[]
  519. THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[]
  520. #ifdef CONFIG_IWMMXT
  521. @ Test if we need to give access to iWMMXt coprocessors
  522. ldr r5, [r10, #TI_FLAGS]
  523. rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
  524. movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
  525. bcs iwmmxt_task_enable
  526. #endif
  527. ARM( add pc, pc, r8, lsr #6 )
  528. THUMB( lsl r8, r8, #2 )
  529. THUMB( add pc, r8 )
  530. nop
  531. movw_pc lr @ CP#0
  532. W(b) do_fpe @ CP#1 (FPE)
  533. W(b) do_fpe @ CP#2 (FPE)
  534. movw_pc lr @ CP#3
  535. #ifdef CONFIG_CRUNCH
  536. b crunch_task_enable @ CP#4 (MaverickCrunch)
  537. b crunch_task_enable @ CP#5 (MaverickCrunch)
  538. b crunch_task_enable @ CP#6 (MaverickCrunch)
  539. #else
  540. movw_pc lr @ CP#4
  541. movw_pc lr @ CP#5
  542. movw_pc lr @ CP#6
  543. #endif
  544. movw_pc lr @ CP#7
  545. movw_pc lr @ CP#8
  546. movw_pc lr @ CP#9
  547. #ifdef CONFIG_VFP
  548. W(b) do_vfp @ CP#10 (VFP)
  549. W(b) do_vfp @ CP#11 (VFP)
  550. #else
  551. movw_pc lr @ CP#10 (VFP)
  552. movw_pc lr @ CP#11 (VFP)
  553. #endif
  554. movw_pc lr @ CP#12
  555. movw_pc lr @ CP#13
  556. movw_pc lr @ CP#14 (Debug)
  557. movw_pc lr @ CP#15 (Control)
  558. #ifdef CONFIG_NEON
  559. .align 6
  560. .LCneon_arm_opcodes:
  561. .word 0xfe000000 @ mask
  562. .word 0xf2000000 @ opcode
  563. .word 0xff100000 @ mask
  564. .word 0xf4000000 @ opcode
  565. .word 0x00000000 @ mask
  566. .word 0x00000000 @ opcode
  567. .LCneon_thumb_opcodes:
  568. .word 0xef000000 @ mask
  569. .word 0xef000000 @ opcode
  570. .word 0xff100000 @ mask
  571. .word 0xf9000000 @ opcode
  572. .word 0x00000000 @ mask
  573. .word 0x00000000 @ opcode
  574. #endif
  575. do_fpe:
  576. enable_irq
  577. ldr r4, .LCfp
  578. add r10, r10, #TI_FPSTATE @ r10 = workspace
  579. ldr pc, [r4] @ Call FP module USR entry point
  580. /*
  581. * The FP module is called with these registers set:
  582. * r0 = instruction
  583. * r2 = PC+4
  584. * r9 = normal "successful" return address
  585. * r10 = FP workspace
  586. * lr = unrecognised FP instruction return address
  587. */
  588. .pushsection .data
  589. ENTRY(fp_enter)
  590. .word no_fp
  591. .popsection
  592. ENTRY(no_fp)
  593. mov pc, lr
  594. ENDPROC(no_fp)
  595. __und_usr_unknown:
  596. enable_irq
  597. mov r0, sp
  598. adr lr, BSYM(ret_from_exception)
  599. b do_undefinstr
  600. ENDPROC(__und_usr_unknown)
  601. .align 5
  602. __pabt_usr:
  603. usr_entry
  604. mov r0, r2 @ pass address of aborted instruction.
  605. #ifdef MULTI_PABORT
  606. ldr r4, .LCprocfns
  607. mov lr, pc
  608. ldr pc, [r4, #PROCESSOR_PABT_FUNC]
  609. #else
  610. bl CPU_PABORT_HANDLER
  611. #endif
  612. debug_entry r1
  613. enable_irq @ Enable interrupts
  614. mov r2, sp @ regs
  615. bl do_PrefetchAbort @ call abort handler
  616. UNWIND(.fnend )
  617. /* fall through */
  618. /*
  619. * This is the return code to user mode for abort handlers
  620. */
  621. ENTRY(ret_from_exception)
  622. UNWIND(.fnstart )
  623. UNWIND(.cantunwind )
  624. get_thread_info tsk
  625. mov why, #0
  626. b ret_to_user
  627. UNWIND(.fnend )
  628. ENDPROC(__pabt_usr)
  629. ENDPROC(ret_from_exception)
  630. /*
  631. * Register switch for ARMv3 and ARMv4 processors
  632. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  633. * previous and next are guaranteed not to be the same.
  634. */
  635. ENTRY(__switch_to)
  636. UNWIND(.fnstart )
  637. UNWIND(.cantunwind )
  638. add ip, r1, #TI_CPU_SAVE
  639. ldr r3, [r2, #TI_TP_VALUE]
  640. ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack
  641. THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
  642. THUMB( str sp, [ip], #4 )
  643. THUMB( str lr, [ip], #4 )
  644. #ifdef CONFIG_CPU_USE_DOMAINS
  645. ldr r6, [r2, #TI_CPU_DOMAIN]
  646. #endif
  647. set_tls r3, r4, r5
  648. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  649. ldr r7, [r2, #TI_TASK]
  650. ldr r8, =__stack_chk_guard
  651. ldr r7, [r7, #TSK_STACK_CANARY]
  652. #endif
  653. #ifdef CONFIG_CPU_USE_DOMAINS
  654. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  655. #endif
  656. mov r5, r0
  657. add r4, r2, #TI_CPU_SAVE
  658. ldr r0, =thread_notify_head
  659. mov r1, #THREAD_NOTIFY_SWITCH
  660. bl atomic_notifier_call_chain
  661. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  662. str r7, [r8]
  663. #endif
  664. THUMB( mov ip, r4 )
  665. mov r0, r5
  666. ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously
  667. THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously
  668. THUMB( ldr sp, [ip], #4 )
  669. THUMB( ldr pc, [ip] )
  670. UNWIND(.fnend )
  671. ENDPROC(__switch_to)
  672. __INIT
  673. /*
  674. * User helpers.
  675. *
  676. * These are segment of kernel provided user code reachable from user space
  677. * at a fixed address in kernel memory. This is used to provide user space
  678. * with some operations which require kernel help because of unimplemented
  679. * native feature and/or instructions in many ARM CPUs. The idea is for
  680. * this code to be executed directly in user mode for best efficiency but
  681. * which is too intimate with the kernel counter part to be left to user
  682. * libraries. In fact this code might even differ from one CPU to another
  683. * depending on the available instruction set and restrictions like on
  684. * SMP systems. In other words, the kernel reserves the right to change
  685. * this code as needed without warning. Only the entry points and their
  686. * results are guaranteed to be stable.
  687. *
  688. * Each segment is 32-byte aligned and will be moved to the top of the high
  689. * vector page. New segments (if ever needed) must be added in front of
  690. * existing ones. This mechanism should be used only for things that are
  691. * really small and justified, and not be abused freely.
  692. *
  693. * User space is expected to implement those things inline when optimizing
  694. * for a processor that has the necessary native support, but only if such
  695. * resulting binaries are already to be incompatible with earlier ARM
  696. * processors due to the use of unsupported instructions other than what
  697. * is provided here. In other words don't make binaries unable to run on
  698. * earlier processors just for the sake of not using these kernel helpers
  699. * if your compiled code is not going to use the new instructions for other
  700. * purpose.
  701. */
  702. THUMB( .arm )
  703. .macro usr_ret, reg
  704. #ifdef CONFIG_ARM_THUMB
  705. bx \reg
  706. #else
  707. mov pc, \reg
  708. #endif
  709. .endm
  710. .align 5
  711. .globl __kuser_helper_start
  712. __kuser_helper_start:
  713. /*
  714. * Reference prototype:
  715. *
  716. * void __kernel_memory_barrier(void)
  717. *
  718. * Input:
  719. *
  720. * lr = return address
  721. *
  722. * Output:
  723. *
  724. * none
  725. *
  726. * Clobbered:
  727. *
  728. * none
  729. *
  730. * Definition and user space usage example:
  731. *
  732. * typedef void (__kernel_dmb_t)(void);
  733. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  734. *
  735. * Apply any needed memory barrier to preserve consistency with data modified
  736. * manually and __kuser_cmpxchg usage.
  737. *
  738. * This could be used as follows:
  739. *
  740. * #define __kernel_dmb() \
  741. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  742. * : : : "r0", "lr","cc" )
  743. */
  744. __kuser_memory_barrier: @ 0xffff0fa0
  745. smp_dmb arm
  746. usr_ret lr
  747. .align 5
  748. /*
  749. * Reference prototype:
  750. *
  751. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  752. *
  753. * Input:
  754. *
  755. * r0 = oldval
  756. * r1 = newval
  757. * r2 = ptr
  758. * lr = return address
  759. *
  760. * Output:
  761. *
  762. * r0 = returned value (zero or non-zero)
  763. * C flag = set if r0 == 0, clear if r0 != 0
  764. *
  765. * Clobbered:
  766. *
  767. * r3, ip, flags
  768. *
  769. * Definition and user space usage example:
  770. *
  771. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  772. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  773. *
  774. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  775. * Return zero if *ptr was changed or non-zero if no exchange happened.
  776. * The C flag is also set if *ptr was changed to allow for assembly
  777. * optimization in the calling code.
  778. *
  779. * Notes:
  780. *
  781. * - This routine already includes memory barriers as needed.
  782. *
  783. * For example, a user space atomic_add implementation could look like this:
  784. *
  785. * #define atomic_add(ptr, val) \
  786. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  787. * register unsigned int __result asm("r1"); \
  788. * asm volatile ( \
  789. * "1: @ atomic_add\n\t" \
  790. * "ldr r0, [r2]\n\t" \
  791. * "mov r3, #0xffff0fff\n\t" \
  792. * "add lr, pc, #4\n\t" \
  793. * "add r1, r0, %2\n\t" \
  794. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  795. * "bcc 1b" \
  796. * : "=&r" (__result) \
  797. * : "r" (__ptr), "rIL" (val) \
  798. * : "r0","r3","ip","lr","cc","memory" ); \
  799. * __result; })
  800. */
  801. __kuser_cmpxchg: @ 0xffff0fc0
  802. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  803. /*
  804. * Poor you. No fast solution possible...
  805. * The kernel itself must perform the operation.
  806. * A special ghost syscall is used for that (see traps.c).
  807. */
  808. stmfd sp!, {r7, lr}
  809. ldr r7, 1f @ it's 20 bits
  810. swi __ARM_NR_cmpxchg
  811. ldmfd sp!, {r7, pc}
  812. 1: .word __ARM_NR_cmpxchg
  813. #elif __LINUX_ARM_ARCH__ < 6
  814. #ifdef CONFIG_MMU
  815. /*
  816. * The only thing that can break atomicity in this cmpxchg
  817. * implementation is either an IRQ or a data abort exception
  818. * causing another process/thread to be scheduled in the middle
  819. * of the critical sequence. To prevent this, code is added to
  820. * the IRQ and data abort exception handlers to set the pc back
  821. * to the beginning of the critical section if it is found to be
  822. * within that critical section (see kuser_cmpxchg_fixup).
  823. */
  824. 1: ldr r3, [r2] @ load current val
  825. subs r3, r3, r0 @ compare with oldval
  826. 2: streq r1, [r2] @ store newval if eq
  827. rsbs r0, r3, #0 @ set return val and C flag
  828. usr_ret lr
  829. .text
  830. kuser_cmpxchg_fixup:
  831. @ Called from kuser_cmpxchg_check macro.
  832. @ r2 = address of interrupted insn (must be preserved).
  833. @ sp = saved regs. r7 and r8 are clobbered.
  834. @ 1b = first critical insn, 2b = last critical insn.
  835. @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
  836. mov r7, #0xffff0fff
  837. sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
  838. subs r8, r2, r7
  839. rsbcss r8, r8, #(2b - 1b)
  840. strcs r7, [sp, #S_PC]
  841. mov pc, lr
  842. .previous
  843. #else
  844. #warning "NPTL on non MMU needs fixing"
  845. mov r0, #-1
  846. adds r0, r0, #0
  847. usr_ret lr
  848. #endif
  849. #else
  850. smp_dmb arm
  851. 1: ldrex r3, [r2]
  852. subs r3, r3, r0
  853. strexeq r3, r1, [r2]
  854. teqeq r3, #1
  855. beq 1b
  856. rsbs r0, r3, #0
  857. /* beware -- each __kuser slot must be 8 instructions max */
  858. ALT_SMP(b __kuser_memory_barrier)
  859. ALT_UP(usr_ret lr)
  860. #endif
  861. .align 5
  862. /*
  863. * Reference prototype:
  864. *
  865. * int __kernel_get_tls(void)
  866. *
  867. * Input:
  868. *
  869. * lr = return address
  870. *
  871. * Output:
  872. *
  873. * r0 = TLS value
  874. *
  875. * Clobbered:
  876. *
  877. * none
  878. *
  879. * Definition and user space usage example:
  880. *
  881. * typedef int (__kernel_get_tls_t)(void);
  882. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  883. *
  884. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  885. *
  886. * This could be used as follows:
  887. *
  888. * #define __kernel_get_tls() \
  889. * ({ register unsigned int __val asm("r0"); \
  890. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  891. * : "=r" (__val) : : "lr","cc" ); \
  892. * __val; })
  893. */
  894. __kuser_get_tls: @ 0xffff0fe0
  895. ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init
  896. usr_ret lr
  897. mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code
  898. .rep 4
  899. .word 0 @ 0xffff0ff0 software TLS value, then
  900. .endr @ pad up to __kuser_helper_version
  901. /*
  902. * Reference declaration:
  903. *
  904. * extern unsigned int __kernel_helper_version;
  905. *
  906. * Definition and user space usage example:
  907. *
  908. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  909. *
  910. * User space may read this to determine the curent number of helpers
  911. * available.
  912. */
  913. __kuser_helper_version: @ 0xffff0ffc
  914. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  915. .globl __kuser_helper_end
  916. __kuser_helper_end:
  917. THUMB( .thumb )
  918. /*
  919. * Vector stubs.
  920. *
  921. * This code is copied to 0xffff0200 so we can use branches in the
  922. * vectors, rather than ldr's. Note that this code must not
  923. * exceed 0x300 bytes.
  924. *
  925. * Common stub entry macro:
  926. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  927. *
  928. * SP points to a minimal amount of processor-private memory, the address
  929. * of which is copied into r0 for the mode specific abort handler.
  930. */
  931. .macro vector_stub, name, mode, correction=0
  932. .align 5
  933. vector_\name:
  934. .if \correction
  935. sub lr, lr, #\correction
  936. .endif
  937. @
  938. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  939. @ (parent CPSR)
  940. @
  941. stmia sp, {r0, lr} @ save r0, lr
  942. mrs lr, spsr
  943. str lr, [sp, #8] @ save spsr
  944. @
  945. @ Prepare for SVC32 mode. IRQs remain disabled.
  946. @
  947. mrs r0, cpsr
  948. eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
  949. msr spsr_cxsf, r0
  950. @
  951. @ the branch table must immediately follow this code
  952. @
  953. and lr, lr, #0x0f
  954. THUMB( adr r0, 1f )
  955. THUMB( ldr lr, [r0, lr, lsl #2] )
  956. mov r0, sp
  957. ARM( ldr lr, [pc, lr, lsl #2] )
  958. movs pc, lr @ branch to handler in SVC mode
  959. ENDPROC(vector_\name)
  960. .align 2
  961. @ handler addresses follow this label
  962. 1:
  963. .endm
  964. .globl __stubs_start
  965. __stubs_start:
  966. /*
  967. * Interrupt dispatcher
  968. */
  969. vector_stub irq, IRQ_MODE, 4
  970. .long __irq_usr @ 0 (USR_26 / USR_32)
  971. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  972. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  973. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  974. .long __irq_invalid @ 4
  975. .long __irq_invalid @ 5
  976. .long __irq_invalid @ 6
  977. .long __irq_invalid @ 7
  978. .long __irq_invalid @ 8
  979. .long __irq_invalid @ 9
  980. .long __irq_invalid @ a
  981. .long __irq_invalid @ b
  982. .long __irq_invalid @ c
  983. .long __irq_invalid @ d
  984. .long __irq_invalid @ e
  985. .long __irq_invalid @ f
  986. /*
  987. * Data abort dispatcher
  988. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  989. */
  990. vector_stub dabt, ABT_MODE, 8
  991. .long __dabt_usr @ 0 (USR_26 / USR_32)
  992. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  993. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  994. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  995. .long __dabt_invalid @ 4
  996. .long __dabt_invalid @ 5
  997. .long __dabt_invalid @ 6
  998. .long __dabt_invalid @ 7
  999. .long __dabt_invalid @ 8
  1000. .long __dabt_invalid @ 9
  1001. .long __dabt_invalid @ a
  1002. .long __dabt_invalid @ b
  1003. .long __dabt_invalid @ c
  1004. .long __dabt_invalid @ d
  1005. .long __dabt_invalid @ e
  1006. .long __dabt_invalid @ f
  1007. /*
  1008. * Prefetch abort dispatcher
  1009. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  1010. */
  1011. vector_stub pabt, ABT_MODE, 4
  1012. .long __pabt_usr @ 0 (USR_26 / USR_32)
  1013. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  1014. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  1015. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  1016. .long __pabt_invalid @ 4
  1017. .long __pabt_invalid @ 5
  1018. .long __pabt_invalid @ 6
  1019. .long __pabt_invalid @ 7
  1020. .long __pabt_invalid @ 8
  1021. .long __pabt_invalid @ 9
  1022. .long __pabt_invalid @ a
  1023. .long __pabt_invalid @ b
  1024. .long __pabt_invalid @ c
  1025. .long __pabt_invalid @ d
  1026. .long __pabt_invalid @ e
  1027. .long __pabt_invalid @ f
  1028. /*
  1029. * Undef instr entry dispatcher
  1030. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  1031. */
  1032. vector_stub und, UND_MODE
  1033. .long __und_usr @ 0 (USR_26 / USR_32)
  1034. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  1035. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  1036. .long __und_svc @ 3 (SVC_26 / SVC_32)
  1037. .long __und_invalid @ 4
  1038. .long __und_invalid @ 5
  1039. .long __und_invalid @ 6
  1040. .long __und_invalid @ 7
  1041. .long __und_invalid @ 8
  1042. .long __und_invalid @ 9
  1043. .long __und_invalid @ a
  1044. .long __und_invalid @ b
  1045. .long __und_invalid @ c
  1046. .long __und_invalid @ d
  1047. .long __und_invalid @ e
  1048. .long __und_invalid @ f
  1049. .align 5
  1050. /*=============================================================================
  1051. * Undefined FIQs
  1052. *-----------------------------------------------------------------------------
  1053. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  1054. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  1055. * Basically to switch modes, we *HAVE* to clobber one register... brain
  1056. * damage alert! I don't think that we can execute any code in here in any
  1057. * other mode than FIQ... Ok you can switch to another mode, but you can't
  1058. * get out of that mode without clobbering one register.
  1059. */
  1060. vector_fiq:
  1061. disable_fiq
  1062. subs pc, lr, #4
  1063. /*=============================================================================
  1064. * Address exception handler
  1065. *-----------------------------------------------------------------------------
  1066. * These aren't too critical.
  1067. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  1068. */
  1069. vector_addrexcptn:
  1070. b vector_addrexcptn
  1071. /*
  1072. * We group all the following data together to optimise
  1073. * for CPUs with separate I & D caches.
  1074. */
  1075. .align 5
  1076. .LCvswi:
  1077. .word vector_swi
  1078. .globl __stubs_end
  1079. __stubs_end:
  1080. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  1081. .globl __vectors_start
  1082. __vectors_start:
  1083. ARM( swi SYS_ERROR0 )
  1084. THUMB( svc #0 )
  1085. THUMB( nop )
  1086. W(b) vector_und + stubs_offset
  1087. W(ldr) pc, .LCvswi + stubs_offset
  1088. W(b) vector_pabt + stubs_offset
  1089. W(b) vector_dabt + stubs_offset
  1090. W(b) vector_addrexcptn + stubs_offset
  1091. W(b) vector_irq + stubs_offset
  1092. W(b) vector_fiq + stubs_offset
  1093. .globl __vectors_end
  1094. __vectors_end:
  1095. .data
  1096. .globl cr_alignment
  1097. .globl cr_no_alignment
  1098. cr_alignment:
  1099. .space 4
  1100. cr_no_alignment:
  1101. .space 4
  1102. #ifdef CONFIG_MULTI_IRQ_HANDLER
  1103. .globl handle_arch_irq
  1104. handle_arch_irq:
  1105. .space 4
  1106. #endif