entry-armv.S 26 KB

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