entry_32.S 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@fsmlabs.com) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@fsmlabs.com>
  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. */
  21. #include <linux/errno.h>
  22. #include <linux/sys.h>
  23. #include <linux/threads.h>
  24. #include <asm/reg.h>
  25. #include <asm/page.h>
  26. #include <asm/mmu.h>
  27. #include <asm/cputable.h>
  28. #include <asm/thread_info.h>
  29. #include <asm/ppc_asm.h>
  30. #include <asm/asm-offsets.h>
  31. #include <asm/unistd.h>
  32. #include <asm/ftrace.h>
  33. #include <asm/ptrace.h>
  34. /*
  35. * MSR_KERNEL is > 0x10000 on 4xx/Book-E since it include MSR_CE.
  36. */
  37. #if MSR_KERNEL >= 0x10000
  38. #define LOAD_MSR_KERNEL(r, x) lis r,(x)@h; ori r,r,(x)@l
  39. #else
  40. #define LOAD_MSR_KERNEL(r, x) li r,(x)
  41. #endif
  42. #ifdef CONFIG_BOOKE
  43. .globl mcheck_transfer_to_handler
  44. mcheck_transfer_to_handler:
  45. mfspr r0,SPRN_DSRR0
  46. stw r0,_DSRR0(r11)
  47. mfspr r0,SPRN_DSRR1
  48. stw r0,_DSRR1(r11)
  49. /* fall through */
  50. .globl debug_transfer_to_handler
  51. debug_transfer_to_handler:
  52. mfspr r0,SPRN_CSRR0
  53. stw r0,_CSRR0(r11)
  54. mfspr r0,SPRN_CSRR1
  55. stw r0,_CSRR1(r11)
  56. /* fall through */
  57. .globl crit_transfer_to_handler
  58. crit_transfer_to_handler:
  59. #ifdef CONFIG_PPC_BOOK3E_MMU
  60. mfspr r0,SPRN_MAS0
  61. stw r0,MAS0(r11)
  62. mfspr r0,SPRN_MAS1
  63. stw r0,MAS1(r11)
  64. mfspr r0,SPRN_MAS2
  65. stw r0,MAS2(r11)
  66. mfspr r0,SPRN_MAS3
  67. stw r0,MAS3(r11)
  68. mfspr r0,SPRN_MAS6
  69. stw r0,MAS6(r11)
  70. #ifdef CONFIG_PHYS_64BIT
  71. mfspr r0,SPRN_MAS7
  72. stw r0,MAS7(r11)
  73. #endif /* CONFIG_PHYS_64BIT */
  74. #endif /* CONFIG_PPC_BOOK3E_MMU */
  75. #ifdef CONFIG_44x
  76. mfspr r0,SPRN_MMUCR
  77. stw r0,MMUCR(r11)
  78. #endif
  79. mfspr r0,SPRN_SRR0
  80. stw r0,_SRR0(r11)
  81. mfspr r0,SPRN_SRR1
  82. stw r0,_SRR1(r11)
  83. /* set the stack limit to the current stack
  84. * and set the limit to protect the thread_info
  85. * struct
  86. */
  87. mfspr r8,SPRN_SPRG_THREAD
  88. lwz r0,KSP_LIMIT(r8)
  89. stw r0,SAVED_KSP_LIMIT(r11)
  90. rlwimi r0,r1,0,0,(31-THREAD_SHIFT)
  91. stw r0,KSP_LIMIT(r8)
  92. /* fall through */
  93. #endif
  94. #ifdef CONFIG_40x
  95. .globl crit_transfer_to_handler
  96. crit_transfer_to_handler:
  97. lwz r0,crit_r10@l(0)
  98. stw r0,GPR10(r11)
  99. lwz r0,crit_r11@l(0)
  100. stw r0,GPR11(r11)
  101. mfspr r0,SPRN_SRR0
  102. stw r0,crit_srr0@l(0)
  103. mfspr r0,SPRN_SRR1
  104. stw r0,crit_srr1@l(0)
  105. /* set the stack limit to the current stack
  106. * and set the limit to protect the thread_info
  107. * struct
  108. */
  109. mfspr r8,SPRN_SPRG_THREAD
  110. lwz r0,KSP_LIMIT(r8)
  111. stw r0,saved_ksp_limit@l(0)
  112. rlwimi r0,r1,0,0,(31-THREAD_SHIFT)
  113. stw r0,KSP_LIMIT(r8)
  114. /* fall through */
  115. #endif
  116. /*
  117. * This code finishes saving the registers to the exception frame
  118. * and jumps to the appropriate handler for the exception, turning
  119. * on address translation.
  120. * Note that we rely on the caller having set cr0.eq iff the exception
  121. * occurred in kernel mode (i.e. MSR:PR = 0).
  122. */
  123. .globl transfer_to_handler_full
  124. transfer_to_handler_full:
  125. SAVE_NVGPRS(r11)
  126. /* fall through */
  127. .globl transfer_to_handler
  128. transfer_to_handler:
  129. stw r2,GPR2(r11)
  130. stw r12,_NIP(r11)
  131. stw r9,_MSR(r11)
  132. andi. r2,r9,MSR_PR
  133. mfctr r12
  134. mfspr r2,SPRN_XER
  135. stw r12,_CTR(r11)
  136. stw r2,_XER(r11)
  137. mfspr r12,SPRN_SPRG_THREAD
  138. addi r2,r12,-THREAD
  139. tovirt(r2,r2) /* set r2 to current */
  140. beq 2f /* if from user, fix up THREAD.regs */
  141. addi r11,r1,STACK_FRAME_OVERHEAD
  142. stw r11,PT_REGS(r12)
  143. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  144. /* Check to see if the dbcr0 register is set up to debug. Use the
  145. internal debug mode bit to do this. */
  146. lwz r12,THREAD_DBCR0(r12)
  147. andis. r12,r12,DBCR0_IDM@h
  148. beq+ 3f
  149. /* From user and task is ptraced - load up global dbcr0 */
  150. li r12,-1 /* clear all pending debug events */
  151. mtspr SPRN_DBSR,r12
  152. lis r11,global_dbcr0@ha
  153. tophys(r11,r11)
  154. addi r11,r11,global_dbcr0@l
  155. #ifdef CONFIG_SMP
  156. CURRENT_THREAD_INFO(r9, r1)
  157. lwz r9,TI_CPU(r9)
  158. slwi r9,r9,3
  159. add r11,r11,r9
  160. #endif
  161. lwz r12,0(r11)
  162. mtspr SPRN_DBCR0,r12
  163. lwz r12,4(r11)
  164. addi r12,r12,-1
  165. stw r12,4(r11)
  166. #endif
  167. b 3f
  168. 2: /* if from kernel, check interrupted DOZE/NAP mode and
  169. * check for stack overflow
  170. */
  171. lwz r9,KSP_LIMIT(r12)
  172. cmplw r1,r9 /* if r1 <= ksp_limit */
  173. ble- stack_ovf /* then the kernel stack overflowed */
  174. 5:
  175. #if defined(CONFIG_6xx) || defined(CONFIG_E500)
  176. CURRENT_THREAD_INFO(r9, r1)
  177. tophys(r9,r9) /* check local flags */
  178. lwz r12,TI_LOCAL_FLAGS(r9)
  179. mtcrf 0x01,r12
  180. bt- 31-TLF_NAPPING,4f
  181. bt- 31-TLF_SLEEPING,7f
  182. #endif /* CONFIG_6xx || CONFIG_E500 */
  183. .globl transfer_to_handler_cont
  184. transfer_to_handler_cont:
  185. 3:
  186. mflr r9
  187. lwz r11,0(r9) /* virtual address of handler */
  188. lwz r9,4(r9) /* where to go when done */
  189. #ifdef CONFIG_TRACE_IRQFLAGS
  190. lis r12,reenable_mmu@h
  191. ori r12,r12,reenable_mmu@l
  192. mtspr SPRN_SRR0,r12
  193. mtspr SPRN_SRR1,r10
  194. SYNC
  195. RFI
  196. reenable_mmu: /* re-enable mmu so we can */
  197. mfmsr r10
  198. lwz r12,_MSR(r1)
  199. xor r10,r10,r12
  200. andi. r10,r10,MSR_EE /* Did EE change? */
  201. beq 1f
  202. /*
  203. * The trace_hardirqs_off will use CALLER_ADDR0 and CALLER_ADDR1.
  204. * If from user mode there is only one stack frame on the stack, and
  205. * accessing CALLER_ADDR1 will cause oops. So we need create a dummy
  206. * stack frame to make trace_hardirqs_off happy.
  207. *
  208. * This is handy because we also need to save a bunch of GPRs,
  209. * r3 can be different from GPR3(r1) at this point, r9 and r11
  210. * contains the old MSR and handler address respectively,
  211. * r4 & r5 can contain page fault arguments that need to be passed
  212. * along as well. r12, CCR, CTR, XER etc... are left clobbered as
  213. * they aren't useful past this point (aren't syscall arguments),
  214. * the rest is restored from the exception frame.
  215. */
  216. stwu r1,-32(r1)
  217. stw r9,8(r1)
  218. stw r11,12(r1)
  219. stw r3,16(r1)
  220. stw r4,20(r1)
  221. stw r5,24(r1)
  222. bl trace_hardirqs_off
  223. lwz r5,24(r1)
  224. lwz r4,20(r1)
  225. lwz r3,16(r1)
  226. lwz r11,12(r1)
  227. lwz r9,8(r1)
  228. addi r1,r1,32
  229. lwz r0,GPR0(r1)
  230. lwz r6,GPR6(r1)
  231. lwz r7,GPR7(r1)
  232. lwz r8,GPR8(r1)
  233. 1: mtctr r11
  234. mtlr r9
  235. bctr /* jump to handler */
  236. #else /* CONFIG_TRACE_IRQFLAGS */
  237. mtspr SPRN_SRR0,r11
  238. mtspr SPRN_SRR1,r10
  239. mtlr r9
  240. SYNC
  241. RFI /* jump to handler, enable MMU */
  242. #endif /* CONFIG_TRACE_IRQFLAGS */
  243. #if defined (CONFIG_6xx) || defined(CONFIG_E500)
  244. 4: rlwinm r12,r12,0,~_TLF_NAPPING
  245. stw r12,TI_LOCAL_FLAGS(r9)
  246. b power_save_ppc32_restore
  247. 7: rlwinm r12,r12,0,~_TLF_SLEEPING
  248. stw r12,TI_LOCAL_FLAGS(r9)
  249. lwz r9,_MSR(r11) /* if sleeping, clear MSR.EE */
  250. rlwinm r9,r9,0,~MSR_EE
  251. lwz r12,_LINK(r11) /* and return to address in LR */
  252. b fast_exception_return
  253. #endif
  254. /*
  255. * On kernel stack overflow, load up an initial stack pointer
  256. * and call StackOverflow(regs), which should not return.
  257. */
  258. stack_ovf:
  259. /* sometimes we use a statically-allocated stack, which is OK. */
  260. lis r12,_end@h
  261. ori r12,r12,_end@l
  262. cmplw r1,r12
  263. ble 5b /* r1 <= &_end is OK */
  264. SAVE_NVGPRS(r11)
  265. addi r3,r1,STACK_FRAME_OVERHEAD
  266. lis r1,init_thread_union@ha
  267. addi r1,r1,init_thread_union@l
  268. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  269. lis r9,StackOverflow@ha
  270. addi r9,r9,StackOverflow@l
  271. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  272. FIX_SRR1(r10,r12)
  273. mtspr SPRN_SRR0,r9
  274. mtspr SPRN_SRR1,r10
  275. SYNC
  276. RFI
  277. /*
  278. * Handle a system call.
  279. */
  280. .stabs "arch/powerpc/kernel/",N_SO,0,0,0f
  281. .stabs "entry_32.S",N_SO,0,0,0f
  282. 0:
  283. _GLOBAL(DoSyscall)
  284. stw r3,ORIG_GPR3(r1)
  285. li r12,0
  286. stw r12,RESULT(r1)
  287. lwz r11,_CCR(r1) /* Clear SO bit in CR */
  288. rlwinm r11,r11,0,4,2
  289. stw r11,_CCR(r1)
  290. #ifdef CONFIG_TRACE_IRQFLAGS
  291. /* Return from syscalls can (and generally will) hard enable
  292. * interrupts. You aren't supposed to call a syscall with
  293. * interrupts disabled in the first place. However, to ensure
  294. * that we get it right vs. lockdep if it happens, we force
  295. * that hard enable here with appropriate tracing if we see
  296. * that we have been called with interrupts off
  297. */
  298. mfmsr r11
  299. andi. r12,r11,MSR_EE
  300. bne+ 1f
  301. /* We came in with interrupts disabled, we enable them now */
  302. bl trace_hardirqs_on
  303. mfmsr r11
  304. lwz r0,GPR0(r1)
  305. lwz r3,GPR3(r1)
  306. lwz r4,GPR4(r1)
  307. ori r11,r11,MSR_EE
  308. lwz r5,GPR5(r1)
  309. lwz r6,GPR6(r1)
  310. lwz r7,GPR7(r1)
  311. lwz r8,GPR8(r1)
  312. mtmsr r11
  313. 1:
  314. #endif /* CONFIG_TRACE_IRQFLAGS */
  315. CURRENT_THREAD_INFO(r10, r1)
  316. lwz r11,TI_FLAGS(r10)
  317. andi. r11,r11,_TIF_SYSCALL_DOTRACE
  318. bne- syscall_dotrace
  319. syscall_dotrace_cont:
  320. cmplwi 0,r0,NR_syscalls
  321. lis r10,sys_call_table@h
  322. ori r10,r10,sys_call_table@l
  323. slwi r0,r0,2
  324. bge- 66f
  325. lwzx r10,r10,r0 /* Fetch system call handler [ptr] */
  326. mtlr r10
  327. addi r9,r1,STACK_FRAME_OVERHEAD
  328. PPC440EP_ERR42
  329. blrl /* Call handler */
  330. .globl ret_from_syscall
  331. ret_from_syscall:
  332. mr r6,r3
  333. CURRENT_THREAD_INFO(r12, r1)
  334. /* disable interrupts so current_thread_info()->flags can't change */
  335. LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
  336. /* Note: We don't bother telling lockdep about it */
  337. SYNC
  338. MTMSRD(r10)
  339. lwz r9,TI_FLAGS(r12)
  340. li r8,-_LAST_ERRNO
  341. andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
  342. bne- syscall_exit_work
  343. cmplw 0,r3,r8
  344. blt+ syscall_exit_cont
  345. lwz r11,_CCR(r1) /* Load CR */
  346. neg r3,r3
  347. oris r11,r11,0x1000 /* Set SO bit in CR */
  348. stw r11,_CCR(r1)
  349. syscall_exit_cont:
  350. lwz r8,_MSR(r1)
  351. #ifdef CONFIG_TRACE_IRQFLAGS
  352. /* If we are going to return from the syscall with interrupts
  353. * off, we trace that here. It shouldn't happen though but we
  354. * want to catch the bugger if it does right ?
  355. */
  356. andi. r10,r8,MSR_EE
  357. bne+ 1f
  358. stw r3,GPR3(r1)
  359. bl trace_hardirqs_off
  360. lwz r3,GPR3(r1)
  361. 1:
  362. #endif /* CONFIG_TRACE_IRQFLAGS */
  363. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  364. /* If the process has its own DBCR0 value, load it up. The internal
  365. debug mode bit tells us that dbcr0 should be loaded. */
  366. lwz r0,THREAD+THREAD_DBCR0(r2)
  367. andis. r10,r0,DBCR0_IDM@h
  368. bnel- load_dbcr0
  369. #endif
  370. #ifdef CONFIG_44x
  371. BEGIN_MMU_FTR_SECTION
  372. lis r4,icache_44x_need_flush@ha
  373. lwz r5,icache_44x_need_flush@l(r4)
  374. cmplwi cr0,r5,0
  375. bne- 2f
  376. 1:
  377. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_47x)
  378. #endif /* CONFIG_44x */
  379. BEGIN_FTR_SECTION
  380. lwarx r7,0,r1
  381. END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
  382. stwcx. r0,0,r1 /* to clear the reservation */
  383. lwz r4,_LINK(r1)
  384. lwz r5,_CCR(r1)
  385. mtlr r4
  386. mtcr r5
  387. lwz r7,_NIP(r1)
  388. FIX_SRR1(r8, r0)
  389. lwz r2,GPR2(r1)
  390. lwz r1,GPR1(r1)
  391. mtspr SPRN_SRR0,r7
  392. mtspr SPRN_SRR1,r8
  393. SYNC
  394. RFI
  395. #ifdef CONFIG_44x
  396. 2: li r7,0
  397. iccci r0,r0
  398. stw r7,icache_44x_need_flush@l(r4)
  399. b 1b
  400. #endif /* CONFIG_44x */
  401. 66: li r3,-ENOSYS
  402. b ret_from_syscall
  403. .globl ret_from_fork
  404. ret_from_fork:
  405. REST_NVGPRS(r1)
  406. bl schedule_tail
  407. li r3,0
  408. b ret_from_syscall
  409. .globl ret_from_kernel_thread
  410. ret_from_kernel_thread:
  411. REST_NVGPRS(r1)
  412. bl schedule_tail
  413. mtlr r14
  414. mr r3,r15
  415. PPC440EP_ERR42
  416. blrl
  417. li r3,0
  418. b ret_from_syscall
  419. /* Traced system call support */
  420. syscall_dotrace:
  421. SAVE_NVGPRS(r1)
  422. li r0,0xc00
  423. stw r0,_TRAP(r1)
  424. addi r3,r1,STACK_FRAME_OVERHEAD
  425. bl do_syscall_trace_enter
  426. /*
  427. * Restore argument registers possibly just changed.
  428. * We use the return value of do_syscall_trace_enter
  429. * for call number to look up in the table (r0).
  430. */
  431. mr r0,r3
  432. lwz r3,GPR3(r1)
  433. lwz r4,GPR4(r1)
  434. lwz r5,GPR5(r1)
  435. lwz r6,GPR6(r1)
  436. lwz r7,GPR7(r1)
  437. lwz r8,GPR8(r1)
  438. REST_NVGPRS(r1)
  439. b syscall_dotrace_cont
  440. syscall_exit_work:
  441. andi. r0,r9,_TIF_RESTOREALL
  442. beq+ 0f
  443. REST_NVGPRS(r1)
  444. b 2f
  445. 0: cmplw 0,r3,r8
  446. blt+ 1f
  447. andi. r0,r9,_TIF_NOERROR
  448. bne- 1f
  449. lwz r11,_CCR(r1) /* Load CR */
  450. neg r3,r3
  451. oris r11,r11,0x1000 /* Set SO bit in CR */
  452. stw r11,_CCR(r1)
  453. 1: stw r6,RESULT(r1) /* Save result */
  454. stw r3,GPR3(r1) /* Update return value */
  455. 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
  456. beq 4f
  457. /* Clear per-syscall TIF flags if any are set. */
  458. li r11,_TIF_PERSYSCALL_MASK
  459. addi r12,r12,TI_FLAGS
  460. 3: lwarx r8,0,r12
  461. andc r8,r8,r11
  462. #ifdef CONFIG_IBM405_ERR77
  463. dcbt 0,r12
  464. #endif
  465. stwcx. r8,0,r12
  466. bne- 3b
  467. subi r12,r12,TI_FLAGS
  468. 4: /* Anything which requires enabling interrupts? */
  469. andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
  470. beq ret_from_except
  471. /* Re-enable interrupts. There is no need to trace that with
  472. * lockdep as we are supposed to have IRQs on at this point
  473. */
  474. ori r10,r10,MSR_EE
  475. SYNC
  476. MTMSRD(r10)
  477. /* Save NVGPRS if they're not saved already */
  478. lwz r4,_TRAP(r1)
  479. andi. r4,r4,1
  480. beq 5f
  481. SAVE_NVGPRS(r1)
  482. li r4,0xc00
  483. stw r4,_TRAP(r1)
  484. 5:
  485. addi r3,r1,STACK_FRAME_OVERHEAD
  486. bl do_syscall_trace_leave
  487. b ret_from_except_full
  488. /*
  489. * The fork/clone functions need to copy the full register set into
  490. * the child process. Therefore we need to save all the nonvolatile
  491. * registers (r13 - r31) before calling the C code.
  492. */
  493. .globl ppc_fork
  494. ppc_fork:
  495. SAVE_NVGPRS(r1)
  496. lwz r0,_TRAP(r1)
  497. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  498. stw r0,_TRAP(r1) /* register set saved */
  499. b sys_fork
  500. .globl ppc_vfork
  501. ppc_vfork:
  502. SAVE_NVGPRS(r1)
  503. lwz r0,_TRAP(r1)
  504. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  505. stw r0,_TRAP(r1) /* register set saved */
  506. b sys_vfork
  507. .globl ppc_clone
  508. ppc_clone:
  509. SAVE_NVGPRS(r1)
  510. lwz r0,_TRAP(r1)
  511. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  512. stw r0,_TRAP(r1) /* register set saved */
  513. b sys_clone
  514. .globl ppc_swapcontext
  515. ppc_swapcontext:
  516. SAVE_NVGPRS(r1)
  517. lwz r0,_TRAP(r1)
  518. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  519. stw r0,_TRAP(r1) /* register set saved */
  520. b sys_swapcontext
  521. /*
  522. * Top-level page fault handling.
  523. * This is in assembler because if do_page_fault tells us that
  524. * it is a bad kernel page fault, we want to save the non-volatile
  525. * registers before calling bad_page_fault.
  526. */
  527. .globl handle_page_fault
  528. handle_page_fault:
  529. stw r4,_DAR(r1)
  530. addi r3,r1,STACK_FRAME_OVERHEAD
  531. bl do_page_fault
  532. cmpwi r3,0
  533. beq+ ret_from_except
  534. SAVE_NVGPRS(r1)
  535. lwz r0,_TRAP(r1)
  536. clrrwi r0,r0,1
  537. stw r0,_TRAP(r1)
  538. mr r5,r3
  539. addi r3,r1,STACK_FRAME_OVERHEAD
  540. lwz r4,_DAR(r1)
  541. bl bad_page_fault
  542. b ret_from_except_full
  543. /*
  544. * This routine switches between two different tasks. The process
  545. * state of one is saved on its kernel stack. Then the state
  546. * of the other is restored from its kernel stack. The memory
  547. * management hardware is updated to the second process's state.
  548. * Finally, we can return to the second process.
  549. * On entry, r3 points to the THREAD for the current task, r4
  550. * points to the THREAD for the new task.
  551. *
  552. * This routine is always called with interrupts disabled.
  553. *
  554. * Note: there are two ways to get to the "going out" portion
  555. * of this code; either by coming in via the entry (_switch)
  556. * or via "fork" which must set up an environment equivalent
  557. * to the "_switch" path. If you change this , you'll have to
  558. * change the fork code also.
  559. *
  560. * The code which creates the new task context is in 'copy_thread'
  561. * in arch/ppc/kernel/process.c
  562. */
  563. _GLOBAL(_switch)
  564. stwu r1,-INT_FRAME_SIZE(r1)
  565. mflr r0
  566. stw r0,INT_FRAME_SIZE+4(r1)
  567. /* r3-r12 are caller saved -- Cort */
  568. SAVE_NVGPRS(r1)
  569. stw r0,_NIP(r1) /* Return to switch caller */
  570. mfmsr r11
  571. li r0,MSR_FP /* Disable floating-point */
  572. #ifdef CONFIG_ALTIVEC
  573. BEGIN_FTR_SECTION
  574. oris r0,r0,MSR_VEC@h /* Disable altivec */
  575. mfspr r12,SPRN_VRSAVE /* save vrsave register value */
  576. stw r12,THREAD+THREAD_VRSAVE(r2)
  577. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  578. #endif /* CONFIG_ALTIVEC */
  579. #ifdef CONFIG_SPE
  580. BEGIN_FTR_SECTION
  581. oris r0,r0,MSR_SPE@h /* Disable SPE */
  582. mfspr r12,SPRN_SPEFSCR /* save spefscr register value */
  583. stw r12,THREAD+THREAD_SPEFSCR(r2)
  584. END_FTR_SECTION_IFSET(CPU_FTR_SPE)
  585. #endif /* CONFIG_SPE */
  586. and. r0,r0,r11 /* FP or altivec or SPE enabled? */
  587. beq+ 1f
  588. andc r11,r11,r0
  589. MTMSRD(r11)
  590. isync
  591. 1: stw r11,_MSR(r1)
  592. mfcr r10
  593. stw r10,_CCR(r1)
  594. stw r1,KSP(r3) /* Set old stack pointer */
  595. #ifdef CONFIG_SMP
  596. /* We need a sync somewhere here to make sure that if the
  597. * previous task gets rescheduled on another CPU, it sees all
  598. * stores it has performed on this one.
  599. */
  600. sync
  601. #endif /* CONFIG_SMP */
  602. tophys(r0,r4)
  603. CLR_TOP32(r0)
  604. mtspr SPRN_SPRG_THREAD,r0 /* Update current THREAD phys addr */
  605. lwz r1,KSP(r4) /* Load new stack pointer */
  606. /* save the old current 'last' for return value */
  607. mr r3,r2
  608. addi r2,r4,-THREAD /* Update current */
  609. #ifdef CONFIG_ALTIVEC
  610. BEGIN_FTR_SECTION
  611. lwz r0,THREAD+THREAD_VRSAVE(r2)
  612. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  613. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  614. #endif /* CONFIG_ALTIVEC */
  615. #ifdef CONFIG_SPE
  616. BEGIN_FTR_SECTION
  617. lwz r0,THREAD+THREAD_SPEFSCR(r2)
  618. mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */
  619. END_FTR_SECTION_IFSET(CPU_FTR_SPE)
  620. #endif /* CONFIG_SPE */
  621. lwz r0,_CCR(r1)
  622. mtcrf 0xFF,r0
  623. /* r3-r12 are destroyed -- Cort */
  624. REST_NVGPRS(r1)
  625. lwz r4,_NIP(r1) /* Return to _switch caller in new task */
  626. mtlr r4
  627. addi r1,r1,INT_FRAME_SIZE
  628. blr
  629. .globl fast_exception_return
  630. fast_exception_return:
  631. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  632. andi. r10,r9,MSR_RI /* check for recoverable interrupt */
  633. beq 1f /* if not, we've got problems */
  634. #endif
  635. 2: REST_4GPRS(3, r11)
  636. lwz r10,_CCR(r11)
  637. REST_GPR(1, r11)
  638. mtcr r10
  639. lwz r10,_LINK(r11)
  640. mtlr r10
  641. REST_GPR(10, r11)
  642. mtspr SPRN_SRR1,r9
  643. mtspr SPRN_SRR0,r12
  644. REST_GPR(9, r11)
  645. REST_GPR(12, r11)
  646. lwz r11,GPR11(r11)
  647. SYNC
  648. RFI
  649. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  650. /* check if the exception happened in a restartable section */
  651. 1: lis r3,exc_exit_restart_end@ha
  652. addi r3,r3,exc_exit_restart_end@l
  653. cmplw r12,r3
  654. bge 3f
  655. lis r4,exc_exit_restart@ha
  656. addi r4,r4,exc_exit_restart@l
  657. cmplw r12,r4
  658. blt 3f
  659. lis r3,fee_restarts@ha
  660. tophys(r3,r3)
  661. lwz r5,fee_restarts@l(r3)
  662. addi r5,r5,1
  663. stw r5,fee_restarts@l(r3)
  664. mr r12,r4 /* restart at exc_exit_restart */
  665. b 2b
  666. .section .bss
  667. .align 2
  668. fee_restarts:
  669. .space 4
  670. .previous
  671. /* aargh, a nonrecoverable interrupt, panic */
  672. /* aargh, we don't know which trap this is */
  673. /* but the 601 doesn't implement the RI bit, so assume it's OK */
  674. 3:
  675. BEGIN_FTR_SECTION
  676. b 2b
  677. END_FTR_SECTION_IFSET(CPU_FTR_601)
  678. li r10,-1
  679. stw r10,_TRAP(r11)
  680. addi r3,r1,STACK_FRAME_OVERHEAD
  681. lis r10,MSR_KERNEL@h
  682. ori r10,r10,MSR_KERNEL@l
  683. bl transfer_to_handler_full
  684. .long nonrecoverable_exception
  685. .long ret_from_except
  686. #endif
  687. .globl ret_from_except_full
  688. ret_from_except_full:
  689. REST_NVGPRS(r1)
  690. /* fall through */
  691. .globl ret_from_except
  692. ret_from_except:
  693. /* Hard-disable interrupts so that current_thread_info()->flags
  694. * can't change between when we test it and when we return
  695. * from the interrupt. */
  696. /* Note: We don't bother telling lockdep about it */
  697. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  698. SYNC /* Some chip revs have problems here... */
  699. MTMSRD(r10) /* disable interrupts */
  700. lwz r3,_MSR(r1) /* Returning to user mode? */
  701. andi. r0,r3,MSR_PR
  702. beq resume_kernel
  703. user_exc_return: /* r10 contains MSR_KERNEL here */
  704. /* Check current_thread_info()->flags */
  705. CURRENT_THREAD_INFO(r9, r1)
  706. lwz r9,TI_FLAGS(r9)
  707. andi. r0,r9,_TIF_USER_WORK_MASK
  708. bne do_work
  709. restore_user:
  710. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  711. /* Check whether this process has its own DBCR0 value. The internal
  712. debug mode bit tells us that dbcr0 should be loaded. */
  713. lwz r0,THREAD+THREAD_DBCR0(r2)
  714. andis. r10,r0,DBCR0_IDM@h
  715. bnel- load_dbcr0
  716. #endif
  717. b restore
  718. /* N.B. the only way to get here is from the beq following ret_from_except. */
  719. resume_kernel:
  720. /* check current_thread_info, _TIF_EMULATE_STACK_STORE */
  721. CURRENT_THREAD_INFO(r9, r1)
  722. lwz r8,TI_FLAGS(r9)
  723. andis. r0,r8,_TIF_EMULATE_STACK_STORE@h
  724. beq+ 1f
  725. addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
  726. lwz r3,GPR1(r1)
  727. subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
  728. mr r4,r1 /* src: current exception frame */
  729. mr r1,r3 /* Reroute the trampoline frame to r1 */
  730. /* Copy from the original to the trampoline. */
  731. li r5,INT_FRAME_SIZE/4 /* size: INT_FRAME_SIZE */
  732. li r6,0 /* start offset: 0 */
  733. mtctr r5
  734. 2: lwzx r0,r6,r4
  735. stwx r0,r6,r3
  736. addi r6,r6,4
  737. bdnz 2b
  738. /* Do real store operation to complete stwu */
  739. lwz r5,GPR1(r1)
  740. stw r8,0(r5)
  741. /* Clear _TIF_EMULATE_STACK_STORE flag */
  742. lis r11,_TIF_EMULATE_STACK_STORE@h
  743. addi r5,r9,TI_FLAGS
  744. 0: lwarx r8,0,r5
  745. andc r8,r8,r11
  746. #ifdef CONFIG_IBM405_ERR77
  747. dcbt 0,r5
  748. #endif
  749. stwcx. r8,0,r5
  750. bne- 0b
  751. 1:
  752. #ifdef CONFIG_PREEMPT
  753. /* check current_thread_info->preempt_count */
  754. lwz r0,TI_PREEMPT(r9)
  755. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  756. bne restore
  757. andi. r8,r8,_TIF_NEED_RESCHED
  758. beq+ restore
  759. lwz r3,_MSR(r1)
  760. andi. r0,r3,MSR_EE /* interrupts off? */
  761. beq restore /* don't schedule if so */
  762. #ifdef CONFIG_TRACE_IRQFLAGS
  763. /* Lockdep thinks irqs are enabled, we need to call
  764. * preempt_schedule_irq with IRQs off, so we inform lockdep
  765. * now that we -did- turn them off already
  766. */
  767. bl trace_hardirqs_off
  768. #endif
  769. 1: bl preempt_schedule_irq
  770. CURRENT_THREAD_INFO(r9, r1)
  771. lwz r3,TI_FLAGS(r9)
  772. andi. r0,r3,_TIF_NEED_RESCHED
  773. bne- 1b
  774. #ifdef CONFIG_TRACE_IRQFLAGS
  775. /* And now, to properly rebalance the above, we tell lockdep they
  776. * are being turned back on, which will happen when we return
  777. */
  778. bl trace_hardirqs_on
  779. #endif
  780. #endif /* CONFIG_PREEMPT */
  781. /* interrupts are hard-disabled at this point */
  782. restore:
  783. #ifdef CONFIG_44x
  784. BEGIN_MMU_FTR_SECTION
  785. b 1f
  786. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
  787. lis r4,icache_44x_need_flush@ha
  788. lwz r5,icache_44x_need_flush@l(r4)
  789. cmplwi cr0,r5,0
  790. beq+ 1f
  791. li r6,0
  792. iccci r0,r0
  793. stw r6,icache_44x_need_flush@l(r4)
  794. 1:
  795. #endif /* CONFIG_44x */
  796. lwz r9,_MSR(r1)
  797. #ifdef CONFIG_TRACE_IRQFLAGS
  798. /* Lockdep doesn't know about the fact that IRQs are temporarily turned
  799. * off in this assembly code while peeking at TI_FLAGS() and such. However
  800. * we need to inform it if the exception turned interrupts off, and we
  801. * are about to trun them back on.
  802. *
  803. * The problem here sadly is that we don't know whether the exceptions was
  804. * one that turned interrupts off or not. So we always tell lockdep about
  805. * turning them on here when we go back to wherever we came from with EE
  806. * on, even if that may meen some redudant calls being tracked. Maybe later
  807. * we could encode what the exception did somewhere or test the exception
  808. * type in the pt_regs but that sounds overkill
  809. */
  810. andi. r10,r9,MSR_EE
  811. beq 1f
  812. /*
  813. * Since the ftrace irqsoff latency trace checks CALLER_ADDR1,
  814. * which is the stack frame here, we need to force a stack frame
  815. * in case we came from user space.
  816. */
  817. stwu r1,-32(r1)
  818. mflr r0
  819. stw r0,4(r1)
  820. stwu r1,-32(r1)
  821. bl trace_hardirqs_on
  822. lwz r1,0(r1)
  823. lwz r1,0(r1)
  824. lwz r9,_MSR(r1)
  825. 1:
  826. #endif /* CONFIG_TRACE_IRQFLAGS */
  827. lwz r0,GPR0(r1)
  828. lwz r2,GPR2(r1)
  829. REST_4GPRS(3, r1)
  830. REST_2GPRS(7, r1)
  831. lwz r10,_XER(r1)
  832. lwz r11,_CTR(r1)
  833. mtspr SPRN_XER,r10
  834. mtctr r11
  835. PPC405_ERR77(0,r1)
  836. BEGIN_FTR_SECTION
  837. lwarx r11,0,r1
  838. END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
  839. stwcx. r0,0,r1 /* to clear the reservation */
  840. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  841. andi. r10,r9,MSR_RI /* check if this exception occurred */
  842. beql nonrecoverable /* at a bad place (MSR:RI = 0) */
  843. lwz r10,_CCR(r1)
  844. lwz r11,_LINK(r1)
  845. mtcrf 0xFF,r10
  846. mtlr r11
  847. /*
  848. * Once we put values in SRR0 and SRR1, we are in a state
  849. * where exceptions are not recoverable, since taking an
  850. * exception will trash SRR0 and SRR1. Therefore we clear the
  851. * MSR:RI bit to indicate this. If we do take an exception,
  852. * we can't return to the point of the exception but we
  853. * can restart the exception exit path at the label
  854. * exc_exit_restart below. -- paulus
  855. */
  856. LOAD_MSR_KERNEL(r10,MSR_KERNEL & ~MSR_RI)
  857. SYNC
  858. MTMSRD(r10) /* clear the RI bit */
  859. .globl exc_exit_restart
  860. exc_exit_restart:
  861. lwz r12,_NIP(r1)
  862. FIX_SRR1(r9,r10)
  863. mtspr SPRN_SRR0,r12
  864. mtspr SPRN_SRR1,r9
  865. REST_4GPRS(9, r1)
  866. lwz r1,GPR1(r1)
  867. .globl exc_exit_restart_end
  868. exc_exit_restart_end:
  869. SYNC
  870. RFI
  871. #else /* !(CONFIG_4xx || CONFIG_BOOKE) */
  872. /*
  873. * This is a bit different on 4xx/Book-E because it doesn't have
  874. * the RI bit in the MSR.
  875. * The TLB miss handler checks if we have interrupted
  876. * the exception exit path and restarts it if so
  877. * (well maybe one day it will... :).
  878. */
  879. lwz r11,_LINK(r1)
  880. mtlr r11
  881. lwz r10,_CCR(r1)
  882. mtcrf 0xff,r10
  883. REST_2GPRS(9, r1)
  884. .globl exc_exit_restart
  885. exc_exit_restart:
  886. lwz r11,_NIP(r1)
  887. lwz r12,_MSR(r1)
  888. exc_exit_start:
  889. mtspr SPRN_SRR0,r11
  890. mtspr SPRN_SRR1,r12
  891. REST_2GPRS(11, r1)
  892. lwz r1,GPR1(r1)
  893. .globl exc_exit_restart_end
  894. exc_exit_restart_end:
  895. PPC405_ERR77_SYNC
  896. rfi
  897. b . /* prevent prefetch past rfi */
  898. /*
  899. * Returning from a critical interrupt in user mode doesn't need
  900. * to be any different from a normal exception. For a critical
  901. * interrupt in the kernel, we just return (without checking for
  902. * preemption) since the interrupt may have happened at some crucial
  903. * place (e.g. inside the TLB miss handler), and because we will be
  904. * running with r1 pointing into critical_stack, not the current
  905. * process's kernel stack (and therefore current_thread_info() will
  906. * give the wrong answer).
  907. * We have to restore various SPRs that may have been in use at the
  908. * time of the critical interrupt.
  909. *
  910. */
  911. #ifdef CONFIG_40x
  912. #define PPC_40x_TURN_OFF_MSR_DR \
  913. /* avoid any possible TLB misses here by turning off MSR.DR, we \
  914. * assume the instructions here are mapped by a pinned TLB entry */ \
  915. li r10,MSR_IR; \
  916. mtmsr r10; \
  917. isync; \
  918. tophys(r1, r1);
  919. #else
  920. #define PPC_40x_TURN_OFF_MSR_DR
  921. #endif
  922. #define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \
  923. REST_NVGPRS(r1); \
  924. lwz r3,_MSR(r1); \
  925. andi. r3,r3,MSR_PR; \
  926. LOAD_MSR_KERNEL(r10,MSR_KERNEL); \
  927. bne user_exc_return; \
  928. lwz r0,GPR0(r1); \
  929. lwz r2,GPR2(r1); \
  930. REST_4GPRS(3, r1); \
  931. REST_2GPRS(7, r1); \
  932. lwz r10,_XER(r1); \
  933. lwz r11,_CTR(r1); \
  934. mtspr SPRN_XER,r10; \
  935. mtctr r11; \
  936. PPC405_ERR77(0,r1); \
  937. stwcx. r0,0,r1; /* to clear the reservation */ \
  938. lwz r11,_LINK(r1); \
  939. mtlr r11; \
  940. lwz r10,_CCR(r1); \
  941. mtcrf 0xff,r10; \
  942. PPC_40x_TURN_OFF_MSR_DR; \
  943. lwz r9,_DEAR(r1); \
  944. lwz r10,_ESR(r1); \
  945. mtspr SPRN_DEAR,r9; \
  946. mtspr SPRN_ESR,r10; \
  947. lwz r11,_NIP(r1); \
  948. lwz r12,_MSR(r1); \
  949. mtspr exc_lvl_srr0,r11; \
  950. mtspr exc_lvl_srr1,r12; \
  951. lwz r9,GPR9(r1); \
  952. lwz r12,GPR12(r1); \
  953. lwz r10,GPR10(r1); \
  954. lwz r11,GPR11(r1); \
  955. lwz r1,GPR1(r1); \
  956. PPC405_ERR77_SYNC; \
  957. exc_lvl_rfi; \
  958. b .; /* prevent prefetch past exc_lvl_rfi */
  959. #define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \
  960. lwz r9,_##exc_lvl_srr0(r1); \
  961. lwz r10,_##exc_lvl_srr1(r1); \
  962. mtspr SPRN_##exc_lvl_srr0,r9; \
  963. mtspr SPRN_##exc_lvl_srr1,r10;
  964. #if defined(CONFIG_PPC_BOOK3E_MMU)
  965. #ifdef CONFIG_PHYS_64BIT
  966. #define RESTORE_MAS7 \
  967. lwz r11,MAS7(r1); \
  968. mtspr SPRN_MAS7,r11;
  969. #else
  970. #define RESTORE_MAS7
  971. #endif /* CONFIG_PHYS_64BIT */
  972. #define RESTORE_MMU_REGS \
  973. lwz r9,MAS0(r1); \
  974. lwz r10,MAS1(r1); \
  975. lwz r11,MAS2(r1); \
  976. mtspr SPRN_MAS0,r9; \
  977. lwz r9,MAS3(r1); \
  978. mtspr SPRN_MAS1,r10; \
  979. lwz r10,MAS6(r1); \
  980. mtspr SPRN_MAS2,r11; \
  981. mtspr SPRN_MAS3,r9; \
  982. mtspr SPRN_MAS6,r10; \
  983. RESTORE_MAS7;
  984. #elif defined(CONFIG_44x)
  985. #define RESTORE_MMU_REGS \
  986. lwz r9,MMUCR(r1); \
  987. mtspr SPRN_MMUCR,r9;
  988. #else
  989. #define RESTORE_MMU_REGS
  990. #endif
  991. #ifdef CONFIG_40x
  992. .globl ret_from_crit_exc
  993. ret_from_crit_exc:
  994. mfspr r9,SPRN_SPRG_THREAD
  995. lis r10,saved_ksp_limit@ha;
  996. lwz r10,saved_ksp_limit@l(r10);
  997. tovirt(r9,r9);
  998. stw r10,KSP_LIMIT(r9)
  999. lis r9,crit_srr0@ha;
  1000. lwz r9,crit_srr0@l(r9);
  1001. lis r10,crit_srr1@ha;
  1002. lwz r10,crit_srr1@l(r10);
  1003. mtspr SPRN_SRR0,r9;
  1004. mtspr SPRN_SRR1,r10;
  1005. RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
  1006. #endif /* CONFIG_40x */
  1007. #ifdef CONFIG_BOOKE
  1008. .globl ret_from_crit_exc
  1009. ret_from_crit_exc:
  1010. mfspr r9,SPRN_SPRG_THREAD
  1011. lwz r10,SAVED_KSP_LIMIT(r1)
  1012. stw r10,KSP_LIMIT(r9)
  1013. RESTORE_xSRR(SRR0,SRR1);
  1014. RESTORE_MMU_REGS;
  1015. RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
  1016. .globl ret_from_debug_exc
  1017. ret_from_debug_exc:
  1018. mfspr r9,SPRN_SPRG_THREAD
  1019. lwz r10,SAVED_KSP_LIMIT(r1)
  1020. stw r10,KSP_LIMIT(r9)
  1021. lwz r9,THREAD_INFO-THREAD(r9)
  1022. CURRENT_THREAD_INFO(r10, r1)
  1023. lwz r10,TI_PREEMPT(r10)
  1024. stw r10,TI_PREEMPT(r9)
  1025. RESTORE_xSRR(SRR0,SRR1);
  1026. RESTORE_xSRR(CSRR0,CSRR1);
  1027. RESTORE_MMU_REGS;
  1028. RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, PPC_RFDI)
  1029. .globl ret_from_mcheck_exc
  1030. ret_from_mcheck_exc:
  1031. mfspr r9,SPRN_SPRG_THREAD
  1032. lwz r10,SAVED_KSP_LIMIT(r1)
  1033. stw r10,KSP_LIMIT(r9)
  1034. RESTORE_xSRR(SRR0,SRR1);
  1035. RESTORE_xSRR(CSRR0,CSRR1);
  1036. RESTORE_xSRR(DSRR0,DSRR1);
  1037. RESTORE_MMU_REGS;
  1038. RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, PPC_RFMCI)
  1039. #endif /* CONFIG_BOOKE */
  1040. /*
  1041. * Load the DBCR0 value for a task that is being ptraced,
  1042. * having first saved away the global DBCR0. Note that r0
  1043. * has the dbcr0 value to set upon entry to this.
  1044. */
  1045. load_dbcr0:
  1046. mfmsr r10 /* first disable debug exceptions */
  1047. rlwinm r10,r10,0,~MSR_DE
  1048. mtmsr r10
  1049. isync
  1050. mfspr r10,SPRN_DBCR0
  1051. lis r11,global_dbcr0@ha
  1052. addi r11,r11,global_dbcr0@l
  1053. #ifdef CONFIG_SMP
  1054. CURRENT_THREAD_INFO(r9, r1)
  1055. lwz r9,TI_CPU(r9)
  1056. slwi r9,r9,3
  1057. add r11,r11,r9
  1058. #endif
  1059. stw r10,0(r11)
  1060. mtspr SPRN_DBCR0,r0
  1061. lwz r10,4(r11)
  1062. addi r10,r10,1
  1063. stw r10,4(r11)
  1064. li r11,-1
  1065. mtspr SPRN_DBSR,r11 /* clear all pending debug events */
  1066. blr
  1067. .section .bss
  1068. .align 4
  1069. global_dbcr0:
  1070. .space 8*NR_CPUS
  1071. .previous
  1072. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  1073. do_work: /* r10 contains MSR_KERNEL here */
  1074. andi. r0,r9,_TIF_NEED_RESCHED
  1075. beq do_user_signal
  1076. do_resched: /* r10 contains MSR_KERNEL here */
  1077. /* Note: We don't need to inform lockdep that we are enabling
  1078. * interrupts here. As far as it knows, they are already enabled
  1079. */
  1080. ori r10,r10,MSR_EE
  1081. SYNC
  1082. MTMSRD(r10) /* hard-enable interrupts */
  1083. bl schedule
  1084. recheck:
  1085. /* Note: And we don't tell it we are disabling them again
  1086. * neither. Those disable/enable cycles used to peek at
  1087. * TI_FLAGS aren't advertised.
  1088. */
  1089. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  1090. SYNC
  1091. MTMSRD(r10) /* disable interrupts */
  1092. CURRENT_THREAD_INFO(r9, r1)
  1093. lwz r9,TI_FLAGS(r9)
  1094. andi. r0,r9,_TIF_NEED_RESCHED
  1095. bne- do_resched
  1096. andi. r0,r9,_TIF_USER_WORK_MASK
  1097. beq restore_user
  1098. do_user_signal: /* r10 contains MSR_KERNEL here */
  1099. ori r10,r10,MSR_EE
  1100. SYNC
  1101. MTMSRD(r10) /* hard-enable interrupts */
  1102. /* save r13-r31 in the exception frame, if not already done */
  1103. lwz r3,_TRAP(r1)
  1104. andi. r0,r3,1
  1105. beq 2f
  1106. SAVE_NVGPRS(r1)
  1107. rlwinm r3,r3,0,0,30
  1108. stw r3,_TRAP(r1)
  1109. 2: addi r3,r1,STACK_FRAME_OVERHEAD
  1110. mr r4,r9
  1111. bl do_notify_resume
  1112. REST_NVGPRS(r1)
  1113. b recheck
  1114. /*
  1115. * We come here when we are at the end of handling an exception
  1116. * that occurred at a place where taking an exception will lose
  1117. * state information, such as the contents of SRR0 and SRR1.
  1118. */
  1119. nonrecoverable:
  1120. lis r10,exc_exit_restart_end@ha
  1121. addi r10,r10,exc_exit_restart_end@l
  1122. cmplw r12,r10
  1123. bge 3f
  1124. lis r11,exc_exit_restart@ha
  1125. addi r11,r11,exc_exit_restart@l
  1126. cmplw r12,r11
  1127. blt 3f
  1128. lis r10,ee_restarts@ha
  1129. lwz r12,ee_restarts@l(r10)
  1130. addi r12,r12,1
  1131. stw r12,ee_restarts@l(r10)
  1132. mr r12,r11 /* restart at exc_exit_restart */
  1133. blr
  1134. 3: /* OK, we can't recover, kill this process */
  1135. /* but the 601 doesn't implement the RI bit, so assume it's OK */
  1136. BEGIN_FTR_SECTION
  1137. blr
  1138. END_FTR_SECTION_IFSET(CPU_FTR_601)
  1139. lwz r3,_TRAP(r1)
  1140. andi. r0,r3,1
  1141. beq 4f
  1142. SAVE_NVGPRS(r1)
  1143. rlwinm r3,r3,0,0,30
  1144. stw r3,_TRAP(r1)
  1145. 4: addi r3,r1,STACK_FRAME_OVERHEAD
  1146. bl nonrecoverable_exception
  1147. /* shouldn't return */
  1148. b 4b
  1149. .section .bss
  1150. .align 2
  1151. ee_restarts:
  1152. .space 4
  1153. .previous
  1154. /*
  1155. * PROM code for specific machines follows. Put it
  1156. * here so it's easy to add arch-specific sections later.
  1157. * -- Cort
  1158. */
  1159. #ifdef CONFIG_PPC_RTAS
  1160. /*
  1161. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  1162. * called with the MMU off.
  1163. */
  1164. _GLOBAL(enter_rtas)
  1165. stwu r1,-INT_FRAME_SIZE(r1)
  1166. mflr r0
  1167. stw r0,INT_FRAME_SIZE+4(r1)
  1168. LOAD_REG_ADDR(r4, rtas)
  1169. lis r6,1f@ha /* physical return address for rtas */
  1170. addi r6,r6,1f@l
  1171. tophys(r6,r6)
  1172. tophys(r7,r1)
  1173. lwz r8,RTASENTRY(r4)
  1174. lwz r4,RTASBASE(r4)
  1175. mfmsr r9
  1176. stw r9,8(r1)
  1177. LOAD_MSR_KERNEL(r0,MSR_KERNEL)
  1178. SYNC /* disable interrupts so SRR0/1 */
  1179. MTMSRD(r0) /* don't get trashed */
  1180. li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  1181. mtlr r6
  1182. mtspr SPRN_SPRG_RTAS,r7
  1183. mtspr SPRN_SRR0,r8
  1184. mtspr SPRN_SRR1,r9
  1185. RFI
  1186. 1: tophys(r9,r1)
  1187. lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
  1188. lwz r9,8(r9) /* original msr value */
  1189. FIX_SRR1(r9,r0)
  1190. addi r1,r1,INT_FRAME_SIZE
  1191. li r0,0
  1192. mtspr SPRN_SPRG_RTAS,r0
  1193. mtspr SPRN_SRR0,r8
  1194. mtspr SPRN_SRR1,r9
  1195. RFI /* return to caller */
  1196. .globl machine_check_in_rtas
  1197. machine_check_in_rtas:
  1198. twi 31,0,0
  1199. /* XXX load up BATs and panic */
  1200. #endif /* CONFIG_PPC_RTAS */
  1201. #ifdef CONFIG_FUNCTION_TRACER
  1202. #ifdef CONFIG_DYNAMIC_FTRACE
  1203. _GLOBAL(mcount)
  1204. _GLOBAL(_mcount)
  1205. /*
  1206. * It is required that _mcount on PPC32 must preserve the
  1207. * link register. But we have r0 to play with. We use r0
  1208. * to push the return address back to the caller of mcount
  1209. * into the ctr register, restore the link register and
  1210. * then jump back using the ctr register.
  1211. */
  1212. mflr r0
  1213. mtctr r0
  1214. lwz r0, 4(r1)
  1215. mtlr r0
  1216. bctr
  1217. _GLOBAL(ftrace_caller)
  1218. MCOUNT_SAVE_FRAME
  1219. /* r3 ends up with link register */
  1220. subi r3, r3, MCOUNT_INSN_SIZE
  1221. .globl ftrace_call
  1222. ftrace_call:
  1223. bl ftrace_stub
  1224. nop
  1225. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1226. .globl ftrace_graph_call
  1227. ftrace_graph_call:
  1228. b ftrace_graph_stub
  1229. _GLOBAL(ftrace_graph_stub)
  1230. #endif
  1231. MCOUNT_RESTORE_FRAME
  1232. /* old link register ends up in ctr reg */
  1233. bctr
  1234. #else
  1235. _GLOBAL(mcount)
  1236. _GLOBAL(_mcount)
  1237. MCOUNT_SAVE_FRAME
  1238. subi r3, r3, MCOUNT_INSN_SIZE
  1239. LOAD_REG_ADDR(r5, ftrace_trace_function)
  1240. lwz r5,0(r5)
  1241. mtctr r5
  1242. bctrl
  1243. nop
  1244. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1245. b ftrace_graph_caller
  1246. #endif
  1247. MCOUNT_RESTORE_FRAME
  1248. bctr
  1249. #endif
  1250. _GLOBAL(ftrace_stub)
  1251. blr
  1252. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1253. _GLOBAL(ftrace_graph_caller)
  1254. /* load r4 with local address */
  1255. lwz r4, 44(r1)
  1256. subi r4, r4, MCOUNT_INSN_SIZE
  1257. /* Grab the LR out of the caller stack frame */
  1258. lwz r3,52(r1)
  1259. bl prepare_ftrace_return
  1260. nop
  1261. /*
  1262. * prepare_ftrace_return gives us the address we divert to.
  1263. * Change the LR in the callers stack frame to this.
  1264. */
  1265. stw r3,52(r1)
  1266. MCOUNT_RESTORE_FRAME
  1267. /* old link register ends up in ctr reg */
  1268. bctr
  1269. _GLOBAL(return_to_handler)
  1270. /* need to save return values */
  1271. stwu r1, -32(r1)
  1272. stw r3, 20(r1)
  1273. stw r4, 16(r1)
  1274. stw r31, 12(r1)
  1275. mr r31, r1
  1276. bl ftrace_return_to_handler
  1277. nop
  1278. /* return value has real return address */
  1279. mtlr r3
  1280. lwz r3, 20(r1)
  1281. lwz r4, 16(r1)
  1282. lwz r31,12(r1)
  1283. lwz r1, 0(r1)
  1284. /* Jump back to real return address */
  1285. blr
  1286. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  1287. #endif /* CONFIG_FUNCTION_TRACER */