entry_32.S 35 KB

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