head_8xx.S 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  6. * Low-level exception handlers and MMU support
  7. * rewritten by Paul Mackerras.
  8. * Copyright (C) 1996 Paul Mackerras.
  9. * MPC8xx modifications by Dan Malek
  10. * Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
  11. *
  12. * This file contains low-level support and setup for PowerPC 8xx
  13. * embedded processors, including trap and interrupt dispatch.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. *
  20. */
  21. #include <linux/init.h>
  22. #include <asm/processor.h>
  23. #include <asm/page.h>
  24. #include <asm/mmu.h>
  25. #include <asm/cache.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/cputable.h>
  28. #include <asm/thread_info.h>
  29. #include <asm/ppc_asm.h>
  30. #include <asm/asm-offsets.h>
  31. #include <asm/ptrace.h>
  32. #include <asm/export.h>
  33. #if CONFIG_TASK_SIZE <= 0x80000000 && CONFIG_PAGE_OFFSET >= 0x80000000
  34. /* By simply checking Address >= 0x80000000, we know if its a kernel address */
  35. #define SIMPLE_KERNEL_ADDRESS 1
  36. #endif
  37. /*
  38. * We need an ITLB miss handler for kernel addresses if:
  39. * - Either we have modules
  40. * - Or we have not pinned the first 8M
  41. */
  42. #if defined(CONFIG_MODULES) || !defined(CONFIG_PIN_TLB_TEXT) || \
  43. defined(CONFIG_DEBUG_PAGEALLOC)
  44. #define ITLB_MISS_KERNEL 1
  45. #endif
  46. /*
  47. * Value for the bits that have fixed value in RPN entries.
  48. * Also used for tagging DAR for DTLBerror.
  49. */
  50. #define RPN_PATTERN 0x00f0
  51. #define PAGE_SHIFT_512K 19
  52. #define PAGE_SHIFT_8M 23
  53. __HEAD
  54. _ENTRY(_stext);
  55. _ENTRY(_start);
  56. /* MPC8xx
  57. * This port was done on an MBX board with an 860. Right now I only
  58. * support an ELF compressed (zImage) boot from EPPC-Bug because the
  59. * code there loads up some registers before calling us:
  60. * r3: ptr to board info data
  61. * r4: initrd_start or if no initrd then 0
  62. * r5: initrd_end - unused if r4 is 0
  63. * r6: Start of command line string
  64. * r7: End of command line string
  65. *
  66. * I decided to use conditional compilation instead of checking PVR and
  67. * adding more processor specific branches around code I don't need.
  68. * Since this is an embedded processor, I also appreciate any memory
  69. * savings I can get.
  70. *
  71. * The MPC8xx does not have any BATs, but it supports large page sizes.
  72. * We first initialize the MMU to support 8M byte pages, then load one
  73. * entry into each of the instruction and data TLBs to map the first
  74. * 8M 1:1. I also mapped an additional I/O space 1:1 so we can get to
  75. * the "internal" processor registers before MMU_init is called.
  76. *
  77. * -- Dan
  78. */
  79. .globl __start
  80. __start:
  81. mr r31,r3 /* save device tree ptr */
  82. /* We have to turn on the MMU right away so we get cache modes
  83. * set correctly.
  84. */
  85. bl initial_mmu
  86. /* We now have the lower 8 Meg mapped into TLB entries, and the caches
  87. * ready to work.
  88. */
  89. turn_on_mmu:
  90. mfmsr r0
  91. ori r0,r0,MSR_DR|MSR_IR
  92. mtspr SPRN_SRR1,r0
  93. lis r0,start_here@h
  94. ori r0,r0,start_here@l
  95. mtspr SPRN_SRR0,r0
  96. rfi /* enables MMU */
  97. /*
  98. * Exception entry code. This code runs with address translation
  99. * turned off, i.e. using physical addresses.
  100. * We assume sprg3 has the physical address of the current
  101. * task's thread_struct.
  102. */
  103. #define EXCEPTION_PROLOG \
  104. mtspr SPRN_SPRG_SCRATCH0, r10; \
  105. mtspr SPRN_SPRG_SCRATCH1, r11; \
  106. mfcr r10; \
  107. EXCEPTION_PROLOG_1; \
  108. EXCEPTION_PROLOG_2
  109. #define EXCEPTION_PROLOG_1 \
  110. mfspr r11,SPRN_SRR1; /* check whether user or kernel */ \
  111. andi. r11,r11,MSR_PR; \
  112. tophys(r11,r1); /* use tophys(r1) if kernel */ \
  113. beq 1f; \
  114. mfspr r11,SPRN_SPRG_THREAD; \
  115. lwz r11,THREAD_INFO-THREAD(r11); \
  116. addi r11,r11,THREAD_SIZE; \
  117. tophys(r11,r11); \
  118. 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
  119. #define EXCEPTION_PROLOG_2 \
  120. stw r10,_CCR(r11); /* save registers */ \
  121. stw r12,GPR12(r11); \
  122. stw r9,GPR9(r11); \
  123. mfspr r10,SPRN_SPRG_SCRATCH0; \
  124. stw r10,GPR10(r11); \
  125. mfspr r12,SPRN_SPRG_SCRATCH1; \
  126. stw r12,GPR11(r11); \
  127. mflr r10; \
  128. stw r10,_LINK(r11); \
  129. mfspr r12,SPRN_SRR0; \
  130. mfspr r9,SPRN_SRR1; \
  131. stw r1,GPR1(r11); \
  132. stw r1,0(r11); \
  133. tovirt(r1,r11); /* set new kernel sp */ \
  134. li r10,MSR_KERNEL & ~(MSR_IR|MSR_DR); /* can take exceptions */ \
  135. mtmsr r10; \
  136. stw r0,GPR0(r11); \
  137. SAVE_4GPRS(3, r11); \
  138. SAVE_2GPRS(7, r11)
  139. /*
  140. * Note: code which follows this uses cr0.eq (set if from kernel),
  141. * r11, r12 (SRR0), and r9 (SRR1).
  142. *
  143. * Note2: once we have set r1 we are in a position to take exceptions
  144. * again, and we could thus set MSR:RI at that point.
  145. */
  146. /*
  147. * Exception vectors.
  148. */
  149. #define EXCEPTION(n, label, hdlr, xfer) \
  150. . = n; \
  151. label: \
  152. EXCEPTION_PROLOG; \
  153. addi r3,r1,STACK_FRAME_OVERHEAD; \
  154. xfer(n, hdlr)
  155. #define EXC_XFER_TEMPLATE(n, hdlr, trap, copyee, tfer, ret) \
  156. li r10,trap; \
  157. stw r10,_TRAP(r11); \
  158. li r10,MSR_KERNEL; \
  159. copyee(r10, r9); \
  160. bl tfer; \
  161. i##n: \
  162. .long hdlr; \
  163. .long ret
  164. #define COPY_EE(d, s) rlwimi d,s,0,16,16
  165. #define NOCOPY(d, s)
  166. #define EXC_XFER_STD(n, hdlr) \
  167. EXC_XFER_TEMPLATE(n, hdlr, n, NOCOPY, transfer_to_handler_full, \
  168. ret_from_except_full)
  169. #define EXC_XFER_LITE(n, hdlr) \
  170. EXC_XFER_TEMPLATE(n, hdlr, n+1, NOCOPY, transfer_to_handler, \
  171. ret_from_except)
  172. #define EXC_XFER_EE(n, hdlr) \
  173. EXC_XFER_TEMPLATE(n, hdlr, n, COPY_EE, transfer_to_handler_full, \
  174. ret_from_except_full)
  175. #define EXC_XFER_EE_LITE(n, hdlr) \
  176. EXC_XFER_TEMPLATE(n, hdlr, n+1, COPY_EE, transfer_to_handler, \
  177. ret_from_except)
  178. /* System reset */
  179. EXCEPTION(0x100, Reset, system_reset_exception, EXC_XFER_STD)
  180. /* Machine check */
  181. . = 0x200
  182. MachineCheck:
  183. EXCEPTION_PROLOG
  184. mfspr r4,SPRN_DAR
  185. stw r4,_DAR(r11)
  186. li r5,RPN_PATTERN
  187. mtspr SPRN_DAR,r5 /* Tag DAR, to be used in DTLB Error */
  188. mfspr r5,SPRN_DSISR
  189. stw r5,_DSISR(r11)
  190. addi r3,r1,STACK_FRAME_OVERHEAD
  191. EXC_XFER_STD(0x200, machine_check_exception)
  192. /* Data access exception.
  193. * This is "never generated" by the MPC8xx.
  194. */
  195. . = 0x300
  196. DataAccess:
  197. /* Instruction access exception.
  198. * This is "never generated" by the MPC8xx.
  199. */
  200. . = 0x400
  201. InstructionAccess:
  202. /* External interrupt */
  203. EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
  204. /* Alignment exception */
  205. . = 0x600
  206. Alignment:
  207. EXCEPTION_PROLOG
  208. mfspr r4,SPRN_DAR
  209. stw r4,_DAR(r11)
  210. li r5,RPN_PATTERN
  211. mtspr SPRN_DAR,r5 /* Tag DAR, to be used in DTLB Error */
  212. mfspr r5,SPRN_DSISR
  213. stw r5,_DSISR(r11)
  214. addi r3,r1,STACK_FRAME_OVERHEAD
  215. EXC_XFER_EE(0x600, alignment_exception)
  216. /* Program check exception */
  217. EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
  218. /* No FPU on MPC8xx. This exception is not supposed to happen.
  219. */
  220. EXCEPTION(0x800, FPUnavailable, unknown_exception, EXC_XFER_STD)
  221. /* Decrementer */
  222. EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
  223. EXCEPTION(0xa00, Trap_0a, unknown_exception, EXC_XFER_EE)
  224. EXCEPTION(0xb00, Trap_0b, unknown_exception, EXC_XFER_EE)
  225. /* System call */
  226. . = 0xc00
  227. SystemCall:
  228. EXCEPTION_PROLOG
  229. EXC_XFER_EE_LITE(0xc00, DoSyscall)
  230. /* Single step - not used on 601 */
  231. EXCEPTION(0xd00, SingleStep, single_step_exception, EXC_XFER_STD)
  232. EXCEPTION(0xe00, Trap_0e, unknown_exception, EXC_XFER_EE)
  233. EXCEPTION(0xf00, Trap_0f, unknown_exception, EXC_XFER_EE)
  234. /* On the MPC8xx, this is a software emulation interrupt. It occurs
  235. * for all unimplemented and illegal instructions.
  236. */
  237. EXCEPTION(0x1000, SoftEmu, emulation_assist_interrupt, EXC_XFER_STD)
  238. . = 0x1100
  239. /*
  240. * For the MPC8xx, this is a software tablewalk to load the instruction
  241. * TLB. The task switch loads the M_TW register with the pointer to the first
  242. * level table.
  243. * If we discover there is no second level table (value is zero) or if there
  244. * is an invalid pte, we load that into the TLB, which causes another fault
  245. * into the TLB Error interrupt where we can handle such problems.
  246. * We have to use the MD_xxx registers for the tablewalk because the
  247. * equivalent MI_xxx registers only perform the attribute functions.
  248. */
  249. #ifdef CONFIG_8xx_CPU15
  250. #define INVALIDATE_ADJACENT_PAGES_CPU15(tmp, addr) \
  251. addi tmp, addr, PAGE_SIZE; \
  252. tlbie tmp; \
  253. addi tmp, addr, -PAGE_SIZE; \
  254. tlbie tmp
  255. #else
  256. #define INVALIDATE_ADJACENT_PAGES_CPU15(tmp, addr)
  257. #endif
  258. InstructionTLBMiss:
  259. mtspr SPRN_SPRG_SCRATCH0, r10
  260. mtspr SPRN_SPRG_SCRATCH1, r11
  261. #if defined(ITLB_MISS_KERNEL) || defined(CONFIG_HUGETLB_PAGE)
  262. mtspr SPRN_SPRG_SCRATCH2, r12
  263. #endif
  264. /* If we are faulting a kernel address, we have to use the
  265. * kernel page tables.
  266. */
  267. mfspr r10, SPRN_SRR0 /* Get effective address of fault */
  268. INVALIDATE_ADJACENT_PAGES_CPU15(r11, r10)
  269. /* Only modules will cause ITLB Misses as we always
  270. * pin the first 8MB of kernel memory */
  271. #if defined(ITLB_MISS_KERNEL) || defined(CONFIG_HUGETLB_PAGE)
  272. mfcr r12
  273. #endif
  274. #ifdef ITLB_MISS_KERNEL
  275. #if defined(SIMPLE_KERNEL_ADDRESS) && defined(CONFIG_PIN_TLB_TEXT)
  276. andis. r11, r10, 0x8000 /* Address >= 0x80000000 */
  277. #else
  278. rlwinm r11, r10, 16, 0xfff8
  279. cmpli cr0, r11, PAGE_OFFSET@h
  280. #ifndef CONFIG_PIN_TLB_TEXT
  281. /* It is assumed that kernel code fits into the first 8M page */
  282. _ENTRY(ITLBMiss_cmp)
  283. cmpli cr7, r11, (PAGE_OFFSET + 0x0800000)@h
  284. #endif
  285. #endif
  286. #endif
  287. mfspr r11, SPRN_M_TW /* Get level 1 table */
  288. #ifdef ITLB_MISS_KERNEL
  289. #if defined(SIMPLE_KERNEL_ADDRESS) && defined(CONFIG_PIN_TLB_TEXT)
  290. beq+ 3f
  291. #else
  292. blt+ 3f
  293. #endif
  294. #ifndef CONFIG_PIN_TLB_TEXT
  295. blt cr7, ITLBMissLinear
  296. #endif
  297. lis r11, (swapper_pg_dir-PAGE_OFFSET)@ha
  298. 3:
  299. #endif
  300. /* Insert level 1 index */
  301. rlwimi r11, r10, 32 - ((PAGE_SHIFT - 2) << 1), (PAGE_SHIFT - 2) << 1, 29
  302. lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r11) /* Get the level 1 entry */
  303. /* Extract level 2 index */
  304. rlwinm r10, r10, 32 - (PAGE_SHIFT - 2), 32 - PAGE_SHIFT, 29
  305. #ifdef CONFIG_HUGETLB_PAGE
  306. mtcr r11
  307. bt- 28, 10f /* bit 28 = Large page (8M) */
  308. bt- 29, 20f /* bit 29 = Large page (8M or 512k) */
  309. #endif
  310. rlwimi r10, r11, 0, 0, 32 - PAGE_SHIFT - 1 /* Add level 2 base */
  311. lwz r10, 0(r10) /* Get the pte */
  312. 4:
  313. #if defined(ITLB_MISS_KERNEL) || defined(CONFIG_HUGETLB_PAGE)
  314. mtcr r12
  315. #endif
  316. /* Load the MI_TWC with the attributes for this "segment." */
  317. mtspr SPRN_MI_TWC, r11 /* Set segment attributes */
  318. rlwinm r11, r10, 32-7, _PAGE_PRESENT
  319. and r11, r11, r10
  320. rlwimi r10, r11, 0, _PAGE_PRESENT
  321. li r11, RPN_PATTERN | 0x200
  322. /* The Linux PTE won't go exactly into the MMU TLB.
  323. * Software indicator bits 20 and 23 must be clear.
  324. * Software indicator bits 22, 24, 25, 26, and 27 must be
  325. * set. All other Linux PTE bits control the behavior
  326. * of the MMU.
  327. */
  328. rlwimi r11, r10, 4, 0x0400 /* Copy _PAGE_EXEC into bit 21 */
  329. rlwimi r10, r11, 0, 0x0ff0 /* Set 22, 24-27, clear 20,23 */
  330. mtspr SPRN_MI_RPN, r10 /* Update TLB entry */
  331. /* Restore registers */
  332. _ENTRY(itlb_miss_exit_1)
  333. mfspr r10, SPRN_SPRG_SCRATCH0
  334. mfspr r11, SPRN_SPRG_SCRATCH1
  335. #if defined(ITLB_MISS_KERNEL) || defined(CONFIG_HUGETLB_PAGE)
  336. mfspr r12, SPRN_SPRG_SCRATCH2
  337. #endif
  338. rfi
  339. #ifdef CONFIG_PERF_EVENTS
  340. _ENTRY(itlb_miss_perf)
  341. lis r10, (itlb_miss_counter - PAGE_OFFSET)@ha
  342. lwz r11, (itlb_miss_counter - PAGE_OFFSET)@l(r10)
  343. addi r11, r11, 1
  344. stw r11, (itlb_miss_counter - PAGE_OFFSET)@l(r10)
  345. #endif
  346. mfspr r10, SPRN_SPRG_SCRATCH0
  347. mfspr r11, SPRN_SPRG_SCRATCH1
  348. #if defined(ITLB_MISS_KERNEL) || defined(CONFIG_HUGETLB_PAGE)
  349. mfspr r12, SPRN_SPRG_SCRATCH2
  350. #endif
  351. rfi
  352. #ifdef CONFIG_HUGETLB_PAGE
  353. 10: /* 8M pages */
  354. #ifdef CONFIG_PPC_16K_PAGES
  355. /* Extract level 2 index */
  356. rlwinm r10, r10, 32 - (PAGE_SHIFT_8M - PAGE_SHIFT), 32 + PAGE_SHIFT_8M - (PAGE_SHIFT << 1), 29
  357. /* Add level 2 base */
  358. rlwimi r10, r11, 0, 0, 32 + PAGE_SHIFT_8M - (PAGE_SHIFT << 1) - 1
  359. #else
  360. /* Level 2 base */
  361. rlwinm r10, r11, 0, ~HUGEPD_SHIFT_MASK
  362. #endif
  363. lwz r10, 0(r10) /* Get the pte */
  364. b 4b
  365. 20: /* 512k pages */
  366. /* Extract level 2 index */
  367. rlwinm r10, r10, 32 - (PAGE_SHIFT_512K - PAGE_SHIFT), 32 + PAGE_SHIFT_512K - (PAGE_SHIFT << 1), 29
  368. /* Add level 2 base */
  369. rlwimi r10, r11, 0, 0, 32 + PAGE_SHIFT_512K - (PAGE_SHIFT << 1) - 1
  370. lwz r10, 0(r10) /* Get the pte */
  371. b 4b
  372. #endif
  373. . = 0x1200
  374. DataStoreTLBMiss:
  375. mtspr SPRN_SPRG_SCRATCH0, r10
  376. mtspr SPRN_SPRG_SCRATCH1, r11
  377. mtspr SPRN_SPRG_SCRATCH2, r12
  378. mfcr r12
  379. /* If we are faulting a kernel address, we have to use the
  380. * kernel page tables.
  381. */
  382. mfspr r10, SPRN_MD_EPN
  383. rlwinm r11, r10, 16, 0xfff8
  384. cmpli cr0, r11, PAGE_OFFSET@h
  385. mfspr r11, SPRN_M_TW /* Get level 1 table */
  386. blt+ 3f
  387. rlwinm r11, r10, 16, 0xfff8
  388. #ifndef CONFIG_PIN_TLB_IMMR
  389. cmpli cr0, r11, VIRT_IMMR_BASE@h
  390. #endif
  391. _ENTRY(DTLBMiss_cmp)
  392. cmpli cr7, r11, (PAGE_OFFSET + 0x1800000)@h
  393. #ifndef CONFIG_PIN_TLB_IMMR
  394. _ENTRY(DTLBMiss_jmp)
  395. beq- DTLBMissIMMR
  396. #endif
  397. blt cr7, DTLBMissLinear
  398. lis r11, (swapper_pg_dir-PAGE_OFFSET)@ha
  399. 3:
  400. /* Insert level 1 index */
  401. rlwimi r11, r10, 32 - ((PAGE_SHIFT - 2) << 1), (PAGE_SHIFT - 2) << 1, 29
  402. lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r11) /* Get the level 1 entry */
  403. /* We have a pte table, so load fetch the pte from the table.
  404. */
  405. /* Extract level 2 index */
  406. rlwinm r10, r10, 32 - (PAGE_SHIFT - 2), 32 - PAGE_SHIFT, 29
  407. #ifdef CONFIG_HUGETLB_PAGE
  408. mtcr r11
  409. bt- 28, 10f /* bit 28 = Large page (8M) */
  410. bt- 29, 20f /* bit 29 = Large page (8M or 512k) */
  411. #endif
  412. rlwimi r10, r11, 0, 0, 32 - PAGE_SHIFT - 1 /* Add level 2 base */
  413. lwz r10, 0(r10) /* Get the pte */
  414. 4:
  415. mtcr r12
  416. /* Insert the Guarded flag into the TWC from the Linux PTE.
  417. * It is bit 27 of both the Linux PTE and the TWC (at least
  418. * I got that right :-). It will be better when we can put
  419. * this into the Linux pgd/pmd and load it in the operation
  420. * above.
  421. */
  422. rlwimi r11, r10, 0, _PAGE_GUARDED
  423. mtspr SPRN_MD_TWC, r11
  424. /* Both _PAGE_ACCESSED and _PAGE_PRESENT has to be set.
  425. * We also need to know if the insn is a load/store, so:
  426. * Clear _PAGE_PRESENT and load that which will
  427. * trap into DTLB Error with store bit set accordinly.
  428. */
  429. /* PRESENT=0x1, ACCESSED=0x20
  430. * r11 = ((r10 & PRESENT) & ((r10 & ACCESSED) >> 5));
  431. * r10 = (r10 & ~PRESENT) | r11;
  432. */
  433. rlwinm r11, r10, 32-7, _PAGE_PRESENT
  434. and r11, r11, r10
  435. rlwimi r10, r11, 0, _PAGE_PRESENT
  436. /* The Linux PTE won't go exactly into the MMU TLB.
  437. * Software indicator bits 24, 25, 26, and 27 must be
  438. * set. All other Linux PTE bits control the behavior
  439. * of the MMU.
  440. */
  441. li r11, RPN_PATTERN
  442. rlwimi r10, r11, 0, 24, 27 /* Set 24-27 */
  443. mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
  444. /* Restore registers */
  445. mtspr SPRN_DAR, r11 /* Tag DAR */
  446. _ENTRY(dtlb_miss_exit_1)
  447. mfspr r10, SPRN_SPRG_SCRATCH0
  448. mfspr r11, SPRN_SPRG_SCRATCH1
  449. mfspr r12, SPRN_SPRG_SCRATCH2
  450. rfi
  451. #ifdef CONFIG_PERF_EVENTS
  452. _ENTRY(dtlb_miss_perf)
  453. lis r10, (dtlb_miss_counter - PAGE_OFFSET)@ha
  454. lwz r11, (dtlb_miss_counter - PAGE_OFFSET)@l(r10)
  455. addi r11, r11, 1
  456. stw r11, (dtlb_miss_counter - PAGE_OFFSET)@l(r10)
  457. #endif
  458. mfspr r10, SPRN_SPRG_SCRATCH0
  459. mfspr r11, SPRN_SPRG_SCRATCH1
  460. mfspr r12, SPRN_SPRG_SCRATCH2
  461. rfi
  462. #ifdef CONFIG_HUGETLB_PAGE
  463. 10: /* 8M pages */
  464. /* Extract level 2 index */
  465. #ifdef CONFIG_PPC_16K_PAGES
  466. rlwinm r10, r10, 32 - (PAGE_SHIFT_8M - PAGE_SHIFT), 32 + PAGE_SHIFT_8M - (PAGE_SHIFT << 1), 29
  467. /* Add level 2 base */
  468. rlwimi r10, r11, 0, 0, 32 + PAGE_SHIFT_8M - (PAGE_SHIFT << 1) - 1
  469. #else
  470. /* Level 2 base */
  471. rlwinm r10, r11, 0, ~HUGEPD_SHIFT_MASK
  472. #endif
  473. lwz r10, 0(r10) /* Get the pte */
  474. b 4b
  475. 20: /* 512k pages */
  476. /* Extract level 2 index */
  477. rlwinm r10, r10, 32 - (PAGE_SHIFT_512K - PAGE_SHIFT), 32 + PAGE_SHIFT_512K - (PAGE_SHIFT << 1), 29
  478. /* Add level 2 base */
  479. rlwimi r10, r11, 0, 0, 32 + PAGE_SHIFT_512K - (PAGE_SHIFT << 1) - 1
  480. lwz r10, 0(r10) /* Get the pte */
  481. b 4b
  482. #endif
  483. /* This is an instruction TLB error on the MPC8xx. This could be due
  484. * to many reasons, such as executing guarded memory or illegal instruction
  485. * addresses. There is nothing to do but handle a big time error fault.
  486. */
  487. . = 0x1300
  488. InstructionTLBError:
  489. EXCEPTION_PROLOG
  490. mr r4,r12
  491. andis. r5,r9,DSISR_SRR1_MATCH_32S@h /* Filter relevant SRR1 bits */
  492. andis. r10,r9,SRR1_ISI_NOPT@h
  493. beq+ 1f
  494. tlbie r4
  495. itlbie:
  496. /* 0x400 is InstructionAccess exception, needed by bad_page_fault() */
  497. 1: EXC_XFER_LITE(0x400, handle_page_fault)
  498. /* This is the data TLB error on the MPC8xx. This could be due to
  499. * many reasons, including a dirty update to a pte. We bail out to
  500. * a higher level function that can handle it.
  501. */
  502. . = 0x1400
  503. DataTLBError:
  504. mtspr SPRN_SPRG_SCRATCH0, r10
  505. mtspr SPRN_SPRG_SCRATCH1, r11
  506. mfcr r10
  507. mfspr r11, SPRN_DAR
  508. cmpwi cr0, r11, RPN_PATTERN
  509. beq- FixupDAR /* must be a buggy dcbX, icbi insn. */
  510. DARFixed:/* Return from dcbx instruction bug workaround */
  511. EXCEPTION_PROLOG_1
  512. EXCEPTION_PROLOG_2
  513. mfspr r5,SPRN_DSISR
  514. stw r5,_DSISR(r11)
  515. mfspr r4,SPRN_DAR
  516. andis. r10,r5,DSISR_NOHPTE@h
  517. beq+ 1f
  518. tlbie r4
  519. dtlbie:
  520. 1: li r10,RPN_PATTERN
  521. mtspr SPRN_DAR,r10 /* Tag DAR, to be used in DTLB Error */
  522. /* 0x300 is DataAccess exception, needed by bad_page_fault() */
  523. EXC_XFER_LITE(0x300, handle_page_fault)
  524. EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_EE)
  525. EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_EE)
  526. EXCEPTION(0x1700, Trap_17, unknown_exception, EXC_XFER_EE)
  527. EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_EE)
  528. EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_EE)
  529. EXCEPTION(0x1a00, Trap_1a, unknown_exception, EXC_XFER_EE)
  530. EXCEPTION(0x1b00, Trap_1b, unknown_exception, EXC_XFER_EE)
  531. /* On the MPC8xx, these next four traps are used for development
  532. * support of breakpoints and such. Someday I will get around to
  533. * using them.
  534. */
  535. . = 0x1c00
  536. DataBreakpoint:
  537. mtspr SPRN_SPRG_SCRATCH0, r10
  538. mtspr SPRN_SPRG_SCRATCH1, r11
  539. mfcr r10
  540. mfspr r11, SPRN_SRR0
  541. cmplwi cr0, r11, (dtlbie - PAGE_OFFSET)@l
  542. cmplwi cr7, r11, (itlbie - PAGE_OFFSET)@l
  543. beq- cr0, 11f
  544. beq- cr7, 11f
  545. EXCEPTION_PROLOG_1
  546. EXCEPTION_PROLOG_2
  547. addi r3,r1,STACK_FRAME_OVERHEAD
  548. mfspr r4,SPRN_BAR
  549. stw r4,_DAR(r11)
  550. mfspr r5,SPRN_DSISR
  551. EXC_XFER_EE(0x1c00, do_break)
  552. 11:
  553. mtcr r10
  554. mfspr r10, SPRN_SPRG_SCRATCH0
  555. mfspr r11, SPRN_SPRG_SCRATCH1
  556. rfi
  557. #ifdef CONFIG_PERF_EVENTS
  558. . = 0x1d00
  559. InstructionBreakpoint:
  560. mtspr SPRN_SPRG_SCRATCH0, r10
  561. mtspr SPRN_SPRG_SCRATCH1, r11
  562. lis r10, (instruction_counter - PAGE_OFFSET)@ha
  563. lwz r11, (instruction_counter - PAGE_OFFSET)@l(r10)
  564. addi r11, r11, -1
  565. stw r11, (instruction_counter - PAGE_OFFSET)@l(r10)
  566. lis r10, 0xffff
  567. ori r10, r10, 0x01
  568. mtspr SPRN_COUNTA, r10
  569. mfspr r10, SPRN_SPRG_SCRATCH0
  570. mfspr r11, SPRN_SPRG_SCRATCH1
  571. rfi
  572. #else
  573. EXCEPTION(0x1d00, Trap_1d, unknown_exception, EXC_XFER_EE)
  574. #endif
  575. EXCEPTION(0x1e00, Trap_1e, unknown_exception, EXC_XFER_EE)
  576. EXCEPTION(0x1f00, Trap_1f, unknown_exception, EXC_XFER_EE)
  577. . = 0x2000
  578. /*
  579. * Bottom part of DataStoreTLBMiss handlers for IMMR area and linear RAM.
  580. * not enough space in the DataStoreTLBMiss area.
  581. */
  582. DTLBMissIMMR:
  583. mtcr r12
  584. /* Set 512k byte guarded page and mark it valid */
  585. li r10, MD_PS512K | MD_GUARDED | MD_SVALID
  586. mtspr SPRN_MD_TWC, r10
  587. mfspr r10, SPRN_IMMR /* Get current IMMR */
  588. rlwinm r10, r10, 0, 0xfff80000 /* Get 512 kbytes boundary */
  589. ori r10, r10, 0xf0 | MD_SPS16K | _PAGE_PRIVILEGED | _PAGE_DIRTY | \
  590. _PAGE_PRESENT | _PAGE_NO_CACHE
  591. mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
  592. li r11, RPN_PATTERN
  593. mtspr SPRN_DAR, r11 /* Tag DAR */
  594. _ENTRY(dtlb_miss_exit_2)
  595. mfspr r10, SPRN_SPRG_SCRATCH0
  596. mfspr r11, SPRN_SPRG_SCRATCH1
  597. mfspr r12, SPRN_SPRG_SCRATCH2
  598. rfi
  599. DTLBMissLinear:
  600. mtcr r12
  601. /* Set 8M byte page and mark it valid */
  602. li r11, MD_PS8MEG | MD_SVALID
  603. mtspr SPRN_MD_TWC, r11
  604. rlwinm r10, r10, 0, 0x0f800000 /* 8xx supports max 256Mb RAM */
  605. ori r10, r10, 0xf0 | MD_SPS16K | _PAGE_PRIVILEGED | _PAGE_DIRTY | \
  606. _PAGE_PRESENT
  607. mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
  608. li r11, RPN_PATTERN
  609. mtspr SPRN_DAR, r11 /* Tag DAR */
  610. _ENTRY(dtlb_miss_exit_3)
  611. mfspr r10, SPRN_SPRG_SCRATCH0
  612. mfspr r11, SPRN_SPRG_SCRATCH1
  613. mfspr r12, SPRN_SPRG_SCRATCH2
  614. rfi
  615. #ifndef CONFIG_PIN_TLB_TEXT
  616. ITLBMissLinear:
  617. mtcr r12
  618. /* Set 8M byte page and mark it valid */
  619. li r11, MI_PS8MEG | MI_SVALID
  620. mtspr SPRN_MI_TWC, r11
  621. rlwinm r10, r10, 0, 0x0f800000 /* 8xx supports max 256Mb RAM */
  622. ori r10, r10, 0xf0 | MI_SPS16K | _PAGE_PRIVILEGED | _PAGE_DIRTY | \
  623. _PAGE_PRESENT
  624. mtspr SPRN_MI_RPN, r10 /* Update TLB entry */
  625. _ENTRY(itlb_miss_exit_2)
  626. mfspr r10, SPRN_SPRG_SCRATCH0
  627. mfspr r11, SPRN_SPRG_SCRATCH1
  628. mfspr r12, SPRN_SPRG_SCRATCH2
  629. rfi
  630. #endif
  631. /* This is the procedure to calculate the data EA for buggy dcbx,dcbi instructions
  632. * by decoding the registers used by the dcbx instruction and adding them.
  633. * DAR is set to the calculated address.
  634. */
  635. /* define if you don't want to use self modifying code */
  636. #define NO_SELF_MODIFYING_CODE
  637. FixupDAR:/* Entry point for dcbx workaround. */
  638. mtspr SPRN_SPRG_SCRATCH2, r10
  639. /* fetch instruction from memory. */
  640. mfspr r10, SPRN_SRR0
  641. rlwinm r11, r10, 16, 0xfff8
  642. cmpli cr0, r11, PAGE_OFFSET@h
  643. mfspr r11, SPRN_M_TW /* Get level 1 table */
  644. blt+ 3f
  645. rlwinm r11, r10, 16, 0xfff8
  646. _ENTRY(FixupDAR_cmp)
  647. cmpli cr7, r11, (PAGE_OFFSET + 0x1800000)@h
  648. /* create physical page address from effective address */
  649. tophys(r11, r10)
  650. blt- cr7, 201f
  651. lis r11, (swapper_pg_dir-PAGE_OFFSET)@ha
  652. /* Insert level 1 index */
  653. 3: rlwimi r11, r10, 32 - ((PAGE_SHIFT - 2) << 1), (PAGE_SHIFT - 2) << 1, 29
  654. lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r11) /* Get the level 1 entry */
  655. mtcr r11
  656. bt 28,200f /* bit 28 = Large page (8M) */
  657. bt 29,202f /* bit 29 = Large page (8M or 512K) */
  658. rlwinm r11, r11,0,0,19 /* Extract page descriptor page address */
  659. /* Insert level 2 index */
  660. rlwimi r11, r10, 32 - (PAGE_SHIFT - 2), 32 - PAGE_SHIFT, 29
  661. lwz r11, 0(r11) /* Get the pte */
  662. /* concat physical page address(r11) and page offset(r10) */
  663. rlwimi r11, r10, 0, 32 - PAGE_SHIFT, 31
  664. 201: lwz r11,0(r11)
  665. /* Check if it really is a dcbx instruction. */
  666. /* dcbt and dcbtst does not generate DTLB Misses/Errors,
  667. * no need to include them here */
  668. xoris r10, r11, 0x7c00 /* check if major OP code is 31 */
  669. rlwinm r10, r10, 0, 21, 5
  670. cmpwi cr0, r10, 2028 /* Is dcbz? */
  671. beq+ 142f
  672. cmpwi cr0, r10, 940 /* Is dcbi? */
  673. beq+ 142f
  674. cmpwi cr0, r10, 108 /* Is dcbst? */
  675. beq+ 144f /* Fix up store bit! */
  676. cmpwi cr0, r10, 172 /* Is dcbf? */
  677. beq+ 142f
  678. cmpwi cr0, r10, 1964 /* Is icbi? */
  679. beq+ 142f
  680. 141: mfspr r10,SPRN_SPRG_SCRATCH2
  681. b DARFixed /* Nope, go back to normal TLB processing */
  682. /* concat physical page address(r11) and page offset(r10) */
  683. 200:
  684. #ifdef CONFIG_PPC_16K_PAGES
  685. rlwinm r11, r11, 0, 0, 32 + PAGE_SHIFT_8M - (PAGE_SHIFT << 1) - 1
  686. rlwimi r11, r10, 32 - (PAGE_SHIFT_8M - 2), 32 + PAGE_SHIFT_8M - (PAGE_SHIFT << 1), 29
  687. #else
  688. rlwinm r11, r10, 0, ~HUGEPD_SHIFT_MASK
  689. #endif
  690. lwz r11, 0(r11) /* Get the pte */
  691. /* concat physical page address(r11) and page offset(r10) */
  692. rlwimi r11, r10, 0, 32 - PAGE_SHIFT_8M, 31
  693. b 201b
  694. 202:
  695. rlwinm r11, r11, 0, 0, 32 + PAGE_SHIFT_512K - (PAGE_SHIFT << 1) - 1
  696. rlwimi r11, r10, 32 - (PAGE_SHIFT_512K - 2), 32 + PAGE_SHIFT_512K - (PAGE_SHIFT << 1), 29
  697. lwz r11, 0(r11) /* Get the pte */
  698. /* concat physical page address(r11) and page offset(r10) */
  699. rlwimi r11, r10, 0, 32 - PAGE_SHIFT_512K, 31
  700. b 201b
  701. 144: mfspr r10, SPRN_DSISR
  702. rlwinm r10, r10,0,7,5 /* Clear store bit for buggy dcbst insn */
  703. mtspr SPRN_DSISR, r10
  704. 142: /* continue, it was a dcbx, dcbi instruction. */
  705. #ifndef NO_SELF_MODIFYING_CODE
  706. andis. r10,r11,0x1f /* test if reg RA is r0 */
  707. li r10,modified_instr@l
  708. dcbtst r0,r10 /* touch for store */
  709. rlwinm r11,r11,0,0,20 /* Zero lower 10 bits */
  710. oris r11,r11,640 /* Transform instr. to a "add r10,RA,RB" */
  711. ori r11,r11,532
  712. stw r11,0(r10) /* store add/and instruction */
  713. dcbf 0,r10 /* flush new instr. to memory. */
  714. icbi 0,r10 /* invalidate instr. cache line */
  715. mfspr r11, SPRN_SPRG_SCRATCH1 /* restore r11 */
  716. mfspr r10, SPRN_SPRG_SCRATCH0 /* restore r10 */
  717. isync /* Wait until new instr is loaded from memory */
  718. modified_instr:
  719. .space 4 /* this is where the add instr. is stored */
  720. bne+ 143f
  721. subf r10,r0,r10 /* r10=r10-r0, only if reg RA is r0 */
  722. 143: mtdar r10 /* store faulting EA in DAR */
  723. mfspr r10,SPRN_SPRG_SCRATCH2
  724. b DARFixed /* Go back to normal TLB handling */
  725. #else
  726. mfctr r10
  727. mtdar r10 /* save ctr reg in DAR */
  728. rlwinm r10, r11, 24, 24, 28 /* offset into jump table for reg RB */
  729. addi r10, r10, 150f@l /* add start of table */
  730. mtctr r10 /* load ctr with jump address */
  731. xor r10, r10, r10 /* sum starts at zero */
  732. bctr /* jump into table */
  733. 150:
  734. add r10, r10, r0 ;b 151f
  735. add r10, r10, r1 ;b 151f
  736. add r10, r10, r2 ;b 151f
  737. add r10, r10, r3 ;b 151f
  738. add r10, r10, r4 ;b 151f
  739. add r10, r10, r5 ;b 151f
  740. add r10, r10, r6 ;b 151f
  741. add r10, r10, r7 ;b 151f
  742. add r10, r10, r8 ;b 151f
  743. add r10, r10, r9 ;b 151f
  744. mtctr r11 ;b 154f /* r10 needs special handling */
  745. mtctr r11 ;b 153f /* r11 needs special handling */
  746. add r10, r10, r12 ;b 151f
  747. add r10, r10, r13 ;b 151f
  748. add r10, r10, r14 ;b 151f
  749. add r10, r10, r15 ;b 151f
  750. add r10, r10, r16 ;b 151f
  751. add r10, r10, r17 ;b 151f
  752. add r10, r10, r18 ;b 151f
  753. add r10, r10, r19 ;b 151f
  754. add r10, r10, r20 ;b 151f
  755. add r10, r10, r21 ;b 151f
  756. add r10, r10, r22 ;b 151f
  757. add r10, r10, r23 ;b 151f
  758. add r10, r10, r24 ;b 151f
  759. add r10, r10, r25 ;b 151f
  760. add r10, r10, r26 ;b 151f
  761. add r10, r10, r27 ;b 151f
  762. add r10, r10, r28 ;b 151f
  763. add r10, r10, r29 ;b 151f
  764. add r10, r10, r30 ;b 151f
  765. add r10, r10, r31
  766. 151:
  767. rlwinm. r11,r11,19,24,28 /* offset into jump table for reg RA */
  768. beq 152f /* if reg RA is zero, don't add it */
  769. addi r11, r11, 150b@l /* add start of table */
  770. mtctr r11 /* load ctr with jump address */
  771. rlwinm r11,r11,0,16,10 /* make sure we don't execute this more than once */
  772. bctr /* jump into table */
  773. 152:
  774. mfdar r11
  775. mtctr r11 /* restore ctr reg from DAR */
  776. mtdar r10 /* save fault EA to DAR */
  777. mfspr r10,SPRN_SPRG_SCRATCH2
  778. b DARFixed /* Go back to normal TLB handling */
  779. /* special handling for r10,r11 since these are modified already */
  780. 153: mfspr r11, SPRN_SPRG_SCRATCH1 /* load r11 from SPRN_SPRG_SCRATCH1 */
  781. add r10, r10, r11 /* add it */
  782. mfctr r11 /* restore r11 */
  783. b 151b
  784. 154: mfspr r11, SPRN_SPRG_SCRATCH0 /* load r10 from SPRN_SPRG_SCRATCH0 */
  785. add r10, r10, r11 /* add it */
  786. mfctr r11 /* restore r11 */
  787. b 151b
  788. #endif
  789. /*
  790. * This is where the main kernel code starts.
  791. */
  792. start_here:
  793. /* ptr to current */
  794. lis r2,init_task@h
  795. ori r2,r2,init_task@l
  796. /* ptr to phys current thread */
  797. tophys(r4,r2)
  798. addi r4,r4,THREAD /* init task's THREAD */
  799. mtspr SPRN_SPRG_THREAD,r4
  800. /* stack */
  801. lis r1,init_thread_union@ha
  802. addi r1,r1,init_thread_union@l
  803. li r0,0
  804. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  805. lis r6, swapper_pg_dir@ha
  806. tophys(r6,r6)
  807. mtspr SPRN_M_TW, r6
  808. bl early_init /* We have to do this with MMU on */
  809. /*
  810. * Decide what sort of machine this is and initialize the MMU.
  811. */
  812. li r3,0
  813. mr r4,r31
  814. bl machine_init
  815. bl MMU_init
  816. /*
  817. * Go back to running unmapped so we can load up new values
  818. * and change to using our exception vectors.
  819. * On the 8xx, all we have to do is invalidate the TLB to clear
  820. * the old 8M byte TLB mappings and load the page table base register.
  821. */
  822. /* The right way to do this would be to track it down through
  823. * init's THREAD like the context switch code does, but this is
  824. * easier......until someone changes init's static structures.
  825. */
  826. lis r4,2f@h
  827. ori r4,r4,2f@l
  828. tophys(r4,r4)
  829. li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  830. mtspr SPRN_SRR0,r4
  831. mtspr SPRN_SRR1,r3
  832. rfi
  833. /* Load up the kernel context */
  834. 2:
  835. tlbia /* Clear all TLB entries */
  836. sync /* wait for tlbia/tlbie to finish */
  837. /* set up the PTE pointers for the Abatron bdiGDB.
  838. */
  839. lis r5, abatron_pteptrs@h
  840. ori r5, r5, abatron_pteptrs@l
  841. stw r5, 0xf0(0) /* Must match your Abatron config file */
  842. tophys(r5,r5)
  843. lis r6, swapper_pg_dir@h
  844. ori r6, r6, swapper_pg_dir@l
  845. stw r6, 0(r5)
  846. /* Now turn on the MMU for real! */
  847. li r4,MSR_KERNEL
  848. lis r3,start_kernel@h
  849. ori r3,r3,start_kernel@l
  850. mtspr SPRN_SRR0,r3
  851. mtspr SPRN_SRR1,r4
  852. rfi /* enable MMU and jump to start_kernel */
  853. /* Set up the initial MMU state so we can do the first level of
  854. * kernel initialization. This maps the first 8 MBytes of memory 1:1
  855. * virtual to physical. Also, set the cache mode since that is defined
  856. * by TLB entries and perform any additional mapping (like of the IMMR).
  857. * If configured to pin some TLBs, we pin the first 8 Mbytes of kernel,
  858. * 24 Mbytes of data, and the 512k IMMR space. Anything not covered by
  859. * these mappings is mapped by page tables.
  860. */
  861. initial_mmu:
  862. li r8, 0
  863. mtspr SPRN_MI_CTR, r8 /* remove PINNED ITLB entries */
  864. lis r10, MD_RESETVAL@h
  865. #ifndef CONFIG_8xx_COPYBACK
  866. oris r10, r10, MD_WTDEF@h
  867. #endif
  868. mtspr SPRN_MD_CTR, r10 /* remove PINNED DTLB entries */
  869. tlbia /* Invalidate all TLB entries */
  870. #ifdef CONFIG_PIN_TLB_TEXT
  871. lis r8, MI_RSV4I@h
  872. ori r8, r8, 0x1c00
  873. mtspr SPRN_MI_CTR, r8 /* Set instruction MMU control */
  874. #endif
  875. #ifdef CONFIG_PIN_TLB_DATA
  876. oris r10, r10, MD_RSV4I@h
  877. mtspr SPRN_MD_CTR, r10 /* Set data TLB control */
  878. #endif
  879. /* Now map the lower 8 Meg into the ITLB. */
  880. lis r8, KERNELBASE@h /* Create vaddr for TLB */
  881. ori r8, r8, MI_EVALID /* Mark it valid */
  882. mtspr SPRN_MI_EPN, r8
  883. li r8, MI_PS8MEG /* Set 8M byte page */
  884. ori r8, r8, MI_SVALID /* Make it valid */
  885. mtspr SPRN_MI_TWC, r8
  886. li r8, MI_BOOTINIT /* Create RPN for address 0 */
  887. mtspr SPRN_MI_RPN, r8 /* Store TLB entry */
  888. lis r8, MI_APG_INIT@h /* Set protection modes */
  889. ori r8, r8, MI_APG_INIT@l
  890. mtspr SPRN_MI_AP, r8
  891. lis r8, MD_APG_INIT@h
  892. ori r8, r8, MD_APG_INIT@l
  893. mtspr SPRN_MD_AP, r8
  894. /* Map a 512k page for the IMMR to get the processor
  895. * internal registers (among other things).
  896. */
  897. #ifdef CONFIG_PIN_TLB_IMMR
  898. oris r10, r10, MD_RSV4I@h
  899. ori r10, r10, 0x1c00
  900. mtspr SPRN_MD_CTR, r10
  901. mfspr r9, 638 /* Get current IMMR */
  902. andis. r9, r9, 0xfff8 /* Get 512 kbytes boundary */
  903. lis r8, VIRT_IMMR_BASE@h /* Create vaddr for TLB */
  904. ori r8, r8, MD_EVALID /* Mark it valid */
  905. mtspr SPRN_MD_EPN, r8
  906. li r8, MD_PS512K | MD_GUARDED /* Set 512k byte page */
  907. ori r8, r8, MD_SVALID /* Make it valid */
  908. mtspr SPRN_MD_TWC, r8
  909. mr r8, r9 /* Create paddr for TLB */
  910. ori r8, r8, MI_BOOTINIT|0x2 /* Inhibit cache -- Cort */
  911. mtspr SPRN_MD_RPN, r8
  912. #endif
  913. /* Since the cache is enabled according to the information we
  914. * just loaded into the TLB, invalidate and enable the caches here.
  915. * We should probably check/set other modes....later.
  916. */
  917. lis r8, IDC_INVALL@h
  918. mtspr SPRN_IC_CST, r8
  919. mtspr SPRN_DC_CST, r8
  920. lis r8, IDC_ENABLE@h
  921. mtspr SPRN_IC_CST, r8
  922. #ifdef CONFIG_8xx_COPYBACK
  923. mtspr SPRN_DC_CST, r8
  924. #else
  925. /* For a debug option, I left this here to easily enable
  926. * the write through cache mode
  927. */
  928. lis r8, DC_SFWT@h
  929. mtspr SPRN_DC_CST, r8
  930. lis r8, IDC_ENABLE@h
  931. mtspr SPRN_DC_CST, r8
  932. #endif
  933. /* Disable debug mode entry on breakpoints */
  934. mfspr r8, SPRN_DER
  935. #ifdef CONFIG_PERF_EVENTS
  936. rlwinm r8, r8, 0, ~0xc
  937. #else
  938. rlwinm r8, r8, 0, ~0x8
  939. #endif
  940. mtspr SPRN_DER, r8
  941. blr
  942. /*
  943. * We put a few things here that have to be page-aligned.
  944. * This stuff goes at the beginning of the data segment,
  945. * which is page-aligned.
  946. */
  947. .data
  948. .globl sdata
  949. sdata:
  950. .globl empty_zero_page
  951. .align PAGE_SHIFT
  952. empty_zero_page:
  953. .space PAGE_SIZE
  954. EXPORT_SYMBOL(empty_zero_page)
  955. .globl swapper_pg_dir
  956. swapper_pg_dir:
  957. .space PGD_TABLE_SIZE
  958. /* Room for two PTE table poiners, usually the kernel and current user
  959. * pointer to their respective root page table (pgdir).
  960. */
  961. abatron_pteptrs:
  962. .space 8
  963. #ifdef CONFIG_PERF_EVENTS
  964. .globl itlb_miss_counter
  965. itlb_miss_counter:
  966. .space 4
  967. .globl dtlb_miss_counter
  968. dtlb_miss_counter:
  969. .space 4
  970. .globl instruction_counter
  971. instruction_counter:
  972. .space 4
  973. #endif