head_44x.S 32 KB

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