entry-armv.S 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. * linux/arch/arm/kernel/entry-armv.S
  3. *
  4. * Copyright (C) 1996,1997,1998 Russell King.
  5. * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk)
  6. * nommu support by Hyok S. Choi (hyok.choi@samsung.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Low-level vector interface routines
  13. *
  14. * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction
  15. * that causes it to save wrong values... Be aware!
  16. */
  17. #include <asm/memory.h>
  18. #include <asm/glue.h>
  19. #include <asm/vfpmacros.h>
  20. #include <asm/arch/entry-macro.S>
  21. #include <asm/thread_notify.h>
  22. #include "entry-header.S"
  23. /*
  24. * Interrupt handling. Preserves r7, r8, r9
  25. */
  26. .macro irq_handler
  27. get_irqnr_preamble r5, lr
  28. 1: get_irqnr_and_base r0, r6, r5, lr
  29. movne r1, sp
  30. @
  31. @ routine called with r0 = irq number, r1 = struct pt_regs *
  32. @
  33. adrne lr, 1b
  34. bne asm_do_IRQ
  35. #ifdef CONFIG_SMP
  36. /*
  37. * XXX
  38. *
  39. * this macro assumes that irqstat (r6) and base (r5) are
  40. * preserved from get_irqnr_and_base above
  41. */
  42. test_for_ipi r0, r6, r5, lr
  43. movne r0, sp
  44. adrne lr, 1b
  45. bne do_IPI
  46. #ifdef CONFIG_LOCAL_TIMERS
  47. test_for_ltirq r0, r6, r5, lr
  48. movne r0, sp
  49. adrne lr, 1b
  50. bne do_local_timer
  51. #endif
  52. #endif
  53. .endm
  54. #ifdef CONFIG_KPROBES
  55. .section .kprobes.text,"ax",%progbits
  56. #else
  57. .text
  58. #endif
  59. /*
  60. * Invalid mode handlers
  61. */
  62. .macro inv_entry, reason
  63. sub sp, sp, #S_FRAME_SIZE
  64. stmib sp, {r1 - lr}
  65. mov r1, #\reason
  66. .endm
  67. __pabt_invalid:
  68. inv_entry BAD_PREFETCH
  69. b common_invalid
  70. __dabt_invalid:
  71. inv_entry BAD_DATA
  72. b common_invalid
  73. __irq_invalid:
  74. inv_entry BAD_IRQ
  75. b common_invalid
  76. __und_invalid:
  77. inv_entry BAD_UNDEFINSTR
  78. @
  79. @ XXX fall through to common_invalid
  80. @
  81. @
  82. @ common_invalid - generic code for failed exception (re-entrant version of handlers)
  83. @
  84. common_invalid:
  85. zero_fp
  86. ldmia r0, {r4 - r6}
  87. add r0, sp, #S_PC @ here for interlock avoidance
  88. mov r7, #-1 @ "" "" "" ""
  89. str r4, [sp] @ save preserved r0
  90. stmia r0, {r5 - r7} @ lr_<exception>,
  91. @ cpsr_<exception>, "old_r0"
  92. mov r0, sp
  93. b bad_mode
  94. /*
  95. * SVC mode handlers
  96. */
  97. #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
  98. #define SPFIX(code...) code
  99. #else
  100. #define SPFIX(code...)
  101. #endif
  102. .macro svc_entry, stack_hole=0
  103. sub sp, sp, #(S_FRAME_SIZE + \stack_hole)
  104. SPFIX( tst sp, #4 )
  105. SPFIX( bicne sp, sp, #4 )
  106. stmib sp, {r1 - r12}
  107. ldmia r0, {r1 - r3}
  108. add r5, sp, #S_SP @ here for interlock avoidance
  109. mov r4, #-1 @ "" "" "" ""
  110. add r0, sp, #(S_FRAME_SIZE + \stack_hole)
  111. SPFIX( addne r0, r0, #4 )
  112. str r1, [sp] @ save the "real" r0 copied
  113. @ from the exception stack
  114. mov r1, lr
  115. @
  116. @ We are now ready to fill in the remaining blanks on the stack:
  117. @
  118. @ r0 - sp_svc
  119. @ r1 - lr_svc
  120. @ r2 - lr_<exception>, already fixed up for correct return/restart
  121. @ r3 - spsr_<exception>
  122. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  123. @
  124. stmia r5, {r0 - r4}
  125. .endm
  126. .align 5
  127. __dabt_svc:
  128. svc_entry
  129. @
  130. @ get ready to re-enable interrupts if appropriate
  131. @
  132. mrs r9, cpsr
  133. tst r3, #PSR_I_BIT
  134. biceq r9, r9, #PSR_I_BIT
  135. @
  136. @ Call the processor-specific abort handler:
  137. @
  138. @ r2 - aborted context pc
  139. @ r3 - aborted context cpsr
  140. @
  141. @ The abort handler must return the aborted address in r0, and
  142. @ the fault status register in r1. r9 must be preserved.
  143. @
  144. #ifdef MULTI_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. * NEON is a special case that has to be handled here. Not all
  431. * NEON instructions are co-processor instructions, so we have
  432. * to make a special case of checking for them. Plus, there's
  433. * five groups of them, so we have a table of mask/opcode pairs
  434. * to check against, and if any match then we branch off into the
  435. * NEON handler code.
  436. *
  437. * Emulators may wish to make use of the following registers:
  438. * r0 = instruction opcode.
  439. * r2 = PC+4
  440. * r9 = normal "successful" return address
  441. * r10 = this threads thread_info structure.
  442. * lr = unrecognised instruction return address
  443. */
  444. call_fpe:
  445. #ifdef CONFIG_NEON
  446. adr r6, .LCneon_opcodes
  447. 2:
  448. ldr r7, [r6], #4 @ mask value
  449. cmp r7, #0 @ end mask?
  450. beq 1f
  451. and r8, r0, r7
  452. ldr r7, [r6], #4 @ opcode bits matching in mask
  453. cmp r8, r7 @ NEON instruction?
  454. bne 2b
  455. get_thread_info r10
  456. mov r7, #1
  457. strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
  458. strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
  459. b do_vfp @ let VFP handler handle this
  460. 1:
  461. #endif
  462. tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
  463. #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
  464. and r8, r0, #0x0f000000 @ mask out op-code bits
  465. teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
  466. #endif
  467. moveq pc, lr
  468. get_thread_info r10 @ get current thread
  469. and r8, r0, #0x00000f00 @ mask out CP number
  470. mov r7, #1
  471. add r6, r10, #TI_USED_CP
  472. strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
  473. #ifdef CONFIG_IWMMXT
  474. @ Test if we need to give access to iWMMXt coprocessors
  475. ldr r5, [r10, #TI_FLAGS]
  476. rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
  477. movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
  478. bcs iwmmxt_task_enable
  479. #endif
  480. add pc, pc, r8, lsr #6
  481. mov r0, r0
  482. mov pc, lr @ CP#0
  483. b do_fpe @ CP#1 (FPE)
  484. b do_fpe @ CP#2 (FPE)
  485. mov pc, lr @ CP#3
  486. #ifdef CONFIG_CRUNCH
  487. b crunch_task_enable @ CP#4 (MaverickCrunch)
  488. b crunch_task_enable @ CP#5 (MaverickCrunch)
  489. b crunch_task_enable @ CP#6 (MaverickCrunch)
  490. #else
  491. mov pc, lr @ CP#4
  492. mov pc, lr @ CP#5
  493. mov pc, lr @ CP#6
  494. #endif
  495. mov pc, lr @ CP#7
  496. mov pc, lr @ CP#8
  497. mov pc, lr @ CP#9
  498. #ifdef CONFIG_VFP
  499. b do_vfp @ CP#10 (VFP)
  500. b do_vfp @ CP#11 (VFP)
  501. #else
  502. mov pc, lr @ CP#10 (VFP)
  503. mov pc, lr @ CP#11 (VFP)
  504. #endif
  505. mov pc, lr @ CP#12
  506. mov pc, lr @ CP#13
  507. mov pc, lr @ CP#14 (Debug)
  508. mov pc, lr @ CP#15 (Control)
  509. #ifdef CONFIG_NEON
  510. .align 6
  511. .LCneon_opcodes:
  512. .word 0xfe000000 @ mask
  513. .word 0xf2000000 @ opcode
  514. .word 0xff100000 @ mask
  515. .word 0xf4000000 @ opcode
  516. .word 0x00000000 @ mask
  517. .word 0x00000000 @ opcode
  518. #endif
  519. do_fpe:
  520. enable_irq
  521. ldr r4, .LCfp
  522. add r10, r10, #TI_FPSTATE @ r10 = workspace
  523. ldr pc, [r4] @ Call FP module USR entry point
  524. /*
  525. * The FP module is called with these registers set:
  526. * r0 = instruction
  527. * r2 = PC+4
  528. * r9 = normal "successful" return address
  529. * r10 = FP workspace
  530. * lr = unrecognised FP instruction return address
  531. */
  532. .data
  533. ENTRY(fp_enter)
  534. .word no_fp
  535. .previous
  536. no_fp: mov pc, lr
  537. __und_usr_unknown:
  538. mov r0, sp
  539. adr lr, ret_from_exception
  540. b do_undefinstr
  541. .align 5
  542. __pabt_usr:
  543. usr_entry
  544. enable_irq @ Enable interrupts
  545. mov r0, r2 @ address (pc)
  546. mov r1, sp @ regs
  547. bl do_PrefetchAbort @ call abort handler
  548. /* fall through */
  549. /*
  550. * This is the return code to user mode for abort handlers
  551. */
  552. ENTRY(ret_from_exception)
  553. get_thread_info tsk
  554. mov why, #0
  555. b ret_to_user
  556. /*
  557. * Register switch for ARMv3 and ARMv4 processors
  558. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  559. * previous and next are guaranteed not to be the same.
  560. */
  561. ENTRY(__switch_to)
  562. add ip, r1, #TI_CPU_SAVE
  563. ldr r3, [r2, #TI_TP_VALUE]
  564. stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
  565. #ifdef CONFIG_MMU
  566. ldr r6, [r2, #TI_CPU_DOMAIN]
  567. #endif
  568. #if __LINUX_ARM_ARCH__ >= 6
  569. #ifdef CONFIG_CPU_32v6K
  570. clrex
  571. #else
  572. strex r5, r4, [ip] @ Clear exclusive monitor
  573. #endif
  574. #endif
  575. #if defined(CONFIG_HAS_TLS_REG)
  576. mcr p15, 0, r3, c13, c0, 3 @ set TLS register
  577. #elif !defined(CONFIG_TLS_REG_EMUL)
  578. mov r4, #0xffff0fff
  579. str r3, [r4, #-15] @ TLS val at 0xffff0ff0
  580. #endif
  581. #ifdef CONFIG_MMU
  582. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  583. #endif
  584. mov r5, r0
  585. add r4, r2, #TI_CPU_SAVE
  586. ldr r0, =thread_notify_head
  587. mov r1, #THREAD_NOTIFY_SWITCH
  588. bl atomic_notifier_call_chain
  589. mov r0, r5
  590. ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
  591. __INIT
  592. /*
  593. * User helpers.
  594. *
  595. * These are segment of kernel provided user code reachable from user space
  596. * at a fixed address in kernel memory. This is used to provide user space
  597. * with some operations which require kernel help because of unimplemented
  598. * native feature and/or instructions in many ARM CPUs. The idea is for
  599. * this code to be executed directly in user mode for best efficiency but
  600. * which is too intimate with the kernel counter part to be left to user
  601. * libraries. In fact this code might even differ from one CPU to another
  602. * depending on the available instruction set and restrictions like on
  603. * SMP systems. In other words, the kernel reserves the right to change
  604. * this code as needed without warning. Only the entry points and their
  605. * results are guaranteed to be stable.
  606. *
  607. * Each segment is 32-byte aligned and will be moved to the top of the high
  608. * vector page. New segments (if ever needed) must be added in front of
  609. * existing ones. This mechanism should be used only for things that are
  610. * really small and justified, and not be abused freely.
  611. *
  612. * User space is expected to implement those things inline when optimizing
  613. * for a processor that has the necessary native support, but only if such
  614. * resulting binaries are already to be incompatible with earlier ARM
  615. * processors due to the use of unsupported instructions other than what
  616. * is provided here. In other words don't make binaries unable to run on
  617. * earlier processors just for the sake of not using these kernel helpers
  618. * if your compiled code is not going to use the new instructions for other
  619. * purpose.
  620. */
  621. .macro usr_ret, reg
  622. #ifdef CONFIG_ARM_THUMB
  623. bx \reg
  624. #else
  625. mov pc, \reg
  626. #endif
  627. .endm
  628. .align 5
  629. .globl __kuser_helper_start
  630. __kuser_helper_start:
  631. /*
  632. * Reference prototype:
  633. *
  634. * void __kernel_memory_barrier(void)
  635. *
  636. * Input:
  637. *
  638. * lr = return address
  639. *
  640. * Output:
  641. *
  642. * none
  643. *
  644. * Clobbered:
  645. *
  646. * none
  647. *
  648. * Definition and user space usage example:
  649. *
  650. * typedef void (__kernel_dmb_t)(void);
  651. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  652. *
  653. * Apply any needed memory barrier to preserve consistency with data modified
  654. * manually and __kuser_cmpxchg usage.
  655. *
  656. * This could be used as follows:
  657. *
  658. * #define __kernel_dmb() \
  659. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  660. * : : : "r0", "lr","cc" )
  661. */
  662. __kuser_memory_barrier: @ 0xffff0fa0
  663. #if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
  664. mcr p15, 0, r0, c7, c10, 5 @ dmb
  665. #endif
  666. usr_ret lr
  667. .align 5
  668. /*
  669. * Reference prototype:
  670. *
  671. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  672. *
  673. * Input:
  674. *
  675. * r0 = oldval
  676. * r1 = newval
  677. * r2 = ptr
  678. * lr = return address
  679. *
  680. * Output:
  681. *
  682. * r0 = returned value (zero or non-zero)
  683. * C flag = set if r0 == 0, clear if r0 != 0
  684. *
  685. * Clobbered:
  686. *
  687. * r3, ip, flags
  688. *
  689. * Definition and user space usage example:
  690. *
  691. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  692. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  693. *
  694. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  695. * Return zero if *ptr was changed or non-zero if no exchange happened.
  696. * The C flag is also set if *ptr was changed to allow for assembly
  697. * optimization in the calling code.
  698. *
  699. * Notes:
  700. *
  701. * - This routine already includes memory barriers as needed.
  702. *
  703. * For example, a user space atomic_add implementation could look like this:
  704. *
  705. * #define atomic_add(ptr, val) \
  706. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  707. * register unsigned int __result asm("r1"); \
  708. * asm volatile ( \
  709. * "1: @ atomic_add\n\t" \
  710. * "ldr r0, [r2]\n\t" \
  711. * "mov r3, #0xffff0fff\n\t" \
  712. * "add lr, pc, #4\n\t" \
  713. * "add r1, r0, %2\n\t" \
  714. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  715. * "bcc 1b" \
  716. * : "=&r" (__result) \
  717. * : "r" (__ptr), "rIL" (val) \
  718. * : "r0","r3","ip","lr","cc","memory" ); \
  719. * __result; })
  720. */
  721. __kuser_cmpxchg: @ 0xffff0fc0
  722. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  723. /*
  724. * Poor you. No fast solution possible...
  725. * The kernel itself must perform the operation.
  726. * A special ghost syscall is used for that (see traps.c).
  727. */
  728. stmfd sp!, {r7, lr}
  729. mov r7, #0xff00 @ 0xfff0 into r7 for EABI
  730. orr r7, r7, #0xf0
  731. swi #0x9ffff0
  732. ldmfd sp!, {r7, pc}
  733. #elif __LINUX_ARM_ARCH__ < 6
  734. #ifdef CONFIG_MMU
  735. /*
  736. * The only thing that can break atomicity in this cmpxchg
  737. * implementation is either an IRQ or a data abort exception
  738. * causing another process/thread to be scheduled in the middle
  739. * of the critical sequence. To prevent this, code is added to
  740. * the IRQ and data abort exception handlers to set the pc back
  741. * to the beginning of the critical section if it is found to be
  742. * within that critical section (see kuser_cmpxchg_fixup).
  743. */
  744. 1: ldr r3, [r2] @ load current val
  745. subs r3, r3, r0 @ compare with oldval
  746. 2: streq r1, [r2] @ store newval if eq
  747. rsbs r0, r3, #0 @ set return val and C flag
  748. usr_ret lr
  749. .text
  750. kuser_cmpxchg_fixup:
  751. @ Called from kuser_cmpxchg_check macro.
  752. @ r2 = address of interrupted insn (must be preserved).
  753. @ sp = saved regs. r7 and r8 are clobbered.
  754. @ 1b = first critical insn, 2b = last critical insn.
  755. @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
  756. mov r7, #0xffff0fff
  757. sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
  758. subs r8, r2, r7
  759. rsbcss r8, r8, #(2b - 1b)
  760. strcs r7, [sp, #S_PC]
  761. mov pc, lr
  762. .previous
  763. #else
  764. #warning "NPTL on non MMU needs fixing"
  765. mov r0, #-1
  766. adds r0, r0, #0
  767. usr_ret lr
  768. #endif
  769. #else
  770. #ifdef CONFIG_SMP
  771. mcr p15, 0, r0, c7, c10, 5 @ dmb
  772. #endif
  773. 1: ldrex r3, [r2]
  774. subs r3, r3, r0
  775. strexeq r3, r1, [r2]
  776. teqeq r3, #1
  777. beq 1b
  778. rsbs r0, r3, #0
  779. /* beware -- each __kuser slot must be 8 instructions max */
  780. #ifdef CONFIG_SMP
  781. b __kuser_memory_barrier
  782. #else
  783. usr_ret lr
  784. #endif
  785. #endif
  786. .align 5
  787. /*
  788. * Reference prototype:
  789. *
  790. * int __kernel_get_tls(void)
  791. *
  792. * Input:
  793. *
  794. * lr = return address
  795. *
  796. * Output:
  797. *
  798. * r0 = TLS value
  799. *
  800. * Clobbered:
  801. *
  802. * none
  803. *
  804. * Definition and user space usage example:
  805. *
  806. * typedef int (__kernel_get_tls_t)(void);
  807. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  808. *
  809. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  810. *
  811. * This could be used as follows:
  812. *
  813. * #define __kernel_get_tls() \
  814. * ({ register unsigned int __val asm("r0"); \
  815. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  816. * : "=r" (__val) : : "lr","cc" ); \
  817. * __val; })
  818. */
  819. __kuser_get_tls: @ 0xffff0fe0
  820. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  821. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  822. #else
  823. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  824. #endif
  825. usr_ret lr
  826. .rep 5
  827. .word 0 @ pad up to __kuser_helper_version
  828. .endr
  829. /*
  830. * Reference declaration:
  831. *
  832. * extern unsigned int __kernel_helper_version;
  833. *
  834. * Definition and user space usage example:
  835. *
  836. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  837. *
  838. * User space may read this to determine the curent number of helpers
  839. * available.
  840. */
  841. __kuser_helper_version: @ 0xffff0ffc
  842. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  843. .globl __kuser_helper_end
  844. __kuser_helper_end:
  845. /*
  846. * Vector stubs.
  847. *
  848. * This code is copied to 0xffff0200 so we can use branches in the
  849. * vectors, rather than ldr's. Note that this code must not
  850. * exceed 0x300 bytes.
  851. *
  852. * Common stub entry macro:
  853. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  854. *
  855. * SP points to a minimal amount of processor-private memory, the address
  856. * of which is copied into r0 for the mode specific abort handler.
  857. */
  858. .macro vector_stub, name, mode, correction=0
  859. .align 5
  860. vector_\name:
  861. .if \correction
  862. sub lr, lr, #\correction
  863. .endif
  864. @
  865. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  866. @ (parent CPSR)
  867. @
  868. stmia sp, {r0, lr} @ save r0, lr
  869. mrs lr, spsr
  870. str lr, [sp, #8] @ save spsr
  871. @
  872. @ Prepare for SVC32 mode. IRQs remain disabled.
  873. @
  874. mrs r0, cpsr
  875. eor r0, r0, #(\mode ^ SVC_MODE)
  876. msr spsr_cxsf, r0
  877. @
  878. @ the branch table must immediately follow this code
  879. @
  880. and lr, lr, #0x0f
  881. mov r0, sp
  882. ldr lr, [pc, lr, lsl #2]
  883. movs pc, lr @ branch to handler in SVC mode
  884. .endm
  885. .globl __stubs_start
  886. __stubs_start:
  887. /*
  888. * Interrupt dispatcher
  889. */
  890. vector_stub irq, IRQ_MODE, 4
  891. .long __irq_usr @ 0 (USR_26 / USR_32)
  892. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  893. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  894. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  895. .long __irq_invalid @ 4
  896. .long __irq_invalid @ 5
  897. .long __irq_invalid @ 6
  898. .long __irq_invalid @ 7
  899. .long __irq_invalid @ 8
  900. .long __irq_invalid @ 9
  901. .long __irq_invalid @ a
  902. .long __irq_invalid @ b
  903. .long __irq_invalid @ c
  904. .long __irq_invalid @ d
  905. .long __irq_invalid @ e
  906. .long __irq_invalid @ f
  907. /*
  908. * Data abort dispatcher
  909. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  910. */
  911. vector_stub dabt, ABT_MODE, 8
  912. .long __dabt_usr @ 0 (USR_26 / USR_32)
  913. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  914. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  915. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  916. .long __dabt_invalid @ 4
  917. .long __dabt_invalid @ 5
  918. .long __dabt_invalid @ 6
  919. .long __dabt_invalid @ 7
  920. .long __dabt_invalid @ 8
  921. .long __dabt_invalid @ 9
  922. .long __dabt_invalid @ a
  923. .long __dabt_invalid @ b
  924. .long __dabt_invalid @ c
  925. .long __dabt_invalid @ d
  926. .long __dabt_invalid @ e
  927. .long __dabt_invalid @ f
  928. /*
  929. * Prefetch abort dispatcher
  930. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  931. */
  932. vector_stub pabt, ABT_MODE, 4
  933. .long __pabt_usr @ 0 (USR_26 / USR_32)
  934. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  935. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  936. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  937. .long __pabt_invalid @ 4
  938. .long __pabt_invalid @ 5
  939. .long __pabt_invalid @ 6
  940. .long __pabt_invalid @ 7
  941. .long __pabt_invalid @ 8
  942. .long __pabt_invalid @ 9
  943. .long __pabt_invalid @ a
  944. .long __pabt_invalid @ b
  945. .long __pabt_invalid @ c
  946. .long __pabt_invalid @ d
  947. .long __pabt_invalid @ e
  948. .long __pabt_invalid @ f
  949. /*
  950. * Undef instr entry dispatcher
  951. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  952. */
  953. vector_stub und, UND_MODE
  954. .long __und_usr @ 0 (USR_26 / USR_32)
  955. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  956. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  957. .long __und_svc @ 3 (SVC_26 / SVC_32)
  958. .long __und_invalid @ 4
  959. .long __und_invalid @ 5
  960. .long __und_invalid @ 6
  961. .long __und_invalid @ 7
  962. .long __und_invalid @ 8
  963. .long __und_invalid @ 9
  964. .long __und_invalid @ a
  965. .long __und_invalid @ b
  966. .long __und_invalid @ c
  967. .long __und_invalid @ d
  968. .long __und_invalid @ e
  969. .long __und_invalid @ f
  970. .align 5
  971. /*=============================================================================
  972. * Undefined FIQs
  973. *-----------------------------------------------------------------------------
  974. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  975. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  976. * Basically to switch modes, we *HAVE* to clobber one register... brain
  977. * damage alert! I don't think that we can execute any code in here in any
  978. * other mode than FIQ... Ok you can switch to another mode, but you can't
  979. * get out of that mode without clobbering one register.
  980. */
  981. vector_fiq:
  982. disable_fiq
  983. subs pc, lr, #4
  984. /*=============================================================================
  985. * Address exception handler
  986. *-----------------------------------------------------------------------------
  987. * These aren't too critical.
  988. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  989. */
  990. vector_addrexcptn:
  991. b vector_addrexcptn
  992. /*
  993. * We group all the following data together to optimise
  994. * for CPUs with separate I & D caches.
  995. */
  996. .align 5
  997. .LCvswi:
  998. .word vector_swi
  999. .globl __stubs_end
  1000. __stubs_end:
  1001. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  1002. .globl __vectors_start
  1003. __vectors_start:
  1004. swi SYS_ERROR0
  1005. b vector_und + stubs_offset
  1006. ldr pc, .LCvswi + stubs_offset
  1007. b vector_pabt + stubs_offset
  1008. b vector_dabt + stubs_offset
  1009. b vector_addrexcptn + stubs_offset
  1010. b vector_irq + stubs_offset
  1011. b vector_fiq + stubs_offset
  1012. .globl __vectors_end
  1013. __vectors_end:
  1014. .data
  1015. .globl cr_alignment
  1016. .globl cr_no_alignment
  1017. cr_alignment:
  1018. .space 4
  1019. cr_no_alignment:
  1020. .space 4