entry-armv.S 29 KB

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