entry-armv.S 28 KB

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