entry-armv.S 28 KB

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