head_40x.S 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. /*
  2. * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
  3. * Initial PowerPC version.
  4. * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
  5. * Rewritten for PReP
  6. * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
  7. * Low-level exception handers, MMU support, and rewrite.
  8. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  9. * PowerPC 8xx modifications.
  10. * Copyright (c) 1998-1999 TiVo, Inc.
  11. * PowerPC 403GCX modifications.
  12. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  13. * PowerPC 403GCX/405GP modifications.
  14. * Copyright 2000 MontaVista Software Inc.
  15. * PPC405 modifications
  16. * PowerPC 403GCX/405GP modifications.
  17. * Author: MontaVista Software, Inc.
  18. * frank_rowand@mvista.com or source@mvista.com
  19. * debbie_chu@mvista.com
  20. *
  21. *
  22. * Module name: head_4xx.S
  23. *
  24. * Description:
  25. * Kernel execution entry point code.
  26. *
  27. * This program is free software; you can redistribute it and/or
  28. * modify it under the terms of the GNU General Public License
  29. * as published by the Free Software Foundation; either version
  30. * 2 of the License, or (at your option) any later version.
  31. *
  32. */
  33. #include <linux/init.h>
  34. #include <asm/processor.h>
  35. #include <asm/page.h>
  36. #include <asm/mmu.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/cputable.h>
  39. #include <asm/thread_info.h>
  40. #include <asm/ppc_asm.h>
  41. #include <asm/asm-offsets.h>
  42. #include <asm/ptrace.h>
  43. /* As with the other PowerPC ports, it is expected that when code
  44. * execution begins here, the following registers contain valid, yet
  45. * optional, information:
  46. *
  47. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  48. * r4 - Starting address of the init RAM disk
  49. * r5 - Ending address of the init RAM disk
  50. * r6 - Start of kernel command line string (e.g. "mem=96m")
  51. * r7 - End of kernel command line string
  52. *
  53. * This is all going to change RSN when we add bi_recs....... -- Dan
  54. */
  55. __HEAD
  56. _ENTRY(_stext);
  57. _ENTRY(_start);
  58. mr r31,r3 /* save device tree ptr */
  59. /* We have to turn on the MMU right away so we get cache modes
  60. * set correctly.
  61. */
  62. bl initial_mmu
  63. /* We now have the lower 16 Meg mapped into TLB entries, and the caches
  64. * ready to work.
  65. */
  66. turn_on_mmu:
  67. lis r0,MSR_KERNEL@h
  68. ori r0,r0,MSR_KERNEL@l
  69. mtspr SPRN_SRR1,r0
  70. lis r0,start_here@h
  71. ori r0,r0,start_here@l
  72. mtspr SPRN_SRR0,r0
  73. SYNC
  74. rfi /* enables MMU */
  75. b . /* prevent prefetch past rfi */
  76. /*
  77. * This area is used for temporarily saving registers during the
  78. * critical exception prolog.
  79. */
  80. . = 0xc0
  81. crit_save:
  82. _ENTRY(crit_r10)
  83. .space 4
  84. _ENTRY(crit_r11)
  85. .space 4
  86. _ENTRY(crit_srr0)
  87. .space 4
  88. _ENTRY(crit_srr1)
  89. .space 4
  90. _ENTRY(saved_ksp_limit)
  91. .space 4
  92. /*
  93. * Exception vector entry code. This code runs with address translation
  94. * turned off (i.e. using physical addresses). We assume SPRG_THREAD has
  95. * the physical address of the current task thread_struct.
  96. * Note that we have to have decremented r1 before we write to any fields
  97. * of the exception frame, since a critical interrupt could occur at any
  98. * time, and it will write to the area immediately below the current r1.
  99. */
  100. #define NORMAL_EXCEPTION_PROLOG \
  101. mtspr SPRN_SPRG_SCRATCH0,r10; /* save two registers to work with */\
  102. mtspr SPRN_SPRG_SCRATCH1,r11; \
  103. mtspr SPRN_SPRG_SCRATCH2,r1; \
  104. mfcr r10; /* save CR in r10 for now */\
  105. mfspr r11,SPRN_SRR1; /* check whether user or kernel */\
  106. andi. r11,r11,MSR_PR; \
  107. beq 1f; \
  108. mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\
  109. lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\
  110. addi r1,r1,THREAD_SIZE; \
  111. 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\
  112. tophys(r11,r1); \
  113. stw r10,_CCR(r11); /* save various registers */\
  114. stw r12,GPR12(r11); \
  115. stw r9,GPR9(r11); \
  116. mfspr r10,SPRN_SPRG_SCRATCH0; \
  117. stw r10,GPR10(r11); \
  118. mfspr r12,SPRN_SPRG_SCRATCH1; \
  119. stw r12,GPR11(r11); \
  120. mflr r10; \
  121. stw r10,_LINK(r11); \
  122. mfspr r10,SPRN_SPRG_SCRATCH2; \
  123. mfspr r12,SPRN_SRR0; \
  124. stw r10,GPR1(r11); \
  125. mfspr r9,SPRN_SRR1; \
  126. stw r10,0(r11); \
  127. rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
  128. stw r0,GPR0(r11); \
  129. SAVE_4GPRS(3, r11); \
  130. SAVE_2GPRS(7, r11)
  131. /*
  132. * Exception prolog for critical exceptions. This is a little different
  133. * from the normal exception prolog above since a critical exception
  134. * can potentially occur at any point during normal exception processing.
  135. * Thus we cannot use the same SPRG registers as the normal prolog above.
  136. * Instead we use a couple of words of memory at low physical addresses.
  137. * This is OK since we don't support SMP on these processors.
  138. */
  139. #define CRITICAL_EXCEPTION_PROLOG \
  140. stw r10,crit_r10@l(0); /* save two registers to work with */\
  141. stw r11,crit_r11@l(0); \
  142. mfcr r10; /* save CR in r10 for now */\
  143. mfspr r11,SPRN_SRR3; /* check whether user or kernel */\
  144. andi. r11,r11,MSR_PR; \
  145. lis r11,critirq_ctx@ha; \
  146. tophys(r11,r11); \
  147. lwz r11,critirq_ctx@l(r11); \
  148. beq 1f; \
  149. /* COMING FROM USER MODE */ \
  150. mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\
  151. lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
  152. 1: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\
  153. tophys(r11,r11); \
  154. stw r10,_CCR(r11); /* save various registers */\
  155. stw r12,GPR12(r11); \
  156. stw r9,GPR9(r11); \
  157. mflr r10; \
  158. stw r10,_LINK(r11); \
  159. mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
  160. stw r12,_DEAR(r11); /* since they may have had stuff */\
  161. mfspr r9,SPRN_ESR; /* in them at the point where the */\
  162. stw r9,_ESR(r11); /* exception was taken */\
  163. mfspr r12,SPRN_SRR2; \
  164. stw r1,GPR1(r11); \
  165. mfspr r9,SPRN_SRR3; \
  166. stw r1,0(r11); \
  167. tovirt(r1,r11); \
  168. rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
  169. stw r0,GPR0(r11); \
  170. SAVE_4GPRS(3, r11); \
  171. SAVE_2GPRS(7, r11)
  172. /*
  173. * State at this point:
  174. * r9 saved in stack frame, now saved SRR3 & ~MSR_WE
  175. * r10 saved in crit_r10 and in stack frame, trashed
  176. * r11 saved in crit_r11 and in stack frame,
  177. * now phys stack/exception frame pointer
  178. * r12 saved in stack frame, now saved SRR2
  179. * CR saved in stack frame, CR0.EQ = !SRR3.PR
  180. * LR, DEAR, ESR in stack frame
  181. * r1 saved in stack frame, now virt stack/excframe pointer
  182. * r0, r3-r8 saved in stack frame
  183. */
  184. /*
  185. * Exception vectors.
  186. */
  187. #define START_EXCEPTION(n, label) \
  188. . = n; \
  189. label:
  190. #define EXCEPTION(n, label, hdlr, xfer) \
  191. START_EXCEPTION(n, label); \
  192. NORMAL_EXCEPTION_PROLOG; \
  193. addi r3,r1,STACK_FRAME_OVERHEAD; \
  194. xfer(n, hdlr)
  195. #define CRITICAL_EXCEPTION(n, label, hdlr) \
  196. START_EXCEPTION(n, label); \
  197. CRITICAL_EXCEPTION_PROLOG; \
  198. addi r3,r1,STACK_FRAME_OVERHEAD; \
  199. EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  200. NOCOPY, crit_transfer_to_handler, \
  201. ret_from_crit_exc)
  202. #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
  203. li r10,trap; \
  204. stw r10,_TRAP(r11); \
  205. lis r10,msr@h; \
  206. ori r10,r10,msr@l; \
  207. copyee(r10, r9); \
  208. bl tfer; \
  209. .long hdlr; \
  210. .long ret
  211. #define COPY_EE(d, s) rlwimi d,s,0,16,16
  212. #define NOCOPY(d, s)
  213. #define EXC_XFER_STD(n, hdlr) \
  214. EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
  215. ret_from_except_full)
  216. #define EXC_XFER_LITE(n, hdlr) \
  217. EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
  218. ret_from_except)
  219. #define EXC_XFER_EE(n, hdlr) \
  220. EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
  221. ret_from_except_full)
  222. #define EXC_XFER_EE_LITE(n, hdlr) \
  223. EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
  224. ret_from_except)
  225. /*
  226. * 0x0100 - Critical Interrupt Exception
  227. */
  228. CRITICAL_EXCEPTION(0x0100, CriticalInterrupt, unknown_exception)
  229. /*
  230. * 0x0200 - Machine Check Exception
  231. */
  232. CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  233. /*
  234. * 0x0300 - Data Storage Exception
  235. * This happens for just a few reasons. U0 set (but we don't do that),
  236. * or zone protection fault (user violation, write to protected page).
  237. * If this is just an update of modified status, we do that quickly
  238. * and exit. Otherwise, we call heavywight functions to do the work.
  239. */
  240. START_EXCEPTION(0x0300, DataStorage)
  241. mtspr SPRN_SPRG_SCRATCH0, r10 /* Save some working registers */
  242. mtspr SPRN_SPRG_SCRATCH1, r11
  243. #ifdef CONFIG_403GCX
  244. stw r12, 0(r0)
  245. stw r9, 4(r0)
  246. mfcr r11
  247. mfspr r12, SPRN_PID
  248. stw r11, 8(r0)
  249. stw r12, 12(r0)
  250. #else
  251. mtspr SPRN_SPRG_SCRATCH3, r12
  252. mtspr SPRN_SPRG_SCRATCH4, r9
  253. mfcr r11
  254. mfspr r12, SPRN_PID
  255. mtspr SPRN_SPRG_SCRATCH6, r11
  256. mtspr SPRN_SPRG_SCRATCH5, r12
  257. #endif
  258. /* First, check if it was a zone fault (which means a user
  259. * tried to access a kernel or read-protected page - always
  260. * a SEGV). All other faults here must be stores, so no
  261. * need to check ESR_DST as well. */
  262. mfspr r10, SPRN_ESR
  263. andis. r10, r10, ESR_DIZ@h
  264. bne 2f
  265. mfspr r10, SPRN_DEAR /* Get faulting address */
  266. /* If we are faulting a kernel address, we have to use the
  267. * kernel page tables.
  268. */
  269. lis r11, PAGE_OFFSET@h
  270. cmplw r10, r11
  271. blt+ 3f
  272. lis r11, swapper_pg_dir@h
  273. ori r11, r11, swapper_pg_dir@l
  274. li r9, 0
  275. mtspr SPRN_PID, r9 /* TLB will have 0 TID */
  276. b 4f
  277. /* Get the PGD for the current thread.
  278. */
  279. 3:
  280. mfspr r11,SPRN_SPRG_THREAD
  281. lwz r11,PGDIR(r11)
  282. 4:
  283. tophys(r11, r11)
  284. rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */
  285. lwz r11, 0(r11) /* Get L1 entry */
  286. rlwinm. r12, r11, 0, 0, 19 /* Extract L2 (pte) base address */
  287. beq 2f /* Bail if no table */
  288. rlwimi r12, r10, 22, 20, 29 /* Compute PTE address */
  289. lwz r11, 0(r12) /* Get Linux PTE */
  290. andi. r9, r11, _PAGE_RW /* Is it writeable? */
  291. beq 2f /* Bail if not */
  292. /* Update 'changed'.
  293. */
  294. ori r11, r11, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE
  295. stw r11, 0(r12) /* Update Linux page table */
  296. /* Most of the Linux PTE is ready to load into the TLB LO.
  297. * We set ZSEL, where only the LS-bit determines user access.
  298. * We set execute, because we don't have the granularity to
  299. * properly set this at the page level (Linux problem).
  300. * If shared is set, we cause a zero PID->TID load.
  301. * Many of these bits are software only. Bits we don't set
  302. * here we (properly should) assume have the appropriate value.
  303. */
  304. li r12, 0x0ce2
  305. andc r11, r11, r12 /* Make sure 20, 21 are zero */
  306. /* find the TLB index that caused the fault. It has to be here.
  307. */
  308. tlbsx r9, 0, r10
  309. tlbwe r11, r9, TLB_DATA /* Load TLB LO */
  310. /* Done...restore registers and get out of here.
  311. */
  312. #ifdef CONFIG_403GCX
  313. lwz r12, 12(r0)
  314. lwz r11, 8(r0)
  315. mtspr SPRN_PID, r12
  316. mtcr r11
  317. lwz r9, 4(r0)
  318. lwz r12, 0(r0)
  319. #else
  320. mfspr r12, SPRN_SPRG_SCRATCH5
  321. mfspr r11, SPRN_SPRG_SCRATCH6
  322. mtspr SPRN_PID, r12
  323. mtcr r11
  324. mfspr r9, SPRN_SPRG_SCRATCH4
  325. mfspr r12, SPRN_SPRG_SCRATCH3
  326. #endif
  327. mfspr r11, SPRN_SPRG_SCRATCH1
  328. mfspr r10, SPRN_SPRG_SCRATCH0
  329. PPC405_ERR77_SYNC
  330. rfi /* Should sync shadow TLBs */
  331. b . /* prevent prefetch past rfi */
  332. 2:
  333. /* The bailout. Restore registers to pre-exception conditions
  334. * and call the heavyweights to help us out.
  335. */
  336. #ifdef CONFIG_403GCX
  337. lwz r12, 12(r0)
  338. lwz r11, 8(r0)
  339. mtspr SPRN_PID, r12
  340. mtcr r11
  341. lwz r9, 4(r0)
  342. lwz r12, 0(r0)
  343. #else
  344. mfspr r12, SPRN_SPRG_SCRATCH5
  345. mfspr r11, SPRN_SPRG_SCRATCH6
  346. mtspr SPRN_PID, r12
  347. mtcr r11
  348. mfspr r9, SPRN_SPRG_SCRATCH4
  349. mfspr r12, SPRN_SPRG_SCRATCH3
  350. #endif
  351. mfspr r11, SPRN_SPRG_SCRATCH1
  352. mfspr r10, SPRN_SPRG_SCRATCH0
  353. b DataAccess
  354. /*
  355. * 0x0400 - Instruction Storage Exception
  356. * This is caused by a fetch from non-execute or guarded pages.
  357. */
  358. START_EXCEPTION(0x0400, InstructionAccess)
  359. NORMAL_EXCEPTION_PROLOG
  360. mr r4,r12 /* Pass SRR0 as arg2 */
  361. li r5,0 /* Pass zero as arg3 */
  362. EXC_XFER_LITE(0x400, handle_page_fault)
  363. /* 0x0500 - External Interrupt Exception */
  364. EXCEPTION(0x0500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
  365. /* 0x0600 - Alignment Exception */
  366. START_EXCEPTION(0x0600, Alignment)
  367. NORMAL_EXCEPTION_PROLOG
  368. mfspr r4,SPRN_DEAR /* Grab the DEAR and save it */
  369. stw r4,_DEAR(r11)
  370. addi r3,r1,STACK_FRAME_OVERHEAD
  371. EXC_XFER_EE(0x600, alignment_exception)
  372. /* 0x0700 - Program Exception */
  373. START_EXCEPTION(0x0700, ProgramCheck)
  374. NORMAL_EXCEPTION_PROLOG
  375. mfspr r4,SPRN_ESR /* Grab the ESR and save it */
  376. stw r4,_ESR(r11)
  377. addi r3,r1,STACK_FRAME_OVERHEAD
  378. EXC_XFER_STD(0x700, program_check_exception)
  379. EXCEPTION(0x0800, Trap_08, unknown_exception, EXC_XFER_EE)
  380. EXCEPTION(0x0900, Trap_09, unknown_exception, EXC_XFER_EE)
  381. EXCEPTION(0x0A00, Trap_0A, unknown_exception, EXC_XFER_EE)
  382. EXCEPTION(0x0B00, Trap_0B, unknown_exception, EXC_XFER_EE)
  383. /* 0x0C00 - System Call Exception */
  384. START_EXCEPTION(0x0C00, SystemCall)
  385. NORMAL_EXCEPTION_PROLOG
  386. EXC_XFER_EE_LITE(0xc00, DoSyscall)
  387. EXCEPTION(0x0D00, Trap_0D, unknown_exception, EXC_XFER_EE)
  388. EXCEPTION(0x0E00, Trap_0E, unknown_exception, EXC_XFER_EE)
  389. EXCEPTION(0x0F00, Trap_0F, unknown_exception, EXC_XFER_EE)
  390. /* 0x1000 - Programmable Interval Timer (PIT) Exception */
  391. . = 0x1000
  392. b Decrementer
  393. /* 0x1010 - Fixed Interval Timer (FIT) Exception
  394. */
  395. . = 0x1010
  396. b FITException
  397. /* 0x1020 - Watchdog Timer (WDT) Exception
  398. */
  399. . = 0x1020
  400. b WDTException
  401. /* 0x1100 - Data TLB Miss Exception
  402. * As the name implies, translation is not in the MMU, so search the
  403. * page tables and fix it. The only purpose of this function is to
  404. * load TLB entries from the page table if they exist.
  405. */
  406. START_EXCEPTION(0x1100, DTLBMiss)
  407. mtspr SPRN_SPRG_SCRATCH0, r10 /* Save some working registers */
  408. mtspr SPRN_SPRG_SCRATCH1, r11
  409. #ifdef CONFIG_403GCX
  410. stw r12, 0(r0)
  411. stw r9, 4(r0)
  412. mfcr r11
  413. mfspr r12, SPRN_PID
  414. stw r11, 8(r0)
  415. stw r12, 12(r0)
  416. #else
  417. mtspr SPRN_SPRG_SCRATCH3, r12
  418. mtspr SPRN_SPRG_SCRATCH4, r9
  419. mfcr r11
  420. mfspr r12, SPRN_PID
  421. mtspr SPRN_SPRG_SCRATCH6, r11
  422. mtspr SPRN_SPRG_SCRATCH5, r12
  423. #endif
  424. mfspr r10, SPRN_DEAR /* Get faulting address */
  425. /* If we are faulting a kernel address, we have to use the
  426. * kernel page tables.
  427. */
  428. lis r11, PAGE_OFFSET@h
  429. cmplw r10, r11
  430. blt+ 3f
  431. lis r11, swapper_pg_dir@h
  432. ori r11, r11, swapper_pg_dir@l
  433. li r9, 0
  434. mtspr SPRN_PID, r9 /* TLB will have 0 TID */
  435. b 4f
  436. /* Get the PGD for the current thread.
  437. */
  438. 3:
  439. mfspr r11,SPRN_SPRG_THREAD
  440. lwz r11,PGDIR(r11)
  441. 4:
  442. tophys(r11, r11)
  443. rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */
  444. lwz r12, 0(r11) /* Get L1 entry */
  445. andi. r9, r12, _PMD_PRESENT /* Check if it points to a PTE page */
  446. beq 2f /* Bail if no table */
  447. rlwimi r12, r10, 22, 20, 29 /* Compute PTE address */
  448. lwz r11, 0(r12) /* Get Linux PTE */
  449. andi. r9, r11, _PAGE_PRESENT
  450. beq 5f
  451. ori r11, r11, _PAGE_ACCESSED
  452. stw r11, 0(r12)
  453. /* Create TLB tag. This is the faulting address plus a static
  454. * set of bits. These are size, valid, E, U0.
  455. */
  456. li r12, 0x00c0
  457. rlwimi r10, r12, 0, 20, 31
  458. b finish_tlb_load
  459. 2: /* Check for possible large-page pmd entry */
  460. rlwinm. r9, r12, 2, 22, 24
  461. beq 5f
  462. /* Create TLB tag. This is the faulting address, plus a static
  463. * set of bits (valid, E, U0) plus the size from the PMD.
  464. */
  465. ori r9, r9, 0x40
  466. rlwimi r10, r9, 0, 20, 31
  467. mr r11, r12
  468. b finish_tlb_load
  469. 5:
  470. /* The bailout. Restore registers to pre-exception conditions
  471. * and call the heavyweights to help us out.
  472. */
  473. #ifdef CONFIG_403GCX
  474. lwz r12, 12(r0)
  475. lwz r11, 8(r0)
  476. mtspr SPRN_PID, r12
  477. mtcr r11
  478. lwz r9, 4(r0)
  479. lwz r12, 0(r0)
  480. #else
  481. mfspr r12, SPRN_SPRG_SCRATCH5
  482. mfspr r11, SPRN_SPRG_SCRATCH6
  483. mtspr SPRN_PID, r12
  484. mtcr r11
  485. mfspr r9, SPRN_SPRG_SCRATCH4
  486. mfspr r12, SPRN_SPRG_SCRATCH3
  487. #endif
  488. mfspr r11, SPRN_SPRG_SCRATCH1
  489. mfspr r10, SPRN_SPRG_SCRATCH0
  490. b DataAccess
  491. /* 0x1200 - Instruction TLB Miss Exception
  492. * Nearly the same as above, except we get our information from different
  493. * registers and bailout to a different point.
  494. */
  495. START_EXCEPTION(0x1200, ITLBMiss)
  496. mtspr SPRN_SPRG_SCRATCH0, r10 /* Save some working registers */
  497. mtspr SPRN_SPRG_SCRATCH1, r11
  498. #ifdef CONFIG_403GCX
  499. stw r12, 0(r0)
  500. stw r9, 4(r0)
  501. mfcr r11
  502. mfspr r12, SPRN_PID
  503. stw r11, 8(r0)
  504. stw r12, 12(r0)
  505. #else
  506. mtspr SPRN_SPRG_SCRATCH3, r12
  507. mtspr SPRN_SPRG_SCRATCH4, r9
  508. mfcr r11
  509. mfspr r12, SPRN_PID
  510. mtspr SPRN_SPRG_SCRATCH6, r11
  511. mtspr SPRN_SPRG_SCRATCH5, r12
  512. #endif
  513. mfspr r10, SPRN_SRR0 /* Get faulting address */
  514. /* If we are faulting a kernel address, we have to use the
  515. * kernel page tables.
  516. */
  517. lis r11, PAGE_OFFSET@h
  518. cmplw r10, r11
  519. blt+ 3f
  520. lis r11, swapper_pg_dir@h
  521. ori r11, r11, swapper_pg_dir@l
  522. li r9, 0
  523. mtspr SPRN_PID, r9 /* TLB will have 0 TID */
  524. b 4f
  525. /* Get the PGD for the current thread.
  526. */
  527. 3:
  528. mfspr r11,SPRN_SPRG_THREAD
  529. lwz r11,PGDIR(r11)
  530. 4:
  531. tophys(r11, r11)
  532. rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */
  533. lwz r12, 0(r11) /* Get L1 entry */
  534. andi. r9, r12, _PMD_PRESENT /* Check if it points to a PTE page */
  535. beq 2f /* Bail if no table */
  536. rlwimi r12, r10, 22, 20, 29 /* Compute PTE address */
  537. lwz r11, 0(r12) /* Get Linux PTE */
  538. andi. r9, r11, _PAGE_PRESENT
  539. beq 5f
  540. ori r11, r11, _PAGE_ACCESSED
  541. stw r11, 0(r12)
  542. /* Create TLB tag. This is the faulting address plus a static
  543. * set of bits. These are size, valid, E, U0.
  544. */
  545. li r12, 0x00c0
  546. rlwimi r10, r12, 0, 20, 31
  547. b finish_tlb_load
  548. 2: /* Check for possible large-page pmd entry */
  549. rlwinm. r9, r12, 2, 22, 24
  550. beq 5f
  551. /* Create TLB tag. This is the faulting address, plus a static
  552. * set of bits (valid, E, U0) plus the size from the PMD.
  553. */
  554. ori r9, r9, 0x40
  555. rlwimi r10, r9, 0, 20, 31
  556. mr r11, r12
  557. b finish_tlb_load
  558. 5:
  559. /* The bailout. Restore registers to pre-exception conditions
  560. * and call the heavyweights to help us out.
  561. */
  562. #ifdef CONFIG_403GCX
  563. lwz r12, 12(r0)
  564. lwz r11, 8(r0)
  565. mtspr SPRN_PID, r12
  566. mtcr r11
  567. lwz r9, 4(r0)
  568. lwz r12, 0(r0)
  569. #else
  570. mfspr r12, SPRN_SPRG_SCRATCH5
  571. mfspr r11, SPRN_SPRG_SCRATCH6
  572. mtspr SPRN_PID, r12
  573. mtcr r11
  574. mfspr r9, SPRN_SPRG_SCRATCH4
  575. mfspr r12, SPRN_SPRG_SCRATCH3
  576. #endif
  577. mfspr r11, SPRN_SPRG_SCRATCH1
  578. mfspr r10, SPRN_SPRG_SCRATCH0
  579. b InstructionAccess
  580. EXCEPTION(0x1300, Trap_13, unknown_exception, EXC_XFER_EE)
  581. EXCEPTION(0x1400, Trap_14, unknown_exception, EXC_XFER_EE)
  582. EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_EE)
  583. EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_EE)
  584. #ifdef CONFIG_IBM405_ERR51
  585. /* 405GP errata 51 */
  586. START_EXCEPTION(0x1700, Trap_17)
  587. b DTLBMiss
  588. #else
  589. EXCEPTION(0x1700, Trap_17, unknown_exception, EXC_XFER_EE)
  590. #endif
  591. EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_EE)
  592. EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_EE)
  593. EXCEPTION(0x1A00, Trap_1A, unknown_exception, EXC_XFER_EE)
  594. EXCEPTION(0x1B00, Trap_1B, unknown_exception, EXC_XFER_EE)
  595. EXCEPTION(0x1C00, Trap_1C, unknown_exception, EXC_XFER_EE)
  596. EXCEPTION(0x1D00, Trap_1D, unknown_exception, EXC_XFER_EE)
  597. EXCEPTION(0x1E00, Trap_1E, unknown_exception, EXC_XFER_EE)
  598. EXCEPTION(0x1F00, Trap_1F, unknown_exception, EXC_XFER_EE)
  599. /* Check for a single step debug exception while in an exception
  600. * handler before state has been saved. This is to catch the case
  601. * where an instruction that we are trying to single step causes
  602. * an exception (eg ITLB/DTLB miss) and thus the first instruction of
  603. * the exception handler generates a single step debug exception.
  604. *
  605. * If we get a debug trap on the first instruction of an exception handler,
  606. * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
  607. * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
  608. * The exception handler was handling a non-critical interrupt, so it will
  609. * save (and later restore) the MSR via SPRN_SRR1, which will still have
  610. * the MSR_DE bit set.
  611. */
  612. /* 0x2000 - Debug Exception */
  613. START_EXCEPTION(0x2000, DebugTrap)
  614. CRITICAL_EXCEPTION_PROLOG
  615. /*
  616. * If this is a single step or branch-taken exception in an
  617. * exception entry sequence, it was probably meant to apply to
  618. * the code where the exception occurred (since exception entry
  619. * doesn't turn off DE automatically). We simulate the effect
  620. * of turning off DE on entry to an exception handler by turning
  621. * off DE in the SRR3 value and clearing the debug status.
  622. */
  623. mfspr r10,SPRN_DBSR /* check single-step/branch taken */
  624. andis. r10,r10,DBSR_IC@h
  625. beq+ 2f
  626. andi. r10,r9,MSR_IR|MSR_PR /* check supervisor + MMU off */
  627. beq 1f /* branch and fix it up */
  628. mfspr r10,SPRN_SRR2 /* Faulting instruction address */
  629. cmplwi r10,0x2100
  630. bgt+ 2f /* address above exception vectors */
  631. /* here it looks like we got an inappropriate debug exception. */
  632. 1: rlwinm r9,r9,0,~MSR_DE /* clear DE in the SRR3 value */
  633. lis r10,DBSR_IC@h /* clear the IC event */
  634. mtspr SPRN_DBSR,r10
  635. /* restore state and get out */
  636. lwz r10,_CCR(r11)
  637. lwz r0,GPR0(r11)
  638. lwz r1,GPR1(r11)
  639. mtcrf 0x80,r10
  640. mtspr SPRN_SRR2,r12
  641. mtspr SPRN_SRR3,r9
  642. lwz r9,GPR9(r11)
  643. lwz r12,GPR12(r11)
  644. lwz r10,crit_r10@l(0)
  645. lwz r11,crit_r11@l(0)
  646. PPC405_ERR77_SYNC
  647. rfci
  648. b .
  649. /* continue normal handling for a critical exception... */
  650. 2: mfspr r4,SPRN_DBSR
  651. addi r3,r1,STACK_FRAME_OVERHEAD
  652. EXC_XFER_TEMPLATE(DebugException, 0x2002, \
  653. (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  654. NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
  655. /* Programmable Interval Timer (PIT) Exception. (from 0x1000) */
  656. Decrementer:
  657. NORMAL_EXCEPTION_PROLOG
  658. lis r0,TSR_PIS@h
  659. mtspr SPRN_TSR,r0 /* Clear the PIT exception */
  660. addi r3,r1,STACK_FRAME_OVERHEAD
  661. EXC_XFER_LITE(0x1000, timer_interrupt)
  662. /* Fixed Interval Timer (FIT) Exception. (from 0x1010) */
  663. FITException:
  664. NORMAL_EXCEPTION_PROLOG
  665. addi r3,r1,STACK_FRAME_OVERHEAD;
  666. EXC_XFER_EE(0x1010, unknown_exception)
  667. /* Watchdog Timer (WDT) Exception. (from 0x1020) */
  668. WDTException:
  669. CRITICAL_EXCEPTION_PROLOG;
  670. addi r3,r1,STACK_FRAME_OVERHEAD;
  671. EXC_XFER_TEMPLATE(WatchdogException, 0x1020+2,
  672. (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)),
  673. NOCOPY, crit_transfer_to_handler,
  674. ret_from_crit_exc)
  675. /*
  676. * The other Data TLB exceptions bail out to this point
  677. * if they can't resolve the lightweight TLB fault.
  678. */
  679. DataAccess:
  680. NORMAL_EXCEPTION_PROLOG
  681. mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
  682. stw r5,_ESR(r11)
  683. mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */
  684. EXC_XFER_LITE(0x300, handle_page_fault)
  685. /* Other PowerPC processors, namely those derived from the 6xx-series
  686. * have vectors from 0x2100 through 0x2F00 defined, but marked as reserved.
  687. * However, for the 4xx-series processors these are neither defined nor
  688. * reserved.
  689. */
  690. /* Damn, I came up one instruction too many to fit into the
  691. * exception space :-). Both the instruction and data TLB
  692. * miss get to this point to load the TLB.
  693. * r10 - TLB_TAG value
  694. * r11 - Linux PTE
  695. * r12, r9 - available to use
  696. * PID - loaded with proper value when we get here
  697. * Upon exit, we reload everything and RFI.
  698. * Actually, it will fit now, but oh well.....a common place
  699. * to load the TLB.
  700. */
  701. tlb_4xx_index:
  702. .long 0
  703. finish_tlb_load:
  704. /* load the next available TLB index.
  705. */
  706. lwz r9, tlb_4xx_index@l(0)
  707. addi r9, r9, 1
  708. andi. r9, r9, (PPC40X_TLB_SIZE-1)
  709. stw r9, tlb_4xx_index@l(0)
  710. 6:
  711. /*
  712. * Clear out the software-only bits in the PTE to generate the
  713. * TLB_DATA value. These are the bottom 2 bits of the RPM, the
  714. * top 3 bits of the zone field, and M.
  715. */
  716. li r12, 0x0ce2
  717. andc r11, r11, r12
  718. tlbwe r11, r9, TLB_DATA /* Load TLB LO */
  719. tlbwe r10, r9, TLB_TAG /* Load TLB HI */
  720. /* Done...restore registers and get out of here.
  721. */
  722. #ifdef CONFIG_403GCX
  723. lwz r12, 12(r0)
  724. lwz r11, 8(r0)
  725. mtspr SPRN_PID, r12
  726. mtcr r11
  727. lwz r9, 4(r0)
  728. lwz r12, 0(r0)
  729. #else
  730. mfspr r12, SPRN_SPRG_SCRATCH5
  731. mfspr r11, SPRN_SPRG_SCRATCH6
  732. mtspr SPRN_PID, r12
  733. mtcr r11
  734. mfspr r9, SPRN_SPRG_SCRATCH4
  735. mfspr r12, SPRN_SPRG_SCRATCH3
  736. #endif
  737. mfspr r11, SPRN_SPRG_SCRATCH1
  738. mfspr r10, SPRN_SPRG_SCRATCH0
  739. PPC405_ERR77_SYNC
  740. rfi /* Should sync shadow TLBs */
  741. b . /* prevent prefetch past rfi */
  742. /* extern void giveup_fpu(struct task_struct *prev)
  743. *
  744. * The PowerPC 4xx family of processors do not have an FPU, so this just
  745. * returns.
  746. */
  747. _ENTRY(giveup_fpu)
  748. blr
  749. /* This is where the main kernel code starts.
  750. */
  751. start_here:
  752. /* ptr to current */
  753. lis r2,init_task@h
  754. ori r2,r2,init_task@l
  755. /* ptr to phys current thread */
  756. tophys(r4,r2)
  757. addi r4,r4,THREAD /* init task's THREAD */
  758. mtspr SPRN_SPRG_THREAD,r4
  759. /* stack */
  760. lis r1,init_thread_union@ha
  761. addi r1,r1,init_thread_union@l
  762. li r0,0
  763. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  764. bl early_init /* We have to do this with MMU on */
  765. /*
  766. * Decide what sort of machine this is and initialize the MMU.
  767. */
  768. li r3,0
  769. mr r4,r31
  770. bl machine_init
  771. bl MMU_init
  772. /* Go back to running unmapped so we can load up new values
  773. * and change to using our exception vectors.
  774. * On the 4xx, all we have to do is invalidate the TLB to clear
  775. * the old 16M byte TLB mappings.
  776. */
  777. lis r4,2f@h
  778. ori r4,r4,2f@l
  779. tophys(r4,r4)
  780. lis r3,(MSR_KERNEL & ~(MSR_IR|MSR_DR))@h
  781. ori r3,r3,(MSR_KERNEL & ~(MSR_IR|MSR_DR))@l
  782. mtspr SPRN_SRR0,r4
  783. mtspr SPRN_SRR1,r3
  784. rfi
  785. b . /* prevent prefetch past rfi */
  786. /* Load up the kernel context */
  787. 2:
  788. sync /* Flush to memory before changing TLB */
  789. tlbia
  790. isync /* Flush shadow TLBs */
  791. /* set up the PTE pointers for the Abatron bdiGDB.
  792. */
  793. lis r6, swapper_pg_dir@h
  794. ori r6, r6, swapper_pg_dir@l
  795. lis r5, abatron_pteptrs@h
  796. ori r5, r5, abatron_pteptrs@l
  797. stw r5, 0xf0(r0) /* Must match your Abatron config file */
  798. tophys(r5,r5)
  799. stw r6, 0(r5)
  800. /* Now turn on the MMU for real! */
  801. lis r4,MSR_KERNEL@h
  802. ori r4,r4,MSR_KERNEL@l
  803. lis r3,start_kernel@h
  804. ori r3,r3,start_kernel@l
  805. mtspr SPRN_SRR0,r3
  806. mtspr SPRN_SRR1,r4
  807. rfi /* enable MMU and jump to start_kernel */
  808. b . /* prevent prefetch past rfi */
  809. /* Set up the initial MMU state so we can do the first level of
  810. * kernel initialization. This maps the first 16 MBytes of memory 1:1
  811. * virtual to physical and more importantly sets the cache mode.
  812. */
  813. initial_mmu:
  814. tlbia /* Invalidate all TLB entries */
  815. isync
  816. /* We should still be executing code at physical address 0x0000xxxx
  817. * at this point. However, start_here is at virtual address
  818. * 0xC000xxxx. So, set up a TLB mapping to cover this once
  819. * translation is enabled.
  820. */
  821. lis r3,KERNELBASE@h /* Load the kernel virtual address */
  822. ori r3,r3,KERNELBASE@l
  823. tophys(r4,r3) /* Load the kernel physical address */
  824. iccci r0,r3 /* Invalidate the i-cache before use */
  825. /* Load the kernel PID.
  826. */
  827. li r0,0
  828. mtspr SPRN_PID,r0
  829. sync
  830. /* Configure and load one entry into TLB slots 63 */
  831. clrrwi r4,r4,10 /* Mask off the real page number */
  832. ori r4,r4,(TLB_WR | TLB_EX) /* Set the write and execute bits */
  833. clrrwi r3,r3,10 /* Mask off the effective page number */
  834. ori r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_16M))
  835. li r0,63 /* TLB slot 63 */
  836. tlbwe r4,r0,TLB_DATA /* Load the data portion of the entry */
  837. tlbwe r3,r0,TLB_TAG /* Load the tag portion of the entry */
  838. #if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(SERIAL_DEBUG_IO_BASE)
  839. /* Load a TLB entry for the UART, so that ppc4xx_progress() can use
  840. * the UARTs nice and early. We use a 4k real==virtual mapping. */
  841. lis r3,SERIAL_DEBUG_IO_BASE@h
  842. ori r3,r3,SERIAL_DEBUG_IO_BASE@l
  843. mr r4,r3
  844. clrrwi r4,r4,12
  845. ori r4,r4,(TLB_WR|TLB_I|TLB_M|TLB_G)
  846. clrrwi r3,r3,12
  847. ori r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_4K))
  848. li r0,0 /* TLB slot 0 */
  849. tlbwe r4,r0,TLB_DATA
  850. tlbwe r3,r0,TLB_TAG
  851. #endif /* CONFIG_SERIAL_DEBUG_TEXT && SERIAL_DEBUG_IO_BASE */
  852. isync
  853. /* Establish the exception vector base
  854. */
  855. lis r4,KERNELBASE@h /* EVPR only uses the high 16-bits */
  856. tophys(r0,r4) /* Use the physical address */
  857. mtspr SPRN_EVPR,r0
  858. blr
  859. _GLOBAL(abort)
  860. mfspr r13,SPRN_DBCR0
  861. oris r13,r13,DBCR0_RST_SYSTEM@h
  862. mtspr SPRN_DBCR0,r13
  863. _GLOBAL(set_context)
  864. #ifdef CONFIG_BDI_SWITCH
  865. /* Context switch the PTE pointer for the Abatron BDI2000.
  866. * The PGDIR is the second parameter.
  867. */
  868. lis r5, KERNELBASE@h
  869. lwz r5, 0xf0(r5)
  870. stw r4, 0x4(r5)
  871. #endif
  872. sync
  873. mtspr SPRN_PID,r3
  874. isync /* Need an isync to flush shadow */
  875. /* TLBs after changing PID */
  876. blr
  877. /* We put a few things here that have to be page-aligned. This stuff
  878. * goes at the beginning of the data segment, which is page-aligned.
  879. */
  880. .data
  881. .align 12
  882. .globl sdata
  883. sdata:
  884. .globl empty_zero_page
  885. empty_zero_page:
  886. .space 4096
  887. .globl swapper_pg_dir
  888. swapper_pg_dir:
  889. .space PGD_TABLE_SIZE
  890. /* Room for two PTE pointers, usually the kernel and current user pointers
  891. * to their respective root page table.
  892. */
  893. abatron_pteptrs:
  894. .space 8