head_4xx.S 28 KB

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