entry_32.S 35 KB

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