entry-armv.S 28 KB

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