head_44x.S 33 KB

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