entry-armv.S 28 KB

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