head_44x.S 32 KB

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