entry-armv.S 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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 <asm/unistd.h>
  24. #include <asm/tls.h>
  25. #include "entry-header.S"
  26. /*
  27. * Interrupt handling. Preserves r7, r8, r9
  28. */
  29. .macro irq_handler
  30. get_irqnr_preamble r5, lr
  31. 1: get_irqnr_and_base r0, r6, r5, lr
  32. movne r1, sp
  33. @
  34. @ routine called with r0 = irq number, r1 = struct pt_regs *
  35. @
  36. adrne lr, BSYM(1b)
  37. bne asm_do_IRQ
  38. #ifdef CONFIG_SMP
  39. /*
  40. * XXX
  41. *
  42. * this macro assumes that irqstat (r6) and base (r5) are
  43. * preserved from get_irqnr_and_base above
  44. */
  45. test_for_ipi r0, r6, r5, lr
  46. movne r0, sp
  47. adrne lr, BSYM(1b)
  48. bne do_IPI
  49. #ifdef CONFIG_LOCAL_TIMERS
  50. test_for_ltirq r0, r6, r5, lr
  51. movne r0, sp
  52. adrne lr, BSYM(1b)
  53. bne do_local_timer
  54. #endif
  55. #endif
  56. .endm
  57. #ifdef CONFIG_KPROBES
  58. .section .kprobes.text,"ax",%progbits
  59. #else
  60. .text
  61. #endif
  62. /*
  63. * Invalid mode handlers
  64. */
  65. .macro inv_entry, reason
  66. sub sp, sp, #S_FRAME_SIZE
  67. ARM( stmib sp, {r1 - lr} )
  68. THUMB( stmia sp, {r0 - r12} )
  69. THUMB( str sp, [sp, #S_SP] )
  70. THUMB( str lr, [sp, #S_LR] )
  71. mov r1, #\reason
  72. .endm
  73. __pabt_invalid:
  74. inv_entry BAD_PREFETCH
  75. b common_invalid
  76. ENDPROC(__pabt_invalid)
  77. __dabt_invalid:
  78. inv_entry BAD_DATA
  79. b common_invalid
  80. ENDPROC(__dabt_invalid)
  81. __irq_invalid:
  82. inv_entry BAD_IRQ
  83. b common_invalid
  84. ENDPROC(__irq_invalid)
  85. __und_invalid:
  86. inv_entry BAD_UNDEFINSTR
  87. @
  88. @ XXX fall through to common_invalid
  89. @
  90. @
  91. @ common_invalid - generic code for failed exception (re-entrant version of handlers)
  92. @
  93. common_invalid:
  94. zero_fp
  95. ldmia r0, {r4 - r6}
  96. add r0, sp, #S_PC @ here for interlock avoidance
  97. mov r7, #-1 @ "" "" "" ""
  98. str r4, [sp] @ save preserved r0
  99. stmia r0, {r5 - r7} @ lr_<exception>,
  100. @ cpsr_<exception>, "old_r0"
  101. mov r0, sp
  102. b bad_mode
  103. ENDPROC(__und_invalid)
  104. /*
  105. * SVC mode handlers
  106. */
  107. #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
  108. #define SPFIX(code...) code
  109. #else
  110. #define SPFIX(code...)
  111. #endif
  112. .macro svc_entry, stack_hole=0
  113. UNWIND(.fnstart )
  114. UNWIND(.save {r0 - pc} )
  115. sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
  116. #ifdef CONFIG_THUMB2_KERNEL
  117. SPFIX( str r0, [sp] ) @ temporarily saved
  118. SPFIX( mov r0, sp )
  119. SPFIX( tst r0, #4 ) @ test original stack alignment
  120. SPFIX( ldr r0, [sp] ) @ restored
  121. #else
  122. SPFIX( tst sp, #4 )
  123. #endif
  124. SPFIX( subeq sp, sp, #4 )
  125. stmia sp, {r1 - r12}
  126. ldmia r0, {r1 - r3}
  127. add r5, sp, #S_SP - 4 @ here for interlock avoidance
  128. mov r4, #-1 @ "" "" "" ""
  129. add r0, sp, #(S_FRAME_SIZE + \stack_hole - 4)
  130. SPFIX( addeq r0, r0, #4 )
  131. str r1, [sp, #-4]! @ save the "real" r0 copied
  132. @ from the exception stack
  133. mov r1, lr
  134. @
  135. @ We are now ready to fill in the remaining blanks on the stack:
  136. @
  137. @ r0 - sp_svc
  138. @ r1 - lr_svc
  139. @ r2 - lr_<exception>, already fixed up for correct return/restart
  140. @ r3 - spsr_<exception>
  141. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  142. @
  143. stmia r5, {r0 - r4}
  144. .endm
  145. .align 5
  146. __dabt_svc:
  147. svc_entry
  148. @
  149. @ get ready to re-enable interrupts if appropriate
  150. @
  151. mrs r9, cpsr
  152. tst r3, #PSR_I_BIT
  153. biceq r9, r9, #PSR_I_BIT
  154. @
  155. @ Call the processor-specific abort handler:
  156. @
  157. @ r2 - aborted context pc
  158. @ r3 - aborted context cpsr
  159. @
  160. @ The abort handler must return the aborted address in r0, and
  161. @ the fault status register in r1. r9 must be preserved.
  162. @
  163. #ifdef MULTI_DABORT
  164. ldr r4, .LCprocfns
  165. mov lr, pc
  166. ldr pc, [r4, #PROCESSOR_DABT_FUNC]
  167. #else
  168. bl CPU_DABORT_HANDLER
  169. #endif
  170. @
  171. @ set desired IRQ state, then call main handler
  172. @
  173. msr cpsr_c, r9
  174. mov r2, sp
  175. bl do_DataAbort
  176. @
  177. @ IRQs off again before pulling preserved data off the stack
  178. @
  179. disable_irq_notrace
  180. @
  181. @ restore SPSR and restart the instruction
  182. @
  183. ldr r2, [sp, #S_PSR]
  184. svc_exit r2 @ return from exception
  185. UNWIND(.fnend )
  186. ENDPROC(__dabt_svc)
  187. .align 5
  188. __irq_svc:
  189. svc_entry
  190. #ifdef CONFIG_TRACE_IRQFLAGS
  191. bl trace_hardirqs_off
  192. #endif
  193. #ifdef CONFIG_PREEMPT
  194. get_thread_info tsk
  195. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  196. add r7, r8, #1 @ increment it
  197. str r7, [tsk, #TI_PREEMPT]
  198. #endif
  199. irq_handler
  200. #ifdef CONFIG_PREEMPT
  201. str r8, [tsk, #TI_PREEMPT] @ restore preempt count
  202. ldr r0, [tsk, #TI_FLAGS] @ get flags
  203. teq r8, #0 @ if preempt count != 0
  204. movne r0, #0 @ force flags to 0
  205. tst r0, #_TIF_NEED_RESCHED
  206. blne svc_preempt
  207. #endif
  208. ldr r4, [sp, #S_PSR] @ irqs are already disabled
  209. #ifdef CONFIG_TRACE_IRQFLAGS
  210. tst r4, #PSR_I_BIT
  211. bleq trace_hardirqs_on
  212. #endif
  213. svc_exit r4 @ return from exception
  214. UNWIND(.fnend )
  215. ENDPROC(__irq_svc)
  216. .ltorg
  217. #ifdef CONFIG_PREEMPT
  218. svc_preempt:
  219. mov r8, lr
  220. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  221. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  222. tst r0, #_TIF_NEED_RESCHED
  223. moveq pc, r8 @ go again
  224. b 1b
  225. #endif
  226. .align 5
  227. __und_svc:
  228. #ifdef CONFIG_KPROBES
  229. @ If a kprobe is about to simulate a "stmdb sp..." instruction,
  230. @ it obviously needs free stack space which then will belong to
  231. @ the saved context.
  232. svc_entry 64
  233. #else
  234. svc_entry
  235. #endif
  236. @
  237. @ call emulation code, which returns using r9 if it has emulated
  238. @ the instruction, or the more conventional lr if we are to treat
  239. @ this as a real undefined instruction
  240. @
  241. @ r0 - instruction
  242. @
  243. #ifndef CONFIG_THUMB2_KERNEL
  244. ldr r0, [r2, #-4]
  245. #else
  246. ldrh r0, [r2, #-2] @ Thumb instruction at LR - 2
  247. and r9, r0, #0xf800
  248. cmp r9, #0xe800 @ 32-bit instruction if xx >= 0
  249. ldrhhs r9, [r2] @ bottom 16 bits
  250. orrhs r0, r9, r0, lsl #16
  251. #endif
  252. adr r9, BSYM(1f)
  253. bl call_fpe
  254. mov r0, sp @ struct pt_regs *regs
  255. bl do_undefinstr
  256. @
  257. @ IRQs off again before pulling preserved data off the stack
  258. @
  259. 1: disable_irq_notrace
  260. @
  261. @ restore SPSR and restart the instruction
  262. @
  263. ldr r2, [sp, #S_PSR] @ Get SVC cpsr
  264. svc_exit r2 @ return from exception
  265. UNWIND(.fnend )
  266. ENDPROC(__und_svc)
  267. .align 5
  268. __pabt_svc:
  269. svc_entry
  270. @
  271. @ re-enable interrupts if appropriate
  272. @
  273. mrs r9, cpsr
  274. tst r3, #PSR_I_BIT
  275. biceq r9, r9, #PSR_I_BIT
  276. mov r0, r2 @ pass address of aborted instruction.
  277. #ifdef MULTI_PABORT
  278. ldr r4, .LCprocfns
  279. mov lr, pc
  280. ldr pc, [r4, #PROCESSOR_PABT_FUNC]
  281. #else
  282. bl CPU_PABORT_HANDLER
  283. #endif
  284. msr cpsr_c, r9 @ Maybe enable interrupts
  285. mov r2, sp @ regs
  286. bl do_PrefetchAbort @ call abort handler
  287. @
  288. @ IRQs off again before pulling preserved data off the stack
  289. @
  290. disable_irq_notrace
  291. @
  292. @ restore SPSR and restart the instruction
  293. @
  294. ldr r2, [sp, #S_PSR]
  295. svc_exit r2 @ return from exception
  296. UNWIND(.fnend )
  297. ENDPROC(__pabt_svc)
  298. .align 5
  299. .LCcralign:
  300. .word cr_alignment
  301. #ifdef MULTI_DABORT
  302. .LCprocfns:
  303. .word processor
  304. #endif
  305. .LCfp:
  306. .word fp_enter
  307. /*
  308. * User mode handlers
  309. *
  310. * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
  311. */
  312. #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
  313. #error "sizeof(struct pt_regs) must be a multiple of 8"
  314. #endif
  315. .macro usr_entry
  316. UNWIND(.fnstart )
  317. UNWIND(.cantunwind ) @ don't unwind the user space
  318. sub sp, sp, #S_FRAME_SIZE
  319. ARM( stmib sp, {r1 - r12} )
  320. THUMB( stmia sp, {r0 - r12} )
  321. ldmia r0, {r1 - r3}
  322. add r0, sp, #S_PC @ here for interlock avoidance
  323. mov r4, #-1 @ "" "" "" ""
  324. str r1, [sp] @ save the "real" r0 copied
  325. @ from the exception stack
  326. @
  327. @ We are now ready to fill in the remaining blanks on the stack:
  328. @
  329. @ r2 - lr_<exception>, already fixed up for correct return/restart
  330. @ r3 - spsr_<exception>
  331. @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
  332. @
  333. @ Also, separately save sp_usr and lr_usr
  334. @
  335. stmia r0, {r2 - r4}
  336. ARM( stmdb r0, {sp, lr}^ )
  337. THUMB( store_user_sp_lr r0, r1, S_SP - S_PC )
  338. @
  339. @ Enable the alignment trap while in kernel mode
  340. @
  341. alignment_trap r0
  342. @
  343. @ Clear FP to mark the first stack frame
  344. @
  345. zero_fp
  346. .endm
  347. .macro kuser_cmpxchg_check
  348. #if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
  349. #ifndef CONFIG_MMU
  350. #warning "NPTL on non MMU needs fixing"
  351. #else
  352. @ Make sure our user space atomic helper is restarted
  353. @ if it was interrupted in a critical region. Here we
  354. @ perform a quick test inline since it should be false
  355. @ 99.9999% of the time. The rest is done out of line.
  356. cmp r2, #TASK_SIZE
  357. blhs kuser_cmpxchg_fixup
  358. #endif
  359. #endif
  360. .endm
  361. .align 5
  362. __dabt_usr:
  363. usr_entry
  364. kuser_cmpxchg_check
  365. @
  366. @ Call the processor-specific abort handler:
  367. @
  368. @ r2 - aborted context pc
  369. @ r3 - aborted context cpsr
  370. @
  371. @ The abort handler must return the aborted address in r0, and
  372. @ the fault status register in r1.
  373. @
  374. #ifdef MULTI_DABORT
  375. ldr r4, .LCprocfns
  376. mov lr, pc
  377. ldr pc, [r4, #PROCESSOR_DABT_FUNC]
  378. #else
  379. bl CPU_DABORT_HANDLER
  380. #endif
  381. @
  382. @ IRQs on, then call the main handler
  383. @
  384. enable_irq
  385. mov r2, sp
  386. adr lr, BSYM(ret_from_exception)
  387. b do_DataAbort
  388. UNWIND(.fnend )
  389. ENDPROC(__dabt_usr)
  390. .align 5
  391. __irq_usr:
  392. usr_entry
  393. kuser_cmpxchg_check
  394. get_thread_info tsk
  395. #ifdef CONFIG_PREEMPT
  396. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  397. add r7, r8, #1 @ increment it
  398. str r7, [tsk, #TI_PREEMPT]
  399. #endif
  400. irq_handler
  401. #ifdef CONFIG_PREEMPT
  402. ldr r0, [tsk, #TI_PREEMPT]
  403. str r8, [tsk, #TI_PREEMPT]
  404. teq r0, r7
  405. ARM( strne r0, [r0, -r0] )
  406. THUMB( movne r0, #0 )
  407. THUMB( strne r0, [r0] )
  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. .pushsection .fixup, "ax"
  459. 4: mov pc, r9
  460. .popsection
  461. .pushsection __ex_table,"a"
  462. .long 1b, 4b
  463. #if __LINUX_ARM_ARCH__ >= 7
  464. .long 2b, 4b
  465. .long 3b, 4b
  466. #endif
  467. .popsection
  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. .pushsection .data
  600. ENTRY(fp_enter)
  601. .word no_fp
  602. .popsection
  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. set_tls r3, r4, r5
  658. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  659. ldr r7, [r2, #TI_TASK]
  660. ldr r8, =__stack_chk_guard
  661. ldr r7, [r7, #TSK_STACK_CANARY]
  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. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  672. str r7, [r8]
  673. #endif
  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. ldr r7, =1f @ it's 20 bits
  820. swi __ARM_NR_cmpxchg
  821. ldmfd sp!, {r7, pc}
  822. 1: .word __ARM_NR_cmpxchg
  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. smp_dmb
  861. 1: ldrex r3, [r2]
  862. subs r3, r3, r0
  863. strexeq r3, r1, [r2]
  864. teqeq r3, #1
  865. beq 1b
  866. rsbs r0, r3, #0
  867. /* beware -- each __kuser slot must be 8 instructions max */
  868. #ifdef CONFIG_SMP
  869. b __kuser_memory_barrier
  870. #else
  871. usr_ret lr
  872. #endif
  873. #endif
  874. .align 5
  875. /*
  876. * Reference prototype:
  877. *
  878. * int __kernel_get_tls(void)
  879. *
  880. * Input:
  881. *
  882. * lr = return address
  883. *
  884. * Output:
  885. *
  886. * r0 = TLS value
  887. *
  888. * Clobbered:
  889. *
  890. * none
  891. *
  892. * Definition and user space usage example:
  893. *
  894. * typedef int (__kernel_get_tls_t)(void);
  895. * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
  896. *
  897. * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
  898. *
  899. * This could be used as follows:
  900. *
  901. * #define __kernel_get_tls() \
  902. * ({ register unsigned int __val asm("r0"); \
  903. * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
  904. * : "=r" (__val) : : "lr","cc" ); \
  905. * __val; })
  906. */
  907. __kuser_get_tls: @ 0xffff0fe0
  908. ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init
  909. usr_ret lr
  910. mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code
  911. .rep 4
  912. .word 0 @ 0xffff0ff0 software TLS value, then
  913. .endr @ pad up to __kuser_helper_version
  914. /*
  915. * Reference declaration:
  916. *
  917. * extern unsigned int __kernel_helper_version;
  918. *
  919. * Definition and user space usage example:
  920. *
  921. * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
  922. *
  923. * User space may read this to determine the curent number of helpers
  924. * available.
  925. */
  926. __kuser_helper_version: @ 0xffff0ffc
  927. .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
  928. .globl __kuser_helper_end
  929. __kuser_helper_end:
  930. THUMB( .thumb )
  931. /*
  932. * Vector stubs.
  933. *
  934. * This code is copied to 0xffff0200 so we can use branches in the
  935. * vectors, rather than ldr's. Note that this code must not
  936. * exceed 0x300 bytes.
  937. *
  938. * Common stub entry macro:
  939. * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  940. *
  941. * SP points to a minimal amount of processor-private memory, the address
  942. * of which is copied into r0 for the mode specific abort handler.
  943. */
  944. .macro vector_stub, name, mode, correction=0
  945. .align 5
  946. vector_\name:
  947. .if \correction
  948. sub lr, lr, #\correction
  949. .endif
  950. @
  951. @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
  952. @ (parent CPSR)
  953. @
  954. stmia sp, {r0, lr} @ save r0, lr
  955. mrs lr, spsr
  956. str lr, [sp, #8] @ save spsr
  957. @
  958. @ Prepare for SVC32 mode. IRQs remain disabled.
  959. @
  960. mrs r0, cpsr
  961. eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
  962. msr spsr_cxsf, r0
  963. @
  964. @ the branch table must immediately follow this code
  965. @
  966. and lr, lr, #0x0f
  967. THUMB( adr r0, 1f )
  968. THUMB( ldr lr, [r0, lr, lsl #2] )
  969. mov r0, sp
  970. ARM( ldr lr, [pc, lr, lsl #2] )
  971. movs pc, lr @ branch to handler in SVC mode
  972. ENDPROC(vector_\name)
  973. .align 2
  974. @ handler addresses follow this label
  975. 1:
  976. .endm
  977. .globl __stubs_start
  978. __stubs_start:
  979. /*
  980. * Interrupt dispatcher
  981. */
  982. vector_stub irq, IRQ_MODE, 4
  983. .long __irq_usr @ 0 (USR_26 / USR_32)
  984. .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
  985. .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
  986. .long __irq_svc @ 3 (SVC_26 / SVC_32)
  987. .long __irq_invalid @ 4
  988. .long __irq_invalid @ 5
  989. .long __irq_invalid @ 6
  990. .long __irq_invalid @ 7
  991. .long __irq_invalid @ 8
  992. .long __irq_invalid @ 9
  993. .long __irq_invalid @ a
  994. .long __irq_invalid @ b
  995. .long __irq_invalid @ c
  996. .long __irq_invalid @ d
  997. .long __irq_invalid @ e
  998. .long __irq_invalid @ f
  999. /*
  1000. * Data abort dispatcher
  1001. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  1002. */
  1003. vector_stub dabt, ABT_MODE, 8
  1004. .long __dabt_usr @ 0 (USR_26 / USR_32)
  1005. .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
  1006. .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
  1007. .long __dabt_svc @ 3 (SVC_26 / SVC_32)
  1008. .long __dabt_invalid @ 4
  1009. .long __dabt_invalid @ 5
  1010. .long __dabt_invalid @ 6
  1011. .long __dabt_invalid @ 7
  1012. .long __dabt_invalid @ 8
  1013. .long __dabt_invalid @ 9
  1014. .long __dabt_invalid @ a
  1015. .long __dabt_invalid @ b
  1016. .long __dabt_invalid @ c
  1017. .long __dabt_invalid @ d
  1018. .long __dabt_invalid @ e
  1019. .long __dabt_invalid @ f
  1020. /*
  1021. * Prefetch abort dispatcher
  1022. * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
  1023. */
  1024. vector_stub pabt, ABT_MODE, 4
  1025. .long __pabt_usr @ 0 (USR_26 / USR_32)
  1026. .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
  1027. .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
  1028. .long __pabt_svc @ 3 (SVC_26 / SVC_32)
  1029. .long __pabt_invalid @ 4
  1030. .long __pabt_invalid @ 5
  1031. .long __pabt_invalid @ 6
  1032. .long __pabt_invalid @ 7
  1033. .long __pabt_invalid @ 8
  1034. .long __pabt_invalid @ 9
  1035. .long __pabt_invalid @ a
  1036. .long __pabt_invalid @ b
  1037. .long __pabt_invalid @ c
  1038. .long __pabt_invalid @ d
  1039. .long __pabt_invalid @ e
  1040. .long __pabt_invalid @ f
  1041. /*
  1042. * Undef instr entry dispatcher
  1043. * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
  1044. */
  1045. vector_stub und, UND_MODE
  1046. .long __und_usr @ 0 (USR_26 / USR_32)
  1047. .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
  1048. .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
  1049. .long __und_svc @ 3 (SVC_26 / SVC_32)
  1050. .long __und_invalid @ 4
  1051. .long __und_invalid @ 5
  1052. .long __und_invalid @ 6
  1053. .long __und_invalid @ 7
  1054. .long __und_invalid @ 8
  1055. .long __und_invalid @ 9
  1056. .long __und_invalid @ a
  1057. .long __und_invalid @ b
  1058. .long __und_invalid @ c
  1059. .long __und_invalid @ d
  1060. .long __und_invalid @ e
  1061. .long __und_invalid @ f
  1062. .align 5
  1063. /*=============================================================================
  1064. * Undefined FIQs
  1065. *-----------------------------------------------------------------------------
  1066. * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
  1067. * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
  1068. * Basically to switch modes, we *HAVE* to clobber one register... brain
  1069. * damage alert! I don't think that we can execute any code in here in any
  1070. * other mode than FIQ... Ok you can switch to another mode, but you can't
  1071. * get out of that mode without clobbering one register.
  1072. */
  1073. vector_fiq:
  1074. disable_fiq
  1075. subs pc, lr, #4
  1076. /*=============================================================================
  1077. * Address exception handler
  1078. *-----------------------------------------------------------------------------
  1079. * These aren't too critical.
  1080. * (they're not supposed to happen, and won't happen in 32-bit data mode).
  1081. */
  1082. vector_addrexcptn:
  1083. b vector_addrexcptn
  1084. /*
  1085. * We group all the following data together to optimise
  1086. * for CPUs with separate I & D caches.
  1087. */
  1088. .align 5
  1089. .LCvswi:
  1090. .word vector_swi
  1091. .globl __stubs_end
  1092. __stubs_end:
  1093. .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
  1094. .globl __vectors_start
  1095. __vectors_start:
  1096. ARM( swi SYS_ERROR0 )
  1097. THUMB( svc #0 )
  1098. THUMB( nop )
  1099. W(b) vector_und + stubs_offset
  1100. W(ldr) pc, .LCvswi + stubs_offset
  1101. W(b) vector_pabt + stubs_offset
  1102. W(b) vector_dabt + stubs_offset
  1103. W(b) vector_addrexcptn + stubs_offset
  1104. W(b) vector_irq + stubs_offset
  1105. W(b) vector_fiq + stubs_offset
  1106. .globl __vectors_end
  1107. __vectors_end:
  1108. .data
  1109. .globl cr_alignment
  1110. .globl cr_no_alignment
  1111. cr_alignment:
  1112. .space 4
  1113. cr_no_alignment:
  1114. .space 4