head_40x.S 28 KB

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