head_44x.S 29 KB

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