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