entry_32.S 34 KB

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