entry-armv.S 26 KB

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