head_40x.S 28 KB

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