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. #ifdef CONFIG_CPU_ENDIAN_BE8
  423. reveq r0, r0 @ little endian instruction
  424. #endif
  425. beq call_fpe
  426. @ Thumb instruction
  427. #if __LINUX_ARM_ARCH__ >= 7
  428. 2: ldrht r5, [r4], #2
  429. and r0, r5, #0xf800 @ mask bits 111x x... .... ....
  430. cmp r0, #0xe800 @ 32bit instruction if xx != 0
  431. blo __und_usr_unknown
  432. 3: ldrht r0, [r4]
  433. add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
  434. orr r0, r0, r5, lsl #16
  435. #else
  436. b __und_usr_unknown
  437. #endif
  438. UNWIND(.fnend )
  439. ENDPROC(__und_usr)
  440. @
  441. @ fallthrough to call_fpe
  442. @
  443. /*
  444. * The out of line fixup for the ldrt above.
  445. */
  446. .section .fixup, "ax"
  447. 4: mov pc, r9
  448. .previous
  449. .section __ex_table,"a"
  450. .long 1b, 4b
  451. #if __LINUX_ARM_ARCH__ >= 7
  452. .long 2b, 4b
  453. .long 3b, 4b
  454. #endif
  455. .previous
  456. /*
  457. * Check whether the instruction is a co-processor instruction.
  458. * If yes, we need to call the relevant co-processor handler.
  459. *
  460. * Note that we don't do a full check here for the co-processor
  461. * instructions; all instructions with bit 27 set are well
  462. * defined. The only instructions that should fault are the
  463. * co-processor instructions. However, we have to watch out
  464. * for the ARM6/ARM7 SWI bug.
  465. *
  466. * NEON is a special case that has to be handled here. Not all
  467. * NEON instructions are co-processor instructions, so we have
  468. * to make a special case of checking for them. Plus, there's
  469. * five groups of them, so we have a table of mask/opcode pairs
  470. * to check against, and if any match then we branch off into the
  471. * NEON handler code.
  472. *
  473. * Emulators may wish to make use of the following registers:
  474. * r0 = instruction opcode.
  475. * r2 = PC+4
  476. * r9 = normal "successful" return address
  477. * r10 = this threads thread_info structure.
  478. * lr = unrecognised instruction return address
  479. */
  480. @
  481. @ Fall-through from Thumb-2 __und_usr
  482. @
  483. #ifdef CONFIG_NEON
  484. adr r6, .LCneon_thumb_opcodes
  485. b 2f
  486. #endif
  487. call_fpe:
  488. #ifdef CONFIG_NEON
  489. adr r6, .LCneon_arm_opcodes
  490. 2:
  491. ldr r7, [r6], #4 @ mask value
  492. cmp r7, #0 @ end mask?
  493. beq 1f
  494. and r8, r0, r7
  495. ldr r7, [r6], #4 @ opcode bits matching in mask
  496. cmp r8, r7 @ NEON instruction?
  497. bne 2b
  498. get_thread_info r10
  499. mov r7, #1
  500. strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
  501. strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
  502. b do_vfp @ let VFP handler handle this
  503. 1:
  504. #endif
  505. tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
  506. tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
  507. #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
  508. and r8, r0, #0x0f000000 @ mask out op-code bits
  509. teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
  510. #endif
  511. moveq pc, lr
  512. get_thread_info r10 @ get current thread
  513. and r8, r0, #0x00000f00 @ mask out CP number
  514. mov r7, #1
  515. add r6, r10, #TI_USED_CP
  516. strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
  517. #ifdef CONFIG_IWMMXT
  518. @ Test if we need to give access to iWMMXt coprocessors
  519. ldr r5, [r10, #TI_FLAGS]
  520. rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
  521. movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
  522. bcs iwmmxt_task_enable
  523. #endif
  524. add pc, pc, r8, lsr #6
  525. mov r0, r0
  526. mov pc, lr @ CP#0
  527. b do_fpe @ CP#1 (FPE)
  528. b do_fpe @ CP#2 (FPE)
  529. mov pc, lr @ CP#3
  530. #ifdef CONFIG_CRUNCH
  531. b crunch_task_enable @ CP#4 (MaverickCrunch)
  532. b crunch_task_enable @ CP#5 (MaverickCrunch)
  533. b crunch_task_enable @ CP#6 (MaverickCrunch)
  534. #else
  535. mov pc, lr @ CP#4
  536. mov pc, lr @ CP#5
  537. mov pc, lr @ CP#6
  538. #endif
  539. mov pc, lr @ CP#7
  540. mov pc, lr @ CP#8
  541. mov pc, lr @ CP#9
  542. #ifdef CONFIG_VFP
  543. b do_vfp @ CP#10 (VFP)
  544. b do_vfp @ CP#11 (VFP)
  545. #else
  546. mov pc, lr @ CP#10 (VFP)
  547. mov pc, lr @ CP#11 (VFP)
  548. #endif
  549. mov pc, lr @ CP#12
  550. mov pc, lr @ CP#13
  551. mov pc, lr @ CP#14 (Debug)
  552. mov pc, lr @ CP#15 (Control)
  553. #ifdef CONFIG_NEON
  554. .align 6
  555. .LCneon_arm_opcodes:
  556. .word 0xfe000000 @ mask
  557. .word 0xf2000000 @ opcode
  558. .word 0xff100000 @ mask
  559. .word 0xf4000000 @ opcode
  560. .word 0x00000000 @ mask
  561. .word 0x00000000 @ opcode
  562. .LCneon_thumb_opcodes:
  563. .word 0xef000000 @ mask
  564. .word 0xef000000 @ opcode
  565. .word 0xff100000 @ mask
  566. .word 0xf9000000 @ opcode
  567. .word 0x00000000 @ mask
  568. .word 0x00000000 @ opcode
  569. #endif
  570. do_fpe:
  571. enable_irq
  572. ldr r4, .LCfp
  573. add r10, r10, #TI_FPSTATE @ r10 = workspace
  574. ldr pc, [r4] @ Call FP module USR entry point
  575. /*
  576. * The FP module is called with these registers set:
  577. * r0 = instruction
  578. * r2 = PC+4
  579. * r9 = normal "successful" return address
  580. * r10 = FP workspace
  581. * lr = unrecognised FP instruction return address
  582. */
  583. .data
  584. ENTRY(fp_enter)
  585. .word no_fp
  586. .previous
  587. no_fp: mov pc, lr
  588. __und_usr_unknown:
  589. enable_irq
  590. mov r0, sp
  591. adr lr, ret_from_exception
  592. b do_undefinstr
  593. ENDPROC(__und_usr_unknown)
  594. .align 5
  595. __pabt_usr:
  596. usr_entry
  597. #ifdef MULTI_PABORT
  598. mov r0, r2 @ pass address of aborted instruction.
  599. ldr r4, .LCprocfns
  600. mov lr, pc
  601. ldr pc, [r4, #PROCESSOR_PABT_FUNC]
  602. #else
  603. CPU_PABORT_HANDLER(r0, r2)
  604. #endif
  605. enable_irq @ Enable interrupts
  606. mov r1, sp @ regs
  607. bl do_PrefetchAbort @ call abort handler
  608. UNWIND(.fnend )
  609. /* fall through */
  610. /*
  611. * This is the return code to user mode for abort handlers
  612. */
  613. ENTRY(ret_from_exception)
  614. UNWIND(.fnstart )
  615. UNWIND(.cantunwind )
  616. get_thread_info tsk
  617. mov why, #0
  618. b ret_to_user
  619. UNWIND(.fnend )
  620. ENDPROC(__pabt_usr)
  621. ENDPROC(ret_from_exception)
  622. /*
  623. * Register switch for ARMv3 and ARMv4 processors
  624. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  625. * previous and next are guaranteed not to be the same.
  626. */
  627. ENTRY(__switch_to)
  628. UNWIND(.fnstart )
  629. UNWIND(.cantunwind )
  630. add ip, r1, #TI_CPU_SAVE
  631. ldr r3, [r2, #TI_TP_VALUE]
  632. stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
  633. #ifdef CONFIG_MMU
  634. ldr r6, [r2, #TI_CPU_DOMAIN]
  635. #endif
  636. #if __LINUX_ARM_ARCH__ >= 6
  637. #ifdef CONFIG_CPU_32v6K
  638. clrex
  639. #else
  640. strex r5, r4, [ip] @ Clear exclusive monitor
  641. #endif
  642. #endif
  643. #if defined(CONFIG_HAS_TLS_REG)
  644. mcr p15, 0, r3, c13, c0, 3 @ set TLS register
  645. #elif !defined(CONFIG_TLS_REG_EMUL)
  646. mov r4, #0xffff0fff
  647. str r3, [r4, #-15] @ TLS val at 0xffff0ff0
  648. #endif
  649. #ifdef CONFIG_MMU
  650. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  651. #endif
  652. mov r5, r0
  653. add r4, r2, #TI_CPU_SAVE
  654. ldr r0, =thread_notify_head
  655. mov r1, #THREAD_NOTIFY_SWITCH
  656. bl atomic_notifier_call_chain
  657. mov r0, r5
  658. ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
  659. UNWIND(.fnend )
  660. ENDPROC(__switch_to)
  661. __INIT
  662. /*
  663. * User helpers.
  664. *
  665. * These are segment of kernel provided user code reachable from user space
  666. * at a fixed address in kernel memory. This is used to provide user space
  667. * with some operations which require kernel help because of unimplemented
  668. * native feature and/or instructions in many ARM CPUs. The idea is for
  669. * this code to be executed directly in user mode for best efficiency but
  670. * which is too intimate with the kernel counter part to be left to user
  671. * libraries. In fact this code might even differ from one CPU to another
  672. * depending on the available instruction set and restrictions like on
  673. * SMP systems. In other words, the kernel reserves the right to change
  674. * this code as needed without warning. Only the entry points and their
  675. * results are guaranteed to be stable.
  676. *
  677. * Each segment is 32-byte aligned and will be moved to the top of the high
  678. * vector page. New segments (if ever needed) must be added in front of
  679. * existing ones. This mechanism should be used only for things that are
  680. * really small and justified, and not be abused freely.
  681. *
  682. * User space is expected to implement those things inline when optimizing
  683. * for a processor that has the necessary native support, but only if such
  684. * resulting binaries are already to be incompatible with earlier ARM
  685. * processors due to the use of unsupported instructions other than what
  686. * is provided here. In other words don't make binaries unable to run on
  687. * earlier processors just for the sake of not using these kernel helpers
  688. * if your compiled code is not going to use the new instructions for other
  689. * purpose.
  690. */
  691. .macro usr_ret, reg
  692. #ifdef CONFIG_ARM_THUMB
  693. bx \reg
  694. #else
  695. mov pc, \reg
  696. #endif
  697. .endm
  698. .align 5
  699. .globl __kuser_helper_start
  700. __kuser_helper_start:
  701. /*
  702. * Reference prototype:
  703. *
  704. * void __kernel_memory_barrier(void)
  705. *
  706. * Input:
  707. *
  708. * lr = return address
  709. *
  710. * Output:
  711. *
  712. * none
  713. *
  714. * Clobbered:
  715. *
  716. * none
  717. *
  718. * Definition and user space usage example:
  719. *
  720. * typedef void (__kernel_dmb_t)(void);
  721. * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
  722. *
  723. * Apply any needed memory barrier to preserve consistency with data modified
  724. * manually and __kuser_cmpxchg usage.
  725. *
  726. * This could be used as follows:
  727. *
  728. * #define __kernel_dmb() \
  729. * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
  730. * : : : "r0", "lr","cc" )
  731. */
  732. __kuser_memory_barrier: @ 0xffff0fa0
  733. smp_dmb
  734. usr_ret lr
  735. .align 5
  736. /*
  737. * Reference prototype:
  738. *
  739. * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
  740. *
  741. * Input:
  742. *
  743. * r0 = oldval
  744. * r1 = newval
  745. * r2 = ptr
  746. * lr = return address
  747. *
  748. * Output:
  749. *
  750. * r0 = returned value (zero or non-zero)
  751. * C flag = set if r0 == 0, clear if r0 != 0
  752. *
  753. * Clobbered:
  754. *
  755. * r3, ip, flags
  756. *
  757. * Definition and user space usage example:
  758. *
  759. * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
  760. * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
  761. *
  762. * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
  763. * Return zero if *ptr was changed or non-zero if no exchange happened.
  764. * The C flag is also set if *ptr was changed to allow for assembly
  765. * optimization in the calling code.
  766. *
  767. * Notes:
  768. *
  769. * - This routine already includes memory barriers as needed.
  770. *
  771. * For example, a user space atomic_add implementation could look like this:
  772. *
  773. * #define atomic_add(ptr, val) \
  774. * ({ register unsigned int *__ptr asm("r2") = (ptr); \
  775. * register unsigned int __result asm("r1"); \
  776. * asm volatile ( \
  777. * "1: @ atomic_add\n\t" \
  778. * "ldr r0, [r2]\n\t" \
  779. * "mov r3, #0xffff0fff\n\t" \
  780. * "add lr, pc, #4\n\t" \
  781. * "add r1, r0, %2\n\t" \
  782. * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  783. * "bcc 1b" \
  784. * : "=&r" (__result) \
  785. * : "r" (__ptr), "rIL" (val) \
  786. * : "r0","r3","ip","lr","cc","memory" ); \
  787. * __result; })
  788. */
  789. __kuser_cmpxchg: @ 0xffff0fc0
  790. #if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  791. /*
  792. * Poor you. No fast solution possible...
  793. * The kernel itself must perform the operation.
  794. * A special ghost syscall is used for that (see traps.c).
  795. */
  796. stmfd sp!, {r7, lr}
  797. mov r7, #0xff00 @ 0xfff0 into r7 for EABI
  798. orr r7, r7, #0xf0
  799. swi #0x9ffff0
  800. ldmfd sp!, {r7, pc}
  801. #elif __LINUX_ARM_ARCH__ < 6
  802. #ifdef CONFIG_MMU
  803. /*
  804. * The only thing that can break atomicity in this cmpxchg
  805. * implementation is either an IRQ or a data abort exception
  806. * causing another process/thread to be scheduled in the middle
  807. * of the critical sequence. To prevent this, code is added to
  808. * the IRQ and data abort exception handlers to set the pc back
  809. * to the beginning of the critical section if it is found to be
  810. * within that critical section (see kuser_cmpxchg_fixup).
  811. */
  812. 1: ldr r3, [r2] @ load current val
  813. subs r3, r3, r0 @ compare with oldval
  814. 2: streq r1, [r2] @ store newval if eq
  815. rsbs r0, r3, #0 @ set return val and C flag
  816. usr_ret lr
  817. .text
  818. kuser_cmpxchg_fixup:
  819. @ Called from kuser_cmpxchg_check macro.
  820. @ r2 = address of interrupted insn (must be preserved).
  821. @ sp = saved regs. r7 and r8 are clobbered.
  822. @ 1b = first critical insn, 2b = last critical insn.
  823. @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
  824. mov r7, #0xffff0fff
  825. sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
  826. subs r8, r2, r7
  827. rsbcss r8, r8, #(2b - 1b)
  828. strcs r7, [sp, #S_PC]
  829. mov pc, lr
  830. .previous
  831. #else
  832. #warning "NPTL on non MMU needs fixing"
  833. mov r0, #-1
  834. adds r0, r0, #0
  835. usr_ret lr
  836. #endif
  837. #else
  838. #ifdef CONFIG_SMP
  839. mcr p15, 0, r0, c7, c10, 5 @ dmb
  840. #endif
  841. 1: ldrex r3, [r2]
  842. subs r3, r3, r0
  843. strexeq r3, r1, [r2]
  844. teqeq r3, #1
  845. beq 1b
  846. rsbs r0, r3, #0
  847. /* beware -- each __kuser slot must be 8 instructions max */
  848. #ifdef CONFIG_SMP
  849. b __kuser_memory_barrier
  850. #else
  851. usr_ret lr
  852. #endif
  853. #endif
  854. .align 5
  855. /*
  856. * Reference prototype:
  857. *
  858. * int __kernel_get_tls(void)
  859. *
  860. * Input:
  861. *
  862. * lr = return address
  863. *
  864. * Output:
  865. *
  866. * r0 = TLS value
  867. *
  868. * Clobbered:
  869. *
  870. * none
  871. *
  872. * Definition and user space usage example:
  873. *
  874. * typedef int (__kernel_get_tls_t)(void);
  875. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  876. *
  877. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  878. *
  879. * This could be used as follows:
  880. *
  881. * #define __kernel_get_tls() \
  882. * ({ register unsigned int __val asm("r0"); \
  883. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  884. * : "=r" (__val) : : "lr","cc" ); \
  885. * __val; })
  886. */
  887. __kuser_get_tls: @ 0xffff0fe0
  888. #if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
  889. ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
  890. #else
  891. mrc p15, 0, r0, c13, c0, 3 @ read TLS register
  892. #endif
  893. usr_ret lr
  894. .rep 5
  895. .word 0 @ pad up to __kuser_helper_version
  896. .endr
  897. /*
  898. * Reference declaration:
  899. *
  900. * extern unsigned int __kernel_helper_version;
  901. *
  902. * Definition and user space usage example:
  903. *
  904. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  905. *
  906. * User space may read this to determine the curent number of helpers
  907. * available.
  908. */
  909. __kuser_helper_version: @ 0xffff0ffc
  910. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  911. .globl __kuser_helper_end
  912. __kuser_helper_end:
  913. /*
  914. * Vector stubs.
  915. *
  916. * This code is copied to 0xffff0200 so we can use branches in the
  917. * vectors, rather than ldr's. Note that this code must not
  918. * exceed 0x300 bytes.
  919. *
  920. * Common stub entry macro:
  921. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  922. *
  923. * SP points to a minimal amount of processor-private memory, the address
  924. * of which is copied into r0 for the mode specific abort handler.
  925. */
  926. .macro vector_stub, name, mode, correction=0
  927. .align 5
  928. vector_\name:
  929. .if \correction
  930. sub lr, lr, #\correction
  931. .endif
  932. @
  933. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  934. @ (parent CPSR)
  935. @
  936. stmia sp, {r0, lr} @ save r0, lr
  937. mrs lr, spsr
  938. str lr, [sp, #8] @ save spsr
  939. @
  940. @ Prepare for SVC32 mode. IRQs remain disabled.
  941. @
  942. mrs r0, cpsr
  943. eor r0, r0, #(\mode ^ SVC_MODE)
  944. msr spsr_cxsf, r0
  945. @
  946. @ the branch table must immediately follow this code
  947. @
  948. and lr, lr, #0x0f
  949. mov r0, sp
  950. ldr lr, [pc, lr, lsl #2]
  951. movs pc, lr @ branch to handler in SVC mode
  952. ENDPROC(vector_\name)
  953. .endm
  954. .globl __stubs_start
  955. __stubs_start:
  956. /*
  957. * Interrupt dispatcher
  958. */
  959. vector_stub irq, IRQ_MODE, 4
  960. .long __irq_usr @ 0 (USR_26 / USR_32)
  961. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  962. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  963. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  964. .long __irq_invalid @ 4
  965. .long __irq_invalid @ 5
  966. .long __irq_invalid @ 6
  967. .long __irq_invalid @ 7
  968. .long __irq_invalid @ 8
  969. .long __irq_invalid @ 9
  970. .long __irq_invalid @ a
  971. .long __irq_invalid @ b
  972. .long __irq_invalid @ c
  973. .long __irq_invalid @ d
  974. .long __irq_invalid @ e
  975. .long __irq_invalid @ f
  976. /*
  977. * Data abort dispatcher
  978. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  979. */
  980. vector_stub dabt, ABT_MODE, 8
  981. .long __dabt_usr @ 0 (USR_26 / USR_32)
  982. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  983. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  984. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  985. .long __dabt_invalid @ 4
  986. .long __dabt_invalid @ 5
  987. .long __dabt_invalid @ 6
  988. .long __dabt_invalid @ 7
  989. .long __dabt_invalid @ 8
  990. .long __dabt_invalid @ 9
  991. .long __dabt_invalid @ a
  992. .long __dabt_invalid @ b
  993. .long __dabt_invalid @ c
  994. .long __dabt_invalid @ d
  995. .long __dabt_invalid @ e
  996. .long __dabt_invalid @ f
  997. /*
  998. * Prefetch abort dispatcher
  999. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  1000. */
  1001. vector_stub pabt, ABT_MODE, 4
  1002. .long __pabt_usr @ 0 (USR_26 / USR_32)
  1003. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  1004. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  1005. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  1006. .long __pabt_invalid @ 4
  1007. .long __pabt_invalid @ 5
  1008. .long __pabt_invalid @ 6
  1009. .long __pabt_invalid @ 7
  1010. .long __pabt_invalid @ 8
  1011. .long __pabt_invalid @ 9
  1012. .long __pabt_invalid @ a
  1013. .long __pabt_invalid @ b
  1014. .long __pabt_invalid @ c
  1015. .long __pabt_invalid @ d
  1016. .long __pabt_invalid @ e
  1017. .long __pabt_invalid @ f
  1018. /*
  1019. * Undef instr entry dispatcher
  1020. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  1021. */
  1022. vector_stub und, UND_MODE
  1023. .long __und_usr @ 0 (USR_26 / USR_32)
  1024. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  1025. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  1026. .long __und_svc @ 3 (SVC_26 / SVC_32)
  1027. .long __und_invalid @ 4
  1028. .long __und_invalid @ 5
  1029. .long __und_invalid @ 6
  1030. .long __und_invalid @ 7
  1031. .long __und_invalid @ 8
  1032. .long __und_invalid @ 9
  1033. .long __und_invalid @ a
  1034. .long __und_invalid @ b
  1035. .long __und_invalid @ c
  1036. .long __und_invalid @ d
  1037. .long __und_invalid @ e
  1038. .long __und_invalid @ f
  1039. .align 5
  1040. /*=============================================================================
  1041. * Undefined FIQs
  1042. *-----------------------------------------------------------------------------
  1043. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  1044. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  1045. * Basically to switch modes, we *HAVE* to clobber one register... brain
  1046. * damage alert! I don't think that we can execute any code in here in any
  1047. * other mode than FIQ... Ok you can switch to another mode, but you can't
  1048. * get out of that mode without clobbering one register.
  1049. */
  1050. vector_fiq:
  1051. disable_fiq
  1052. subs pc, lr, #4
  1053. /*=============================================================================
  1054. * Address exception handler
  1055. *-----------------------------------------------------------------------------
  1056. * These aren't too critical.
  1057. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  1058. */
  1059. vector_addrexcptn:
  1060. b vector_addrexcptn
  1061. /*
  1062. * We group all the following data together to optimise
  1063. * for CPUs with separate I & D caches.
  1064. */
  1065. .align 5
  1066. .LCvswi:
  1067. .word vector_swi
  1068. .globl __stubs_end
  1069. __stubs_end:
  1070. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  1071. .globl __vectors_start
  1072. __vectors_start:
  1073. swi SYS_ERROR0
  1074. b vector_und + stubs_offset
  1075. ldr pc, .LCvswi + stubs_offset
  1076. b vector_pabt + stubs_offset
  1077. b vector_dabt + stubs_offset
  1078. b vector_addrexcptn + stubs_offset
  1079. b vector_irq + stubs_offset
  1080. b vector_fiq + stubs_offset
  1081. .globl __vectors_end
  1082. __vectors_end:
  1083. .data
  1084. .globl cr_alignment
  1085. .globl cr_no_alignment
  1086. cr_alignment:
  1087. .space 4
  1088. cr_no_alignment:
  1089. .space 4