entry-armv.S 24 KB

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