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