head_44x.S 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Kernel execution entry point code.
  4. *
  5. * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
  6. * Initial PowerPC version.
  7. * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
  8. * Rewritten for PReP
  9. * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
  10. * Low-level exception handers, MMU support, and rewrite.
  11. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  12. * PowerPC 8xx modifications.
  13. * Copyright (c) 1998-1999 TiVo, Inc.
  14. * PowerPC 403GCX modifications.
  15. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  16. * PowerPC 403GCX/405GP modifications.
  17. * Copyright 2000 MontaVista Software Inc.
  18. * PPC405 modifications
  19. * PowerPC 403GCX/405GP modifications.
  20. * Author: MontaVista Software, Inc.
  21. * frank_rowand@mvista.com or source@mvista.com
  22. * debbie_chu@mvista.com
  23. * Copyright 2002-2005 MontaVista Software, Inc.
  24. * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
  25. */
  26. #include <linux/init.h>
  27. #include <linux/pgtable.h>
  28. #include <asm/processor.h>
  29. #include <asm/page.h>
  30. #include <asm/mmu.h>
  31. #include <asm/cputable.h>
  32. #include <asm/thread_info.h>
  33. #include <asm/ppc_asm.h>
  34. #include <asm/asm-offsets.h>
  35. #include <asm/ptrace.h>
  36. #include <asm/synch.h>
  37. #include <asm/code-patching-asm.h>
  38. #include "head_booke.h"
  39. /* As with the other PowerPC ports, it is expected that when code
  40. * execution begins here, the following registers contain valid, yet
  41. * optional, information:
  42. *
  43. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  44. * r4 - Starting address of the init RAM disk
  45. * r5 - Ending address of the init RAM disk
  46. * r6 - Start of kernel command line string (e.g. "mem=128")
  47. * r7 - End of kernel command line string
  48. *
  49. */
  50. __HEAD
  51. _GLOBAL(_stext);
  52. _GLOBAL(_start);
  53. /*
  54. * Reserve a word at a fixed location to store the address
  55. * of abatron_pteptrs
  56. */
  57. nop
  58. mr r31,r3 /* save device tree ptr */
  59. li r24,0 /* CPU number */
  60. #ifdef CONFIG_RELOCATABLE
  61. /*
  62. * Relocate ourselves to the current runtime address.
  63. * This is called only by the Boot CPU.
  64. * "relocate" is called with our current runtime virutal
  65. * address.
  66. * r21 will be loaded with the physical runtime address of _stext
  67. */
  68. bcl 20,31,$+4 /* Get our runtime address */
  69. 0: mflr r21 /* Make it accessible */
  70. addis r21,r21,(_stext - 0b)@ha
  71. addi r21,r21,(_stext - 0b)@l /* Get our current runtime base */
  72. /*
  73. * We have the runtime (virutal) address of our base.
  74. * We calculate our shift of offset from a 256M page.
  75. * We could map the 256M page we belong to at PAGE_OFFSET and
  76. * get going from there.
  77. */
  78. lis r4,KERNELBASE@h
  79. ori r4,r4,KERNELBASE@l
  80. rlwinm r6,r21,0,4,31 /* r6 = PHYS_START % 256M */
  81. rlwinm r5,r4,0,4,31 /* r5 = KERNELBASE % 256M */
  82. subf r3,r5,r6 /* r3 = r6 - r5 */
  83. add r3,r4,r3 /* Required Virutal Address */
  84. bl relocate
  85. #endif
  86. bl init_cpu_state
  87. /*
  88. * This is where the main kernel code starts.
  89. */
  90. /* ptr to current */
  91. lis r2,init_task@h
  92. ori r2,r2,init_task@l
  93. /* ptr to current thread */
  94. addi r4,r2,THREAD /* init task's THREAD */
  95. mtspr SPRN_SPRG_THREAD,r4
  96. /* stack */
  97. lis r1,init_thread_union@h
  98. ori r1,r1,init_thread_union@l
  99. li r0,0
  100. stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
  101. bl early_init
  102. #ifdef CONFIG_RELOCATABLE
  103. /*
  104. * Relocatable kernel support based on processing of dynamic
  105. * relocation entries.
  106. *
  107. * r25 will contain RPN/ERPN for the start address of memory
  108. * r21 will contain the current offset of _stext
  109. */
  110. lis r3,kernstart_addr@ha
  111. la r3,kernstart_addr@l(r3)
  112. /*
  113. * Compute the kernstart_addr.
  114. * kernstart_addr => (r6,r8)
  115. * kernstart_addr & ~0xfffffff => (r6,r7)
  116. */
  117. rlwinm r6,r25,0,28,31 /* ERPN. Bits 32-35 of Address */
  118. rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */
  119. rlwinm r8,r21,0,4,31 /* r8 = (_stext & 0xfffffff) */
  120. or r8,r7,r8 /* Compute the lower 32bit of kernstart_addr */
  121. /* Store kernstart_addr */
  122. stw r6,0(r3) /* higher 32bit */
  123. stw r8,4(r3) /* lower 32bit */
  124. /*
  125. * Compute the virt_phys_offset :
  126. * virt_phys_offset = stext.run - kernstart_addr
  127. *
  128. * stext.run = (KERNELBASE & ~0xfffffff) + (kernstart_addr & 0xfffffff)
  129. * When we relocate, we have :
  130. *
  131. * (kernstart_addr & 0xfffffff) = (stext.run & 0xfffffff)
  132. *
  133. * hence:
  134. * virt_phys_offset = (KERNELBASE & ~0xfffffff) - (kernstart_addr & ~0xfffffff)
  135. *
  136. */
  137. /* KERNELBASE&~0xfffffff => (r4,r5) */
  138. li r4, 0 /* higer 32bit */
  139. lis r5,KERNELBASE@h
  140. rlwinm r5,r5,0,0,3 /* Align to 256M, lower 32bit */
  141. /*
  142. * 64bit subtraction.
  143. */
  144. subfc r5,r7,r5
  145. subfe r4,r6,r4
  146. /* Store virt_phys_offset */
  147. lis r3,virt_phys_offset@ha
  148. la r3,virt_phys_offset@l(r3)
  149. stw r4,0(r3)
  150. stw r5,4(r3)
  151. #elif defined(CONFIG_DYNAMIC_MEMSTART)
  152. /*
  153. * Mapping based, page aligned dynamic kernel loading.
  154. *
  155. * r25 will contain RPN/ERPN for the start address of memory
  156. *
  157. * Add the difference between KERNELBASE and PAGE_OFFSET to the
  158. * start of physical memory to get kernstart_addr.
  159. */
  160. lis r3,kernstart_addr@ha
  161. la r3,kernstart_addr@l(r3)
  162. lis r4,KERNELBASE@h
  163. ori r4,r4,KERNELBASE@l
  164. lis r5,PAGE_OFFSET@h
  165. ori r5,r5,PAGE_OFFSET@l
  166. subf r4,r5,r4
  167. rlwinm r6,r25,0,28,31 /* ERPN */
  168. rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */
  169. add r7,r7,r4
  170. stw r6,0(r3)
  171. stw r7,4(r3)
  172. #endif
  173. /*
  174. * Decide what sort of machine this is and initialize the MMU.
  175. */
  176. #ifdef CONFIG_KASAN
  177. bl kasan_early_init
  178. #endif
  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, do_IRQ)
  232. /* Alignment Interrupt */
  233. ALIGNMENT_EXCEPTION
  234. /* Program Interrupt */
  235. PROGRAM_EXCEPTION
  236. /* Floating Point Unavailable Interrupt */
  237. #ifdef CONFIG_PPC_FPU
  238. FP_UNAVAILABLE_EXCEPTION
  239. #else
  240. EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \
  241. FloatingPointUnavailable, unknown_exception)
  242. #endif
  243. /* System Call Interrupt */
  244. START_EXCEPTION(SystemCall)
  245. SYSCALL_ENTRY 0xc00 BOOKE_INTERRUPT_SYSCALL
  246. /* Auxiliary Processor Unavailable Interrupt */
  247. EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \
  248. AuxillaryProcessorUnavailable, unknown_exception)
  249. /* Decrementer Interrupt */
  250. DECREMENTER_EXCEPTION
  251. /* Fixed Internal Timer Interrupt */
  252. /* TODO: Add FIT support */
  253. EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, unknown_exception)
  254. /* Watchdog Timer Interrupt */
  255. /* TODO: Add watchdog support */
  256. #ifdef CONFIG_BOOKE_WDT
  257. CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException)
  258. #else
  259. CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception)
  260. #endif
  261. /* Data TLB Error Interrupt */
  262. START_EXCEPTION(DataTLBError44x)
  263. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  264. mtspr SPRN_SPRG_WSCRATCH1, r11
  265. mtspr SPRN_SPRG_WSCRATCH2, r12
  266. mtspr SPRN_SPRG_WSCRATCH3, r13
  267. mfcr r11
  268. mtspr SPRN_SPRG_WSCRATCH4, r11
  269. mfspr r10, SPRN_DEAR /* Get faulting address */
  270. /* If we are faulting a kernel address, we have to use the
  271. * kernel page tables.
  272. */
  273. lis r11, PAGE_OFFSET@h
  274. cmplw cr7, r10, r11
  275. blt+ cr7, 3f
  276. lis r11, swapper_pg_dir@h
  277. ori r11, r11, swapper_pg_dir@l
  278. mfspr r12,SPRN_MMUCR
  279. rlwinm r12,r12,0,0,23 /* Clear TID */
  280. b 4f
  281. /* Get the PGD for the current thread */
  282. 3:
  283. mfspr r11,SPRN_SPRG_THREAD
  284. lwz r11,PGDIR(r11)
  285. /* Load PID into MMUCR TID */
  286. mfspr r12,SPRN_MMUCR
  287. mfspr r13,SPRN_PID /* Get PID */
  288. rlwimi r12,r13,0,24,31 /* Set TID */
  289. #ifdef CONFIG_PPC_KUAP
  290. cmpwi r13,0
  291. beq 2f /* KUAP Fault */
  292. #endif
  293. 4:
  294. mtspr SPRN_MMUCR,r12
  295. /* Mask of required permission bits. Note that while we
  296. * do copy ESR:ST to _PAGE_WRITE 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|_PAGE_READ
  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 mismatch */
  326. /* Increment, rollover, and store TLB index */
  327. addi r13,r13,1
  328. patch_site 0f, patch__tlb_44x_hwater_D
  329. /* Compare with watermark (instruction gets patched) */
  330. 0: 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 cr7, r10, r11
  370. blt+ cr7, 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. #ifdef CONFIG_PPC_KUAP
  385. cmpwi r13,0
  386. beq 2f /* KUAP Fault */
  387. #endif
  388. 4:
  389. mtspr SPRN_MMUCR,r12
  390. /* Make up the required permissions */
  391. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  392. /* Compute pgdir/pmd offset */
  393. rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
  394. lwzx r11, r12, r11 /* Get pgd/pmd entry */
  395. rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
  396. beq 2f /* Bail if no table */
  397. /* Compute pte address */
  398. rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
  399. lwz r11, 0(r12) /* Get high word of pte entry */
  400. lwz r12, 4(r12) /* Get low word of pte entry */
  401. lis r10,tlb_44x_index@ha
  402. andc. r13,r13,r12 /* Check permission */
  403. /* Load the next available TLB index */
  404. lwz r13,tlb_44x_index@l(r10)
  405. bne 2f /* Bail if permission mismatch */
  406. /* Increment, rollover, and store TLB index */
  407. addi r13,r13,1
  408. patch_site 0f, patch__tlb_44x_hwater_I
  409. /* Compare with watermark (instruction gets patched) */
  410. 0: cmpwi 0,r13,1 /* reserve entries */
  411. ble 5f
  412. li r13,0
  413. 5:
  414. /* Store the next available TLB index */
  415. stw r13,tlb_44x_index@l(r10)
  416. /* Re-load the faulting address */
  417. mfspr r10,SPRN_SRR0
  418. /* Jump to common TLB load point */
  419. b finish_tlb_load_44x
  420. 2:
  421. /* The bailout. Restore registers to pre-exception conditions
  422. * and call the heavyweights to help us out.
  423. */
  424. mfspr r11, SPRN_SPRG_RSCRATCH4
  425. mtcr r11
  426. mfspr r13, SPRN_SPRG_RSCRATCH3
  427. mfspr r12, SPRN_SPRG_RSCRATCH2
  428. mfspr r11, SPRN_SPRG_RSCRATCH1
  429. mfspr r10, SPRN_SPRG_RSCRATCH0
  430. b InstructionStorage
  431. /*
  432. * Both the instruction and data TLB miss get to this
  433. * point to load the TLB.
  434. * r10 - EA of fault
  435. * r11 - PTE high word value
  436. * r12 - PTE low word value
  437. * r13 - TLB index
  438. * cr7 - Result of comparison with PAGE_OFFSET
  439. * MMUCR - loaded with proper value when we get here
  440. * Upon exit, we reload everything and RFI.
  441. */
  442. finish_tlb_load_44x:
  443. /* Combine RPN & ERPN an write WS 0 */
  444. rlwimi r11,r12,0,0,31-PAGE_SHIFT
  445. tlbwe r11,r13,PPC44x_TLB_XLAT
  446. /*
  447. * Create WS1. This is the faulting address (EPN),
  448. * page size, and valid flag.
  449. */
  450. li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE
  451. /* Insert valid and page size */
  452. rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31
  453. tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */
  454. /* And WS 2 */
  455. li r10,0xf84 /* Mask to apply from PTE */
  456. rlwimi r10,r12,29,30,31 /* DIRTY,READ -> SW,SR position */
  457. and r11,r12,r10 /* Mask PTE bits to keep */
  458. bge cr7,1f /* User page ? no, leave U bits empty */
  459. rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
  460. rlwinm r11,r11,0,~PPC44x_TLB_SX /* Clear SX if User page */
  461. 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */
  462. /* Done...restore registers and get out of here.
  463. */
  464. mfspr r11, SPRN_SPRG_RSCRATCH4
  465. mtcr r11
  466. mfspr r13, SPRN_SPRG_RSCRATCH3
  467. mfspr r12, SPRN_SPRG_RSCRATCH2
  468. mfspr r11, SPRN_SPRG_RSCRATCH1
  469. mfspr r10, SPRN_SPRG_RSCRATCH0
  470. rfi /* Force context change */
  471. /* TLB error interrupts for 476
  472. */
  473. #ifdef CONFIG_PPC_47x
  474. START_EXCEPTION(DataTLBError47x)
  475. mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
  476. mtspr SPRN_SPRG_WSCRATCH1,r11
  477. mtspr SPRN_SPRG_WSCRATCH2,r12
  478. mtspr SPRN_SPRG_WSCRATCH3,r13
  479. mfcr r11
  480. mtspr SPRN_SPRG_WSCRATCH4,r11
  481. mfspr r10,SPRN_DEAR /* Get faulting address */
  482. /* If we are faulting a kernel address, we have to use the
  483. * kernel page tables.
  484. */
  485. lis r11,PAGE_OFFSET@h
  486. cmplw cr7,r10,r11
  487. blt+ cr7,3f
  488. lis r11,swapper_pg_dir@h
  489. ori r11,r11, swapper_pg_dir@l
  490. li r12,0 /* MMUCR = 0 */
  491. b 4f
  492. /* Get the PGD for the current thread and setup MMUCR */
  493. 3: mfspr r11,SPRN_SPRG3
  494. lwz r11,PGDIR(r11)
  495. mfspr r12,SPRN_PID /* Get PID */
  496. #ifdef CONFIG_PPC_KUAP
  497. cmpwi r12,0
  498. beq 2f /* KUAP Fault */
  499. #endif
  500. 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
  501. /* Mask of required permission bits. Note that while we
  502. * do copy ESR:ST to _PAGE_WRITE position as trying to write
  503. * to an RO page is pretty common, we don't do it with
  504. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  505. * event so I'd rather take the overhead when it happens
  506. * rather than adding an instruction here. We should measure
  507. * whether the whole thing is worth it in the first place
  508. * as we could avoid loading SPRN_ESR completely in the first
  509. * place...
  510. *
  511. * TODO: Is it worth doing that mfspr & rlwimi in the first
  512. * place or can we save a couple of instructions here ?
  513. */
  514. mfspr r12,SPRN_ESR
  515. li r13,_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_READ
  516. rlwimi r13,r12,10,30,30
  517. /* Load the PTE */
  518. /* Compute pgdir/pmd offset */
  519. rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
  520. lwzx r11,r12,r11 /* Get pgd/pmd entry */
  521. /* Word 0 is EPN,V,TS,DSIZ */
  522. li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
  523. rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
  524. li r12,0
  525. tlbwe r10,r12,0
  526. /* XXX can we do better ? Need to make sure tlbwe has established
  527. * latch V bit in MMUCR0 before the PTE is loaded further down */
  528. #ifdef CONFIG_SMP
  529. isync
  530. #endif
  531. rlwinm. r12,r11,0,0,20 /* Extract pt base address */
  532. /* Compute pte address */
  533. rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
  534. beq 2f /* Bail if no table */
  535. lwz r11,0(r12) /* Get high word of pte entry */
  536. /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
  537. * bottom of r12 to create a data dependency... We can also use r10
  538. * as destination nowadays
  539. */
  540. #ifdef CONFIG_SMP
  541. lwsync
  542. #endif
  543. lwz r12,4(r12) /* Get low word of pte entry */
  544. andc. r13,r13,r12 /* Check permission */
  545. /* Jump to common tlb load */
  546. beq finish_tlb_load_47x
  547. 2: /* The bailout. Restore registers to pre-exception conditions
  548. * and call the heavyweights to help us out.
  549. */
  550. mfspr r11,SPRN_SPRG_RSCRATCH4
  551. mtcr r11
  552. mfspr r13,SPRN_SPRG_RSCRATCH3
  553. mfspr r12,SPRN_SPRG_RSCRATCH2
  554. mfspr r11,SPRN_SPRG_RSCRATCH1
  555. mfspr r10,SPRN_SPRG_RSCRATCH0
  556. b DataStorage
  557. /* Instruction TLB Error Interrupt */
  558. /*
  559. * Nearly the same as above, except we get our
  560. * information from different registers and bailout
  561. * to a different point.
  562. */
  563. START_EXCEPTION(InstructionTLBError47x)
  564. mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
  565. mtspr SPRN_SPRG_WSCRATCH1,r11
  566. mtspr SPRN_SPRG_WSCRATCH2,r12
  567. mtspr SPRN_SPRG_WSCRATCH3,r13
  568. mfcr r11
  569. mtspr SPRN_SPRG_WSCRATCH4,r11
  570. mfspr r10,SPRN_SRR0 /* Get faulting address */
  571. /* If we are faulting a kernel address, we have to use the
  572. * kernel page tables.
  573. */
  574. lis r11,PAGE_OFFSET@h
  575. cmplw cr7,r10,r11
  576. blt+ cr7,3f
  577. lis r11,swapper_pg_dir@h
  578. ori r11,r11, swapper_pg_dir@l
  579. li r12,0 /* MMUCR = 0 */
  580. b 4f
  581. /* Get the PGD for the current thread and setup MMUCR */
  582. 3: mfspr r11,SPRN_SPRG_THREAD
  583. lwz r11,PGDIR(r11)
  584. mfspr r12,SPRN_PID /* Get PID */
  585. #ifdef CONFIG_PPC_KUAP
  586. cmpwi r12,0
  587. beq 2f /* KUAP Fault */
  588. #endif
  589. 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
  590. /* Make up the required permissions */
  591. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  592. /* Load PTE */
  593. /* Compute pgdir/pmd offset */
  594. rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
  595. lwzx r11,r12,r11 /* Get pgd/pmd entry */
  596. /* Word 0 is EPN,V,TS,DSIZ */
  597. li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
  598. rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
  599. li r12,0
  600. tlbwe r10,r12,0
  601. /* XXX can we do better ? Need to make sure tlbwe has established
  602. * latch V bit in MMUCR0 before the PTE is loaded further down */
  603. #ifdef CONFIG_SMP
  604. isync
  605. #endif
  606. rlwinm. r12,r11,0,0,20 /* Extract pt base address */
  607. /* Compute pte address */
  608. rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
  609. beq 2f /* Bail if no table */
  610. lwz r11,0(r12) /* Get high word of pte entry */
  611. /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
  612. * bottom of r12 to create a data dependency... We can also use r10
  613. * as destination nowadays
  614. */
  615. #ifdef CONFIG_SMP
  616. lwsync
  617. #endif
  618. lwz r12,4(r12) /* Get low word of pte entry */
  619. andc. r13,r13,r12 /* Check permission */
  620. /* Jump to common TLB load point */
  621. beq finish_tlb_load_47x
  622. 2: /* The bailout. Restore registers to pre-exception conditions
  623. * and call the heavyweights to help us out.
  624. */
  625. mfspr r11, SPRN_SPRG_RSCRATCH4
  626. mtcr r11
  627. mfspr r13, SPRN_SPRG_RSCRATCH3
  628. mfspr r12, SPRN_SPRG_RSCRATCH2
  629. mfspr r11, SPRN_SPRG_RSCRATCH1
  630. mfspr r10, SPRN_SPRG_RSCRATCH0
  631. b InstructionStorage
  632. /*
  633. * Both the instruction and data TLB miss get to this
  634. * point to load the TLB.
  635. * r10 - free to use
  636. * r11 - PTE high word value
  637. * r12 - PTE low word value
  638. * r13 - free to use
  639. * cr7 - Result of comparison with PAGE_OFFSET
  640. * MMUCR - loaded with proper value when we get here
  641. * Upon exit, we reload everything and RFI.
  642. */
  643. finish_tlb_load_47x:
  644. /* Combine RPN & ERPN an write WS 1 */
  645. rlwimi r11,r12,0,0,31-PAGE_SHIFT
  646. tlbwe r11,r13,1
  647. /* And make up word 2 */
  648. li r10,0xf84 /* Mask to apply from PTE */
  649. rlwimi r10,r12,29,30,31 /* DIRTY,READ -> SW,SR position */
  650. and r11,r12,r10 /* Mask PTE bits to keep */
  651. bge cr7,1f /* User page ? no, leave U bits empty */
  652. rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
  653. rlwinm r11,r11,0,~PPC47x_TLB2_SX /* Clear SX if User page */
  654. 1: tlbwe r11,r13,2
  655. /* Done...restore registers and get out of here.
  656. */
  657. mfspr r11, SPRN_SPRG_RSCRATCH4
  658. mtcr r11
  659. mfspr r13, SPRN_SPRG_RSCRATCH3
  660. mfspr r12, SPRN_SPRG_RSCRATCH2
  661. mfspr r11, SPRN_SPRG_RSCRATCH1
  662. mfspr r10, SPRN_SPRG_RSCRATCH0
  663. rfi
  664. #endif /* CONFIG_PPC_47x */
  665. /* Debug Interrupt */
  666. /*
  667. * This statement needs to exist at the end of the IVPR
  668. * definition just in case you end up taking a debug
  669. * exception within another exception.
  670. */
  671. DEBUG_CRIT_EXCEPTION
  672. interrupt_end:
  673. /*
  674. * Global functions
  675. */
  676. /*
  677. * Adjust the machine check IVOR on 440A cores
  678. */
  679. _GLOBAL(__fixup_440A_mcheck)
  680. li r3,MachineCheckA@l
  681. mtspr SPRN_IVOR1,r3
  682. sync
  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. bcl 20,31,$+4 /* 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_MIN_SIZE
  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's stack and current */
  871. lis r2,secondary_current@ha
  872. lwz r2,secondary_current@l(r2)
  873. lwz r1,TASK_STACK(r2)
  874. /* Current stack pointer */
  875. addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
  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. bcl 20,31,$+4
  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. #ifdef CONFIG_SMP
  1055. .data
  1056. .align 12
  1057. temp_boot_stack:
  1058. .space 1024
  1059. #endif /* CONFIG_SMP */