entry_64.S 30 KB

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