entry-armv.S 29 KB

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