entry-armv.S 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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_DABORT
  145. ldr r4, .LCprocfns
  146. mov lr, pc
  147. ldr pc, [r4, #PROCESSOR_DABT_FUNC]
  148. #else
  149. bl CPU_DABORT_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. str r8, [tsk, #TI_PREEMPT] @ restore preempt count
  182. ldr r0, [tsk, #TI_FLAGS] @ get flags
  183. teq r8, #0 @ if preempt count != 0
  184. movne r0, #0 @ force flags to 0
  185. tst r0, #_TIF_NEED_RESCHED
  186. blne svc_preempt
  187. #endif
  188. ldr r0, [sp, #S_PSR] @ irqs are already disabled
  189. msr spsr_cxsf, r0
  190. #ifdef CONFIG_TRACE_IRQFLAGS
  191. tst r0, #PSR_I_BIT
  192. bleq trace_hardirqs_on
  193. #endif
  194. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  195. .ltorg
  196. #ifdef CONFIG_PREEMPT
  197. svc_preempt:
  198. mov r8, lr
  199. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  200. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  201. tst r0, #_TIF_NEED_RESCHED
  202. moveq pc, r8 @ go again
  203. b 1b
  204. #endif
  205. .align 5
  206. __und_svc:
  207. #ifdef CONFIG_KPROBES
  208. @ If a kprobe is about to simulate a "stmdb sp..." instruction,
  209. @ it obviously needs free stack space which then will belong to
  210. @ the saved context.
  211. svc_entry 64
  212. #else
  213. svc_entry
  214. #endif
  215. @
  216. @ call emulation code, which returns using r9 if it has emulated
  217. @ the instruction, or the more conventional lr if we are to treat
  218. @ this as a real undefined instruction
  219. @
  220. @ r0 - instruction
  221. @
  222. ldr r0, [r2, #-4]
  223. adr r9, 1f
  224. bl call_fpe
  225. mov r0, sp @ struct pt_regs *regs
  226. bl do_undefinstr
  227. @
  228. @ IRQs off again before pulling preserved data off the stack
  229. @
  230. 1: disable_irq
  231. @
  232. @ restore SPSR and restart the instruction
  233. @
  234. ldr lr, [sp, #S_PSR] @ Get SVC cpsr
  235. msr spsr_cxsf, lr
  236. ldmia sp, {r0 - pc}^ @ Restore SVC registers
  237. .align 5
  238. __pabt_svc:
  239. svc_entry
  240. @
  241. @ re-enable interrupts if appropriate
  242. @
  243. mrs r9, cpsr
  244. tst r3, #PSR_I_BIT
  245. biceq r9, r9, #PSR_I_BIT
  246. @
  247. @ set args, then call main handler
  248. @
  249. @ r0 - address of faulting instruction
  250. @ r1 - pointer to registers on stack
  251. @
  252. #ifdef MULTI_PABORT
  253. mov r0, r2 @ pass address of aborted instruction.
  254. ldr r4, .LCprocfns
  255. mov lr, pc
  256. ldr pc, [r4, #PROCESSOR_PABT_FUNC]
  257. #else
  258. CPU_PABORT_HANDLER(r0, r2)
  259. #endif
  260. msr cpsr_c, r9 @ Maybe enable interrupts
  261. mov r1, sp @ regs
  262. bl do_PrefetchAbort @ call abort handler
  263. @
  264. @ IRQs off again before pulling preserved data off the stack
  265. @
  266. disable_irq
  267. @
  268. @ restore SPSR and restart the instruction
  269. @
  270. ldr r0, [sp, #S_PSR]
  271. msr spsr_cxsf, r0
  272. ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
  273. .align 5
  274. .LCcralign:
  275. .word cr_alignment
  276. #ifdef MULTI_DABORT
  277. .LCprocfns:
  278. .word processor
  279. #endif
  280. .LCfp:
  281. .word fp_enter
  282. /*
  283. * User mode handlers
  284. *
  285. * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
  286. */
  287. #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
  288. #error "sizeof(struct pt_regs) must be a multiple of 8"
  289. #endif
  290. .macro usr_entry
  291. sub sp, sp, #S_FRAME_SIZE
  292. stmib sp, {r1 - r12}
  293. ldmia r0, {r1 - r3}
  294. add r0, sp, #S_PC @ here for interlock avoidance
  295. mov r4, #-1 @ "" "" "" ""
  296. str r1, [sp] @ save the "real" r0 copied
  297. @ from the exception stack
  298. @
  299. @ We are now ready to fill in the remaining blanks on the stack:
  300. @
  301. @ r2 - lr_<exception>, already fixed up for correct return/restart
  302. @ r3 - spsr_<exception>
  303. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  304. @
  305. @ Also, separately save sp_usr and lr_usr
  306. @
  307. stmia r0, {r2 - r4}
  308. stmdb r0, {sp, lr}^
  309. @
  310. @ Enable the alignment trap while in kernel mode
  311. @
  312. alignment_trap r0
  313. @
  314. @ Clear FP to mark the first stack frame
  315. @
  316. zero_fp
  317. .endm
  318. .macro kuser_cmpxchg_check
  319. #if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  320. #ifndef CONFIG_MMU
  321. #warning "NPTL on non MMU needs fixing"
  322. #else
  323. @ Make sure our user space atomic helper is restarted
  324. @ if it was interrupted in a critical region. Here we
  325. @ perform a quick test inline since it should be false
  326. @ 99.9999% of the time. The rest is done out of line.
  327. cmp r2, #TASK_SIZE
  328. blhs kuser_cmpxchg_fixup
  329. #endif
  330. #endif
  331. .endm
  332. .align 5
  333. __dabt_usr:
  334. usr_entry
  335. kuser_cmpxchg_check
  336. @
  337. @ Call the processor-specific abort handler:
  338. @
  339. @ r2 - aborted context pc
  340. @ r3 - aborted context cpsr
  341. @
  342. @ The abort handler must return the aborted address in r0, and
  343. @ the fault status register in r1.
  344. @
  345. #ifdef MULTI_DABORT
  346. ldr r4, .LCprocfns
  347. mov lr, pc
  348. ldr pc, [r4, #PROCESSOR_DABT_FUNC]
  349. #else
  350. bl CPU_DABORT_HANDLER
  351. #endif
  352. @
  353. @ IRQs on, then call the main handler
  354. @
  355. enable_irq
  356. mov r2, sp
  357. adr lr, ret_from_exception
  358. b do_DataAbort
  359. .align 5
  360. __irq_usr:
  361. usr_entry
  362. kuser_cmpxchg_check
  363. #ifdef CONFIG_TRACE_IRQFLAGS
  364. bl trace_hardirqs_off
  365. #endif
  366. get_thread_info tsk
  367. #ifdef CONFIG_PREEMPT
  368. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  369. add r7, r8, #1 @ increment it
  370. str r7, [tsk, #TI_PREEMPT]
  371. #endif
  372. irq_handler
  373. #ifdef CONFIG_PREEMPT
  374. ldr r0, [tsk, #TI_PREEMPT]
  375. str r8, [tsk, #TI_PREEMPT]
  376. teq r0, r7
  377. strne r0, [r0, -r0]
  378. #endif
  379. #ifdef CONFIG_TRACE_IRQFLAGS
  380. bl trace_hardirqs_on
  381. #endif
  382. mov why, #0
  383. b ret_to_user
  384. .ltorg
  385. .align 5
  386. __und_usr:
  387. usr_entry
  388. @
  389. @ fall through to the emulation code, which returns using r9 if
  390. @ it has emulated the instruction, or the more conventional lr
  391. @ if we are to treat this as a real undefined instruction
  392. @
  393. @ r0 - instruction
  394. @
  395. adr r9, ret_from_exception
  396. adr lr, __und_usr_unknown
  397. tst r3, #PSR_T_BIT @ Thumb mode?
  398. subeq r4, r2, #4 @ ARM instr at LR - 4
  399. subne r4, r2, #2 @ Thumb instr at LR - 2
  400. 1: ldreqt r0, [r4]
  401. beq call_fpe
  402. @ Thumb instruction
  403. #if __LINUX_ARM_ARCH__ >= 7
  404. 2: ldrht r5, [r4], #2
  405. and r0, r5, #0xf800 @ mask bits 111x x... .... ....
  406. cmp r0, #0xe800 @ 32bit instruction if xx != 0
  407. blo __und_usr_unknown
  408. 3: ldrht r0, [r4]
  409. add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
  410. orr r0, r0, r5, lsl #16
  411. #else
  412. b __und_usr_unknown
  413. #endif
  414. @
  415. @ fallthrough to call_fpe
  416. @
  417. /*
  418. * The out of line fixup for the ldrt above.
  419. */
  420. .section .fixup, "ax"
  421. 4: mov pc, r9
  422. .previous
  423. .section __ex_table,"a"
  424. .long 1b, 4b
  425. #if __LINUX_ARM_ARCH__ >= 7
  426. .long 2b, 4b
  427. .long 3b, 4b
  428. #endif
  429. .previous
  430. /*
  431. * Check whether the instruction is a co-processor instruction.
  432. * If yes, we need to call the relevant co-processor handler.
  433. *
  434. * Note that we don't do a full check here for the co-processor
  435. * instructions; all instructions with bit 27 set are well
  436. * defined. The only instructions that should fault are the
  437. * co-processor instructions. However, we have to watch out
  438. * for the ARM6/ARM7 SWI bug.
  439. *
  440. * NEON is a special case that has to be handled here. Not all
  441. * NEON instructions are co-processor instructions, so we have
  442. * to make a special case of checking for them. Plus, there's
  443. * five groups of them, so we have a table of mask/opcode pairs
  444. * to check against, and if any match then we branch off into the
  445. * NEON handler code.
  446. *
  447. * Emulators may wish to make use of the following registers:
  448. * r0 = instruction opcode.
  449. * r2 = PC+4
  450. * r9 = normal "successful" return address
  451. * r10 = this threads thread_info structure.
  452. * lr = unrecognised instruction return address
  453. */
  454. @
  455. @ Fall-through from Thumb-2 __und_usr
  456. @
  457. #ifdef CONFIG_NEON
  458. adr r6, .LCneon_thumb_opcodes
  459. b 2f
  460. #endif
  461. call_fpe:
  462. #ifdef CONFIG_NEON
  463. adr r6, .LCneon_arm_opcodes
  464. 2:
  465. ldr r7, [r6], #4 @ mask value
  466. cmp r7, #0 @ end mask?
  467. beq 1f
  468. and r8, r0, r7
  469. ldr r7, [r6], #4 @ opcode bits matching in mask
  470. cmp r8, r7 @ NEON instruction?
  471. bne 2b
  472. get_thread_info r10
  473. mov r7, #1
  474. strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
  475. strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
  476. b do_vfp @ let VFP handler handle this
  477. 1:
  478. #endif
  479. tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
  480. tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
  481. #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
  482. and r8, r0, #0x0f000000 @ mask out op-code bits
  483. teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
  484. #endif
  485. moveq pc, lr
  486. get_thread_info r10 @ get current thread
  487. and r8, r0, #0x00000f00 @ mask out CP number
  488. mov r7, #1
  489. add r6, r10, #TI_USED_CP
  490. strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
  491. #ifdef CONFIG_IWMMXT
  492. @ Test if we need to give access to iWMMXt coprocessors
  493. ldr r5, [r10, #TI_FLAGS]
  494. rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
  495. movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
  496. bcs iwmmxt_task_enable
  497. #endif
  498. add pc, pc, r8, lsr #6
  499. mov r0, r0
  500. mov pc, lr @ CP#0
  501. b do_fpe @ CP#1 (FPE)
  502. b do_fpe @ CP#2 (FPE)
  503. mov pc, lr @ CP#3
  504. #ifdef CONFIG_CRUNCH
  505. b crunch_task_enable @ CP#4 (MaverickCrunch)
  506. b crunch_task_enable @ CP#5 (MaverickCrunch)
  507. b crunch_task_enable @ CP#6 (MaverickCrunch)
  508. #else
  509. mov pc, lr @ CP#4
  510. mov pc, lr @ CP#5
  511. mov pc, lr @ CP#6
  512. #endif
  513. mov pc, lr @ CP#7
  514. mov pc, lr @ CP#8
  515. mov pc, lr @ CP#9
  516. #ifdef CONFIG_VFP
  517. b do_vfp @ CP#10 (VFP)
  518. b do_vfp @ CP#11 (VFP)
  519. #else
  520. mov pc, lr @ CP#10 (VFP)
  521. mov pc, lr @ CP#11 (VFP)
  522. #endif
  523. mov pc, lr @ CP#12
  524. mov pc, lr @ CP#13
  525. mov pc, lr @ CP#14 (Debug)
  526. mov pc, lr @ CP#15 (Control)
  527. #ifdef CONFIG_NEON
  528. .align 6
  529. .LCneon_arm_opcodes:
  530. .word 0xfe000000 @ mask
  531. .word 0xf2000000 @ opcode
  532. .word 0xff100000 @ mask
  533. .word 0xf4000000 @ opcode
  534. .word 0x00000000 @ mask
  535. .word 0x00000000 @ opcode
  536. .LCneon_thumb_opcodes:
  537. .word 0xef000000 @ mask
  538. .word 0xef000000 @ opcode
  539. .word 0xff100000 @ mask
  540. .word 0xf9000000 @ opcode
  541. .word 0x00000000 @ mask
  542. .word 0x00000000 @ opcode
  543. #endif
  544. do_fpe:
  545. enable_irq
  546. ldr r4, .LCfp
  547. add r10, r10, #TI_FPSTATE @ r10 = workspace
  548. ldr pc, [r4] @ Call FP module USR entry point
  549. /*
  550. * The FP module is called with these registers set:
  551. * r0 = instruction
  552. * r2 = PC+4
  553. * r9 = normal "successful" return address
  554. * r10 = FP workspace
  555. * lr = unrecognised FP instruction return address
  556. */
  557. .data
  558. ENTRY(fp_enter)
  559. .word no_fp
  560. .previous
  561. no_fp: mov pc, lr
  562. __und_usr_unknown:
  563. mov r0, sp
  564. adr lr, ret_from_exception
  565. b do_undefinstr
  566. .align 5
  567. __pabt_usr:
  568. usr_entry
  569. #ifdef MULTI_PABORT
  570. mov r0, r2 @ pass address of aborted instruction.
  571. ldr r4, .LCprocfns
  572. mov lr, pc
  573. ldr pc, [r4, #PROCESSOR_PABT_FUNC]
  574. #else
  575. CPU_PABORT_HANDLER(r0, r2)
  576. #endif
  577. enable_irq @ Enable interrupts
  578. mov r1, sp @ regs
  579. bl do_PrefetchAbort @ call abort handler
  580. /* fall through */
  581. /*
  582. * This is the return code to user mode for abort handlers
  583. */
  584. ENTRY(ret_from_exception)
  585. get_thread_info tsk
  586. mov why, #0
  587. b ret_to_user
  588. /*
  589. * Register switch for ARMv3 and ARMv4 processors
  590. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  591. * previous and next are guaranteed not to be the same.
  592. */
  593. ENTRY(__switch_to)
  594. add ip, r1, #TI_CPU_SAVE
  595. ldr r3, [r2, #TI_TP_VALUE]
  596. stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
  597. #ifdef CONFIG_MMU
  598. ldr r6, [r2, #TI_CPU_DOMAIN]
  599. #endif
  600. #if __LINUX_ARM_ARCH__ >= 6
  601. #ifdef CONFIG_CPU_32v6K
  602. clrex
  603. #else
  604. strex r5, r4, [ip] @ Clear exclusive monitor
  605. #endif
  606. #endif
  607. #if defined(CONFIG_HAS_TLS_REG)
  608. mcr p15, 0, r3, c13, c0, 3 @ set TLS register
  609. #elif !defined(CONFIG_TLS_REG_EMUL)
  610. mov r4, #0xffff0fff
  611. str r3, [r4, #-15] @ TLS val at 0xffff0ff0
  612. #endif
  613. #ifdef CONFIG_MMU
  614. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  615. #endif
  616. mov r5, r0
  617. add r4, r2, #TI_CPU_SAVE
  618. ldr r0, =thread_notify_head
  619. mov r1, #THREAD_NOTIFY_SWITCH
  620. bl atomic_notifier_call_chain
  621. mov r0, r5
  622. ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
  623. __INIT
  624. /*
  625. * User helpers.
  626. *
  627. * These are segment of kernel provided user code reachable from user space
  628. * at a fixed address in kernel memory. This is used to provide user space
  629. * with some operations which require kernel help because of unimplemented
  630. * native feature and/or instructions in many ARM CPUs. The idea is for
  631. * this code to be executed directly in user mode for best efficiency but
  632. * which is too intimate with the kernel counter part to be left to user
  633. * libraries. In fact this code might even differ from one CPU to another
  634. * depending on the available instruction set and restrictions like on
  635. * SMP systems. In other words, the kernel reserves the right to change
  636. * this code as needed without warning. Only the entry points and their
  637. * results are guaranteed to be stable.
  638. *
  639. * Each segment is 32-byte aligned and will be moved to the top of the high
  640. * vector page. New segments (if ever needed) must be added in front of
  641. * existing ones. This mechanism should be used only for things that are
  642. * really small and justified, and not be abused freely.
  643. *
  644. * User space is expected to implement those things inline when optimizing
  645. * for a processor that has the necessary native support, but only if such
  646. * resulting binaries are already to be incompatible with earlier ARM
  647. * processors due to the use of unsupported instructions other than what
  648. * is provided here. In other words don't make binaries unable to run on
  649. * earlier processors just for the sake of not using these kernel helpers
  650. * if your compiled code is not going to use the new instructions for other
  651. * purpose.
  652. */
  653. .macro usr_ret, reg
  654. #ifdef CONFIG_ARM_THUMB
  655. bx \reg
  656. #else
  657. mov pc, \reg
  658. #endif
  659. .endm
  660. .align 5
  661. .globl __kuser_helper_start
  662. __kuser_helper_start:
  663. /*
  664. * Reference prototype:
  665. *
  666. * void __kernel_memory_barrier(void)
  667. *
  668. * Input:
  669. *
  670. * lr = return address
  671. *
  672. * Output:
  673. *
  674. * none
  675. *
  676. * Clobbered:
  677. *
  678. * none
  679. *
  680. * Definition and user space usage example:
  681. *
  682. * typedef void (__kernel_dmb_t)(void);
  683. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  684. *
  685. * Apply any needed memory barrier to preserve consistency with data modified
  686. * manually and __kuser_cmpxchg usage.
  687. *
  688. * This could be used as follows:
  689. *
  690. * #define __kernel_dmb() \
  691. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  692. * : : : "r0", "lr","cc" )
  693. */
  694. __kuser_memory_barrier: @ 0xffff0fa0
  695. #if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
  696. mcr p15, 0, r0, c7, c10, 5 @ dmb
  697. #endif
  698. usr_ret lr
  699. .align 5
  700. /*
  701. * Reference prototype:
  702. *
  703. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  704. *
  705. * Input:
  706. *
  707. * r0 = oldval
  708. * r1 = newval
  709. * r2 = ptr
  710. * lr = return address
  711. *
  712. * Output:
  713. *
  714. * r0 = returned value (zero or non-zero)
  715. * C flag = set if r0 == 0, clear if r0 != 0
  716. *
  717. * Clobbered:
  718. *
  719. * r3, ip, flags
  720. *
  721. * Definition and user space usage example:
  722. *
  723. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  724. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  725. *
  726. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  727. * Return zero if *ptr was changed or non-zero if no exchange happened.
  728. * The C flag is also set if *ptr was changed to allow for assembly
  729. * optimization in the calling code.
  730. *
  731. * Notes:
  732. *
  733. * - This routine already includes memory barriers as needed.
  734. *
  735. * For example, a user space atomic_add implementation could look like this:
  736. *
  737. * #define atomic_add(ptr, val) \
  738. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  739. * register unsigned int __result asm("r1"); \
  740. * asm volatile ( \
  741. * "1: @ atomic_add\n\t" \
  742. * "ldr r0, [r2]\n\t" \
  743. * "mov r3, #0xffff0fff\n\t" \
  744. * "add lr, pc, #4\n\t" \
  745. * "add r1, r0, %2\n\t" \
  746. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  747. * "bcc 1b" \
  748. * : "=&r" (__result) \
  749. * : "r" (__ptr), "rIL" (val) \
  750. * : "r0","r3","ip","lr","cc","memory" ); \
  751. * __result; })
  752. */
  753. __kuser_cmpxchg: @ 0xffff0fc0
  754. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  755. /*
  756. * Poor you. No fast solution possible...
  757. * The kernel itself must perform the operation.
  758. * A special ghost syscall is used for that (see traps.c).
  759. */
  760. stmfd sp!, {r7, lr}
  761. mov r7, #0xff00 @ 0xfff0 into r7 for EABI
  762. orr r7, r7, #0xf0
  763. swi #0x9ffff0
  764. ldmfd sp!, {r7, pc}
  765. #elif __LINUX_ARM_ARCH__ < 6
  766. #ifdef CONFIG_MMU
  767. /*
  768. * The only thing that can break atomicity in this cmpxchg
  769. * implementation is either an IRQ or a data abort exception
  770. * causing another process/thread to be scheduled in the middle
  771. * of the critical sequence. To prevent this, code is added to
  772. * the IRQ and data abort exception handlers to set the pc back
  773. * to the beginning of the critical section if it is found to be
  774. * within that critical section (see kuser_cmpxchg_fixup).
  775. */
  776. 1: ldr r3, [r2] @ load current val
  777. subs r3, r3, r0 @ compare with oldval
  778. 2: streq r1, [r2] @ store newval if eq
  779. rsbs r0, r3, #0 @ set return val and C flag
  780. usr_ret lr
  781. .text
  782. kuser_cmpxchg_fixup:
  783. @ Called from kuser_cmpxchg_check macro.
  784. @ r2 = address of interrupted insn (must be preserved).
  785. @ sp = saved regs. r7 and r8 are clobbered.
  786. @ 1b = first critical insn, 2b = last critical insn.
  787. @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
  788. mov r7, #0xffff0fff
  789. sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
  790. subs r8, r2, r7
  791. rsbcss r8, r8, #(2b - 1b)
  792. strcs r7, [sp, #S_PC]
  793. mov pc, lr
  794. .previous
  795. #else
  796. #warning "NPTL on non MMU needs fixing"
  797. mov r0, #-1
  798. adds r0, r0, #0
  799. usr_ret lr
  800. #endif
  801. #else
  802. #ifdef CONFIG_SMP
  803. mcr p15, 0, r0, c7, c10, 5 @ dmb
  804. #endif
  805. 1: ldrex r3, [r2]
  806. subs r3, r3, r0
  807. strexeq r3, r1, [r2]
  808. teqeq r3, #1
  809. beq 1b
  810. rsbs r0, r3, #0
  811. /* beware -- each __kuser slot must be 8 instructions max */
  812. #ifdef CONFIG_SMP
  813. b __kuser_memory_barrier
  814. #else
  815. usr_ret lr
  816. #endif
  817. #endif
  818. .align 5
  819. /*
  820. * Reference prototype:
  821. *
  822. * int __kernel_get_tls(void)
  823. *
  824. * Input:
  825. *
  826. * lr = return address
  827. *
  828. * Output:
  829. *
  830. * r0 = TLS value
  831. *
  832. * Clobbered:
  833. *
  834. * none
  835. *
  836. * Definition and user space usage example:
  837. *
  838. * typedef int (__kernel_get_tls_t)(void);
  839. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  840. *
  841. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  842. *
  843. * This could be used as follows:
  844. *
  845. * #define __kernel_get_tls() \
  846. * ({ register unsigned int __val asm("r0"); \
  847. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  848. * : "=r" (__val) : : "lr","cc" ); \
  849. * __val; })
  850. */
  851. __kuser_get_tls: @ 0xffff0fe0
  852. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  853. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  854. #else
  855. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  856. #endif
  857. usr_ret lr
  858. .rep 5
  859. .word 0 @ pad up to __kuser_helper_version
  860. .endr
  861. /*
  862. * Reference declaration:
  863. *
  864. * extern unsigned int __kernel_helper_version;
  865. *
  866. * Definition and user space usage example:
  867. *
  868. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  869. *
  870. * User space may read this to determine the curent number of helpers
  871. * available.
  872. */
  873. __kuser_helper_version: @ 0xffff0ffc
  874. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  875. .globl __kuser_helper_end
  876. __kuser_helper_end:
  877. /*
  878. * Vector stubs.
  879. *
  880. * This code is copied to 0xffff0200 so we can use branches in the
  881. * vectors, rather than ldr's. Note that this code must not
  882. * exceed 0x300 bytes.
  883. *
  884. * Common stub entry macro:
  885. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  886. *
  887. * SP points to a minimal amount of processor-private memory, the address
  888. * of which is copied into r0 for the mode specific abort handler.
  889. */
  890. .macro vector_stub, name, mode, correction=0
  891. .align 5
  892. vector_\name:
  893. .if \correction
  894. sub lr, lr, #\correction
  895. .endif
  896. @
  897. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  898. @ (parent CPSR)
  899. @
  900. stmia sp, {r0, lr} @ save r0, lr
  901. mrs lr, spsr
  902. str lr, [sp, #8] @ save spsr
  903. @
  904. @ Prepare for SVC32 mode. IRQs remain disabled.
  905. @
  906. mrs r0, cpsr
  907. eor r0, r0, #(\mode ^ SVC_MODE)
  908. msr spsr_cxsf, r0
  909. @
  910. @ the branch table must immediately follow this code
  911. @
  912. and lr, lr, #0x0f
  913. mov r0, sp
  914. ldr lr, [pc, lr, lsl #2]
  915. movs pc, lr @ branch to handler in SVC mode
  916. .endm
  917. .globl __stubs_start
  918. __stubs_start:
  919. /*
  920. * Interrupt dispatcher
  921. */
  922. vector_stub irq, IRQ_MODE, 4
  923. .long __irq_usr @ 0 (USR_26 / USR_32)
  924. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  925. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  926. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  927. .long __irq_invalid @ 4
  928. .long __irq_invalid @ 5
  929. .long __irq_invalid @ 6
  930. .long __irq_invalid @ 7
  931. .long __irq_invalid @ 8
  932. .long __irq_invalid @ 9
  933. .long __irq_invalid @ a
  934. .long __irq_invalid @ b
  935. .long __irq_invalid @ c
  936. .long __irq_invalid @ d
  937. .long __irq_invalid @ e
  938. .long __irq_invalid @ f
  939. /*
  940. * Data abort dispatcher
  941. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  942. */
  943. vector_stub dabt, ABT_MODE, 8
  944. .long __dabt_usr @ 0 (USR_26 / USR_32)
  945. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  946. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  947. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  948. .long __dabt_invalid @ 4
  949. .long __dabt_invalid @ 5
  950. .long __dabt_invalid @ 6
  951. .long __dabt_invalid @ 7
  952. .long __dabt_invalid @ 8
  953. .long __dabt_invalid @ 9
  954. .long __dabt_invalid @ a
  955. .long __dabt_invalid @ b
  956. .long __dabt_invalid @ c
  957. .long __dabt_invalid @ d
  958. .long __dabt_invalid @ e
  959. .long __dabt_invalid @ f
  960. /*
  961. * Prefetch abort dispatcher
  962. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  963. */
  964. vector_stub pabt, ABT_MODE, 4
  965. .long __pabt_usr @ 0 (USR_26 / USR_32)
  966. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  967. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  968. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  969. .long __pabt_invalid @ 4
  970. .long __pabt_invalid @ 5
  971. .long __pabt_invalid @ 6
  972. .long __pabt_invalid @ 7
  973. .long __pabt_invalid @ 8
  974. .long __pabt_invalid @ 9
  975. .long __pabt_invalid @ a
  976. .long __pabt_invalid @ b
  977. .long __pabt_invalid @ c
  978. .long __pabt_invalid @ d
  979. .long __pabt_invalid @ e
  980. .long __pabt_invalid @ f
  981. /*
  982. * Undef instr entry dispatcher
  983. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  984. */
  985. vector_stub und, UND_MODE
  986. .long __und_usr @ 0 (USR_26 / USR_32)
  987. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  988. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  989. .long __und_svc @ 3 (SVC_26 / SVC_32)
  990. .long __und_invalid @ 4
  991. .long __und_invalid @ 5
  992. .long __und_invalid @ 6
  993. .long __und_invalid @ 7
  994. .long __und_invalid @ 8
  995. .long __und_invalid @ 9
  996. .long __und_invalid @ a
  997. .long __und_invalid @ b
  998. .long __und_invalid @ c
  999. .long __und_invalid @ d
  1000. .long __und_invalid @ e
  1001. .long __und_invalid @ f
  1002. .align 5
  1003. /*=============================================================================
  1004. * Undefined FIQs
  1005. *-----------------------------------------------------------------------------
  1006. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  1007. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  1008. * Basically to switch modes, we *HAVE* to clobber one register... brain
  1009. * damage alert! I don't think that we can execute any code in here in any
  1010. * other mode than FIQ... Ok you can switch to another mode, but you can't
  1011. * get out of that mode without clobbering one register.
  1012. */
  1013. vector_fiq:
  1014. disable_fiq
  1015. subs pc, lr, #4
  1016. /*=============================================================================
  1017. * Address exception handler
  1018. *-----------------------------------------------------------------------------
  1019. * These aren't too critical.
  1020. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  1021. */
  1022. vector_addrexcptn:
  1023. b vector_addrexcptn
  1024. /*
  1025. * We group all the following data together to optimise
  1026. * for CPUs with separate I & D caches.
  1027. */
  1028. .align 5
  1029. .LCvswi:
  1030. .word vector_swi
  1031. .globl __stubs_end
  1032. __stubs_end:
  1033. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  1034. .globl __vectors_start
  1035. __vectors_start:
  1036. swi SYS_ERROR0
  1037. b vector_und + stubs_offset
  1038. ldr pc, .LCvswi + stubs_offset
  1039. b vector_pabt + stubs_offset
  1040. b vector_dabt + stubs_offset
  1041. b vector_addrexcptn + stubs_offset
  1042. b vector_irq + stubs_offset
  1043. b vector_fiq + stubs_offset
  1044. .globl __vectors_end
  1045. __vectors_end:
  1046. .data
  1047. .globl cr_alignment
  1048. .globl cr_no_alignment
  1049. cr_alignment:
  1050. .space 4
  1051. cr_no_alignment:
  1052. .space 4