head_8xx.S 31 KB

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