entry-armv.S 29 KB

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