entry-armv.S 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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 that causes
  15. * 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_ABORT
  145. ldr r4, .LCprocfns
  146. mov lr, pc
  147. ldr pc, [r4]
  148. #else
  149. bl CPU_ABORT_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. msr cpsr_c, r9
  257. @
  258. @ set args, then call main handler
  259. @
  260. @ r0 - address of faulting instruction
  261. @ r1 - pointer to registers on stack
  262. @
  263. mov r0, r2 @ address (pc)
  264. mov r1, sp @ regs
  265. bl do_PrefetchAbort @ call abort handler
  266. @
  267. @ IRQs off again before pulling preserved data off the stack
  268. @
  269. disable_irq
  270. @
  271. @ restore SPSR and restart the instruction
  272. @
  273. ldr r0, [sp, #S_PSR]
  274. msr spsr_cxsf, r0
  275. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  276. .align 5
  277. .LCcralign:
  278. .word cr_alignment
  279. #ifdef MULTI_ABORT
  280. .LCprocfns:
  281. .word processor
  282. #endif
  283. .LCfp:
  284. .word fp_enter
  285. #ifdef CONFIG_PREEMPT
  286. .LCirq_stat:
  287. .word irq_stat
  288. #endif
  289. /*
  290. * User mode handlers
  291. *
  292. * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
  293. */
  294. #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
  295. #error "sizeof(struct pt_regs) must be a multiple of 8"
  296. #endif
  297. .macro usr_entry
  298. sub sp, sp, #S_FRAME_SIZE
  299. stmib sp, {r1 - r12}
  300. ldmia r0, {r1 - r3}
  301. add r0, sp, #S_PC @ here for interlock avoidance
  302. mov r4, #-1 @ "" "" "" ""
  303. str r1, [sp] @ save the "real" r0 copied
  304. @ from the exception stack
  305. @
  306. @ We are now ready to fill in the remaining blanks on the stack:
  307. @
  308. @ r2 - lr_<exception>, already fixed up for correct return/restart
  309. @ r3 - spsr_<exception>
  310. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  311. @
  312. @ Also, separately save sp_usr and lr_usr
  313. @
  314. stmia r0, {r2 - r4}
  315. stmdb r0, {sp, lr}^
  316. @
  317. @ Enable the alignment trap while in kernel mode
  318. @
  319. alignment_trap r0
  320. @
  321. @ Clear FP to mark the first stack frame
  322. @
  323. zero_fp
  324. .endm
  325. .macro kuser_cmpxchg_check
  326. #if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  327. #ifndef CONFIG_MMU
  328. #warning "NPTL on non MMU needs fixing"
  329. #else
  330. @ Make sure our user space atomic helper is restarted
  331. @ if it was interrupted in a critical region. Here we
  332. @ perform a quick test inline since it should be false
  333. @ 99.9999% of the time. The rest is done out of line.
  334. cmp r2, #TASK_SIZE
  335. blhs kuser_cmpxchg_fixup
  336. #endif
  337. #endif
  338. .endm
  339. .align 5
  340. __dabt_usr:
  341. usr_entry
  342. kuser_cmpxchg_check
  343. @
  344. @ Call the processor-specific abort handler:
  345. @
  346. @ r2 - aborted context pc
  347. @ r3 - aborted context cpsr
  348. @
  349. @ The abort handler must return the aborted address in r0, and
  350. @ the fault status register in r1.
  351. @
  352. #ifdef MULTI_ABORT
  353. ldr r4, .LCprocfns
  354. mov lr, pc
  355. ldr pc, [r4]
  356. #else
  357. bl CPU_ABORT_HANDLER
  358. #endif
  359. @
  360. @ IRQs on, then call the main handler
  361. @
  362. enable_irq
  363. mov r2, sp
  364. adr lr, ret_from_exception
  365. b do_DataAbort
  366. .align 5
  367. __irq_usr:
  368. usr_entry
  369. kuser_cmpxchg_check
  370. #ifdef CONFIG_TRACE_IRQFLAGS
  371. bl trace_hardirqs_off
  372. #endif
  373. get_thread_info tsk
  374. #ifdef CONFIG_PREEMPT
  375. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  376. add r7, r8, #1 @ increment it
  377. str r7, [tsk, #TI_PREEMPT]
  378. #endif
  379. irq_handler
  380. #ifdef CONFIG_PREEMPT
  381. ldr r0, [tsk, #TI_PREEMPT]
  382. str r8, [tsk, #TI_PREEMPT]
  383. teq r0, r7
  384. strne r0, [r0, -r0]
  385. #endif
  386. #ifdef CONFIG_TRACE_IRQFLAGS
  387. bl trace_hardirqs_on
  388. #endif
  389. mov why, #0
  390. b ret_to_user
  391. .ltorg
  392. .align 5
  393. __und_usr:
  394. usr_entry
  395. tst r3, #PSR_T_BIT @ Thumb mode?
  396. bne __und_usr_unknown @ ignore FP
  397. sub r4, r2, #4
  398. @
  399. @ fall through to the emulation code, which returns using r9 if
  400. @ it has emulated the instruction, or the more conventional lr
  401. @ if we are to treat this as a real undefined instruction
  402. @
  403. @ r0 - instruction
  404. @
  405. adr r9, ret_from_exception
  406. adr lr, __und_usr_unknown
  407. 1: ldrt r0, [r4]
  408. @
  409. @ fallthrough to call_fpe
  410. @
  411. /*
  412. * The out of line fixup for the ldrt above.
  413. */
  414. .section .fixup, "ax"
  415. 2: mov pc, r9
  416. .previous
  417. .section __ex_table,"a"
  418. .long 1b, 2b
  419. .previous
  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. * Emulators may wish to make use of the following registers:
  431. * r0 = instruction opcode.
  432. * r2 = PC+4
  433. * r9 = normal "successful" return address
  434. * r10 = this threads thread_info structure.
  435. * lr = unrecognised instruction return address
  436. */
  437. call_fpe:
  438. tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
  439. #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
  440. and r8, r0, #0x0f000000 @ mask out op-code bits
  441. teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
  442. #endif
  443. moveq pc, lr
  444. get_thread_info r10 @ get current thread
  445. and r8, r0, #0x00000f00 @ mask out CP number
  446. mov r7, #1
  447. add r6, r10, #TI_USED_CP
  448. strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
  449. #ifdef CONFIG_IWMMXT
  450. @ Test if we need to give access to iWMMXt coprocessors
  451. ldr r5, [r10, #TI_FLAGS]
  452. rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
  453. movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
  454. bcs iwmmxt_task_enable
  455. #endif
  456. add pc, pc, r8, lsr #6
  457. mov r0, r0
  458. mov pc, lr @ CP#0
  459. b do_fpe @ CP#1 (FPE)
  460. b do_fpe @ CP#2 (FPE)
  461. mov pc, lr @ CP#3
  462. #ifdef CONFIG_CRUNCH
  463. b crunch_task_enable @ CP#4 (MaverickCrunch)
  464. b crunch_task_enable @ CP#5 (MaverickCrunch)
  465. b crunch_task_enable @ CP#6 (MaverickCrunch)
  466. #else
  467. mov pc, lr @ CP#4
  468. mov pc, lr @ CP#5
  469. mov pc, lr @ CP#6
  470. #endif
  471. mov pc, lr @ CP#7
  472. mov pc, lr @ CP#8
  473. mov pc, lr @ CP#9
  474. #ifdef CONFIG_VFP
  475. b do_vfp @ CP#10 (VFP)
  476. b do_vfp @ CP#11 (VFP)
  477. #else
  478. mov pc, lr @ CP#10 (VFP)
  479. mov pc, lr @ CP#11 (VFP)
  480. #endif
  481. mov pc, lr @ CP#12
  482. mov pc, lr @ CP#13
  483. mov pc, lr @ CP#14 (Debug)
  484. mov pc, lr @ CP#15 (Control)
  485. do_fpe:
  486. enable_irq
  487. ldr r4, .LCfp
  488. add r10, r10, #TI_FPSTATE @ r10 = workspace
  489. ldr pc, [r4] @ Call FP module USR entry point
  490. /*
  491. * The FP module is called with these registers set:
  492. * r0 = instruction
  493. * r2 = PC+4
  494. * r9 = normal "successful" return address
  495. * r10 = FP workspace
  496. * lr = unrecognised FP instruction return address
  497. */
  498. .data
  499. ENTRY(fp_enter)
  500. .word no_fp
  501. .previous
  502. no_fp: mov pc, lr
  503. __und_usr_unknown:
  504. mov r0, sp
  505. adr lr, ret_from_exception
  506. b do_undefinstr
  507. .align 5
  508. __pabt_usr:
  509. usr_entry
  510. enable_irq @ Enable interrupts
  511. mov r0, r2 @ address (pc)
  512. mov r1, sp @ regs
  513. bl do_PrefetchAbort @ call abort handler
  514. /* fall through */
  515. /*
  516. * This is the return code to user mode for abort handlers
  517. */
  518. ENTRY(ret_from_exception)
  519. get_thread_info tsk
  520. mov why, #0
  521. b ret_to_user
  522. /*
  523. * Register switch for ARMv3 and ARMv4 processors
  524. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  525. * previous and next are guaranteed not to be the same.
  526. */
  527. ENTRY(__switch_to)
  528. add ip, r1, #TI_CPU_SAVE
  529. ldr r3, [r2, #TI_TP_VALUE]
  530. stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
  531. #ifdef CONFIG_MMU
  532. ldr r6, [r2, #TI_CPU_DOMAIN]
  533. #endif
  534. #if __LINUX_ARM_ARCH__ >= 6
  535. #ifdef CONFIG_CPU_32v6K
  536. clrex
  537. #else
  538. strex r5, r4, [ip] @ Clear exclusive monitor
  539. #endif
  540. #endif
  541. #if defined(CONFIG_HAS_TLS_REG)
  542. mcr p15, 0, r3, c13, c0, 3 @ set TLS register
  543. #elif !defined(CONFIG_TLS_REG_EMUL)
  544. mov r4, #0xffff0fff
  545. str r3, [r4, #-15] @ TLS val at 0xffff0ff0
  546. #endif
  547. #ifdef CONFIG_MMU
  548. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  549. #endif
  550. mov r5, r0
  551. add r4, r2, #TI_CPU_SAVE
  552. ldr r0, =thread_notify_head
  553. mov r1, #THREAD_NOTIFY_SWITCH
  554. bl atomic_notifier_call_chain
  555. mov r0, r5
  556. ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
  557. __INIT
  558. /*
  559. * User helpers.
  560. *
  561. * These are segment of kernel provided user code reachable from user space
  562. * at a fixed address in kernel memory. This is used to provide user space
  563. * with some operations which require kernel help because of unimplemented
  564. * native feature and/or instructions in many ARM CPUs. The idea is for
  565. * this code to be executed directly in user mode for best efficiency but
  566. * which is too intimate with the kernel counter part to be left to user
  567. * libraries. In fact this code might even differ from one CPU to another
  568. * depending on the available instruction set and restrictions like on
  569. * SMP systems. In other words, the kernel reserves the right to change
  570. * this code as needed without warning. Only the entry points and their
  571. * results are guaranteed to be stable.
  572. *
  573. * Each segment is 32-byte aligned and will be moved to the top of the high
  574. * vector page. New segments (if ever needed) must be added in front of
  575. * existing ones. This mechanism should be used only for things that are
  576. * really small and justified, and not be abused freely.
  577. *
  578. * User space is expected to implement those things inline when optimizing
  579. * for a processor that has the necessary native support, but only if such
  580. * resulting binaries are already to be incompatible with earlier ARM
  581. * processors due to the use of unsupported instructions other than what
  582. * is provided here. In other words don't make binaries unable to run on
  583. * earlier processors just for the sake of not using these kernel helpers
  584. * if your compiled code is not going to use the new instructions for other
  585. * purpose.
  586. */
  587. .macro usr_ret, reg
  588. #ifdef CONFIG_ARM_THUMB
  589. bx \reg
  590. #else
  591. mov pc, \reg
  592. #endif
  593. .endm
  594. .align 5
  595. .globl __kuser_helper_start
  596. __kuser_helper_start:
  597. /*
  598. * Reference prototype:
  599. *
  600. * void __kernel_memory_barrier(void)
  601. *
  602. * Input:
  603. *
  604. * lr = return address
  605. *
  606. * Output:
  607. *
  608. * none
  609. *
  610. * Clobbered:
  611. *
  612. * none
  613. *
  614. * Definition and user space usage example:
  615. *
  616. * typedef void (__kernel_dmb_t)(void);
  617. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  618. *
  619. * Apply any needed memory barrier to preserve consistency with data modified
  620. * manually and __kuser_cmpxchg usage.
  621. *
  622. * This could be used as follows:
  623. *
  624. * #define __kernel_dmb() \
  625. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  626. * : : : "r0", "lr","cc" )
  627. */
  628. __kuser_memory_barrier: @ 0xffff0fa0
  629. #if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
  630. mcr p15, 0, r0, c7, c10, 5 @ dmb
  631. #endif
  632. usr_ret lr
  633. .align 5
  634. /*
  635. * Reference prototype:
  636. *
  637. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  638. *
  639. * Input:
  640. *
  641. * r0 = oldval
  642. * r1 = newval
  643. * r2 = ptr
  644. * lr = return address
  645. *
  646. * Output:
  647. *
  648. * r0 = returned value (zero or non-zero)
  649. * C flag = set if r0 == 0, clear if r0 != 0
  650. *
  651. * Clobbered:
  652. *
  653. * r3, ip, flags
  654. *
  655. * Definition and user space usage example:
  656. *
  657. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  658. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  659. *
  660. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  661. * Return zero if *ptr was changed or non-zero if no exchange happened.
  662. * The C flag is also set if *ptr was changed to allow for assembly
  663. * optimization in the calling code.
  664. *
  665. * Notes:
  666. *
  667. * - This routine already includes memory barriers as needed.
  668. *
  669. * For example, a user space atomic_add implementation could look like this:
  670. *
  671. * #define atomic_add(ptr, val) \
  672. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  673. * register unsigned int __result asm("r1"); \
  674. * asm volatile ( \
  675. * "1: @ atomic_add\n\t" \
  676. * "ldr r0, [r2]\n\t" \
  677. * "mov r3, #0xffff0fff\n\t" \
  678. * "add lr, pc, #4\n\t" \
  679. * "add r1, r0, %2\n\t" \
  680. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  681. * "bcc 1b" \
  682. * : "=&r" (__result) \
  683. * : "r" (__ptr), "rIL" (val) \
  684. * : "r0","r3","ip","lr","cc","memory" ); \
  685. * __result; })
  686. */
  687. __kuser_cmpxchg: @ 0xffff0fc0
  688. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  689. /*
  690. * Poor you. No fast solution possible...
  691. * The kernel itself must perform the operation.
  692. * A special ghost syscall is used for that (see traps.c).
  693. */
  694. stmfd sp!, {r7, lr}
  695. mov r7, #0xff00 @ 0xfff0 into r7 for EABI
  696. orr r7, r7, #0xf0
  697. swi #0x9ffff0
  698. ldmfd sp!, {r7, pc}
  699. #elif __LINUX_ARM_ARCH__ < 6
  700. #ifdef CONFIG_MMU
  701. /*
  702. * The only thing that can break atomicity in this cmpxchg
  703. * implementation is either an IRQ or a data abort exception
  704. * causing another process/thread to be scheduled in the middle
  705. * of the critical sequence. To prevent this, code is added to
  706. * the IRQ and data abort exception handlers to set the pc back
  707. * to the beginning of the critical section if it is found to be
  708. * within that critical section (see kuser_cmpxchg_fixup).
  709. */
  710. 1: ldr r3, [r2] @ load current val
  711. subs r3, r3, r0 @ compare with oldval
  712. 2: streq r1, [r2] @ store newval if eq
  713. rsbs r0, r3, #0 @ set return val and C flag
  714. usr_ret lr
  715. .text
  716. kuser_cmpxchg_fixup:
  717. @ Called from kuser_cmpxchg_check macro.
  718. @ r2 = address of interrupted insn (must be preserved).
  719. @ sp = saved regs. r7 and r8 are clobbered.
  720. @ 1b = first critical insn, 2b = last critical insn.
  721. @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
  722. mov r7, #0xffff0fff
  723. sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
  724. subs r8, r2, r7
  725. rsbcss r8, r8, #(2b - 1b)
  726. strcs r7, [sp, #S_PC]
  727. mov pc, lr
  728. .previous
  729. #else
  730. #warning "NPTL on non MMU needs fixing"
  731. mov r0, #-1
  732. adds r0, r0, #0
  733. usr_ret lr
  734. #endif
  735. #else
  736. #ifdef CONFIG_SMP
  737. mcr p15, 0, r0, c7, c10, 5 @ dmb
  738. #endif
  739. 1: ldrex r3, [r2]
  740. subs r3, r3, r0
  741. strexeq r3, r1, [r2]
  742. teqeq r3, #1
  743. beq 1b
  744. rsbs r0, r3, #0
  745. /* beware -- each __kuser slot must be 8 instructions max */
  746. #ifdef CONFIG_SMP
  747. b __kuser_memory_barrier
  748. #else
  749. usr_ret lr
  750. #endif
  751. #endif
  752. .align 5
  753. /*
  754. * Reference prototype:
  755. *
  756. * int __kernel_get_tls(void)
  757. *
  758. * Input:
  759. *
  760. * lr = return address
  761. *
  762. * Output:
  763. *
  764. * r0 = TLS value
  765. *
  766. * Clobbered:
  767. *
  768. * none
  769. *
  770. * Definition and user space usage example:
  771. *
  772. * typedef int (__kernel_get_tls_t)(void);
  773. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  774. *
  775. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  776. *
  777. * This could be used as follows:
  778. *
  779. * #define __kernel_get_tls() \
  780. * ({ register unsigned int __val asm("r0"); \
  781. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  782. * : "=r" (__val) : : "lr","cc" ); \
  783. * __val; })
  784. */
  785. __kuser_get_tls: @ 0xffff0fe0
  786. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  787. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  788. #else
  789. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  790. #endif
  791. usr_ret lr
  792. .rep 5
  793. .word 0 @ pad up to __kuser_helper_version
  794. .endr
  795. /*
  796. * Reference declaration:
  797. *
  798. * extern unsigned int __kernel_helper_version;
  799. *
  800. * Definition and user space usage example:
  801. *
  802. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  803. *
  804. * User space may read this to determine the curent number of helpers
  805. * available.
  806. */
  807. __kuser_helper_version: @ 0xffff0ffc
  808. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  809. .globl __kuser_helper_end
  810. __kuser_helper_end:
  811. /*
  812. * Vector stubs.
  813. *
  814. * This code is copied to 0xffff0200 so we can use branches in the
  815. * vectors, rather than ldr's. Note that this code must not
  816. * exceed 0x300 bytes.
  817. *
  818. * Common stub entry macro:
  819. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  820. *
  821. * SP points to a minimal amount of processor-private memory, the address
  822. * of which is copied into r0 for the mode specific abort handler.
  823. */
  824. .macro vector_stub, name, mode, correction=0
  825. .align 5
  826. vector_\name:
  827. .if \correction
  828. sub lr, lr, #\correction
  829. .endif
  830. @
  831. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  832. @ (parent CPSR)
  833. @
  834. stmia sp, {r0, lr} @ save r0, lr
  835. mrs lr, spsr
  836. str lr, [sp, #8] @ save spsr
  837. @
  838. @ Prepare for SVC32 mode. IRQs remain disabled.
  839. @
  840. mrs r0, cpsr
  841. eor r0, r0, #(\mode ^ SVC_MODE)
  842. msr spsr_cxsf, r0
  843. @
  844. @ the branch table must immediately follow this code
  845. @
  846. and lr, lr, #0x0f
  847. mov r0, sp
  848. ldr lr, [pc, lr, lsl #2]
  849. movs pc, lr @ branch to handler in SVC mode
  850. .endm
  851. .globl __stubs_start
  852. __stubs_start:
  853. /*
  854. * Interrupt dispatcher
  855. */
  856. vector_stub irq, IRQ_MODE, 4
  857. .long __irq_usr @ 0 (USR_26 / USR_32)
  858. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  859. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  860. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  861. .long __irq_invalid @ 4
  862. .long __irq_invalid @ 5
  863. .long __irq_invalid @ 6
  864. .long __irq_invalid @ 7
  865. .long __irq_invalid @ 8
  866. .long __irq_invalid @ 9
  867. .long __irq_invalid @ a
  868. .long __irq_invalid @ b
  869. .long __irq_invalid @ c
  870. .long __irq_invalid @ d
  871. .long __irq_invalid @ e
  872. .long __irq_invalid @ f
  873. /*
  874. * Data abort dispatcher
  875. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  876. */
  877. vector_stub dabt, ABT_MODE, 8
  878. .long __dabt_usr @ 0 (USR_26 / USR_32)
  879. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  880. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  881. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  882. .long __dabt_invalid @ 4
  883. .long __dabt_invalid @ 5
  884. .long __dabt_invalid @ 6
  885. .long __dabt_invalid @ 7
  886. .long __dabt_invalid @ 8
  887. .long __dabt_invalid @ 9
  888. .long __dabt_invalid @ a
  889. .long __dabt_invalid @ b
  890. .long __dabt_invalid @ c
  891. .long __dabt_invalid @ d
  892. .long __dabt_invalid @ e
  893. .long __dabt_invalid @ f
  894. /*
  895. * Prefetch abort dispatcher
  896. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  897. */
  898. vector_stub pabt, ABT_MODE, 4
  899. .long __pabt_usr @ 0 (USR_26 / USR_32)
  900. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  901. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  902. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  903. .long __pabt_invalid @ 4
  904. .long __pabt_invalid @ 5
  905. .long __pabt_invalid @ 6
  906. .long __pabt_invalid @ 7
  907. .long __pabt_invalid @ 8
  908. .long __pabt_invalid @ 9
  909. .long __pabt_invalid @ a
  910. .long __pabt_invalid @ b
  911. .long __pabt_invalid @ c
  912. .long __pabt_invalid @ d
  913. .long __pabt_invalid @ e
  914. .long __pabt_invalid @ f
  915. /*
  916. * Undef instr entry dispatcher
  917. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  918. */
  919. vector_stub und, UND_MODE
  920. .long __und_usr @ 0 (USR_26 / USR_32)
  921. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  922. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  923. .long __und_svc @ 3 (SVC_26 / SVC_32)
  924. .long __und_invalid @ 4
  925. .long __und_invalid @ 5
  926. .long __und_invalid @ 6
  927. .long __und_invalid @ 7
  928. .long __und_invalid @ 8
  929. .long __und_invalid @ 9
  930. .long __und_invalid @ a
  931. .long __und_invalid @ b
  932. .long __und_invalid @ c
  933. .long __und_invalid @ d
  934. .long __und_invalid @ e
  935. .long __und_invalid @ f
  936. .align 5
  937. /*=============================================================================
  938. * Undefined FIQs
  939. *-----------------------------------------------------------------------------
  940. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  941. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  942. * Basically to switch modes, we *HAVE* to clobber one register... brain
  943. * damage alert! I don't think that we can execute any code in here in any
  944. * other mode than FIQ... Ok you can switch to another mode, but you can't
  945. * get out of that mode without clobbering one register.
  946. */
  947. vector_fiq:
  948. disable_fiq
  949. subs pc, lr, #4
  950. /*=============================================================================
  951. * Address exception handler
  952. *-----------------------------------------------------------------------------
  953. * These aren't too critical.
  954. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  955. */
  956. vector_addrexcptn:
  957. b vector_addrexcptn
  958. /*
  959. * We group all the following data together to optimise
  960. * for CPUs with separate I & D caches.
  961. */
  962. .align 5
  963. .LCvswi:
  964. .word vector_swi
  965. .globl __stubs_end
  966. __stubs_end:
  967. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  968. .globl __vectors_start
  969. __vectors_start:
  970. swi SYS_ERROR0
  971. b vector_und + stubs_offset
  972. ldr pc, .LCvswi + stubs_offset
  973. b vector_pabt + stubs_offset
  974. b vector_dabt + stubs_offset
  975. b vector_addrexcptn + stubs_offset
  976. b vector_irq + stubs_offset
  977. 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