entry-armv.S 29 KB

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