entry-armv.S 29 KB

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