entry-armv.S 26 KB

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