entry-armv.S 24 KB

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