entry-armv.S 29 KB

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