entry-armv.S 28 KB

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