head_44x.S 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. * Kernel execution entry point code.
  3. *
  4. * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
  5. * Initial PowerPC version.
  6. * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Rewritten for PReP
  8. * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
  9. * Low-level exception handers, MMU support, and rewrite.
  10. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  11. * PowerPC 8xx modifications.
  12. * Copyright (c) 1998-1999 TiVo, Inc.
  13. * PowerPC 403GCX modifications.
  14. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  15. * PowerPC 403GCX/405GP modifications.
  16. * Copyright 2000 MontaVista Software Inc.
  17. * PPC405 modifications
  18. * PowerPC 403GCX/405GP modifications.
  19. * Author: MontaVista Software, Inc.
  20. * frank_rowand@mvista.com or source@mvista.com
  21. * debbie_chu@mvista.com
  22. * Copyright 2002-2005 MontaVista Software, Inc.
  23. * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
  24. *
  25. * This program is free software; you can redistribute it and/or modify it
  26. * under the terms of the GNU General Public License as published by the
  27. * Free Software Foundation; either version 2 of the License, or (at your
  28. * option) any later version.
  29. */
  30. #include <linux/init.h>
  31. #include <asm/processor.h>
  32. #include <asm/page.h>
  33. #include <asm/mmu.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/cputable.h>
  36. #include <asm/thread_info.h>
  37. #include <asm/ppc_asm.h>
  38. #include <asm/asm-offsets.h>
  39. #include <asm/ptrace.h>
  40. #include <asm/synch.h>
  41. #include "head_booke.h"
  42. /* As with the other PowerPC ports, it is expected that when code
  43. * execution begins here, the following registers contain valid, yet
  44. * optional, information:
  45. *
  46. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  47. * r4 - Starting address of the init RAM disk
  48. * r5 - Ending address of the init RAM disk
  49. * r6 - Start of kernel command line string (e.g. "mem=128")
  50. * r7 - End of kernel command line string
  51. *
  52. */
  53. __HEAD
  54. _ENTRY(_stext);
  55. _ENTRY(_start);
  56. /*
  57. * Reserve a word at a fixed location to store the address
  58. * of abatron_pteptrs
  59. */
  60. nop
  61. mr r31,r3 /* save device tree ptr */
  62. li r24,0 /* CPU number */
  63. #ifdef CONFIG_RELOCATABLE
  64. /*
  65. * Relocate ourselves to the current runtime address.
  66. * This is called only by the Boot CPU.
  67. * "relocate" is called with our current runtime virutal
  68. * address.
  69. * r21 will be loaded with the physical runtime address of _stext
  70. */
  71. bl 0f /* Get our runtime address */
  72. 0: mflr r21 /* Make it accessible */
  73. addis r21,r21,(_stext - 0b)@ha
  74. addi r21,r21,(_stext - 0b)@l /* Get our current runtime base */
  75. /*
  76. * We have the runtime (virutal) address of our base.
  77. * We calculate our shift of offset from a 256M page.
  78. * We could map the 256M page we belong to at PAGE_OFFSET and
  79. * get going from there.
  80. */
  81. lis r4,KERNELBASE@h
  82. ori r4,r4,KERNELBASE@l
  83. rlwinm r6,r21,0,4,31 /* r6 = PHYS_START % 256M */
  84. rlwinm r5,r4,0,4,31 /* r5 = KERNELBASE % 256M */
  85. subf r3,r5,r6 /* r3 = r6 - r5 */
  86. add r3,r4,r3 /* Required Virutal Address */
  87. bl relocate
  88. #endif
  89. bl init_cpu_state
  90. /*
  91. * This is where the main kernel code starts.
  92. */
  93. /* ptr to current */
  94. lis r2,init_task@h
  95. ori r2,r2,init_task@l
  96. /* ptr to current thread */
  97. addi r4,r2,THREAD /* init task's THREAD */
  98. mtspr SPRN_SPRG_THREAD,r4
  99. /* stack */
  100. lis r1,init_thread_union@h
  101. ori r1,r1,init_thread_union@l
  102. li r0,0
  103. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  104. bl early_init
  105. #ifdef CONFIG_RELOCATABLE
  106. /*
  107. * Relocatable kernel support based on processing of dynamic
  108. * relocation entries.
  109. *
  110. * r25 will contain RPN/ERPN for the start address of memory
  111. * r21 will contain the current offset of _stext
  112. */
  113. lis r3,kernstart_addr@ha
  114. la r3,kernstart_addr@l(r3)
  115. /*
  116. * Compute the kernstart_addr.
  117. * kernstart_addr => (r6,r8)
  118. * kernstart_addr & ~0xfffffff => (r6,r7)
  119. */
  120. rlwinm r6,r25,0,28,31 /* ERPN. Bits 32-35 of Address */
  121. rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */
  122. rlwinm r8,r21,0,4,31 /* r8 = (_stext & 0xfffffff) */
  123. or r8,r7,r8 /* Compute the lower 32bit of kernstart_addr */
  124. /* Store kernstart_addr */
  125. stw r6,0(r3) /* higher 32bit */
  126. stw r8,4(r3) /* lower 32bit */
  127. /*
  128. * Compute the virt_phys_offset :
  129. * virt_phys_offset = stext.run - kernstart_addr
  130. *
  131. * stext.run = (KERNELBASE & ~0xfffffff) + (kernstart_addr & 0xfffffff)
  132. * When we relocate, we have :
  133. *
  134. * (kernstart_addr & 0xfffffff) = (stext.run & 0xfffffff)
  135. *
  136. * hence:
  137. * virt_phys_offset = (KERNELBASE & ~0xfffffff) - (kernstart_addr & ~0xfffffff)
  138. *
  139. */
  140. /* KERNELBASE&~0xfffffff => (r4,r5) */
  141. li r4, 0 /* higer 32bit */
  142. lis r5,KERNELBASE@h
  143. rlwinm r5,r5,0,0,3 /* Align to 256M, lower 32bit */
  144. /*
  145. * 64bit subtraction.
  146. */
  147. subfc r5,r7,r5
  148. subfe r4,r6,r4
  149. /* Store virt_phys_offset */
  150. lis r3,virt_phys_offset@ha
  151. la r3,virt_phys_offset@l(r3)
  152. stw r4,0(r3)
  153. stw r5,4(r3)
  154. #elif defined(CONFIG_DYNAMIC_MEMSTART)
  155. /*
  156. * Mapping based, page aligned dynamic kernel loading.
  157. *
  158. * r25 will contain RPN/ERPN for the start address of memory
  159. *
  160. * Add the difference between KERNELBASE and PAGE_OFFSET to the
  161. * start of physical memory to get kernstart_addr.
  162. */
  163. lis r3,kernstart_addr@ha
  164. la r3,kernstart_addr@l(r3)
  165. lis r4,KERNELBASE@h
  166. ori r4,r4,KERNELBASE@l
  167. lis r5,PAGE_OFFSET@h
  168. ori r5,r5,PAGE_OFFSET@l
  169. subf r4,r5,r4
  170. rlwinm r6,r25,0,28,31 /* ERPN */
  171. rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */
  172. add r7,r7,r4
  173. stw r6,0(r3)
  174. stw r7,4(r3)
  175. #endif
  176. /*
  177. * Decide what sort of machine this is and initialize the MMU.
  178. */
  179. li r3,0
  180. mr r4,r31
  181. bl machine_init
  182. bl MMU_init
  183. /* Setup PTE pointers for the Abatron bdiGDB */
  184. lis r6, swapper_pg_dir@h
  185. ori r6, r6, swapper_pg_dir@l
  186. lis r5, abatron_pteptrs@h
  187. ori r5, r5, abatron_pteptrs@l
  188. lis r4, KERNELBASE@h
  189. ori r4, r4, KERNELBASE@l
  190. stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
  191. stw r6, 0(r5)
  192. /* Clear the Machine Check Syndrome Register */
  193. li r0,0
  194. mtspr SPRN_MCSR,r0
  195. /* Let's move on */
  196. lis r4,start_kernel@h
  197. ori r4,r4,start_kernel@l
  198. lis r3,MSR_KERNEL@h
  199. ori r3,r3,MSR_KERNEL@l
  200. mtspr SPRN_SRR0,r4
  201. mtspr SPRN_SRR1,r3
  202. rfi /* change context and jump to start_kernel */
  203. /*
  204. * Interrupt vector entry code
  205. *
  206. * The Book E MMUs are always on so we don't need to handle
  207. * interrupts in real mode as with previous PPC processors. In
  208. * this case we handle interrupts in the kernel virtual address
  209. * space.
  210. *
  211. * Interrupt vectors are dynamically placed relative to the
  212. * interrupt prefix as determined by the address of interrupt_base.
  213. * The interrupt vectors offsets are programmed using the labels
  214. * for each interrupt vector entry.
  215. *
  216. * Interrupt vectors must be aligned on a 16 byte boundary.
  217. * We align on a 32 byte cache line boundary for good measure.
  218. */
  219. interrupt_base:
  220. /* Critical Input Interrupt */
  221. CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)
  222. /* Machine Check Interrupt */
  223. CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \
  224. machine_check_exception)
  225. MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
  226. /* Data Storage Interrupt */
  227. DATA_STORAGE_EXCEPTION
  228. /* Instruction Storage Interrupt */
  229. INSTRUCTION_STORAGE_EXCEPTION
  230. /* External Input Interrupt */
  231. EXCEPTION(0x0500, BOOKE_INTERRUPT_EXTERNAL, ExternalInput, \
  232. do_IRQ, EXC_XFER_LITE)
  233. /* Alignment Interrupt */
  234. ALIGNMENT_EXCEPTION
  235. /* Program Interrupt */
  236. PROGRAM_EXCEPTION
  237. /* Floating Point Unavailable Interrupt */
  238. #ifdef CONFIG_PPC_FPU
  239. FP_UNAVAILABLE_EXCEPTION
  240. #else
  241. EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \
  242. FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
  243. #endif
  244. /* System Call Interrupt */
  245. START_EXCEPTION(SystemCall)
  246. NORMAL_EXCEPTION_PROLOG(BOOKE_INTERRUPT_SYSCALL)
  247. EXC_XFER_EE_LITE(0x0c00, DoSyscall)
  248. /* Auxiliary Processor Unavailable Interrupt */
  249. EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \
  250. AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
  251. /* Decrementer Interrupt */
  252. DECREMENTER_EXCEPTION
  253. /* Fixed Internal Timer Interrupt */
  254. /* TODO: Add FIT support */
  255. EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, \
  256. unknown_exception, EXC_XFER_EE)
  257. /* Watchdog Timer Interrupt */
  258. /* TODO: Add watchdog support */
  259. #ifdef CONFIG_BOOKE_WDT
  260. CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException)
  261. #else
  262. CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception)
  263. #endif
  264. /* Data TLB Error Interrupt */
  265. START_EXCEPTION(DataTLBError44x)
  266. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  267. mtspr SPRN_SPRG_WSCRATCH1, r11
  268. mtspr SPRN_SPRG_WSCRATCH2, r12
  269. mtspr SPRN_SPRG_WSCRATCH3, r13
  270. mfcr r11
  271. mtspr SPRN_SPRG_WSCRATCH4, r11
  272. mfspr r10, SPRN_DEAR /* Get faulting address */
  273. /* If we are faulting a kernel address, we have to use the
  274. * kernel page tables.
  275. */
  276. lis r11, PAGE_OFFSET@h
  277. cmplw r10, r11
  278. blt+ 3f
  279. lis r11, swapper_pg_dir@h
  280. ori r11, r11, swapper_pg_dir@l
  281. mfspr r12,SPRN_MMUCR
  282. rlwinm r12,r12,0,0,23 /* Clear TID */
  283. b 4f
  284. /* Get the PGD for the current thread */
  285. 3:
  286. mfspr r11,SPRN_SPRG_THREAD
  287. lwz r11,PGDIR(r11)
  288. /* Load PID into MMUCR TID */
  289. mfspr r12,SPRN_MMUCR
  290. mfspr r13,SPRN_PID /* Get PID */
  291. rlwimi r12,r13,0,24,31 /* Set TID */
  292. 4:
  293. mtspr SPRN_MMUCR,r12
  294. /* Mask of required permission bits. Note that while we
  295. * do copy ESR:ST to _PAGE_RW position as trying to write
  296. * to an RO page is pretty common, we don't do it with
  297. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  298. * event so I'd rather take the overhead when it happens
  299. * rather than adding an instruction here. We should measure
  300. * whether the whole thing is worth it in the first place
  301. * as we could avoid loading SPRN_ESR completely in the first
  302. * place...
  303. *
  304. * TODO: Is it worth doing that mfspr & rlwimi in the first
  305. * place or can we save a couple of instructions here ?
  306. */
  307. mfspr r12,SPRN_ESR
  308. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  309. rlwimi r13,r12,10,30,30
  310. /* Load the PTE */
  311. /* Compute pgdir/pmd offset */
  312. rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
  313. lwzx r11, r12, r11 /* Get pgd/pmd entry */
  314. rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
  315. beq 2f /* Bail if no table */
  316. /* Compute pte address */
  317. rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
  318. lwz r11, 0(r12) /* Get high word of pte entry */
  319. lwz r12, 4(r12) /* Get low word of pte entry */
  320. lis r10,tlb_44x_index@ha
  321. andc. r13,r13,r12 /* Check permission */
  322. /* Load the next available TLB index */
  323. lwz r13,tlb_44x_index@l(r10)
  324. bne 2f /* Bail if permission mismach */
  325. /* Increment, rollover, and store TLB index */
  326. addi r13,r13,1
  327. /* Compare with watermark (instruction gets patched) */
  328. .globl tlb_44x_patch_hwater_D
  329. tlb_44x_patch_hwater_D:
  330. cmpwi 0,r13,1 /* reserve entries */
  331. ble 5f
  332. li r13,0
  333. 5:
  334. /* Store the next available TLB index */
  335. stw r13,tlb_44x_index@l(r10)
  336. /* Re-load the faulting address */
  337. mfspr r10,SPRN_DEAR
  338. /* Jump to common tlb load */
  339. b finish_tlb_load_44x
  340. 2:
  341. /* The bailout. Restore registers to pre-exception conditions
  342. * and call the heavyweights to help us out.
  343. */
  344. mfspr r11, SPRN_SPRG_RSCRATCH4
  345. mtcr r11
  346. mfspr r13, SPRN_SPRG_RSCRATCH3
  347. mfspr r12, SPRN_SPRG_RSCRATCH2
  348. mfspr r11, SPRN_SPRG_RSCRATCH1
  349. mfspr r10, SPRN_SPRG_RSCRATCH0
  350. b DataStorage
  351. /* Instruction TLB Error Interrupt */
  352. /*
  353. * Nearly the same as above, except we get our
  354. * information from different registers and bailout
  355. * to a different point.
  356. */
  357. START_EXCEPTION(InstructionTLBError44x)
  358. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  359. mtspr SPRN_SPRG_WSCRATCH1, r11
  360. mtspr SPRN_SPRG_WSCRATCH2, r12
  361. mtspr SPRN_SPRG_WSCRATCH3, r13
  362. mfcr r11
  363. mtspr SPRN_SPRG_WSCRATCH4, r11
  364. mfspr r10, SPRN_SRR0 /* Get faulting address */
  365. /* If we are faulting a kernel address, we have to use the
  366. * kernel page tables.
  367. */
  368. lis r11, PAGE_OFFSET@h
  369. cmplw r10, r11
  370. blt+ 3f
  371. lis r11, swapper_pg_dir@h
  372. ori r11, r11, swapper_pg_dir@l
  373. mfspr r12,SPRN_MMUCR
  374. rlwinm r12,r12,0,0,23 /* Clear TID */
  375. b 4f
  376. /* Get the PGD for the current thread */
  377. 3:
  378. mfspr r11,SPRN_SPRG_THREAD
  379. lwz r11,PGDIR(r11)
  380. /* Load PID into MMUCR TID */
  381. mfspr r12,SPRN_MMUCR
  382. mfspr r13,SPRN_PID /* Get PID */
  383. rlwimi r12,r13,0,24,31 /* Set TID */
  384. 4:
  385. mtspr SPRN_MMUCR,r12
  386. /* Make up the required permissions */
  387. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  388. /* Compute pgdir/pmd offset */
  389. rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
  390. lwzx r11, r12, r11 /* Get pgd/pmd entry */
  391. rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
  392. beq 2f /* Bail if no table */
  393. /* Compute pte address */
  394. rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
  395. lwz r11, 0(r12) /* Get high word of pte entry */
  396. lwz r12, 4(r12) /* Get low word of pte entry */
  397. lis r10,tlb_44x_index@ha
  398. andc. r13,r13,r12 /* Check permission */
  399. /* Load the next available TLB index */
  400. lwz r13,tlb_44x_index@l(r10)
  401. bne 2f /* Bail if permission mismach */
  402. /* Increment, rollover, and store TLB index */
  403. addi r13,r13,1
  404. /* Compare with watermark (instruction gets patched) */
  405. .globl tlb_44x_patch_hwater_I
  406. tlb_44x_patch_hwater_I:
  407. cmpwi 0,r13,1 /* reserve entries */
  408. ble 5f
  409. li r13,0
  410. 5:
  411. /* Store the next available TLB index */
  412. stw r13,tlb_44x_index@l(r10)
  413. /* Re-load the faulting address */
  414. mfspr r10,SPRN_SRR0
  415. /* Jump to common TLB load point */
  416. b finish_tlb_load_44x
  417. 2:
  418. /* The bailout. Restore registers to pre-exception conditions
  419. * and call the heavyweights to help us out.
  420. */
  421. mfspr r11, SPRN_SPRG_RSCRATCH4
  422. mtcr r11
  423. mfspr r13, SPRN_SPRG_RSCRATCH3
  424. mfspr r12, SPRN_SPRG_RSCRATCH2
  425. mfspr r11, SPRN_SPRG_RSCRATCH1
  426. mfspr r10, SPRN_SPRG_RSCRATCH0
  427. b InstructionStorage
  428. /*
  429. * Both the instruction and data TLB miss get to this
  430. * point to load the TLB.
  431. * r10 - EA of fault
  432. * r11 - PTE high word value
  433. * r12 - PTE low word value
  434. * r13 - TLB index
  435. * MMUCR - loaded with proper value when we get here
  436. * Upon exit, we reload everything and RFI.
  437. */
  438. finish_tlb_load_44x:
  439. /* Combine RPN & ERPN an write WS 0 */
  440. rlwimi r11,r12,0,0,31-PAGE_SHIFT
  441. tlbwe r11,r13,PPC44x_TLB_XLAT
  442. /*
  443. * Create WS1. This is the faulting address (EPN),
  444. * page size, and valid flag.
  445. */
  446. li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE
  447. /* Insert valid and page size */
  448. rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31
  449. tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */
  450. /* And WS 2 */
  451. li r10,0xf85 /* Mask to apply from PTE */
  452. rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
  453. and r11,r12,r10 /* Mask PTE bits to keep */
  454. andi. r10,r12,_PAGE_USER /* User page ? */
  455. beq 1f /* nope, leave U bits empty */
  456. rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
  457. 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */
  458. /* Done...restore registers and get out of here.
  459. */
  460. mfspr r11, SPRN_SPRG_RSCRATCH4
  461. mtcr r11
  462. mfspr r13, SPRN_SPRG_RSCRATCH3
  463. mfspr r12, SPRN_SPRG_RSCRATCH2
  464. mfspr r11, SPRN_SPRG_RSCRATCH1
  465. mfspr r10, SPRN_SPRG_RSCRATCH0
  466. rfi /* Force context change */
  467. /* TLB error interrupts for 476
  468. */
  469. #ifdef CONFIG_PPC_47x
  470. START_EXCEPTION(DataTLBError47x)
  471. mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
  472. mtspr SPRN_SPRG_WSCRATCH1,r11
  473. mtspr SPRN_SPRG_WSCRATCH2,r12
  474. mtspr SPRN_SPRG_WSCRATCH3,r13
  475. mfcr r11
  476. mtspr SPRN_SPRG_WSCRATCH4,r11
  477. mfspr r10,SPRN_DEAR /* Get faulting address */
  478. /* If we are faulting a kernel address, we have to use the
  479. * kernel page tables.
  480. */
  481. lis r11,PAGE_OFFSET@h
  482. cmplw cr0,r10,r11
  483. blt+ 3f
  484. lis r11,swapper_pg_dir@h
  485. ori r11,r11, swapper_pg_dir@l
  486. li r12,0 /* MMUCR = 0 */
  487. b 4f
  488. /* Get the PGD for the current thread and setup MMUCR */
  489. 3: mfspr r11,SPRN_SPRG3
  490. lwz r11,PGDIR(r11)
  491. mfspr r12,SPRN_PID /* Get PID */
  492. 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
  493. /* Mask of required permission bits. Note that while we
  494. * do copy ESR:ST to _PAGE_RW position as trying to write
  495. * to an RO page is pretty common, we don't do it with
  496. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  497. * event so I'd rather take the overhead when it happens
  498. * rather than adding an instruction here. We should measure
  499. * whether the whole thing is worth it in the first place
  500. * as we could avoid loading SPRN_ESR completely in the first
  501. * place...
  502. *
  503. * TODO: Is it worth doing that mfspr & rlwimi in the first
  504. * place or can we save a couple of instructions here ?
  505. */
  506. mfspr r12,SPRN_ESR
  507. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  508. rlwimi r13,r12,10,30,30
  509. /* Load the PTE */
  510. /* Compute pgdir/pmd offset */
  511. rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
  512. lwzx r11,r12,r11 /* Get pgd/pmd entry */
  513. /* Word 0 is EPN,V,TS,DSIZ */
  514. li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
  515. rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
  516. li r12,0
  517. tlbwe r10,r12,0
  518. /* XXX can we do better ? Need to make sure tlbwe has established
  519. * latch V bit in MMUCR0 before the PTE is loaded further down */
  520. #ifdef CONFIG_SMP
  521. isync
  522. #endif
  523. rlwinm. r12,r11,0,0,20 /* Extract pt base address */
  524. /* Compute pte address */
  525. rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
  526. beq 2f /* Bail if no table */
  527. lwz r11,0(r12) /* Get high word of pte entry */
  528. /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
  529. * bottom of r12 to create a data dependency... We can also use r10
  530. * as destination nowadays
  531. */
  532. #ifdef CONFIG_SMP
  533. lwsync
  534. #endif
  535. lwz r12,4(r12) /* Get low word of pte entry */
  536. andc. r13,r13,r12 /* Check permission */
  537. /* Jump to common tlb load */
  538. beq finish_tlb_load_47x
  539. 2: /* The bailout. Restore registers to pre-exception conditions
  540. * and call the heavyweights to help us out.
  541. */
  542. mfspr r11,SPRN_SPRG_RSCRATCH4
  543. mtcr r11
  544. mfspr r13,SPRN_SPRG_RSCRATCH3
  545. mfspr r12,SPRN_SPRG_RSCRATCH2
  546. mfspr r11,SPRN_SPRG_RSCRATCH1
  547. mfspr r10,SPRN_SPRG_RSCRATCH0
  548. b DataStorage
  549. /* Instruction TLB Error Interrupt */
  550. /*
  551. * Nearly the same as above, except we get our
  552. * information from different registers and bailout
  553. * to a different point.
  554. */
  555. START_EXCEPTION(InstructionTLBError47x)
  556. mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
  557. mtspr SPRN_SPRG_WSCRATCH1,r11
  558. mtspr SPRN_SPRG_WSCRATCH2,r12
  559. mtspr SPRN_SPRG_WSCRATCH3,r13
  560. mfcr r11
  561. mtspr SPRN_SPRG_WSCRATCH4,r11
  562. mfspr r10,SPRN_SRR0 /* Get faulting address */
  563. /* If we are faulting a kernel address, we have to use the
  564. * kernel page tables.
  565. */
  566. lis r11,PAGE_OFFSET@h
  567. cmplw cr0,r10,r11
  568. blt+ 3f
  569. lis r11,swapper_pg_dir@h
  570. ori r11,r11, swapper_pg_dir@l
  571. li r12,0 /* MMUCR = 0 */
  572. b 4f
  573. /* Get the PGD for the current thread and setup MMUCR */
  574. 3: mfspr r11,SPRN_SPRG_THREAD
  575. lwz r11,PGDIR(r11)
  576. mfspr r12,SPRN_PID /* Get PID */
  577. 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
  578. /* Make up the required permissions */
  579. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  580. /* Load PTE */
  581. /* Compute pgdir/pmd offset */
  582. rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
  583. lwzx r11,r12,r11 /* Get pgd/pmd entry */
  584. /* Word 0 is EPN,V,TS,DSIZ */
  585. li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
  586. rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
  587. li r12,0
  588. tlbwe r10,r12,0
  589. /* XXX can we do better ? Need to make sure tlbwe has established
  590. * latch V bit in MMUCR0 before the PTE is loaded further down */
  591. #ifdef CONFIG_SMP
  592. isync
  593. #endif
  594. rlwinm. r12,r11,0,0,20 /* Extract pt base address */
  595. /* Compute pte address */
  596. rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
  597. beq 2f /* Bail if no table */
  598. lwz r11,0(r12) /* Get high word of pte entry */
  599. /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
  600. * bottom of r12 to create a data dependency... We can also use r10
  601. * as destination nowadays
  602. */
  603. #ifdef CONFIG_SMP
  604. lwsync
  605. #endif
  606. lwz r12,4(r12) /* Get low word of pte entry */
  607. andc. r13,r13,r12 /* Check permission */
  608. /* Jump to common TLB load point */
  609. beq finish_tlb_load_47x
  610. 2: /* The bailout. Restore registers to pre-exception conditions
  611. * and call the heavyweights to help us out.
  612. */
  613. mfspr r11, SPRN_SPRG_RSCRATCH4
  614. mtcr r11
  615. mfspr r13, SPRN_SPRG_RSCRATCH3
  616. mfspr r12, SPRN_SPRG_RSCRATCH2
  617. mfspr r11, SPRN_SPRG_RSCRATCH1
  618. mfspr r10, SPRN_SPRG_RSCRATCH0
  619. b InstructionStorage
  620. /*
  621. * Both the instruction and data TLB miss get to this
  622. * point to load the TLB.
  623. * r10 - free to use
  624. * r11 - PTE high word value
  625. * r12 - PTE low word value
  626. * r13 - free to use
  627. * MMUCR - loaded with proper value when we get here
  628. * Upon exit, we reload everything and RFI.
  629. */
  630. finish_tlb_load_47x:
  631. /* Combine RPN & ERPN an write WS 1 */
  632. rlwimi r11,r12,0,0,31-PAGE_SHIFT
  633. tlbwe r11,r13,1
  634. /* And make up word 2 */
  635. li r10,0xf85 /* Mask to apply from PTE */
  636. rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
  637. and r11,r12,r10 /* Mask PTE bits to keep */
  638. andi. r10,r12,_PAGE_USER /* User page ? */
  639. beq 1f /* nope, leave U bits empty */
  640. rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
  641. 1: tlbwe r11,r13,2
  642. /* Done...restore registers and get out of here.
  643. */
  644. mfspr r11, SPRN_SPRG_RSCRATCH4
  645. mtcr r11
  646. mfspr r13, SPRN_SPRG_RSCRATCH3
  647. mfspr r12, SPRN_SPRG_RSCRATCH2
  648. mfspr r11, SPRN_SPRG_RSCRATCH1
  649. mfspr r10, SPRN_SPRG_RSCRATCH0
  650. rfi
  651. #endif /* CONFIG_PPC_47x */
  652. /* Debug Interrupt */
  653. /*
  654. * This statement needs to exist at the end of the IVPR
  655. * definition just in case you end up taking a debug
  656. * exception within another exception.
  657. */
  658. DEBUG_CRIT_EXCEPTION
  659. interrupt_end:
  660. /*
  661. * Global functions
  662. */
  663. /*
  664. * Adjust the machine check IVOR on 440A cores
  665. */
  666. _GLOBAL(__fixup_440A_mcheck)
  667. li r3,MachineCheckA@l
  668. mtspr SPRN_IVOR1,r3
  669. sync
  670. blr
  671. _GLOBAL(set_context)
  672. #ifdef CONFIG_BDI_SWITCH
  673. /* Context switch the PTE pointer for the Abatron BDI2000.
  674. * The PGDIR is the second parameter.
  675. */
  676. lis r5, abatron_pteptrs@h
  677. ori r5, r5, abatron_pteptrs@l
  678. stw r4, 0x4(r5)
  679. #endif
  680. mtspr SPRN_PID,r3
  681. isync /* Force context change */
  682. blr
  683. /*
  684. * Init CPU state. This is called at boot time or for secondary CPUs
  685. * to setup initial TLB entries, setup IVORs, etc...
  686. *
  687. */
  688. _GLOBAL(init_cpu_state)
  689. mflr r22
  690. #ifdef CONFIG_PPC_47x
  691. /* We use the PVR to differenciate 44x cores from 476 */
  692. mfspr r3,SPRN_PVR
  693. srwi r3,r3,16
  694. cmplwi cr0,r3,PVR_476FPE@h
  695. beq head_start_47x
  696. cmplwi cr0,r3,PVR_476@h
  697. beq head_start_47x
  698. cmplwi cr0,r3,PVR_476_ISS@h
  699. beq head_start_47x
  700. #endif /* CONFIG_PPC_47x */
  701. /*
  702. * In case the firmware didn't do it, we apply some workarounds
  703. * that are good for all 440 core variants here
  704. */
  705. mfspr r3,SPRN_CCR0
  706. rlwinm r3,r3,0,0,27 /* disable icache prefetch */
  707. isync
  708. mtspr SPRN_CCR0,r3
  709. isync
  710. sync
  711. /*
  712. * Set up the initial MMU state for 44x
  713. *
  714. * We are still executing code at the virtual address
  715. * mappings set by the firmware for the base of RAM.
  716. *
  717. * We first invalidate all TLB entries but the one
  718. * we are running from. We then load the KERNELBASE
  719. * mappings so we can begin to use kernel addresses
  720. * natively and so the interrupt vector locations are
  721. * permanently pinned (necessary since Book E
  722. * implementations always have translation enabled).
  723. *
  724. * TODO: Use the known TLB entry we are running from to
  725. * determine which physical region we are located
  726. * in. This can be used to determine where in RAM
  727. * (on a shared CPU system) or PCI memory space
  728. * (on a DRAMless system) we are located.
  729. * For now, we assume a perfect world which means
  730. * we are located at the base of DRAM (physical 0).
  731. */
  732. /*
  733. * Search TLB for entry that we are currently using.
  734. * Invalidate all entries but the one we are using.
  735. */
  736. /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
  737. mfspr r3,SPRN_PID /* Get PID */
  738. mfmsr r4 /* Get MSR */
  739. andi. r4,r4,MSR_IS@l /* TS=1? */
  740. beq wmmucr /* If not, leave STS=0 */
  741. oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */
  742. wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
  743. sync
  744. bl invstr /* Find our address */
  745. invstr: mflr r5 /* Make it accessible */
  746. tlbsx r23,0,r5 /* Find entry we are in */
  747. li r4,0 /* Start at TLB entry 0 */
  748. li r3,0 /* Set PAGEID inval value */
  749. 1: cmpw r23,r4 /* Is this our entry? */
  750. beq skpinv /* If so, skip the inval */
  751. tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
  752. skpinv: addi r4,r4,1 /* Increment */
  753. cmpwi r4,64 /* Are we done? */
  754. bne 1b /* If not, repeat */
  755. isync /* If so, context change */
  756. /*
  757. * Configure and load pinned entry into TLB slot 63.
  758. */
  759. #ifdef CONFIG_NONSTATIC_KERNEL
  760. /*
  761. * In case of a NONSTATIC_KERNEL we reuse the TLB XLAT
  762. * entries of the initial mapping set by the boot loader.
  763. * The XLAT entry is stored in r25
  764. */
  765. /* Read the XLAT entry for our current mapping */
  766. tlbre r25,r23,PPC44x_TLB_XLAT
  767. lis r3,KERNELBASE@h
  768. ori r3,r3,KERNELBASE@l
  769. /* Use our current RPN entry */
  770. mr r4,r25
  771. #else
  772. lis r3,PAGE_OFFSET@h
  773. ori r3,r3,PAGE_OFFSET@l
  774. /* Kernel is at the base of RAM */
  775. li r4, 0 /* Load the kernel physical address */
  776. #endif
  777. /* Load the kernel PID = 0 */
  778. li r0,0
  779. mtspr SPRN_PID,r0
  780. sync
  781. /* Initialize MMUCR */
  782. li r5,0
  783. mtspr SPRN_MMUCR,r5
  784. sync
  785. /* pageid fields */
  786. clrrwi r3,r3,10 /* Mask off the effective page number */
  787. ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
  788. /* xlat fields */
  789. clrrwi r4,r4,10 /* Mask off the real page number */
  790. /* ERPN is 0 for first 4GB page */
  791. /* attrib fields */
  792. /* Added guarded bit to protect against speculative loads/stores */
  793. li r5,0
  794. ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
  795. li r0,63 /* TLB slot 63 */
  796. tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
  797. tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */
  798. tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
  799. /* Force context change */
  800. mfmsr r0
  801. mtspr SPRN_SRR1, r0
  802. lis r0,3f@h
  803. ori r0,r0,3f@l
  804. mtspr SPRN_SRR0,r0
  805. sync
  806. rfi
  807. /* If necessary, invalidate original entry we used */
  808. 3: cmpwi r23,63
  809. beq 4f
  810. li r6,0
  811. tlbwe r6,r23,PPC44x_TLB_PAGEID
  812. isync
  813. 4:
  814. #ifdef CONFIG_PPC_EARLY_DEBUG_44x
  815. /* Add UART mapping for early debug. */
  816. /* pageid fields */
  817. lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
  818. ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K
  819. /* xlat fields */
  820. lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
  821. ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
  822. /* attrib fields */
  823. li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G)
  824. li r0,62 /* TLB slot 0 */
  825. tlbwe r3,r0,PPC44x_TLB_PAGEID
  826. tlbwe r4,r0,PPC44x_TLB_XLAT
  827. tlbwe r5,r0,PPC44x_TLB_ATTRIB
  828. /* Force context change */
  829. isync
  830. #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
  831. /* Establish the interrupt vector offsets */
  832. SET_IVOR(0, CriticalInput);
  833. SET_IVOR(1, MachineCheck);
  834. SET_IVOR(2, DataStorage);
  835. SET_IVOR(3, InstructionStorage);
  836. SET_IVOR(4, ExternalInput);
  837. SET_IVOR(5, Alignment);
  838. SET_IVOR(6, Program);
  839. SET_IVOR(7, FloatingPointUnavailable);
  840. SET_IVOR(8, SystemCall);
  841. SET_IVOR(9, AuxillaryProcessorUnavailable);
  842. SET_IVOR(10, Decrementer);
  843. SET_IVOR(11, FixedIntervalTimer);
  844. SET_IVOR(12, WatchdogTimer);
  845. SET_IVOR(13, DataTLBError44x);
  846. SET_IVOR(14, InstructionTLBError44x);
  847. SET_IVOR(15, DebugCrit);
  848. b head_start_common
  849. #ifdef CONFIG_PPC_47x
  850. #ifdef CONFIG_SMP
  851. /* Entry point for secondary 47x processors */
  852. _GLOBAL(start_secondary_47x)
  853. mr r24,r3 /* CPU number */
  854. bl init_cpu_state
  855. /* Now we need to bolt the rest of kernel memory which
  856. * is done in C code. We must be careful because our task
  857. * struct or our stack can (and will probably) be out
  858. * of reach of the initial 256M TLB entry, so we use a
  859. * small temporary stack in .bss for that. This works
  860. * because only one CPU at a time can be in this code
  861. */
  862. lis r1,temp_boot_stack@h
  863. ori r1,r1,temp_boot_stack@l
  864. addi r1,r1,1024-STACK_FRAME_OVERHEAD
  865. li r0,0
  866. stw r0,0(r1)
  867. bl mmu_init_secondary
  868. /* Now we can get our task struct and real stack pointer */
  869. /* Get current_thread_info and current */
  870. lis r1,secondary_ti@ha
  871. lwz r1,secondary_ti@l(r1)
  872. lwz r2,TI_TASK(r1)
  873. /* Current stack pointer */
  874. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  875. li r0,0
  876. stw r0,0(r1)
  877. /* Kernel stack for exception entry in SPRG3 */
  878. addi r4,r2,THREAD /* init task's THREAD */
  879. mtspr SPRN_SPRG3,r4
  880. b start_secondary
  881. #endif /* CONFIG_SMP */
  882. /*
  883. * Set up the initial MMU state for 44x
  884. *
  885. * We are still executing code at the virtual address
  886. * mappings set by the firmware for the base of RAM.
  887. */
  888. head_start_47x:
  889. /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
  890. mfspr r3,SPRN_PID /* Get PID */
  891. mfmsr r4 /* Get MSR */
  892. andi. r4,r4,MSR_IS@l /* TS=1? */
  893. beq 1f /* If not, leave STS=0 */
  894. oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */
  895. 1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
  896. sync
  897. /* Find the entry we are running from */
  898. bl 1f
  899. 1: mflr r23
  900. tlbsx r23,0,r23
  901. tlbre r24,r23,0
  902. tlbre r25,r23,1
  903. tlbre r26,r23,2
  904. /*
  905. * Cleanup time
  906. */
  907. /* Initialize MMUCR */
  908. li r5,0
  909. mtspr SPRN_MMUCR,r5
  910. sync
  911. clear_all_utlb_entries:
  912. #; Set initial values.
  913. addis r3,0,0x8000
  914. addi r4,0,0
  915. addi r5,0,0
  916. b clear_utlb_entry
  917. #; Align the loop to speed things up.
  918. .align 6
  919. clear_utlb_entry:
  920. tlbwe r4,r3,0
  921. tlbwe r5,r3,1
  922. tlbwe r5,r3,2
  923. addis r3,r3,0x2000
  924. cmpwi r3,0
  925. bne clear_utlb_entry
  926. addis r3,0,0x8000
  927. addis r4,r4,0x100
  928. cmpwi r4,0
  929. bne clear_utlb_entry
  930. #; Restore original entry.
  931. oris r23,r23,0x8000 /* specify the way */
  932. tlbwe r24,r23,0
  933. tlbwe r25,r23,1
  934. tlbwe r26,r23,2
  935. /*
  936. * Configure and load pinned entry into TLB for the kernel core
  937. */
  938. lis r3,PAGE_OFFSET@h
  939. ori r3,r3,PAGE_OFFSET@l
  940. /* Load the kernel PID = 0 */
  941. li r0,0
  942. mtspr SPRN_PID,r0
  943. sync
  944. /* Word 0 */
  945. clrrwi r3,r3,12 /* Mask off the effective page number */
  946. ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M
  947. /* Word 1 - use r25. RPN is the same as the original entry */
  948. /* Word 2 */
  949. li r5,0
  950. ori r5,r5,PPC47x_TLB2_S_RWX
  951. #ifdef CONFIG_SMP
  952. ori r5,r5,PPC47x_TLB2_M
  953. #endif
  954. /* We write to way 0 and bolted 0 */
  955. lis r0,0x8800
  956. tlbwe r3,r0,0
  957. tlbwe r25,r0,1
  958. tlbwe r5,r0,2
  959. /*
  960. * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix
  961. * them up later
  962. */
  963. LOAD_REG_IMMEDIATE(r3, 0x9abcdef0)
  964. mtspr SPRN_SSPCR,r3
  965. mtspr SPRN_USPCR,r3
  966. LOAD_REG_IMMEDIATE(r3, 0x12345670)
  967. mtspr SPRN_ISPCR,r3
  968. /* Force context change */
  969. mfmsr r0
  970. mtspr SPRN_SRR1, r0
  971. lis r0,3f@h
  972. ori r0,r0,3f@l
  973. mtspr SPRN_SRR0,r0
  974. sync
  975. rfi
  976. /* Invalidate original entry we used */
  977. 3:
  978. rlwinm r24,r24,0,21,19 /* clear the "valid" bit */
  979. tlbwe r24,r23,0
  980. addi r24,0,0
  981. tlbwe r24,r23,1
  982. tlbwe r24,r23,2
  983. isync /* Clear out the shadow TLB entries */
  984. #ifdef CONFIG_PPC_EARLY_DEBUG_44x
  985. /* Add UART mapping for early debug. */
  986. /* Word 0 */
  987. lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
  988. ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M
  989. /* Word 1 */
  990. lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
  991. ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
  992. /* Word 2 */
  993. li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG)
  994. /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same
  995. * congruence class as the kernel, we need to make sure of it at
  996. * some point
  997. */
  998. lis r0,0x8d00
  999. tlbwe r3,r0,0
  1000. tlbwe r4,r0,1
  1001. tlbwe r5,r0,2
  1002. /* Force context change */
  1003. isync
  1004. #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
  1005. /* Establish the interrupt vector offsets */
  1006. SET_IVOR(0, CriticalInput);
  1007. SET_IVOR(1, MachineCheckA);
  1008. SET_IVOR(2, DataStorage);
  1009. SET_IVOR(3, InstructionStorage);
  1010. SET_IVOR(4, ExternalInput);
  1011. SET_IVOR(5, Alignment);
  1012. SET_IVOR(6, Program);
  1013. SET_IVOR(7, FloatingPointUnavailable);
  1014. SET_IVOR(8, SystemCall);
  1015. SET_IVOR(9, AuxillaryProcessorUnavailable);
  1016. SET_IVOR(10, Decrementer);
  1017. SET_IVOR(11, FixedIntervalTimer);
  1018. SET_IVOR(12, WatchdogTimer);
  1019. SET_IVOR(13, DataTLBError47x);
  1020. SET_IVOR(14, InstructionTLBError47x);
  1021. SET_IVOR(15, DebugCrit);
  1022. /* We configure icbi to invalidate 128 bytes at a time since the
  1023. * current 32-bit kernel code isn't too happy with icache != dcache
  1024. * block size. We also disable the BTAC as this can cause errors
  1025. * in some circumstances (see IBM Erratum 47).
  1026. */
  1027. mfspr r3,SPRN_CCR0
  1028. oris r3,r3,0x0020
  1029. ori r3,r3,0x0040
  1030. mtspr SPRN_CCR0,r3
  1031. isync
  1032. #endif /* CONFIG_PPC_47x */
  1033. /*
  1034. * Here we are back to code that is common between 44x and 47x
  1035. *
  1036. * We proceed to further kernel initialization and return to the
  1037. * main kernel entry
  1038. */
  1039. head_start_common:
  1040. /* Establish the interrupt vector base */
  1041. lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
  1042. mtspr SPRN_IVPR,r4
  1043. /*
  1044. * If the kernel was loaded at a non-zero 256 MB page, we need to
  1045. * mask off the most significant 4 bits to get the relative address
  1046. * from the start of physical memory
  1047. */
  1048. rlwinm r22,r22,0,4,31
  1049. addis r22,r22,PAGE_OFFSET@h
  1050. mtlr r22
  1051. isync
  1052. blr
  1053. /*
  1054. * We put a few things here that have to be page-aligned. This stuff
  1055. * goes at the beginning of the data segment, which is page-aligned.
  1056. */
  1057. .data
  1058. .align PAGE_SHIFT
  1059. .globl sdata
  1060. sdata:
  1061. .globl empty_zero_page
  1062. empty_zero_page:
  1063. .space PAGE_SIZE
  1064. /*
  1065. * To support >32-bit physical addresses, we use an 8KB pgdir.
  1066. */
  1067. .globl swapper_pg_dir
  1068. swapper_pg_dir:
  1069. .space PGD_TABLE_SIZE
  1070. /*
  1071. * Room for two PTE pointers, usually the kernel and current user pointers
  1072. * to their respective root page table.
  1073. */
  1074. abatron_pteptrs:
  1075. .space 8
  1076. #ifdef CONFIG_SMP
  1077. .align 12
  1078. temp_boot_stack:
  1079. .space 1024
  1080. #endif /* CONFIG_SMP */