entry_32.S 33 KB

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