entry-armv.S 27 KB

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