entry-armv.S 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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_IWMMXT)
  521. bl iwmmxt_task_switch
  522. #elif defined(CONFIG_CPU_XSCALE)
  523. add r4, r2, #TI_CPU_DOMAIN + 40 @ cpu_context_save->extra
  524. ldmib r4, {r4, r5}
  525. mar acc0, r4, r5
  526. #endif
  527. mov r5, r0
  528. add r4, r2, #TI_CPU_SAVE
  529. ldr r0, =thread_notify_head
  530. mov r1, #THREAD_NOTIFY_SWITCH
  531. bl atomic_notifier_call_chain
  532. mov r0, r5
  533. ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
  534. __INIT
  535. /*
  536. * User helpers.
  537. *
  538. * These are segment of kernel provided user code reachable from user space
  539. * at a fixed address in kernel memory. This is used to provide user space
  540. * with some operations which require kernel help because of unimplemented
  541. * native feature and/or instructions in many ARM CPUs. The idea is for
  542. * this code to be executed directly in user mode for best efficiency but
  543. * which is too intimate with the kernel counter part to be left to user
  544. * libraries. In fact this code might even differ from one CPU to another
  545. * depending on the available instruction set and restrictions like on
  546. * SMP systems. In other words, the kernel reserves the right to change
  547. * this code as needed without warning. Only the entry points and their
  548. * results are guaranteed to be stable.
  549. *
  550. * Each segment is 32-byte aligned and will be moved to the top of the high
  551. * vector page. New segments (if ever needed) must be added in front of
  552. * existing ones. This mechanism should be used only for things that are
  553. * really small and justified, and not be abused freely.
  554. *
  555. * User space is expected to implement those things inline when optimizing
  556. * for a processor that has the necessary native support, but only if such
  557. * resulting binaries are already to be incompatible with earlier ARM
  558. * processors due to the use of unsupported instructions other than what
  559. * is provided here. In other words don't make binaries unable to run on
  560. * earlier processors just for the sake of not using these kernel helpers
  561. * if your compiled code is not going to use the new instructions for other
  562. * purpose.
  563. */
  564. .align 5
  565. .globl __kuser_helper_start
  566. __kuser_helper_start:
  567. /*
  568. * Reference prototype:
  569. *
  570. * void __kernel_memory_barrier(void)
  571. *
  572. * Input:
  573. *
  574. * lr = return address
  575. *
  576. * Output:
  577. *
  578. * none
  579. *
  580. * Clobbered:
  581. *
  582. * the Z flag might be lost
  583. *
  584. * Definition and user space usage example:
  585. *
  586. * typedef void (__kernel_dmb_t)(void);
  587. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  588. *
  589. * Apply any needed memory barrier to preserve consistency with data modified
  590. * manually and __kuser_cmpxchg usage.
  591. *
  592. * This could be used as follows:
  593. *
  594. * #define __kernel_dmb() \
  595. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  596. * : : : "r0", "lr","cc" )
  597. */
  598. __kuser_memory_barrier: @ 0xffff0fa0
  599. #if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
  600. mcr p15, 0, r0, c7, c10, 5 @ dmb
  601. #endif
  602. mov pc, lr
  603. .align 5
  604. /*
  605. * Reference prototype:
  606. *
  607. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  608. *
  609. * Input:
  610. *
  611. * r0 = oldval
  612. * r1 = newval
  613. * r2 = ptr
  614. * lr = return address
  615. *
  616. * Output:
  617. *
  618. * r0 = returned value (zero or non-zero)
  619. * C flag = set if r0 == 0, clear if r0 != 0
  620. *
  621. * Clobbered:
  622. *
  623. * r3, ip, flags
  624. *
  625. * Definition and user space usage example:
  626. *
  627. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  628. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  629. *
  630. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  631. * Return zero if *ptr was changed or non-zero if no exchange happened.
  632. * The C flag is also set if *ptr was changed to allow for assembly
  633. * optimization in the calling code.
  634. *
  635. * Notes:
  636. *
  637. * - This routine already includes memory barriers as needed.
  638. *
  639. * - A failure might be transient, i.e. it is possible, although unlikely,
  640. * that "failure" be returned even if *ptr == oldval.
  641. *
  642. * For example, a user space atomic_add implementation could look like this:
  643. *
  644. * #define atomic_add(ptr, val) \
  645. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  646. * register unsigned int __result asm("r1"); \
  647. * asm volatile ( \
  648. * "1: @ atomic_add\n\t" \
  649. * "ldr r0, [r2]\n\t" \
  650. * "mov r3, #0xffff0fff\n\t" \
  651. * "add lr, pc, #4\n\t" \
  652. * "add r1, r0, %2\n\t" \
  653. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  654. * "bcc 1b" \
  655. * : "=&r" (__result) \
  656. * : "r" (__ptr), "rIL" (val) \
  657. * : "r0","r3","ip","lr","cc","memory" ); \
  658. * __result; })
  659. */
  660. __kuser_cmpxchg: @ 0xffff0fc0
  661. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  662. /*
  663. * Poor you. No fast solution possible...
  664. * The kernel itself must perform the operation.
  665. * A special ghost syscall is used for that (see traps.c).
  666. */
  667. stmfd sp!, {r7, lr}
  668. mov r7, #0xff00 @ 0xfff0 into r7 for EABI
  669. orr r7, r7, #0xf0
  670. swi #0x9ffff0
  671. ldmfd sp!, {r7, pc}
  672. #elif __LINUX_ARM_ARCH__ < 6
  673. /*
  674. * Theory of operation:
  675. *
  676. * We set the Z flag before loading oldval. If ever an exception
  677. * occurs we can not be sure the loaded value will still be the same
  678. * when the exception returns, therefore the user exception handler
  679. * will clear the Z flag whenever the interrupted user code was
  680. * actually from the kernel address space (see the usr_entry macro).
  681. *
  682. * The post-increment on the str is used to prevent a race with an
  683. * exception happening just after the str instruction which would
  684. * clear the Z flag although the exchange was done.
  685. */
  686. #ifdef CONFIG_MMU
  687. teq ip, ip @ set Z flag
  688. ldr ip, [r2] @ load current val
  689. add r3, r2, #1 @ prepare store ptr
  690. teqeq ip, r0 @ compare with oldval if still allowed
  691. streq r1, [r3, #-1]! @ store newval if still allowed
  692. subs r0, r2, r3 @ if r2 == r3 the str occured
  693. #else
  694. #warning "NPTL on non MMU needs fixing"
  695. mov r0, #-1
  696. adds r0, r0, #0
  697. #endif
  698. mov pc, lr
  699. #else
  700. #ifdef CONFIG_SMP
  701. mcr p15, 0, r0, c7, c10, 5 @ dmb
  702. #endif
  703. ldrex r3, [r2]
  704. subs r3, r3, r0
  705. strexeq r3, r1, [r2]
  706. rsbs r0, r3, #0
  707. #ifdef CONFIG_SMP
  708. mcr p15, 0, r0, c7, c10, 5 @ dmb
  709. #endif
  710. mov pc, lr
  711. #endif
  712. .align 5
  713. /*
  714. * Reference prototype:
  715. *
  716. * int __kernel_get_tls(void)
  717. *
  718. * Input:
  719. *
  720. * lr = return address
  721. *
  722. * Output:
  723. *
  724. * r0 = TLS value
  725. *
  726. * Clobbered:
  727. *
  728. * the Z flag might be lost
  729. *
  730. * Definition and user space usage example:
  731. *
  732. * typedef int (__kernel_get_tls_t)(void);
  733. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  734. *
  735. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  736. *
  737. * This could be used as follows:
  738. *
  739. * #define __kernel_get_tls() \
  740. * ({ register unsigned int __val asm("r0"); \
  741. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  742. * : "=r" (__val) : : "lr","cc" ); \
  743. * __val; })
  744. */
  745. __kuser_get_tls: @ 0xffff0fe0
  746. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  747. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  748. mov pc, lr
  749. #else
  750. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  751. mov pc, lr
  752. #endif
  753. .rep 5
  754. .word 0 @ pad up to __kuser_helper_version
  755. .endr
  756. /*
  757. * Reference declaration:
  758. *
  759. * extern unsigned int __kernel_helper_version;
  760. *
  761. * Definition and user space usage example:
  762. *
  763. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  764. *
  765. * User space may read this to determine the curent number of helpers
  766. * available.
  767. */
  768. __kuser_helper_version: @ 0xffff0ffc
  769. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  770. .globl __kuser_helper_end
  771. __kuser_helper_end:
  772. /*
  773. * Vector stubs.
  774. *
  775. * This code is copied to 0xffff0200 so we can use branches in the
  776. * vectors, rather than ldr's. Note that this code must not
  777. * exceed 0x300 bytes.
  778. *
  779. * Common stub entry macro:
  780. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  781. *
  782. * SP points to a minimal amount of processor-private memory, the address
  783. * of which is copied into r0 for the mode specific abort handler.
  784. */
  785. .macro vector_stub, name, mode, correction=0
  786. .align 5
  787. vector_\name:
  788. .if \correction
  789. sub lr, lr, #\correction
  790. .endif
  791. @
  792. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  793. @ (parent CPSR)
  794. @
  795. stmia sp, {r0, lr} @ save r0, lr
  796. mrs lr, spsr
  797. str lr, [sp, #8] @ save spsr
  798. @
  799. @ Prepare for SVC32 mode. IRQs remain disabled.
  800. @
  801. mrs r0, cpsr
  802. eor r0, r0, #(\mode ^ SVC_MODE)
  803. msr spsr_cxsf, r0
  804. @
  805. @ the branch table must immediately follow this code
  806. @
  807. and lr, lr, #0x0f
  808. mov r0, sp
  809. ldr lr, [pc, lr, lsl #2]
  810. movs pc, lr @ branch to handler in SVC mode
  811. .endm
  812. .globl __stubs_start
  813. __stubs_start:
  814. /*
  815. * Interrupt dispatcher
  816. */
  817. vector_stub irq, IRQ_MODE, 4
  818. .long __irq_usr @ 0 (USR_26 / USR_32)
  819. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  820. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  821. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  822. .long __irq_invalid @ 4
  823. .long __irq_invalid @ 5
  824. .long __irq_invalid @ 6
  825. .long __irq_invalid @ 7
  826. .long __irq_invalid @ 8
  827. .long __irq_invalid @ 9
  828. .long __irq_invalid @ a
  829. .long __irq_invalid @ b
  830. .long __irq_invalid @ c
  831. .long __irq_invalid @ d
  832. .long __irq_invalid @ e
  833. .long __irq_invalid @ f
  834. /*
  835. * Data abort dispatcher
  836. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  837. */
  838. vector_stub dabt, ABT_MODE, 8
  839. .long __dabt_usr @ 0 (USR_26 / USR_32)
  840. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  841. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  842. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  843. .long __dabt_invalid @ 4
  844. .long __dabt_invalid @ 5
  845. .long __dabt_invalid @ 6
  846. .long __dabt_invalid @ 7
  847. .long __dabt_invalid @ 8
  848. .long __dabt_invalid @ 9
  849. .long __dabt_invalid @ a
  850. .long __dabt_invalid @ b
  851. .long __dabt_invalid @ c
  852. .long __dabt_invalid @ d
  853. .long __dabt_invalid @ e
  854. .long __dabt_invalid @ f
  855. /*
  856. * Prefetch abort dispatcher
  857. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  858. */
  859. vector_stub pabt, ABT_MODE, 4
  860. .long __pabt_usr @ 0 (USR_26 / USR_32)
  861. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  862. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  863. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  864. .long __pabt_invalid @ 4
  865. .long __pabt_invalid @ 5
  866. .long __pabt_invalid @ 6
  867. .long __pabt_invalid @ 7
  868. .long __pabt_invalid @ 8
  869. .long __pabt_invalid @ 9
  870. .long __pabt_invalid @ a
  871. .long __pabt_invalid @ b
  872. .long __pabt_invalid @ c
  873. .long __pabt_invalid @ d
  874. .long __pabt_invalid @ e
  875. .long __pabt_invalid @ f
  876. /*
  877. * Undef instr entry dispatcher
  878. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  879. */
  880. vector_stub und, UND_MODE
  881. .long __und_usr @ 0 (USR_26 / USR_32)
  882. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  883. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  884. .long __und_svc @ 3 (SVC_26 / SVC_32)
  885. .long __und_invalid @ 4
  886. .long __und_invalid @ 5
  887. .long __und_invalid @ 6
  888. .long __und_invalid @ 7
  889. .long __und_invalid @ 8
  890. .long __und_invalid @ 9
  891. .long __und_invalid @ a
  892. .long __und_invalid @ b
  893. .long __und_invalid @ c
  894. .long __und_invalid @ d
  895. .long __und_invalid @ e
  896. .long __und_invalid @ f
  897. .align 5
  898. /*=============================================================================
  899. * Undefined FIQs
  900. *-----------------------------------------------------------------------------
  901. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  902. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  903. * Basically to switch modes, we *HAVE* to clobber one register... brain
  904. * damage alert! I don't think that we can execute any code in here in any
  905. * other mode than FIQ... Ok you can switch to another mode, but you can't
  906. * get out of that mode without clobbering one register.
  907. */
  908. vector_fiq:
  909. disable_fiq
  910. subs pc, lr, #4
  911. /*=============================================================================
  912. * Address exception handler
  913. *-----------------------------------------------------------------------------
  914. * These aren't too critical.
  915. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  916. */
  917. vector_addrexcptn:
  918. b vector_addrexcptn
  919. /*
  920. * We group all the following data together to optimise
  921. * for CPUs with separate I & D caches.
  922. */
  923. .align 5
  924. .LCvswi:
  925. .word vector_swi
  926. .globl __stubs_end
  927. __stubs_end:
  928. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  929. .globl __vectors_start
  930. __vectors_start:
  931. swi SYS_ERROR0
  932. b vector_und + stubs_offset
  933. ldr pc, .LCvswi + stubs_offset
  934. b vector_pabt + stubs_offset
  935. b vector_dabt + stubs_offset
  936. b vector_addrexcptn + stubs_offset
  937. b vector_irq + stubs_offset
  938. b vector_fiq + stubs_offset
  939. .globl __vectors_end
  940. __vectors_end:
  941. .data
  942. .globl cr_alignment
  943. .globl cr_no_alignment
  944. cr_alignment:
  945. .space 4
  946. cr_no_alignment:
  947. .space 4