head_4xx.S 28 KB

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