entry_64.S 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  6. * Adapted for Power Macintosh by Paul Mackerras.
  7. * Low-level exception handlers and MMU support
  8. * rewritten by Paul Mackerras.
  9. * Copyright (C) 1996 Paul Mackerras.
  10. * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
  11. *
  12. * This file contains the system call entry code, context switch
  13. * code, and exception/interrupt return code for PowerPC.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/errno.h>
  21. #include <linux/err.h>
  22. #include <asm/unistd.h>
  23. #include <asm/processor.h>
  24. #include <asm/page.h>
  25. #include <asm/mmu.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/code-patching-asm.h>
  28. #include <asm/ppc_asm.h>
  29. #include <asm/asm-offsets.h>
  30. #include <asm/cputable.h>
  31. #include <asm/firmware.h>
  32. #include <asm/bug.h>
  33. #include <asm/ptrace.h>
  34. #include <asm/irqflags.h>
  35. #include <asm/hw_irq.h>
  36. #include <asm/context_tracking.h>
  37. #include <asm/tm.h>
  38. #include <asm/ppc-opcode.h>
  39. #include <asm/barrier.h>
  40. #include <asm/export.h>
  41. #include <asm/asm-compat.h>
  42. #ifdef CONFIG_PPC_BOOK3S
  43. #include <asm/exception-64s.h>
  44. #else
  45. #include <asm/exception-64e.h>
  46. #endif
  47. #include <asm/feature-fixups.h>
  48. /*
  49. * System calls.
  50. */
  51. .section ".toc","aw"
  52. SYS_CALL_TABLE:
  53. .tc sys_call_table[TC],sys_call_table
  54. /* This value is used to mark exception frames on the stack. */
  55. exception_marker:
  56. .tc ID_EXC_MARKER[TC],STACK_FRAME_REGS_MARKER
  57. .section ".text"
  58. .align 7
  59. .globl system_call_common
  60. system_call_common:
  61. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  62. BEGIN_FTR_SECTION
  63. extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */
  64. bne .Ltabort_syscall
  65. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  66. #endif
  67. andi. r10,r12,MSR_PR
  68. mr r10,r1
  69. addi r1,r1,-INT_FRAME_SIZE
  70. beq- 1f
  71. ld r1,PACAKSAVE(r13)
  72. 1: std r10,0(r1)
  73. std r11,_NIP(r1)
  74. std r12,_MSR(r1)
  75. std r0,GPR0(r1)
  76. std r10,GPR1(r1)
  77. beq 2f /* if from kernel mode */
  78. #ifdef CONFIG_PPC_FSL_BOOK3E
  79. START_BTB_FLUSH_SECTION
  80. BTB_FLUSH(r10)
  81. END_BTB_FLUSH_SECTION
  82. #endif
  83. ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
  84. 2: std r2,GPR2(r1)
  85. std r3,GPR3(r1)
  86. mfcr r2
  87. std r4,GPR4(r1)
  88. std r5,GPR5(r1)
  89. std r6,GPR6(r1)
  90. std r7,GPR7(r1)
  91. std r8,GPR8(r1)
  92. li r11,0
  93. std r11,GPR9(r1)
  94. std r11,GPR10(r1)
  95. std r11,GPR11(r1)
  96. std r11,GPR12(r1)
  97. std r11,_XER(r1)
  98. std r11,_CTR(r1)
  99. std r9,GPR13(r1)
  100. mflr r10
  101. /*
  102. * This clears CR0.SO (bit 28), which is the error indication on
  103. * return from this system call.
  104. */
  105. rldimi r2,r11,28,(63-28)
  106. li r11,0xc01
  107. std r10,_LINK(r1)
  108. std r11,_TRAP(r1)
  109. std r3,ORIG_GPR3(r1)
  110. std r2,_CCR(r1)
  111. ld r2,PACATOC(r13)
  112. addi r9,r1,STACK_FRAME_OVERHEAD
  113. ld r11,exception_marker@toc(r2)
  114. std r11,-16(r9) /* "regshere" marker */
  115. #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
  116. BEGIN_FW_FTR_SECTION
  117. beq 33f
  118. /* if from user, see if there are any DTL entries to process */
  119. ld r10,PACALPPACAPTR(r13) /* get ptr to VPA */
  120. ld r11,PACA_DTL_RIDX(r13) /* get log read index */
  121. addi r10,r10,LPPACA_DTLIDX
  122. LDX_BE r10,0,r10 /* get log write index */
  123. cmpd cr1,r11,r10
  124. beq+ cr1,33f
  125. bl accumulate_stolen_time
  126. REST_GPR(0,r1)
  127. REST_4GPRS(3,r1)
  128. REST_2GPRS(7,r1)
  129. addi r9,r1,STACK_FRAME_OVERHEAD
  130. 33:
  131. END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
  132. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE && CONFIG_PPC_SPLPAR */
  133. /*
  134. * A syscall should always be called with interrupts enabled
  135. * so we just unconditionally hard-enable here. When some kind
  136. * of irq tracing is used, we additionally check that condition
  137. * is correct
  138. */
  139. #if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && defined(CONFIG_BUG)
  140. lbz r10,PACAIRQSOFTMASK(r13)
  141. 1: tdnei r10,IRQS_ENABLED
  142. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  143. #endif
  144. #ifdef CONFIG_PPC_BOOK3E
  145. wrteei 1
  146. #else
  147. li r11,MSR_RI
  148. ori r11,r11,MSR_EE
  149. mtmsrd r11,1
  150. #endif /* CONFIG_PPC_BOOK3E */
  151. system_call: /* label this so stack traces look sane */
  152. /* We do need to set SOFTE in the stack frame or the return
  153. * from interrupt will be painful
  154. */
  155. li r10,IRQS_ENABLED
  156. std r10,SOFTE(r1)
  157. CURRENT_THREAD_INFO(r11, r1)
  158. ld r10,TI_FLAGS(r11)
  159. andi. r11,r10,_TIF_SYSCALL_DOTRACE
  160. bne .Lsyscall_dotrace /* does not return */
  161. cmpldi 0,r0,NR_syscalls
  162. bge- .Lsyscall_enosys
  163. .Lsyscall:
  164. /*
  165. * Need to vector to 32 Bit or default sys_call_table here,
  166. * based on caller's run-mode / personality.
  167. */
  168. ld r11,SYS_CALL_TABLE@toc(2)
  169. andi. r10,r10,_TIF_32BIT
  170. beq 15f
  171. addi r11,r11,8 /* use 32-bit syscall entries */
  172. clrldi r3,r3,32
  173. clrldi r4,r4,32
  174. clrldi r5,r5,32
  175. clrldi r6,r6,32
  176. clrldi r7,r7,32
  177. clrldi r8,r8,32
  178. 15:
  179. slwi r0,r0,4
  180. barrier_nospec_asm
  181. /*
  182. * Prevent the load of the handler below (based on the user-passed
  183. * system call number) being speculatively executed until the test
  184. * against NR_syscalls and branch to .Lsyscall_enosys above has
  185. * committed.
  186. */
  187. ldx r12,r11,r0 /* Fetch system call handler [ptr] */
  188. mtctr r12
  189. bctrl /* Call handler */
  190. .Lsyscall_exit:
  191. std r3,RESULT(r1)
  192. #ifdef CONFIG_DEBUG_RSEQ
  193. /* Check whether the syscall is issued inside a restartable sequence */
  194. addi r3,r1,STACK_FRAME_OVERHEAD
  195. bl rseq_syscall
  196. ld r3,RESULT(r1)
  197. #endif
  198. CURRENT_THREAD_INFO(r12, r1)
  199. ld r8,_MSR(r1)
  200. #ifdef CONFIG_PPC_BOOK3S
  201. /* No MSR:RI on BookE */
  202. andi. r10,r8,MSR_RI
  203. beq- .Lunrecov_restore
  204. #endif
  205. /*
  206. * This is a few instructions into the actual syscall exit path (which actually
  207. * starts at .Lsyscall_exit) to cater to kprobe blacklisting and to reduce the
  208. * number of visible symbols for profiling purposes.
  209. *
  210. * We can probe from system_call until this point as MSR_RI is set. But once it
  211. * is cleared below, we won't be able to take a trap.
  212. *
  213. * This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL().
  214. */
  215. system_call_exit:
  216. /*
  217. * Disable interrupts so current_thread_info()->flags can't change,
  218. * and so that we don't get interrupted after loading SRR0/1.
  219. */
  220. #ifdef CONFIG_PPC_BOOK3E
  221. wrteei 0
  222. #else
  223. /*
  224. * For performance reasons we clear RI the same time that we
  225. * clear EE. We only need to clear RI just before we restore r13
  226. * below, but batching it with EE saves us one expensive mtmsrd call.
  227. * We have to be careful to restore RI if we branch anywhere from
  228. * here (eg syscall_exit_work).
  229. */
  230. li r11,0
  231. mtmsrd r11,1
  232. #endif /* CONFIG_PPC_BOOK3E */
  233. ld r9,TI_FLAGS(r12)
  234. li r11,-MAX_ERRNO
  235. andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
  236. bne- .Lsyscall_exit_work
  237. andi. r0,r8,MSR_FP
  238. beq 2f
  239. #ifdef CONFIG_ALTIVEC
  240. andis. r0,r8,MSR_VEC@h
  241. bne 3f
  242. #endif
  243. 2: addi r3,r1,STACK_FRAME_OVERHEAD
  244. #ifdef CONFIG_PPC_BOOK3S
  245. li r10,MSR_RI
  246. mtmsrd r10,1 /* Restore RI */
  247. #endif
  248. bl restore_math
  249. #ifdef CONFIG_PPC_BOOK3S
  250. li r11,0
  251. mtmsrd r11,1
  252. #endif
  253. ld r8,_MSR(r1)
  254. ld r3,RESULT(r1)
  255. li r11,-MAX_ERRNO
  256. 3: cmpld r3,r11
  257. ld r5,_CCR(r1)
  258. bge- .Lsyscall_error
  259. .Lsyscall_error_cont:
  260. ld r7,_NIP(r1)
  261. BEGIN_FTR_SECTION
  262. stdcx. r0,0,r1 /* to clear the reservation */
  263. END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
  264. andi. r6,r8,MSR_PR
  265. ld r4,_LINK(r1)
  266. beq- 1f
  267. ACCOUNT_CPU_USER_EXIT(r13, r11, r12)
  268. BEGIN_FTR_SECTION
  269. HMT_MEDIUM_LOW
  270. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  271. ld r13,GPR13(r1) /* only restore r13 if returning to usermode */
  272. ld r2,GPR2(r1)
  273. ld r1,GPR1(r1)
  274. mtlr r4
  275. mtcr r5
  276. mtspr SPRN_SRR0,r7
  277. mtspr SPRN_SRR1,r8
  278. RFI_TO_USER
  279. b . /* prevent speculative execution */
  280. /* exit to kernel */
  281. 1: ld r2,GPR2(r1)
  282. ld r1,GPR1(r1)
  283. mtlr r4
  284. mtcr r5
  285. mtspr SPRN_SRR0,r7
  286. mtspr SPRN_SRR1,r8
  287. RFI_TO_KERNEL
  288. b . /* prevent speculative execution */
  289. .Lsyscall_error:
  290. oris r5,r5,0x1000 /* Set SO bit in CR */
  291. neg r3,r3
  292. std r5,_CCR(r1)
  293. b .Lsyscall_error_cont
  294. /* Traced system call support */
  295. .Lsyscall_dotrace:
  296. bl save_nvgprs
  297. addi r3,r1,STACK_FRAME_OVERHEAD
  298. bl do_syscall_trace_enter
  299. /*
  300. * We use the return value of do_syscall_trace_enter() as the syscall
  301. * number. If the syscall was rejected for any reason do_syscall_trace_enter()
  302. * returns an invalid syscall number and the test below against
  303. * NR_syscalls will fail.
  304. */
  305. mr r0,r3
  306. /* Restore argument registers just clobbered and/or possibly changed. */
  307. ld r3,GPR3(r1)
  308. ld r4,GPR4(r1)
  309. ld r5,GPR5(r1)
  310. ld r6,GPR6(r1)
  311. ld r7,GPR7(r1)
  312. ld r8,GPR8(r1)
  313. /* Repopulate r9 and r10 for the syscall path */
  314. addi r9,r1,STACK_FRAME_OVERHEAD
  315. CURRENT_THREAD_INFO(r10, r1)
  316. ld r10,TI_FLAGS(r10)
  317. cmpldi r0,NR_syscalls
  318. blt+ .Lsyscall
  319. /* Return code is already in r3 thanks to do_syscall_trace_enter() */
  320. b .Lsyscall_exit
  321. .Lsyscall_enosys:
  322. li r3,-ENOSYS
  323. b .Lsyscall_exit
  324. .Lsyscall_exit_work:
  325. #ifdef CONFIG_PPC_BOOK3S
  326. li r10,MSR_RI
  327. mtmsrd r10,1 /* Restore RI */
  328. #endif
  329. /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
  330. If TIF_NOERROR is set, just save r3 as it is. */
  331. andi. r0,r9,_TIF_RESTOREALL
  332. beq+ 0f
  333. REST_NVGPRS(r1)
  334. b 2f
  335. 0: cmpld r3,r11 /* r11 is -MAX_ERRNO */
  336. blt+ 1f
  337. andi. r0,r9,_TIF_NOERROR
  338. bne- 1f
  339. ld r5,_CCR(r1)
  340. neg r3,r3
  341. oris r5,r5,0x1000 /* Set SO bit in CR */
  342. std r5,_CCR(r1)
  343. 1: std r3,GPR3(r1)
  344. 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
  345. beq 4f
  346. /* Clear per-syscall TIF flags if any are set. */
  347. li r11,_TIF_PERSYSCALL_MASK
  348. addi r12,r12,TI_FLAGS
  349. 3: ldarx r10,0,r12
  350. andc r10,r10,r11
  351. stdcx. r10,0,r12
  352. bne- 3b
  353. subi r12,r12,TI_FLAGS
  354. 4: /* Anything else left to do? */
  355. BEGIN_FTR_SECTION
  356. lis r3,INIT_PPR@highest /* Set thread.ppr = 3 */
  357. ld r10,PACACURRENT(r13)
  358. sldi r3,r3,32 /* bits 11-13 are used for ppr */
  359. std r3,TASKTHREADPPR(r10)
  360. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  361. andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
  362. beq ret_from_except_lite
  363. /* Re-enable interrupts */
  364. #ifdef CONFIG_PPC_BOOK3E
  365. wrteei 1
  366. #else
  367. li r10,MSR_RI
  368. ori r10,r10,MSR_EE
  369. mtmsrd r10,1
  370. #endif /* CONFIG_PPC_BOOK3E */
  371. bl save_nvgprs
  372. addi r3,r1,STACK_FRAME_OVERHEAD
  373. bl do_syscall_trace_leave
  374. b ret_from_except
  375. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  376. .Ltabort_syscall:
  377. /* Firstly we need to enable TM in the kernel */
  378. mfmsr r10
  379. li r9, 1
  380. rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG
  381. mtmsrd r10, 0
  382. /* tabort, this dooms the transaction, nothing else */
  383. li r9, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
  384. TABORT(R9)
  385. /*
  386. * Return directly to userspace. We have corrupted user register state,
  387. * but userspace will never see that register state. Execution will
  388. * resume after the tbegin of the aborted transaction with the
  389. * checkpointed register state.
  390. */
  391. li r9, MSR_RI
  392. andc r10, r10, r9
  393. mtmsrd r10, 1
  394. mtspr SPRN_SRR0, r11
  395. mtspr SPRN_SRR1, r12
  396. RFI_TO_USER
  397. b . /* prevent speculative execution */
  398. #endif
  399. _ASM_NOKPROBE_SYMBOL(system_call_common);
  400. _ASM_NOKPROBE_SYMBOL(system_call_exit);
  401. /* Save non-volatile GPRs, if not already saved. */
  402. _GLOBAL(save_nvgprs)
  403. ld r11,_TRAP(r1)
  404. andi. r0,r11,1
  405. beqlr-
  406. SAVE_NVGPRS(r1)
  407. clrrdi r0,r11,1
  408. std r0,_TRAP(r1)
  409. blr
  410. _ASM_NOKPROBE_SYMBOL(save_nvgprs);
  411. /*
  412. * The sigsuspend and rt_sigsuspend system calls can call do_signal
  413. * and thus put the process into the stopped state where we might
  414. * want to examine its user state with ptrace. Therefore we need
  415. * to save all the nonvolatile registers (r14 - r31) before calling
  416. * the C code. Similarly, fork, vfork and clone need the full
  417. * register state on the stack so that it can be copied to the child.
  418. */
  419. _GLOBAL(ppc_fork)
  420. bl save_nvgprs
  421. bl sys_fork
  422. b .Lsyscall_exit
  423. _GLOBAL(ppc_vfork)
  424. bl save_nvgprs
  425. bl sys_vfork
  426. b .Lsyscall_exit
  427. _GLOBAL(ppc_clone)
  428. bl save_nvgprs
  429. bl sys_clone
  430. b .Lsyscall_exit
  431. _GLOBAL(ppc32_swapcontext)
  432. bl save_nvgprs
  433. bl compat_sys_swapcontext
  434. b .Lsyscall_exit
  435. _GLOBAL(ppc64_swapcontext)
  436. bl save_nvgprs
  437. bl sys_swapcontext
  438. b .Lsyscall_exit
  439. _GLOBAL(ppc_switch_endian)
  440. bl save_nvgprs
  441. bl sys_switch_endian
  442. b .Lsyscall_exit
  443. _GLOBAL(ret_from_fork)
  444. bl schedule_tail
  445. REST_NVGPRS(r1)
  446. li r3,0
  447. b .Lsyscall_exit
  448. _GLOBAL(ret_from_kernel_thread)
  449. bl schedule_tail
  450. REST_NVGPRS(r1)
  451. mtlr r14
  452. mr r3,r15
  453. #ifdef PPC64_ELF_ABI_v2
  454. mr r12,r14
  455. #endif
  456. blrl
  457. li r3,0
  458. b .Lsyscall_exit
  459. #ifdef CONFIG_PPC_BOOK3S_64
  460. #define FLUSH_COUNT_CACHE \
  461. 1: nop; \
  462. patch_site 1b, patch__call_flush_count_cache
  463. #define BCCTR_FLUSH .long 0x4c400420
  464. .macro nops number
  465. .rept \number
  466. nop
  467. .endr
  468. .endm
  469. .balign 32
  470. .global flush_count_cache
  471. flush_count_cache:
  472. /* Save LR into r9 */
  473. mflr r9
  474. // Flush the link stack
  475. .rept 64
  476. bl .+4
  477. .endr
  478. b 1f
  479. nops 6
  480. .balign 32
  481. /* Restore LR */
  482. 1: mtlr r9
  483. // If we're just flushing the link stack, return here
  484. 3: nop
  485. patch_site 3b patch__flush_link_stack_return
  486. li r9,0x7fff
  487. mtctr r9
  488. BCCTR_FLUSH
  489. 2: nop
  490. patch_site 2b patch__flush_count_cache_return
  491. nops 3
  492. .rept 278
  493. .balign 32
  494. BCCTR_FLUSH
  495. nops 7
  496. .endr
  497. blr
  498. #else
  499. #define FLUSH_COUNT_CACHE
  500. #endif /* CONFIG_PPC_BOOK3S_64 */
  501. /*
  502. * This routine switches between two different tasks. The process
  503. * state of one is saved on its kernel stack. Then the state
  504. * of the other is restored from its kernel stack. The memory
  505. * management hardware is updated to the second process's state.
  506. * Finally, we can return to the second process, via ret_from_except.
  507. * On entry, r3 points to the THREAD for the current task, r4
  508. * points to the THREAD for the new task.
  509. *
  510. * Note: there are two ways to get to the "going out" portion
  511. * of this code; either by coming in via the entry (_switch)
  512. * or via "fork" which must set up an environment equivalent
  513. * to the "_switch" path. If you change this you'll have to change
  514. * the fork code also.
  515. *
  516. * The code which creates the new task context is in 'copy_thread'
  517. * in arch/powerpc/kernel/process.c
  518. */
  519. .align 7
  520. _GLOBAL(_switch)
  521. mflr r0
  522. std r0,16(r1)
  523. stdu r1,-SWITCH_FRAME_SIZE(r1)
  524. /* r3-r13 are caller saved -- Cort */
  525. SAVE_8GPRS(14, r1)
  526. SAVE_10GPRS(22, r1)
  527. std r0,_NIP(r1) /* Return to switch caller */
  528. mfcr r23
  529. std r23,_CCR(r1)
  530. std r1,KSP(r3) /* Set old stack pointer */
  531. FLUSH_COUNT_CACHE
  532. /*
  533. * On SMP kernels, care must be taken because a task may be
  534. * scheduled off CPUx and on to CPUy. Memory ordering must be
  535. * considered.
  536. *
  537. * Cacheable stores on CPUx will be visible when the task is
  538. * scheduled on CPUy by virtue of the core scheduler barriers
  539. * (see "Notes on Program-Order guarantees on SMP systems." in
  540. * kernel/sched/core.c).
  541. *
  542. * Uncacheable stores in the case of involuntary preemption must
  543. * be taken care of. The smp_mb__before_spin_lock() in __schedule()
  544. * is implemented as hwsync on powerpc, which orders MMIO too. So
  545. * long as there is an hwsync in the context switch path, it will
  546. * be executed on the source CPU after the task has performed
  547. * all MMIO ops on that CPU, and on the destination CPU before the
  548. * task performs any MMIO ops there.
  549. */
  550. /*
  551. * The kernel context switch path must contain a spin_lock,
  552. * which contains larx/stcx, which will clear any reservation
  553. * of the task being switched.
  554. */
  555. #ifdef CONFIG_PPC_BOOK3S
  556. /* Cancel all explict user streams as they will have no use after context
  557. * switch and will stop the HW from creating streams itself
  558. */
  559. DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r6)
  560. #endif
  561. addi r6,r4,-THREAD /* Convert THREAD to 'current' */
  562. std r6,PACACURRENT(r13) /* Set new 'current' */
  563. ld r8,KSP(r4) /* new stack pointer */
  564. #ifdef CONFIG_PPC_BOOK3S_64
  565. BEGIN_MMU_FTR_SECTION
  566. b 2f
  567. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
  568. BEGIN_FTR_SECTION
  569. clrrdi r6,r8,28 /* get its ESID */
  570. clrrdi r9,r1,28 /* get current sp ESID */
  571. FTR_SECTION_ELSE
  572. clrrdi r6,r8,40 /* get its 1T ESID */
  573. clrrdi r9,r1,40 /* get current sp 1T ESID */
  574. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_1T_SEGMENT)
  575. clrldi. r0,r6,2 /* is new ESID c00000000? */
  576. cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
  577. cror eq,4*cr1+eq,eq
  578. beq 2f /* if yes, don't slbie it */
  579. /* Bolt in the new stack SLB entry */
  580. ld r7,KSP_VSID(r4) /* Get new stack's VSID */
  581. oris r0,r6,(SLB_ESID_V)@h
  582. ori r0,r0,(SLB_NUM_BOLTED-1)@l
  583. BEGIN_FTR_SECTION
  584. li r9,MMU_SEGSIZE_1T /* insert B field */
  585. oris r6,r6,(MMU_SEGSIZE_1T << SLBIE_SSIZE_SHIFT)@h
  586. rldimi r7,r9,SLB_VSID_SSIZE_SHIFT,0
  587. END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  588. /* Update the last bolted SLB. No write barriers are needed
  589. * here, provided we only update the current CPU's SLB shadow
  590. * buffer.
  591. */
  592. ld r9,PACA_SLBSHADOWPTR(r13)
  593. li r12,0
  594. std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */
  595. li r12,SLBSHADOW_STACKVSID
  596. STDX_BE r7,r12,r9 /* Save VSID */
  597. li r12,SLBSHADOW_STACKESID
  598. STDX_BE r0,r12,r9 /* Save ESID */
  599. /* No need to check for MMU_FTR_NO_SLBIE_B here, since when
  600. * we have 1TB segments, the only CPUs known to have the errata
  601. * only support less than 1TB of system memory and we'll never
  602. * actually hit this code path.
  603. */
  604. isync
  605. slbie r6
  606. slbie r6 /* Workaround POWER5 < DD2.1 issue */
  607. slbmte r7,r0
  608. isync
  609. 2:
  610. #endif /* CONFIG_PPC_BOOK3S_64 */
  611. CURRENT_THREAD_INFO(r7, r8) /* base of new stack */
  612. /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
  613. because we don't need to leave the 288-byte ABI gap at the
  614. top of the kernel stack. */
  615. addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
  616. /*
  617. * PMU interrupts in radix may come in here. They will use r1, not
  618. * PACAKSAVE, so this stack switch will not cause a problem. They
  619. * will store to the process stack, which may then be migrated to
  620. * another CPU. However the rq lock release on this CPU paired with
  621. * the rq lock acquire on the new CPU before the stack becomes
  622. * active on the new CPU, will order those stores.
  623. */
  624. mr r1,r8 /* start using new stack pointer */
  625. std r7,PACAKSAVE(r13)
  626. ld r6,_CCR(r1)
  627. mtcrf 0xFF,r6
  628. /* r3-r13 are destroyed -- Cort */
  629. REST_8GPRS(14, r1)
  630. REST_10GPRS(22, r1)
  631. /* convert old thread to its task_struct for return value */
  632. addi r3,r3,-THREAD
  633. ld r7,_NIP(r1) /* Return to _switch caller in new task */
  634. mtlr r7
  635. addi r1,r1,SWITCH_FRAME_SIZE
  636. blr
  637. .align 7
  638. _GLOBAL(ret_from_except)
  639. ld r11,_TRAP(r1)
  640. andi. r0,r11,1
  641. bne ret_from_except_lite
  642. REST_NVGPRS(r1)
  643. _GLOBAL(ret_from_except_lite)
  644. /*
  645. * Disable interrupts so that current_thread_info()->flags
  646. * can't change between when we test it and when we return
  647. * from the interrupt.
  648. */
  649. #ifdef CONFIG_PPC_BOOK3E
  650. wrteei 0
  651. #else
  652. li r10,MSR_RI
  653. mtmsrd r10,1 /* Update machine state */
  654. #endif /* CONFIG_PPC_BOOK3E */
  655. CURRENT_THREAD_INFO(r9, r1)
  656. ld r3,_MSR(r1)
  657. #ifdef CONFIG_PPC_BOOK3E
  658. ld r10,PACACURRENT(r13)
  659. #endif /* CONFIG_PPC_BOOK3E */
  660. ld r4,TI_FLAGS(r9)
  661. andi. r3,r3,MSR_PR
  662. beq resume_kernel
  663. #ifdef CONFIG_PPC_BOOK3E
  664. lwz r3,(THREAD+THREAD_DBCR0)(r10)
  665. #endif /* CONFIG_PPC_BOOK3E */
  666. /* Check current_thread_info()->flags */
  667. andi. r0,r4,_TIF_USER_WORK_MASK
  668. bne 1f
  669. #ifdef CONFIG_PPC_BOOK3E
  670. /*
  671. * Check to see if the dbcr0 register is set up to debug.
  672. * Use the internal debug mode bit to do this.
  673. */
  674. andis. r0,r3,DBCR0_IDM@h
  675. beq restore
  676. mfmsr r0
  677. rlwinm r0,r0,0,~MSR_DE /* Clear MSR.DE */
  678. mtmsr r0
  679. mtspr SPRN_DBCR0,r3
  680. li r10, -1
  681. mtspr SPRN_DBSR,r10
  682. b restore
  683. #else
  684. addi r3,r1,STACK_FRAME_OVERHEAD
  685. bl restore_math
  686. b restore
  687. #endif
  688. 1: andi. r0,r4,_TIF_NEED_RESCHED
  689. beq 2f
  690. bl restore_interrupts
  691. SCHEDULE_USER
  692. b ret_from_except_lite
  693. 2:
  694. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  695. andi. r0,r4,_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM
  696. bne 3f /* only restore TM if nothing else to do */
  697. addi r3,r1,STACK_FRAME_OVERHEAD
  698. bl restore_tm_state
  699. b restore
  700. 3:
  701. #endif
  702. bl save_nvgprs
  703. /*
  704. * Use a non volatile GPR to save and restore our thread_info flags
  705. * across the call to restore_interrupts.
  706. */
  707. mr r30,r4
  708. bl restore_interrupts
  709. mr r4,r30
  710. addi r3,r1,STACK_FRAME_OVERHEAD
  711. bl do_notify_resume
  712. b ret_from_except
  713. resume_kernel:
  714. /* check current_thread_info, _TIF_EMULATE_STACK_STORE */
  715. andis. r8,r4,_TIF_EMULATE_STACK_STORE@h
  716. beq+ 1f
  717. addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
  718. ld r3,GPR1(r1)
  719. subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
  720. mr r4,r1 /* src: current exception frame */
  721. mr r1,r3 /* Reroute the trampoline frame to r1 */
  722. /* Copy from the original to the trampoline. */
  723. li r5,INT_FRAME_SIZE/8 /* size: INT_FRAME_SIZE */
  724. li r6,0 /* start offset: 0 */
  725. mtctr r5
  726. 2: ldx r0,r6,r4
  727. stdx r0,r6,r3
  728. addi r6,r6,8
  729. bdnz 2b
  730. /* Do real store operation to complete stdu */
  731. ld r5,GPR1(r1)
  732. std r8,0(r5)
  733. /* Clear _TIF_EMULATE_STACK_STORE flag */
  734. lis r11,_TIF_EMULATE_STACK_STORE@h
  735. addi r5,r9,TI_FLAGS
  736. 0: ldarx r4,0,r5
  737. andc r4,r4,r11
  738. stdcx. r4,0,r5
  739. bne- 0b
  740. 1:
  741. #ifdef CONFIG_PREEMPT
  742. /* Check if we need to preempt */
  743. andi. r0,r4,_TIF_NEED_RESCHED
  744. beq+ restore
  745. /* Check that preempt_count() == 0 and interrupts are enabled */
  746. lwz r8,TI_PREEMPT(r9)
  747. cmpwi cr0,r8,0
  748. bne restore
  749. ld r0,SOFTE(r1)
  750. andi. r0,r0,IRQS_DISABLED
  751. bne restore
  752. /*
  753. * Here we are preempting the current task. We want to make
  754. * sure we are soft-disabled first and reconcile irq state.
  755. */
  756. RECONCILE_IRQ_STATE(r3,r4)
  757. 1: bl preempt_schedule_irq
  758. /* Re-test flags and eventually loop */
  759. CURRENT_THREAD_INFO(r9, r1)
  760. ld r4,TI_FLAGS(r9)
  761. andi. r0,r4,_TIF_NEED_RESCHED
  762. bne 1b
  763. /*
  764. * arch_local_irq_restore() from preempt_schedule_irq above may
  765. * enable hard interrupt but we really should disable interrupts
  766. * when we return from the interrupt, and so that we don't get
  767. * interrupted after loading SRR0/1.
  768. */
  769. #ifdef CONFIG_PPC_BOOK3E
  770. wrteei 0
  771. #else
  772. li r10,MSR_RI
  773. mtmsrd r10,1 /* Update machine state */
  774. #endif /* CONFIG_PPC_BOOK3E */
  775. #endif /* CONFIG_PREEMPT */
  776. .globl fast_exc_return_irq
  777. fast_exc_return_irq:
  778. restore:
  779. /*
  780. * This is the main kernel exit path. First we check if we
  781. * are about to re-enable interrupts
  782. */
  783. ld r5,SOFTE(r1)
  784. lbz r6,PACAIRQSOFTMASK(r13)
  785. andi. r5,r5,IRQS_DISABLED
  786. bne .Lrestore_irq_off
  787. /* We are enabling, were we already enabled ? Yes, just return */
  788. andi. r6,r6,IRQS_DISABLED
  789. beq cr0,.Ldo_restore
  790. /*
  791. * We are about to soft-enable interrupts (we are hard disabled
  792. * at this point). We check if there's anything that needs to
  793. * be replayed first.
  794. */
  795. lbz r0,PACAIRQHAPPENED(r13)
  796. cmpwi cr0,r0,0
  797. bne- .Lrestore_check_irq_replay
  798. /*
  799. * Get here when nothing happened while soft-disabled, just
  800. * soft-enable and move-on. We will hard-enable as a side
  801. * effect of rfi
  802. */
  803. .Lrestore_no_replay:
  804. TRACE_ENABLE_INTS
  805. li r0,IRQS_ENABLED
  806. stb r0,PACAIRQSOFTMASK(r13);
  807. /*
  808. * Final return path. BookE is handled in a different file
  809. */
  810. .Ldo_restore:
  811. #ifdef CONFIG_PPC_BOOK3E
  812. b exception_return_book3e
  813. #else
  814. /*
  815. * Clear the reservation. If we know the CPU tracks the address of
  816. * the reservation then we can potentially save some cycles and use
  817. * a larx. On POWER6 and POWER7 this is significantly faster.
  818. */
  819. BEGIN_FTR_SECTION
  820. stdcx. r0,0,r1 /* to clear the reservation */
  821. FTR_SECTION_ELSE
  822. ldarx r4,0,r1
  823. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
  824. /*
  825. * Some code path such as load_up_fpu or altivec return directly
  826. * here. They run entirely hard disabled and do not alter the
  827. * interrupt state. They also don't use lwarx/stwcx. and thus
  828. * are known not to leave dangling reservations.
  829. */
  830. .globl fast_exception_return
  831. fast_exception_return:
  832. ld r3,_MSR(r1)
  833. ld r4,_CTR(r1)
  834. ld r0,_LINK(r1)
  835. mtctr r4
  836. mtlr r0
  837. ld r4,_XER(r1)
  838. mtspr SPRN_XER,r4
  839. REST_8GPRS(5, r1)
  840. andi. r0,r3,MSR_RI
  841. beq- .Lunrecov_restore
  842. /* Load PPR from thread struct before we clear MSR:RI */
  843. BEGIN_FTR_SECTION
  844. ld r2,PACACURRENT(r13)
  845. ld r2,TASKTHREADPPR(r2)
  846. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  847. /*
  848. * Clear RI before restoring r13. If we are returning to
  849. * userspace and we take an exception after restoring r13,
  850. * we end up corrupting the userspace r13 value.
  851. */
  852. li r4,0
  853. mtmsrd r4,1
  854. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  855. /* TM debug */
  856. std r3, PACATMSCRATCH(r13) /* Stash returned-to MSR */
  857. #endif
  858. /*
  859. * r13 is our per cpu area, only restore it if we are returning to
  860. * userspace the value stored in the stack frame may belong to
  861. * another CPU.
  862. */
  863. andi. r0,r3,MSR_PR
  864. beq 1f
  865. BEGIN_FTR_SECTION
  866. mtspr SPRN_PPR,r2 /* Restore PPR */
  867. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  868. ACCOUNT_CPU_USER_EXIT(r13, r2, r4)
  869. REST_GPR(13, r1)
  870. mtspr SPRN_SRR1,r3
  871. ld r2,_CCR(r1)
  872. mtcrf 0xFF,r2
  873. ld r2,_NIP(r1)
  874. mtspr SPRN_SRR0,r2
  875. ld r0,GPR0(r1)
  876. ld r2,GPR2(r1)
  877. ld r3,GPR3(r1)
  878. ld r4,GPR4(r1)
  879. ld r1,GPR1(r1)
  880. RFI_TO_USER
  881. b . /* prevent speculative execution */
  882. 1: mtspr SPRN_SRR1,r3
  883. ld r2,_CCR(r1)
  884. mtcrf 0xFF,r2
  885. ld r2,_NIP(r1)
  886. mtspr SPRN_SRR0,r2
  887. /*
  888. * Leaving a stale exception_marker on the stack can confuse
  889. * the reliable stack unwinder later on. Clear it.
  890. */
  891. li r2,0
  892. std r2,STACK_FRAME_OVERHEAD-16(r1)
  893. ld r0,GPR0(r1)
  894. ld r2,GPR2(r1)
  895. ld r3,GPR3(r1)
  896. ld r4,GPR4(r1)
  897. ld r1,GPR1(r1)
  898. RFI_TO_KERNEL
  899. b . /* prevent speculative execution */
  900. #endif /* CONFIG_PPC_BOOK3E */
  901. /*
  902. * We are returning to a context with interrupts soft disabled.
  903. *
  904. * However, we may also about to hard enable, so we need to
  905. * make sure that in this case, we also clear PACA_IRQ_HARD_DIS
  906. * or that bit can get out of sync and bad things will happen
  907. */
  908. .Lrestore_irq_off:
  909. ld r3,_MSR(r1)
  910. lbz r7,PACAIRQHAPPENED(r13)
  911. andi. r0,r3,MSR_EE
  912. beq 1f
  913. rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS
  914. stb r7,PACAIRQHAPPENED(r13)
  915. 1:
  916. #if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && defined(CONFIG_BUG)
  917. /* The interrupt should not have soft enabled. */
  918. lbz r7,PACAIRQSOFTMASK(r13)
  919. 1: tdeqi r7,IRQS_ENABLED
  920. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  921. #endif
  922. b .Ldo_restore
  923. /*
  924. * Something did happen, check if a re-emit is needed
  925. * (this also clears paca->irq_happened)
  926. */
  927. .Lrestore_check_irq_replay:
  928. /* XXX: We could implement a fast path here where we check
  929. * for irq_happened being just 0x01, in which case we can
  930. * clear it and return. That means that we would potentially
  931. * miss a decrementer having wrapped all the way around.
  932. *
  933. * Still, this might be useful for things like hash_page
  934. */
  935. bl __check_irq_replay
  936. cmpwi cr0,r3,0
  937. beq .Lrestore_no_replay
  938. /*
  939. * We need to re-emit an interrupt. We do so by re-using our
  940. * existing exception frame. We first change the trap value,
  941. * but we need to ensure we preserve the low nibble of it
  942. */
  943. ld r4,_TRAP(r1)
  944. clrldi r4,r4,60
  945. or r4,r4,r3
  946. std r4,_TRAP(r1)
  947. /*
  948. * PACA_IRQ_HARD_DIS won't always be set here, so set it now
  949. * to reconcile the IRQ state. Tracing is already accounted for.
  950. */
  951. lbz r4,PACAIRQHAPPENED(r13)
  952. ori r4,r4,PACA_IRQ_HARD_DIS
  953. stb r4,PACAIRQHAPPENED(r13)
  954. /*
  955. * Then find the right handler and call it. Interrupts are
  956. * still soft-disabled and we keep them that way.
  957. */
  958. cmpwi cr0,r3,0x500
  959. bne 1f
  960. addi r3,r1,STACK_FRAME_OVERHEAD;
  961. bl do_IRQ
  962. b ret_from_except
  963. 1: cmpwi cr0,r3,0xf00
  964. bne 1f
  965. addi r3,r1,STACK_FRAME_OVERHEAD;
  966. bl performance_monitor_exception
  967. b ret_from_except
  968. 1: cmpwi cr0,r3,0xe60
  969. bne 1f
  970. addi r3,r1,STACK_FRAME_OVERHEAD;
  971. bl handle_hmi_exception
  972. b ret_from_except
  973. 1: cmpwi cr0,r3,0x900
  974. bne 1f
  975. addi r3,r1,STACK_FRAME_OVERHEAD;
  976. bl timer_interrupt
  977. b ret_from_except
  978. #ifdef CONFIG_PPC_DOORBELL
  979. 1:
  980. #ifdef CONFIG_PPC_BOOK3E
  981. cmpwi cr0,r3,0x280
  982. #else
  983. cmpwi cr0,r3,0xa00
  984. #endif /* CONFIG_PPC_BOOK3E */
  985. bne 1f
  986. addi r3,r1,STACK_FRAME_OVERHEAD;
  987. bl doorbell_exception
  988. #endif /* CONFIG_PPC_DOORBELL */
  989. 1: b ret_from_except /* What else to do here ? */
  990. .Lunrecov_restore:
  991. addi r3,r1,STACK_FRAME_OVERHEAD
  992. bl unrecoverable_exception
  993. b .Lunrecov_restore
  994. _ASM_NOKPROBE_SYMBOL(ret_from_except);
  995. _ASM_NOKPROBE_SYMBOL(ret_from_except_lite);
  996. _ASM_NOKPROBE_SYMBOL(resume_kernel);
  997. _ASM_NOKPROBE_SYMBOL(fast_exc_return_irq);
  998. _ASM_NOKPROBE_SYMBOL(restore);
  999. _ASM_NOKPROBE_SYMBOL(fast_exception_return);
  1000. #ifdef CONFIG_PPC_RTAS
  1001. /*
  1002. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  1003. * called with the MMU off.
  1004. *
  1005. * In addition, we need to be in 32b mode, at least for now.
  1006. *
  1007. * Note: r3 is an input parameter to rtas, so don't trash it...
  1008. */
  1009. _GLOBAL(enter_rtas)
  1010. mflr r0
  1011. std r0,16(r1)
  1012. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  1013. /* Because RTAS is running in 32b mode, it clobbers the high order half
  1014. * of all registers that it saves. We therefore save those registers
  1015. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  1016. */
  1017. SAVE_GPR(2, r1) /* Save the TOC */
  1018. SAVE_GPR(13, r1) /* Save paca */
  1019. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  1020. SAVE_10GPRS(22, r1) /* ditto */
  1021. mfcr r4
  1022. std r4,_CCR(r1)
  1023. mfctr r5
  1024. std r5,_CTR(r1)
  1025. mfspr r6,SPRN_XER
  1026. std r6,_XER(r1)
  1027. mfdar r7
  1028. std r7,_DAR(r1)
  1029. mfdsisr r8
  1030. std r8,_DSISR(r1)
  1031. /* Temporary workaround to clear CR until RTAS can be modified to
  1032. * ignore all bits.
  1033. */
  1034. li r0,0
  1035. mtcr r0
  1036. #ifdef CONFIG_BUG
  1037. /* There is no way it is acceptable to get here with interrupts enabled,
  1038. * check it with the asm equivalent of WARN_ON
  1039. */
  1040. lbz r0,PACAIRQSOFTMASK(r13)
  1041. 1: tdeqi r0,IRQS_ENABLED
  1042. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  1043. #endif
  1044. /* Hard-disable interrupts */
  1045. mfmsr r6
  1046. rldicl r7,r6,48,1
  1047. rotldi r7,r7,16
  1048. mtmsrd r7,1
  1049. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  1050. * so they are saved in the PACA which allows us to restore
  1051. * our original state after RTAS returns.
  1052. */
  1053. std r1,PACAR1(r13)
  1054. std r6,PACASAVEDMSR(r13)
  1055. /* Setup our real return addr */
  1056. LOAD_REG_ADDR(r4,rtas_return_loc)
  1057. clrldi r4,r4,2 /* convert to realmode address */
  1058. mtlr r4
  1059. li r0,0
  1060. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  1061. andc r0,r6,r0
  1062. li r9,1
  1063. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  1064. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI|MSR_LE
  1065. andc r6,r0,r9
  1066. __enter_rtas:
  1067. sync /* disable interrupts so SRR0/1 */
  1068. mtmsrd r0 /* don't get trashed */
  1069. LOAD_REG_ADDR(r4, rtas)
  1070. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  1071. ld r4,RTASBASE(r4) /* get the rtas->base value */
  1072. mtspr SPRN_SRR0,r5
  1073. mtspr SPRN_SRR1,r6
  1074. RFI_TO_KERNEL
  1075. b . /* prevent speculative execution */
  1076. rtas_return_loc:
  1077. FIXUP_ENDIAN
  1078. /*
  1079. * Clear RI and set SF before anything.
  1080. */
  1081. mfmsr r6
  1082. li r0,MSR_RI
  1083. andc r6,r6,r0
  1084. sldi r0,r0,(MSR_SF_LG - MSR_RI_LG)
  1085. or r6,r6,r0
  1086. sync
  1087. mtmsrd r6
  1088. /* relocation is off at this point */
  1089. GET_PACA(r4)
  1090. clrldi r4,r4,2 /* convert to realmode address */
  1091. bcl 20,31,$+4
  1092. 0: mflr r3
  1093. ld r3,(1f-0b)(r3) /* get &rtas_restore_regs */
  1094. ld r1,PACAR1(r4) /* Restore our SP */
  1095. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  1096. mtspr SPRN_SRR0,r3
  1097. mtspr SPRN_SRR1,r4
  1098. RFI_TO_KERNEL
  1099. b . /* prevent speculative execution */
  1100. _ASM_NOKPROBE_SYMBOL(__enter_rtas)
  1101. _ASM_NOKPROBE_SYMBOL(rtas_return_loc)
  1102. .align 3
  1103. 1: .8byte rtas_restore_regs
  1104. rtas_restore_regs:
  1105. /* relocation is on at this point */
  1106. REST_GPR(2, r1) /* Restore the TOC */
  1107. REST_GPR(13, r1) /* Restore paca */
  1108. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  1109. REST_10GPRS(22, r1) /* ditto */
  1110. GET_PACA(r13)
  1111. ld r4,_CCR(r1)
  1112. mtcr r4
  1113. ld r5,_CTR(r1)
  1114. mtctr r5
  1115. ld r6,_XER(r1)
  1116. mtspr SPRN_XER,r6
  1117. ld r7,_DAR(r1)
  1118. mtdar r7
  1119. ld r8,_DSISR(r1)
  1120. mtdsisr r8
  1121. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  1122. ld r0,16(r1) /* get return address */
  1123. mtlr r0
  1124. blr /* return to caller */
  1125. #endif /* CONFIG_PPC_RTAS */
  1126. _GLOBAL(enter_prom)
  1127. mflr r0
  1128. std r0,16(r1)
  1129. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  1130. /* Because PROM is running in 32b mode, it clobbers the high order half
  1131. * of all registers that it saves. We therefore save those registers
  1132. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  1133. */
  1134. SAVE_GPR(2, r1)
  1135. SAVE_GPR(13, r1)
  1136. SAVE_8GPRS(14, r1)
  1137. SAVE_10GPRS(22, r1)
  1138. mfcr r10
  1139. mfmsr r11
  1140. std r10,_CCR(r1)
  1141. std r11,_MSR(r1)
  1142. /* Put PROM address in SRR0 */
  1143. mtsrr0 r4
  1144. /* Setup our trampoline return addr in LR */
  1145. bcl 20,31,$+4
  1146. 0: mflr r4
  1147. addi r4,r4,(1f - 0b)
  1148. mtlr r4
  1149. /* Prepare a 32-bit mode big endian MSR
  1150. */
  1151. #ifdef CONFIG_PPC_BOOK3E
  1152. rlwinm r11,r11,0,1,31
  1153. mtsrr1 r11
  1154. rfi
  1155. #else /* CONFIG_PPC_BOOK3E */
  1156. LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_ISF | MSR_LE)
  1157. andc r11,r11,r12
  1158. mtsrr1 r11
  1159. RFI_TO_KERNEL
  1160. #endif /* CONFIG_PPC_BOOK3E */
  1161. 1: /* Return from OF */
  1162. FIXUP_ENDIAN
  1163. /* Just make sure that r1 top 32 bits didn't get
  1164. * corrupt by OF
  1165. */
  1166. rldicl r1,r1,0,32
  1167. /* Restore the MSR (back to 64 bits) */
  1168. ld r0,_MSR(r1)
  1169. MTMSRD(r0)
  1170. isync
  1171. /* Restore other registers */
  1172. REST_GPR(2, r1)
  1173. REST_GPR(13, r1)
  1174. REST_8GPRS(14, r1)
  1175. REST_10GPRS(22, r1)
  1176. ld r4,_CCR(r1)
  1177. mtcr r4
  1178. addi r1,r1,PROM_FRAME_SIZE
  1179. ld r0,16(r1)
  1180. mtlr r0
  1181. blr