head_44x.S 33 KB

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