head_44x.S 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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. /*
  660. * Global functions
  661. */
  662. /*
  663. * Adjust the machine check IVOR on 440A cores
  664. */
  665. _GLOBAL(__fixup_440A_mcheck)
  666. li r3,MachineCheckA@l
  667. mtspr SPRN_IVOR1,r3
  668. sync
  669. blr
  670. /*
  671. * extern void giveup_fpu(struct task_struct *prev)
  672. *
  673. * The 44x core does not have an FPU.
  674. */
  675. #ifndef CONFIG_PPC_FPU
  676. _GLOBAL(giveup_fpu)
  677. blr
  678. #endif
  679. _GLOBAL(set_context)
  680. #ifdef CONFIG_BDI_SWITCH
  681. /* Context switch the PTE pointer for the Abatron BDI2000.
  682. * The PGDIR is the second parameter.
  683. */
  684. lis r5, abatron_pteptrs@h
  685. ori r5, r5, abatron_pteptrs@l
  686. stw r4, 0x4(r5)
  687. #endif
  688. mtspr SPRN_PID,r3
  689. isync /* Force context change */
  690. blr
  691. /*
  692. * Init CPU state. This is called at boot time or for secondary CPUs
  693. * to setup initial TLB entries, setup IVORs, etc...
  694. *
  695. */
  696. _GLOBAL(init_cpu_state)
  697. mflr r22
  698. #ifdef CONFIG_PPC_47x
  699. /* We use the PVR to differenciate 44x cores from 476 */
  700. mfspr r3,SPRN_PVR
  701. srwi r3,r3,16
  702. cmplwi cr0,r3,PVR_476FPE@h
  703. beq head_start_47x
  704. cmplwi cr0,r3,PVR_476@h
  705. beq head_start_47x
  706. cmplwi cr0,r3,PVR_476_ISS@h
  707. beq head_start_47x
  708. #endif /* CONFIG_PPC_47x */
  709. /*
  710. * In case the firmware didn't do it, we apply some workarounds
  711. * that are good for all 440 core variants here
  712. */
  713. mfspr r3,SPRN_CCR0
  714. rlwinm r3,r3,0,0,27 /* disable icache prefetch */
  715. isync
  716. mtspr SPRN_CCR0,r3
  717. isync
  718. sync
  719. /*
  720. * Set up the initial MMU state for 44x
  721. *
  722. * We are still executing code at the virtual address
  723. * mappings set by the firmware for the base of RAM.
  724. *
  725. * We first invalidate all TLB entries but the one
  726. * we are running from. We then load the KERNELBASE
  727. * mappings so we can begin to use kernel addresses
  728. * natively and so the interrupt vector locations are
  729. * permanently pinned (necessary since Book E
  730. * implementations always have translation enabled).
  731. *
  732. * TODO: Use the known TLB entry we are running from to
  733. * determine which physical region we are located
  734. * in. This can be used to determine where in RAM
  735. * (on a shared CPU system) or PCI memory space
  736. * (on a DRAMless system) we are located.
  737. * For now, we assume a perfect world which means
  738. * we are located at the base of DRAM (physical 0).
  739. */
  740. /*
  741. * Search TLB for entry that we are currently using.
  742. * Invalidate all entries but the one we are using.
  743. */
  744. /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
  745. mfspr r3,SPRN_PID /* Get PID */
  746. mfmsr r4 /* Get MSR */
  747. andi. r4,r4,MSR_IS@l /* TS=1? */
  748. beq wmmucr /* If not, leave STS=0 */
  749. oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */
  750. wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
  751. sync
  752. bl invstr /* Find our address */
  753. invstr: mflr r5 /* Make it accessible */
  754. tlbsx r23,0,r5 /* Find entry we are in */
  755. li r4,0 /* Start at TLB entry 0 */
  756. li r3,0 /* Set PAGEID inval value */
  757. 1: cmpw r23,r4 /* Is this our entry? */
  758. beq skpinv /* If so, skip the inval */
  759. tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
  760. skpinv: addi r4,r4,1 /* Increment */
  761. cmpwi r4,64 /* Are we done? */
  762. bne 1b /* If not, repeat */
  763. isync /* If so, context change */
  764. /*
  765. * Configure and load pinned entry into TLB slot 63.
  766. */
  767. #ifdef CONFIG_NONSTATIC_KERNEL
  768. /*
  769. * In case of a NONSTATIC_KERNEL we reuse the TLB XLAT
  770. * entries of the initial mapping set by the boot loader.
  771. * The XLAT entry is stored in r25
  772. */
  773. /* Read the XLAT entry for our current mapping */
  774. tlbre r25,r23,PPC44x_TLB_XLAT
  775. lis r3,KERNELBASE@h
  776. ori r3,r3,KERNELBASE@l
  777. /* Use our current RPN entry */
  778. mr r4,r25
  779. #else
  780. lis r3,PAGE_OFFSET@h
  781. ori r3,r3,PAGE_OFFSET@l
  782. /* Kernel is at the base of RAM */
  783. li r4, 0 /* Load the kernel physical address */
  784. #endif
  785. /* Load the kernel PID = 0 */
  786. li r0,0
  787. mtspr SPRN_PID,r0
  788. sync
  789. /* Initialize MMUCR */
  790. li r5,0
  791. mtspr SPRN_MMUCR,r5
  792. sync
  793. /* pageid fields */
  794. clrrwi r3,r3,10 /* Mask off the effective page number */
  795. ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
  796. /* xlat fields */
  797. clrrwi r4,r4,10 /* Mask off the real page number */
  798. /* ERPN is 0 for first 4GB page */
  799. /* attrib fields */
  800. /* Added guarded bit to protect against speculative loads/stores */
  801. li r5,0
  802. ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
  803. li r0,63 /* TLB slot 63 */
  804. tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
  805. tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */
  806. tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
  807. /* Force context change */
  808. mfmsr r0
  809. mtspr SPRN_SRR1, r0
  810. lis r0,3f@h
  811. ori r0,r0,3f@l
  812. mtspr SPRN_SRR0,r0
  813. sync
  814. rfi
  815. /* If necessary, invalidate original entry we used */
  816. 3: cmpwi r23,63
  817. beq 4f
  818. li r6,0
  819. tlbwe r6,r23,PPC44x_TLB_PAGEID
  820. isync
  821. 4:
  822. #ifdef CONFIG_PPC_EARLY_DEBUG_44x
  823. /* Add UART mapping for early debug. */
  824. /* pageid fields */
  825. lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
  826. ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K
  827. /* xlat fields */
  828. lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
  829. ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
  830. /* attrib fields */
  831. li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G)
  832. li r0,62 /* TLB slot 0 */
  833. tlbwe r3,r0,PPC44x_TLB_PAGEID
  834. tlbwe r4,r0,PPC44x_TLB_XLAT
  835. tlbwe r5,r0,PPC44x_TLB_ATTRIB
  836. /* Force context change */
  837. isync
  838. #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
  839. /* Establish the interrupt vector offsets */
  840. SET_IVOR(0, CriticalInput);
  841. SET_IVOR(1, MachineCheck);
  842. SET_IVOR(2, DataStorage);
  843. SET_IVOR(3, InstructionStorage);
  844. SET_IVOR(4, ExternalInput);
  845. SET_IVOR(5, Alignment);
  846. SET_IVOR(6, Program);
  847. SET_IVOR(7, FloatingPointUnavailable);
  848. SET_IVOR(8, SystemCall);
  849. SET_IVOR(9, AuxillaryProcessorUnavailable);
  850. SET_IVOR(10, Decrementer);
  851. SET_IVOR(11, FixedIntervalTimer);
  852. SET_IVOR(12, WatchdogTimer);
  853. SET_IVOR(13, DataTLBError44x);
  854. SET_IVOR(14, InstructionTLBError44x);
  855. SET_IVOR(15, DebugCrit);
  856. b head_start_common
  857. #ifdef CONFIG_PPC_47x
  858. #ifdef CONFIG_SMP
  859. /* Entry point for secondary 47x processors */
  860. _GLOBAL(start_secondary_47x)
  861. mr r24,r3 /* CPU number */
  862. bl init_cpu_state
  863. /* Now we need to bolt the rest of kernel memory which
  864. * is done in C code. We must be careful because our task
  865. * struct or our stack can (and will probably) be out
  866. * of reach of the initial 256M TLB entry, so we use a
  867. * small temporary stack in .bss for that. This works
  868. * because only one CPU at a time can be in this code
  869. */
  870. lis r1,temp_boot_stack@h
  871. ori r1,r1,temp_boot_stack@l
  872. addi r1,r1,1024-STACK_FRAME_OVERHEAD
  873. li r0,0
  874. stw r0,0(r1)
  875. bl mmu_init_secondary
  876. /* Now we can get our task struct and real stack pointer */
  877. /* Get current_thread_info and current */
  878. lis r1,secondary_ti@ha
  879. lwz r1,secondary_ti@l(r1)
  880. lwz r2,TI_TASK(r1)
  881. /* Current stack pointer */
  882. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  883. li r0,0
  884. stw r0,0(r1)
  885. /* Kernel stack for exception entry in SPRG3 */
  886. addi r4,r2,THREAD /* init task's THREAD */
  887. mtspr SPRN_SPRG3,r4
  888. b start_secondary
  889. #endif /* CONFIG_SMP */
  890. /*
  891. * Set up the initial MMU state for 44x
  892. *
  893. * We are still executing code at the virtual address
  894. * mappings set by the firmware for the base of RAM.
  895. */
  896. head_start_47x:
  897. /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
  898. mfspr r3,SPRN_PID /* Get PID */
  899. mfmsr r4 /* Get MSR */
  900. andi. r4,r4,MSR_IS@l /* TS=1? */
  901. beq 1f /* If not, leave STS=0 */
  902. oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */
  903. 1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
  904. sync
  905. /* Find the entry we are running from */
  906. bl 1f
  907. 1: mflr r23
  908. tlbsx r23,0,r23
  909. tlbre r24,r23,0
  910. tlbre r25,r23,1
  911. tlbre r26,r23,2
  912. /*
  913. * Cleanup time
  914. */
  915. /* Initialize MMUCR */
  916. li r5,0
  917. mtspr SPRN_MMUCR,r5
  918. sync
  919. clear_all_utlb_entries:
  920. #; Set initial values.
  921. addis r3,0,0x8000
  922. addi r4,0,0
  923. addi r5,0,0
  924. b clear_utlb_entry
  925. #; Align the loop to speed things up.
  926. .align 6
  927. clear_utlb_entry:
  928. tlbwe r4,r3,0
  929. tlbwe r5,r3,1
  930. tlbwe r5,r3,2
  931. addis r3,r3,0x2000
  932. cmpwi r3,0
  933. bne clear_utlb_entry
  934. addis r3,0,0x8000
  935. addis r4,r4,0x100
  936. cmpwi r4,0
  937. bne clear_utlb_entry
  938. #; Restore original entry.
  939. oris r23,r23,0x8000 /* specify the way */
  940. tlbwe r24,r23,0
  941. tlbwe r25,r23,1
  942. tlbwe r26,r23,2
  943. /*
  944. * Configure and load pinned entry into TLB for the kernel core
  945. */
  946. lis r3,PAGE_OFFSET@h
  947. ori r3,r3,PAGE_OFFSET@l
  948. /* Load the kernel PID = 0 */
  949. li r0,0
  950. mtspr SPRN_PID,r0
  951. sync
  952. /* Word 0 */
  953. clrrwi r3,r3,12 /* Mask off the effective page number */
  954. ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M
  955. /* Word 1 - use r25. RPN is the same as the original entry */
  956. /* Word 2 */
  957. li r5,0
  958. ori r5,r5,PPC47x_TLB2_S_RWX
  959. #ifdef CONFIG_SMP
  960. ori r5,r5,PPC47x_TLB2_M
  961. #endif
  962. /* We write to way 0 and bolted 0 */
  963. lis r0,0x8800
  964. tlbwe r3,r0,0
  965. tlbwe r25,r0,1
  966. tlbwe r5,r0,2
  967. /*
  968. * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix
  969. * them up later
  970. */
  971. LOAD_REG_IMMEDIATE(r3, 0x9abcdef0)
  972. mtspr SPRN_SSPCR,r3
  973. mtspr SPRN_USPCR,r3
  974. LOAD_REG_IMMEDIATE(r3, 0x12345670)
  975. mtspr SPRN_ISPCR,r3
  976. /* Force context change */
  977. mfmsr r0
  978. mtspr SPRN_SRR1, r0
  979. lis r0,3f@h
  980. ori r0,r0,3f@l
  981. mtspr SPRN_SRR0,r0
  982. sync
  983. rfi
  984. /* Invalidate original entry we used */
  985. 3:
  986. rlwinm r24,r24,0,21,19 /* clear the "valid" bit */
  987. tlbwe r24,r23,0
  988. addi r24,0,0
  989. tlbwe r24,r23,1
  990. tlbwe r24,r23,2
  991. isync /* Clear out the shadow TLB entries */
  992. #ifdef CONFIG_PPC_EARLY_DEBUG_44x
  993. /* Add UART mapping for early debug. */
  994. /* Word 0 */
  995. lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
  996. ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M
  997. /* Word 1 */
  998. lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
  999. ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
  1000. /* Word 2 */
  1001. li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG)
  1002. /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same
  1003. * congruence class as the kernel, we need to make sure of it at
  1004. * some point
  1005. */
  1006. lis r0,0x8d00
  1007. tlbwe r3,r0,0
  1008. tlbwe r4,r0,1
  1009. tlbwe r5,r0,2
  1010. /* Force context change */
  1011. isync
  1012. #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
  1013. /* Establish the interrupt vector offsets */
  1014. SET_IVOR(0, CriticalInput);
  1015. SET_IVOR(1, MachineCheckA);
  1016. SET_IVOR(2, DataStorage);
  1017. SET_IVOR(3, InstructionStorage);
  1018. SET_IVOR(4, ExternalInput);
  1019. SET_IVOR(5, Alignment);
  1020. SET_IVOR(6, Program);
  1021. SET_IVOR(7, FloatingPointUnavailable);
  1022. SET_IVOR(8, SystemCall);
  1023. SET_IVOR(9, AuxillaryProcessorUnavailable);
  1024. SET_IVOR(10, Decrementer);
  1025. SET_IVOR(11, FixedIntervalTimer);
  1026. SET_IVOR(12, WatchdogTimer);
  1027. SET_IVOR(13, DataTLBError47x);
  1028. SET_IVOR(14, InstructionTLBError47x);
  1029. SET_IVOR(15, DebugCrit);
  1030. /* We configure icbi to invalidate 128 bytes at a time since the
  1031. * current 32-bit kernel code isn't too happy with icache != dcache
  1032. * block size
  1033. */
  1034. mfspr r3,SPRN_CCR0
  1035. oris r3,r3,0x0020
  1036. mtspr SPRN_CCR0,r3
  1037. isync
  1038. #endif /* CONFIG_PPC_47x */
  1039. /*
  1040. * Here we are back to code that is common between 44x and 47x
  1041. *
  1042. * We proceed to further kernel initialization and return to the
  1043. * main kernel entry
  1044. */
  1045. head_start_common:
  1046. /* Establish the interrupt vector base */
  1047. lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
  1048. mtspr SPRN_IVPR,r4
  1049. /*
  1050. * If the kernel was loaded at a non-zero 256 MB page, we need to
  1051. * mask off the most significant 4 bits to get the relative address
  1052. * from the start of physical memory
  1053. */
  1054. rlwinm r22,r22,0,4,31
  1055. addis r22,r22,PAGE_OFFSET@h
  1056. mtlr r22
  1057. isync
  1058. blr
  1059. /*
  1060. * We put a few things here that have to be page-aligned. This stuff
  1061. * goes at the beginning of the data segment, which is page-aligned.
  1062. */
  1063. .data
  1064. .align PAGE_SHIFT
  1065. .globl sdata
  1066. sdata:
  1067. .globl empty_zero_page
  1068. empty_zero_page:
  1069. .space PAGE_SIZE
  1070. /*
  1071. * To support >32-bit physical addresses, we use an 8KB pgdir.
  1072. */
  1073. .globl swapper_pg_dir
  1074. swapper_pg_dir:
  1075. .space PGD_TABLE_SIZE
  1076. /*
  1077. * Room for two PTE pointers, usually the kernel and current user pointers
  1078. * to their respective root page table.
  1079. */
  1080. abatron_pteptrs:
  1081. .space 8
  1082. #ifdef CONFIG_SMP
  1083. .align 12
  1084. temp_boot_stack:
  1085. .space 1024
  1086. #endif /* CONFIG_SMP */