entry-armv.S 28 KB

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