head_44x.S 29 KB

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