head_fsl_booke.S 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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-2004 MontaVista Software, Inc.
  23. * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
  24. * Copyright 2004 Freescale Semiconductor, Inc
  25. * PowerPC e500 modifications, Kumar Gala <galak@kernel.crashing.org>
  26. *
  27. * This program is free software; you can redistribute it and/or modify it
  28. * under the terms of the GNU General Public License as published by the
  29. * Free Software Foundation; either version 2 of the License, or (at your
  30. * option) any later version.
  31. */
  32. #include <linux/init.h>
  33. #include <linux/threads.h>
  34. #include <asm/processor.h>
  35. #include <asm/page.h>
  36. #include <asm/mmu.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/cputable.h>
  39. #include <asm/thread_info.h>
  40. #include <asm/ppc_asm.h>
  41. #include <asm/asm-offsets.h>
  42. #include <asm/cache.h>
  43. #include <asm/ptrace.h>
  44. #include "head_booke.h"
  45. /* As with the other PowerPC ports, it is expected that when code
  46. * execution begins here, the following registers contain valid, yet
  47. * optional, information:
  48. *
  49. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  50. * r4 - Starting address of the init RAM disk
  51. * r5 - Ending address of the init RAM disk
  52. * r6 - Start of kernel command line string (e.g. "mem=128")
  53. * r7 - End of kernel command line string
  54. *
  55. */
  56. __HEAD
  57. _ENTRY(_stext);
  58. _ENTRY(_start);
  59. /*
  60. * Reserve a word at a fixed location to store the address
  61. * of abatron_pteptrs
  62. */
  63. nop
  64. /* Translate device tree address to physical, save in r30/r31 */
  65. mfmsr r16
  66. mfspr r17,SPRN_PID
  67. rlwinm r17,r17,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  68. rlwimi r17,r16,28,0x00000001 /* turn MSR[DS] into MAS6[SAS] */
  69. mtspr SPRN_MAS6,r17
  70. tlbsx 0,r3 /* must succeed */
  71. mfspr r16,SPRN_MAS1
  72. mfspr r20,SPRN_MAS3
  73. rlwinm r17,r16,25,0x1f /* r17 = log2(page size) */
  74. li r18,1024
  75. slw r18,r18,r17 /* r18 = page size */
  76. addi r18,r18,-1
  77. and r19,r3,r18 /* r19 = page offset */
  78. andc r31,r20,r18 /* r31 = page base */
  79. or r31,r31,r19 /* r31 = devtree phys addr */
  80. mfspr r30,SPRN_MAS7
  81. li r25,0 /* phys kernel start (low) */
  82. li r24,0 /* CPU number */
  83. li r23,0 /* phys kernel start (high) */
  84. /* We try to not make any assumptions about how the boot loader
  85. * setup or used the TLBs. We invalidate all mappings from the
  86. * boot loader and load a single entry in TLB1[0] to map the
  87. * first 64M of kernel memory. Any boot info passed from the
  88. * bootloader needs to live in this first 64M.
  89. *
  90. * Requirement on bootloader:
  91. * - The page we're executing in needs to reside in TLB1 and
  92. * have IPROT=1. If not an invalidate broadcast could
  93. * evict the entry we're currently executing in.
  94. *
  95. * r3 = Index of TLB1 were executing in
  96. * r4 = Current MSR[IS]
  97. * r5 = Index of TLB1 temp mapping
  98. *
  99. * Later in mapin_ram we will correctly map lowmem, and resize TLB1[0]
  100. * if needed
  101. */
  102. _ENTRY(__early_start)
  103. #define ENTRY_MAPPING_BOOT_SETUP
  104. #include "fsl_booke_entry_mapping.S"
  105. #undef ENTRY_MAPPING_BOOT_SETUP
  106. /* Establish the interrupt vector offsets */
  107. SET_IVOR(0, CriticalInput);
  108. SET_IVOR(1, MachineCheck);
  109. SET_IVOR(2, DataStorage);
  110. SET_IVOR(3, InstructionStorage);
  111. SET_IVOR(4, ExternalInput);
  112. SET_IVOR(5, Alignment);
  113. SET_IVOR(6, Program);
  114. SET_IVOR(7, FloatingPointUnavailable);
  115. SET_IVOR(8, SystemCall);
  116. SET_IVOR(9, AuxillaryProcessorUnavailable);
  117. SET_IVOR(10, Decrementer);
  118. SET_IVOR(11, FixedIntervalTimer);
  119. SET_IVOR(12, WatchdogTimer);
  120. SET_IVOR(13, DataTLBError);
  121. SET_IVOR(14, InstructionTLBError);
  122. SET_IVOR(15, DebugCrit);
  123. /* Establish the interrupt vector base */
  124. lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
  125. mtspr SPRN_IVPR,r4
  126. /* Setup the defaults for TLB entries */
  127. li r2,(MAS4_TSIZED(BOOK3E_PAGESZ_4K))@l
  128. #ifdef CONFIG_E200
  129. oris r2,r2,MAS4_TLBSELD(1)@h
  130. #endif
  131. mtspr SPRN_MAS4, r2
  132. #if 0
  133. /* Enable DOZE */
  134. mfspr r2,SPRN_HID0
  135. oris r2,r2,HID0_DOZE@h
  136. mtspr SPRN_HID0, r2
  137. #endif
  138. #if !defined(CONFIG_BDI_SWITCH)
  139. /*
  140. * The Abatron BDI JTAG debugger does not tolerate others
  141. * mucking with the debug registers.
  142. */
  143. lis r2,DBCR0_IDM@h
  144. mtspr SPRN_DBCR0,r2
  145. isync
  146. /* clear any residual debug events */
  147. li r2,-1
  148. mtspr SPRN_DBSR,r2
  149. #endif
  150. #ifdef CONFIG_SMP
  151. /* Check to see if we're the second processor, and jump
  152. * to the secondary_start code if so
  153. */
  154. lis r24, boot_cpuid@h
  155. ori r24, r24, boot_cpuid@l
  156. lwz r24, 0(r24)
  157. cmpwi r24, -1
  158. mfspr r24,SPRN_PIR
  159. bne __secondary_start
  160. #endif
  161. /*
  162. * This is where the main kernel code starts.
  163. */
  164. /* ptr to current */
  165. lis r2,init_task@h
  166. ori r2,r2,init_task@l
  167. /* ptr to current thread */
  168. addi r4,r2,THREAD /* init task's THREAD */
  169. mtspr SPRN_SPRG_THREAD,r4
  170. /* stack */
  171. lis r1,init_thread_union@h
  172. ori r1,r1,init_thread_union@l
  173. li r0,0
  174. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  175. rlwinm r22,r1,0,0,31-THREAD_SHIFT /* current thread_info */
  176. stw r24, TI_CPU(r22)
  177. bl early_init
  178. #ifdef CONFIG_DYNAMIC_MEMSTART
  179. lis r3,kernstart_addr@ha
  180. la r3,kernstart_addr@l(r3)
  181. #ifdef CONFIG_PHYS_64BIT
  182. stw r23,0(r3)
  183. stw r25,4(r3)
  184. #else
  185. stw r25,0(r3)
  186. #endif
  187. #endif
  188. /*
  189. * Decide what sort of machine this is and initialize the MMU.
  190. */
  191. mr r3,r30
  192. mr r4,r31
  193. bl machine_init
  194. bl MMU_init
  195. /* Setup PTE pointers for the Abatron bdiGDB */
  196. lis r6, swapper_pg_dir@h
  197. ori r6, r6, swapper_pg_dir@l
  198. lis r5, abatron_pteptrs@h
  199. ori r5, r5, abatron_pteptrs@l
  200. lis r4, KERNELBASE@h
  201. ori r4, r4, KERNELBASE@l
  202. stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
  203. stw r6, 0(r5)
  204. /* Let's move on */
  205. lis r4,start_kernel@h
  206. ori r4,r4,start_kernel@l
  207. lis r3,MSR_KERNEL@h
  208. ori r3,r3,MSR_KERNEL@l
  209. mtspr SPRN_SRR0,r4
  210. mtspr SPRN_SRR1,r3
  211. rfi /* change context and jump to start_kernel */
  212. /* Macros to hide the PTE size differences
  213. *
  214. * FIND_PTE -- walks the page tables given EA & pgdir pointer
  215. * r10 -- EA of fault
  216. * r11 -- PGDIR pointer
  217. * r12 -- free
  218. * label 2: is the bailout case
  219. *
  220. * if we find the pte (fall through):
  221. * r11 is low pte word
  222. * r12 is pointer to the pte
  223. * r10 is the pshift from the PGD, if we're a hugepage
  224. */
  225. #ifdef CONFIG_PTE_64BIT
  226. #ifdef CONFIG_HUGETLB_PAGE
  227. #define FIND_PTE \
  228. rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \
  229. lwzx r11, r12, r11; /* Get pgd/pmd entry */ \
  230. rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \
  231. blt 1000f; /* Normal non-huge page */ \
  232. beq 2f; /* Bail if no table */ \
  233. oris r11, r11, PD_HUGE@h; /* Put back address bit */ \
  234. andi. r10, r11, HUGEPD_SHIFT_MASK@l; /* extract size field */ \
  235. xor r12, r10, r11; /* drop size bits from pointer */ \
  236. b 1001f; \
  237. 1000: rlwimi r12, r10, 23, 20, 28; /* Compute pte address */ \
  238. li r10, 0; /* clear r10 */ \
  239. 1001: lwz r11, 4(r12); /* Get pte entry */
  240. #else
  241. #define FIND_PTE \
  242. rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \
  243. lwzx r11, r12, r11; /* Get pgd/pmd entry */ \
  244. rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \
  245. beq 2f; /* Bail if no table */ \
  246. rlwimi r12, r10, 23, 20, 28; /* Compute pte address */ \
  247. lwz r11, 4(r12); /* Get pte entry */
  248. #endif /* HUGEPAGE */
  249. #else /* !PTE_64BIT */
  250. #define FIND_PTE \
  251. rlwimi r11, r10, 12, 20, 29; /* Create L1 (pgdir/pmd) address */ \
  252. lwz r11, 0(r11); /* Get L1 entry */ \
  253. rlwinm. r12, r11, 0, 0, 19; /* Extract L2 (pte) base address */ \
  254. beq 2f; /* Bail if no table */ \
  255. rlwimi r12, r10, 22, 20, 29; /* Compute PTE address */ \
  256. lwz r11, 0(r12); /* Get Linux PTE */
  257. #endif
  258. /*
  259. * Interrupt vector entry code
  260. *
  261. * The Book E MMUs are always on so we don't need to handle
  262. * interrupts in real mode as with previous PPC processors. In
  263. * this case we handle interrupts in the kernel virtual address
  264. * space.
  265. *
  266. * Interrupt vectors are dynamically placed relative to the
  267. * interrupt prefix as determined by the address of interrupt_base.
  268. * The interrupt vectors offsets are programmed using the labels
  269. * for each interrupt vector entry.
  270. *
  271. * Interrupt vectors must be aligned on a 16 byte boundary.
  272. * We align on a 32 byte cache line boundary for good measure.
  273. */
  274. interrupt_base:
  275. /* Critical Input Interrupt */
  276. CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)
  277. /* Machine Check Interrupt */
  278. #ifdef CONFIG_E200
  279. /* no RFMCI, MCSRRs on E200 */
  280. CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \
  281. machine_check_exception)
  282. #else
  283. MCHECK_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  284. #endif
  285. /* Data Storage Interrupt */
  286. START_EXCEPTION(DataStorage)
  287. NORMAL_EXCEPTION_PROLOG(DATA_STORAGE)
  288. mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
  289. stw r5,_ESR(r11)
  290. mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */
  291. andis. r10,r5,(ESR_ILK|ESR_DLK)@h
  292. bne 1f
  293. EXC_XFER_LITE(0x0300, handle_page_fault)
  294. 1:
  295. addi r3,r1,STACK_FRAME_OVERHEAD
  296. EXC_XFER_EE_LITE(0x0300, CacheLockingException)
  297. /* Instruction Storage Interrupt */
  298. INSTRUCTION_STORAGE_EXCEPTION
  299. /* External Input Interrupt */
  300. EXCEPTION(0x0500, EXTERNAL, ExternalInput, do_IRQ, EXC_XFER_LITE)
  301. /* Alignment Interrupt */
  302. ALIGNMENT_EXCEPTION
  303. /* Program Interrupt */
  304. PROGRAM_EXCEPTION
  305. /* Floating Point Unavailable Interrupt */
  306. #ifdef CONFIG_PPC_FPU
  307. FP_UNAVAILABLE_EXCEPTION
  308. #else
  309. #ifdef CONFIG_E200
  310. /* E200 treats 'normal' floating point instructions as FP Unavail exception */
  311. EXCEPTION(0x0800, FP_UNAVAIL, FloatingPointUnavailable, \
  312. program_check_exception, EXC_XFER_EE)
  313. #else
  314. EXCEPTION(0x0800, FP_UNAVAIL, FloatingPointUnavailable, \
  315. unknown_exception, EXC_XFER_EE)
  316. #endif
  317. #endif
  318. /* System Call Interrupt */
  319. START_EXCEPTION(SystemCall)
  320. NORMAL_EXCEPTION_PROLOG(SYSCALL)
  321. EXC_XFER_EE_LITE(0x0c00, DoSyscall)
  322. /* Auxiliary Processor Unavailable Interrupt */
  323. EXCEPTION(0x2900, AP_UNAVAIL, AuxillaryProcessorUnavailable, \
  324. unknown_exception, EXC_XFER_EE)
  325. /* Decrementer Interrupt */
  326. DECREMENTER_EXCEPTION
  327. /* Fixed Internal Timer Interrupt */
  328. /* TODO: Add FIT support */
  329. EXCEPTION(0x3100, FIT, FixedIntervalTimer, \
  330. unknown_exception, EXC_XFER_EE)
  331. /* Watchdog Timer Interrupt */
  332. #ifdef CONFIG_BOOKE_WDT
  333. CRITICAL_EXCEPTION(0x3200, WATCHDOG, WatchdogTimer, WatchdogException)
  334. #else
  335. CRITICAL_EXCEPTION(0x3200, WATCHDOG, WatchdogTimer, unknown_exception)
  336. #endif
  337. /* Data TLB Error Interrupt */
  338. START_EXCEPTION(DataTLBError)
  339. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  340. mfspr r10, SPRN_SPRG_THREAD
  341. stw r11, THREAD_NORMSAVE(0)(r10)
  342. stw r12, THREAD_NORMSAVE(1)(r10)
  343. stw r13, THREAD_NORMSAVE(2)(r10)
  344. mfcr r13
  345. stw r13, THREAD_NORMSAVE(3)(r10)
  346. mfspr r10, SPRN_DEAR /* Get faulting address */
  347. /* If we are faulting a kernel address, we have to use the
  348. * kernel page tables.
  349. */
  350. lis r11, PAGE_OFFSET@h
  351. cmplw 5, r10, r11
  352. blt 5, 3f
  353. lis r11, swapper_pg_dir@h
  354. ori r11, r11, swapper_pg_dir@l
  355. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  356. rlwinm r12,r12,0,16,1
  357. mtspr SPRN_MAS1,r12
  358. b 4f
  359. /* Get the PGD for the current thread */
  360. 3:
  361. mfspr r11,SPRN_SPRG_THREAD
  362. lwz r11,PGDIR(r11)
  363. 4:
  364. /* Mask of required permission bits. Note that while we
  365. * do copy ESR:ST to _PAGE_RW position as trying to write
  366. * to an RO page is pretty common, we don't do it with
  367. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  368. * event so I'd rather take the overhead when it happens
  369. * rather than adding an instruction here. We should measure
  370. * whether the whole thing is worth it in the first place
  371. * as we could avoid loading SPRN_ESR completely in the first
  372. * place...
  373. *
  374. * TODO: Is it worth doing that mfspr & rlwimi in the first
  375. * place or can we save a couple of instructions here ?
  376. */
  377. mfspr r12,SPRN_ESR
  378. #ifdef CONFIG_PTE_64BIT
  379. li r13,_PAGE_PRESENT
  380. oris r13,r13,_PAGE_ACCESSED@h
  381. #else
  382. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  383. #endif
  384. rlwimi r13,r12,11,29,29
  385. FIND_PTE
  386. andc. r13,r13,r11 /* Check permission */
  387. #ifdef CONFIG_PTE_64BIT
  388. #ifdef CONFIG_SMP
  389. subf r13,r11,r12 /* create false data dep */
  390. lwzx r13,r11,r13 /* Get upper pte bits */
  391. #else
  392. lwz r13,0(r12) /* Get upper pte bits */
  393. #endif
  394. #endif
  395. bne 2f /* Bail if permission/valid mismach */
  396. /* Jump to common tlb load */
  397. b finish_tlb_load
  398. 2:
  399. /* The bailout. Restore registers to pre-exception conditions
  400. * and call the heavyweights to help us out.
  401. */
  402. mfspr r10, SPRN_SPRG_THREAD
  403. lwz r11, THREAD_NORMSAVE(3)(r10)
  404. mtcr r11
  405. lwz r13, THREAD_NORMSAVE(2)(r10)
  406. lwz r12, THREAD_NORMSAVE(1)(r10)
  407. lwz r11, THREAD_NORMSAVE(0)(r10)
  408. mfspr r10, SPRN_SPRG_RSCRATCH0
  409. b DataStorage
  410. /* Instruction TLB Error Interrupt */
  411. /*
  412. * Nearly the same as above, except we get our
  413. * information from different registers and bailout
  414. * to a different point.
  415. */
  416. START_EXCEPTION(InstructionTLBError)
  417. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  418. mfspr r10, SPRN_SPRG_THREAD
  419. stw r11, THREAD_NORMSAVE(0)(r10)
  420. stw r12, THREAD_NORMSAVE(1)(r10)
  421. stw r13, THREAD_NORMSAVE(2)(r10)
  422. mfcr r13
  423. stw r13, THREAD_NORMSAVE(3)(r10)
  424. mfspr r10, SPRN_SRR0 /* Get faulting address */
  425. /* If we are faulting a kernel address, we have to use the
  426. * kernel page tables.
  427. */
  428. lis r11, PAGE_OFFSET@h
  429. cmplw 5, r10, r11
  430. blt 5, 3f
  431. lis r11, swapper_pg_dir@h
  432. ori r11, r11, swapper_pg_dir@l
  433. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  434. rlwinm r12,r12,0,16,1
  435. mtspr SPRN_MAS1,r12
  436. /* Make up the required permissions for kernel code */
  437. #ifdef CONFIG_PTE_64BIT
  438. li r13,_PAGE_PRESENT | _PAGE_BAP_SX
  439. oris r13,r13,_PAGE_ACCESSED@h
  440. #else
  441. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  442. #endif
  443. b 4f
  444. /* Get the PGD for the current thread */
  445. 3:
  446. mfspr r11,SPRN_SPRG_THREAD
  447. lwz r11,PGDIR(r11)
  448. /* Make up the required permissions for user code */
  449. #ifdef CONFIG_PTE_64BIT
  450. li r13,_PAGE_PRESENT | _PAGE_BAP_UX
  451. oris r13,r13,_PAGE_ACCESSED@h
  452. #else
  453. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  454. #endif
  455. 4:
  456. FIND_PTE
  457. andc. r13,r13,r11 /* Check permission */
  458. #ifdef CONFIG_PTE_64BIT
  459. #ifdef CONFIG_SMP
  460. subf r13,r11,r12 /* create false data dep */
  461. lwzx r13,r11,r13 /* Get upper pte bits */
  462. #else
  463. lwz r13,0(r12) /* Get upper pte bits */
  464. #endif
  465. #endif
  466. bne 2f /* Bail if permission mismach */
  467. /* Jump to common TLB load point */
  468. b finish_tlb_load
  469. 2:
  470. /* The bailout. Restore registers to pre-exception conditions
  471. * and call the heavyweights to help us out.
  472. */
  473. mfspr r10, SPRN_SPRG_THREAD
  474. lwz r11, THREAD_NORMSAVE(3)(r10)
  475. mtcr r11
  476. lwz r13, THREAD_NORMSAVE(2)(r10)
  477. lwz r12, THREAD_NORMSAVE(1)(r10)
  478. lwz r11, THREAD_NORMSAVE(0)(r10)
  479. mfspr r10, SPRN_SPRG_RSCRATCH0
  480. b InstructionStorage
  481. #ifdef CONFIG_SPE
  482. /* SPE Unavailable */
  483. START_EXCEPTION(SPEUnavailable)
  484. NORMAL_EXCEPTION_PROLOG(SPE_UNAVAIL)
  485. bne load_up_spe
  486. addi r3,r1,STACK_FRAME_OVERHEAD
  487. EXC_XFER_EE_LITE(0x2010, KernelSPE)
  488. #else
  489. EXCEPTION(0x2020, SPE_UNAVAIL, SPEUnavailable, \
  490. unknown_exception, EXC_XFER_EE)
  491. #endif /* CONFIG_SPE */
  492. /* SPE Floating Point Data */
  493. #ifdef CONFIG_SPE
  494. EXCEPTION(0x2030, SPE_FP_DATA, SPEFloatingPointData, \
  495. SPEFloatingPointException, EXC_XFER_EE);
  496. /* SPE Floating Point Round */
  497. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  498. SPEFloatingPointRoundException, EXC_XFER_EE)
  499. #else
  500. EXCEPTION(0x2040, SPE_FP_DATA, SPEFloatingPointData, \
  501. unknown_exception, EXC_XFER_EE)
  502. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  503. unknown_exception, EXC_XFER_EE)
  504. #endif /* CONFIG_SPE */
  505. /* Performance Monitor */
  506. EXCEPTION(0x2060, PERFORMANCE_MONITOR, PerformanceMonitor, \
  507. performance_monitor_exception, EXC_XFER_STD)
  508. EXCEPTION(0x2070, DOORBELL, Doorbell, doorbell_exception, EXC_XFER_STD)
  509. CRITICAL_EXCEPTION(0x2080, DOORBELL_CRITICAL, \
  510. CriticalDoorbell, unknown_exception)
  511. /* Debug Interrupt */
  512. DEBUG_DEBUG_EXCEPTION
  513. DEBUG_CRIT_EXCEPTION
  514. /*
  515. * Local functions
  516. */
  517. /*
  518. * Both the instruction and data TLB miss get to this
  519. * point to load the TLB.
  520. * r10 - tsize encoding (if HUGETLB_PAGE) or available to use
  521. * r11 - TLB (info from Linux PTE)
  522. * r12 - available to use
  523. * r13 - upper bits of PTE (if PTE_64BIT) or available to use
  524. * CR5 - results of addr >= PAGE_OFFSET
  525. * MAS0, MAS1 - loaded with proper value when we get here
  526. * MAS2, MAS3 - will need additional info from Linux PTE
  527. * Upon exit, we reload everything and RFI.
  528. */
  529. finish_tlb_load:
  530. #ifdef CONFIG_HUGETLB_PAGE
  531. cmpwi 6, r10, 0 /* check for huge page */
  532. beq 6, finish_tlb_load_cont /* !huge */
  533. /* Alas, we need more scratch registers for hugepages */
  534. mfspr r12, SPRN_SPRG_THREAD
  535. stw r14, THREAD_NORMSAVE(4)(r12)
  536. stw r15, THREAD_NORMSAVE(5)(r12)
  537. stw r16, THREAD_NORMSAVE(6)(r12)
  538. stw r17, THREAD_NORMSAVE(7)(r12)
  539. /* Get the next_tlbcam_idx percpu var */
  540. #ifdef CONFIG_SMP
  541. lwz r12, THREAD_INFO-THREAD(r12)
  542. lwz r15, TI_CPU(r12)
  543. lis r14, __per_cpu_offset@h
  544. ori r14, r14, __per_cpu_offset@l
  545. rlwinm r15, r15, 2, 0, 29
  546. lwzx r16, r14, r15
  547. #else
  548. li r16, 0
  549. #endif
  550. lis r17, next_tlbcam_idx@h
  551. ori r17, r17, next_tlbcam_idx@l
  552. add r17, r17, r16 /* r17 = *next_tlbcam_idx */
  553. lwz r15, 0(r17) /* r15 = next_tlbcam_idx */
  554. lis r14, MAS0_TLBSEL(1)@h /* select TLB1 (TLBCAM) */
  555. rlwimi r14, r15, 16, 4, 15 /* next_tlbcam_idx entry */
  556. mtspr SPRN_MAS0, r14
  557. /* Extract TLB1CFG(NENTRY) */
  558. mfspr r16, SPRN_TLB1CFG
  559. andi. r16, r16, 0xfff
  560. /* Update next_tlbcam_idx, wrapping when necessary */
  561. addi r15, r15, 1
  562. cmpw r15, r16
  563. blt 100f
  564. lis r14, tlbcam_index@h
  565. ori r14, r14, tlbcam_index@l
  566. lwz r15, 0(r14)
  567. 100: stw r15, 0(r17)
  568. /*
  569. * Calc MAS1_TSIZE from r10 (which has pshift encoded)
  570. * tlb_enc = (pshift - 10).
  571. */
  572. subi r15, r10, 10
  573. mfspr r16, SPRN_MAS1
  574. rlwimi r16, r15, 7, 20, 24
  575. mtspr SPRN_MAS1, r16
  576. /* copy the pshift for use later */
  577. mr r14, r10
  578. /* fall through */
  579. #endif /* CONFIG_HUGETLB_PAGE */
  580. /*
  581. * We set execute, because we don't have the granularity to
  582. * properly set this at the page level (Linux problem).
  583. * Many of these bits are software only. Bits we don't set
  584. * here we (properly should) assume have the appropriate value.
  585. */
  586. finish_tlb_load_cont:
  587. #ifdef CONFIG_PTE_64BIT
  588. rlwinm r12, r11, 32-2, 26, 31 /* Move in perm bits */
  589. andi. r10, r11, _PAGE_DIRTY
  590. bne 1f
  591. li r10, MAS3_SW | MAS3_UW
  592. andc r12, r12, r10
  593. 1: rlwimi r12, r13, 20, 0, 11 /* grab RPN[32:43] */
  594. rlwimi r12, r11, 20, 12, 19 /* grab RPN[44:51] */
  595. 2: mtspr SPRN_MAS3, r12
  596. BEGIN_MMU_FTR_SECTION
  597. srwi r10, r13, 12 /* grab RPN[12:31] */
  598. mtspr SPRN_MAS7, r10
  599. END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
  600. #else
  601. li r10, (_PAGE_EXEC | _PAGE_PRESENT)
  602. mr r13, r11
  603. rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */
  604. and r12, r11, r10
  605. andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
  606. slwi r10, r12, 1
  607. or r10, r10, r12
  608. iseleq r12, r12, r10
  609. rlwimi r13, r12, 0, 20, 31 /* Get RPN from PTE, merge w/ perms */
  610. mtspr SPRN_MAS3, r13
  611. #endif
  612. mfspr r12, SPRN_MAS2
  613. #ifdef CONFIG_PTE_64BIT
  614. rlwimi r12, r11, 32-19, 27, 31 /* extract WIMGE from pte */
  615. #else
  616. rlwimi r12, r11, 26, 27, 31 /* extract WIMGE from pte */
  617. #endif
  618. #ifdef CONFIG_HUGETLB_PAGE
  619. beq 6, 3f /* don't mask if page isn't huge */
  620. li r13, 1
  621. slw r13, r13, r14
  622. subi r13, r13, 1
  623. rlwinm r13, r13, 0, 0, 19 /* bottom bits used for WIMGE/etc */
  624. andc r12, r12, r13 /* mask off ea bits within the page */
  625. #endif
  626. 3: mtspr SPRN_MAS2, r12
  627. #ifdef CONFIG_E200
  628. /* Round robin TLB1 entries assignment */
  629. mfspr r12, SPRN_MAS0
  630. /* Extract TLB1CFG(NENTRY) */
  631. mfspr r11, SPRN_TLB1CFG
  632. andi. r11, r11, 0xfff
  633. /* Extract MAS0(NV) */
  634. andi. r13, r12, 0xfff
  635. addi r13, r13, 1
  636. cmpw 0, r13, r11
  637. addi r12, r12, 1
  638. /* check if we need to wrap */
  639. blt 7f
  640. /* wrap back to first free tlbcam entry */
  641. lis r13, tlbcam_index@ha
  642. lwz r13, tlbcam_index@l(r13)
  643. rlwimi r12, r13, 0, 20, 31
  644. 7:
  645. mtspr SPRN_MAS0,r12
  646. #endif /* CONFIG_E200 */
  647. tlb_write_entry:
  648. tlbwe
  649. /* Done...restore registers and get out of here. */
  650. mfspr r10, SPRN_SPRG_THREAD
  651. #ifdef CONFIG_HUGETLB_PAGE
  652. beq 6, 8f /* skip restore for 4k page faults */
  653. lwz r14, THREAD_NORMSAVE(4)(r10)
  654. lwz r15, THREAD_NORMSAVE(5)(r10)
  655. lwz r16, THREAD_NORMSAVE(6)(r10)
  656. lwz r17, THREAD_NORMSAVE(7)(r10)
  657. #endif
  658. 8: lwz r11, THREAD_NORMSAVE(3)(r10)
  659. mtcr r11
  660. lwz r13, THREAD_NORMSAVE(2)(r10)
  661. lwz r12, THREAD_NORMSAVE(1)(r10)
  662. lwz r11, THREAD_NORMSAVE(0)(r10)
  663. mfspr r10, SPRN_SPRG_RSCRATCH0
  664. rfi /* Force context change */
  665. #ifdef CONFIG_SPE
  666. /* Note that the SPE support is closely modeled after the AltiVec
  667. * support. Changes to one are likely to be applicable to the
  668. * other! */
  669. load_up_spe:
  670. /*
  671. * Disable SPE for the task which had SPE previously,
  672. * and save its SPE registers in its thread_struct.
  673. * Enables SPE for use in the kernel on return.
  674. * On SMP we know the SPE units are free, since we give it up every
  675. * switch. -- Kumar
  676. */
  677. mfmsr r5
  678. oris r5,r5,MSR_SPE@h
  679. mtmsr r5 /* enable use of SPE now */
  680. isync
  681. /*
  682. * For SMP, we don't do lazy SPE switching because it just gets too
  683. * horrendously complex, especially when a task switches from one CPU
  684. * to another. Instead we call giveup_spe in switch_to.
  685. */
  686. #ifndef CONFIG_SMP
  687. lis r3,last_task_used_spe@ha
  688. lwz r4,last_task_used_spe@l(r3)
  689. cmpi 0,r4,0
  690. beq 1f
  691. addi r4,r4,THREAD /* want THREAD of last_task_used_spe */
  692. SAVE_32EVRS(0,r10,r4,THREAD_EVR0)
  693. evxor evr10, evr10, evr10 /* clear out evr10 */
  694. evmwumiaa evr10, evr10, evr10 /* evr10 <- ACC = 0 * 0 + ACC */
  695. li r5,THREAD_ACC
  696. evstddx evr10, r4, r5 /* save off accumulator */
  697. lwz r5,PT_REGS(r4)
  698. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  699. lis r10,MSR_SPE@h
  700. andc r4,r4,r10 /* disable SPE for previous task */
  701. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  702. 1:
  703. #endif /* !CONFIG_SMP */
  704. /* enable use of SPE after return */
  705. oris r9,r9,MSR_SPE@h
  706. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  707. li r4,1
  708. li r10,THREAD_ACC
  709. stw r4,THREAD_USED_SPE(r5)
  710. evlddx evr4,r10,r5
  711. evmra evr4,evr4
  712. REST_32EVRS(0,r10,r5,THREAD_EVR0)
  713. #ifndef CONFIG_SMP
  714. subi r4,r5,THREAD
  715. stw r4,last_task_used_spe@l(r3)
  716. #endif /* !CONFIG_SMP */
  717. /* restore registers and return */
  718. 2: REST_4GPRS(3, r11)
  719. lwz r10,_CCR(r11)
  720. REST_GPR(1, r11)
  721. mtcr r10
  722. lwz r10,_LINK(r11)
  723. mtlr r10
  724. REST_GPR(10, r11)
  725. mtspr SPRN_SRR1,r9
  726. mtspr SPRN_SRR0,r12
  727. REST_GPR(9, r11)
  728. REST_GPR(12, r11)
  729. lwz r11,GPR11(r11)
  730. rfi
  731. /*
  732. * SPE unavailable trap from kernel - print a message, but let
  733. * the task use SPE in the kernel until it returns to user mode.
  734. */
  735. KernelSPE:
  736. lwz r3,_MSR(r1)
  737. oris r3,r3,MSR_SPE@h
  738. stw r3,_MSR(r1) /* enable use of SPE after return */
  739. #ifdef CONFIG_PRINTK
  740. lis r3,87f@h
  741. ori r3,r3,87f@l
  742. mr r4,r2 /* current */
  743. lwz r5,_NIP(r1)
  744. bl printk
  745. #endif
  746. b ret_from_except
  747. #ifdef CONFIG_PRINTK
  748. 87: .string "SPE used in kernel (task=%p, pc=%x) \n"
  749. #endif
  750. .align 4,0
  751. #endif /* CONFIG_SPE */
  752. /*
  753. * Global functions
  754. */
  755. /* Adjust or setup IVORs for e200 */
  756. _GLOBAL(__setup_e200_ivors)
  757. li r3,DebugDebug@l
  758. mtspr SPRN_IVOR15,r3
  759. li r3,SPEUnavailable@l
  760. mtspr SPRN_IVOR32,r3
  761. li r3,SPEFloatingPointData@l
  762. mtspr SPRN_IVOR33,r3
  763. li r3,SPEFloatingPointRound@l
  764. mtspr SPRN_IVOR34,r3
  765. sync
  766. blr
  767. /* Adjust or setup IVORs for e500v1/v2 */
  768. _GLOBAL(__setup_e500_ivors)
  769. li r3,DebugCrit@l
  770. mtspr SPRN_IVOR15,r3
  771. li r3,SPEUnavailable@l
  772. mtspr SPRN_IVOR32,r3
  773. li r3,SPEFloatingPointData@l
  774. mtspr SPRN_IVOR33,r3
  775. li r3,SPEFloatingPointRound@l
  776. mtspr SPRN_IVOR34,r3
  777. li r3,PerformanceMonitor@l
  778. mtspr SPRN_IVOR35,r3
  779. sync
  780. blr
  781. /* Adjust or setup IVORs for e500mc */
  782. _GLOBAL(__setup_e500mc_ivors)
  783. li r3,DebugDebug@l
  784. mtspr SPRN_IVOR15,r3
  785. li r3,PerformanceMonitor@l
  786. mtspr SPRN_IVOR35,r3
  787. li r3,Doorbell@l
  788. mtspr SPRN_IVOR36,r3
  789. li r3,CriticalDoorbell@l
  790. mtspr SPRN_IVOR37,r3
  791. sync
  792. blr
  793. /*
  794. * extern void giveup_altivec(struct task_struct *prev)
  795. *
  796. * The e500 core does not have an AltiVec unit.
  797. */
  798. _GLOBAL(giveup_altivec)
  799. blr
  800. #ifdef CONFIG_SPE
  801. /*
  802. * extern void giveup_spe(struct task_struct *prev)
  803. *
  804. */
  805. _GLOBAL(giveup_spe)
  806. mfmsr r5
  807. oris r5,r5,MSR_SPE@h
  808. mtmsr r5 /* enable use of SPE now */
  809. isync
  810. cmpi 0,r3,0
  811. beqlr- /* if no previous owner, done */
  812. addi r3,r3,THREAD /* want THREAD of task */
  813. lwz r5,PT_REGS(r3)
  814. cmpi 0,r5,0
  815. SAVE_32EVRS(0, r4, r3, THREAD_EVR0)
  816. evxor evr6, evr6, evr6 /* clear out evr6 */
  817. evmwumiaa evr6, evr6, evr6 /* evr6 <- ACC = 0 * 0 + ACC */
  818. li r4,THREAD_ACC
  819. evstddx evr6, r4, r3 /* save off accumulator */
  820. beq 1f
  821. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  822. lis r3,MSR_SPE@h
  823. andc r4,r4,r3 /* disable SPE for previous task */
  824. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  825. 1:
  826. #ifndef CONFIG_SMP
  827. li r5,0
  828. lis r4,last_task_used_spe@ha
  829. stw r5,last_task_used_spe@l(r4)
  830. #endif /* !CONFIG_SMP */
  831. blr
  832. #endif /* CONFIG_SPE */
  833. /*
  834. * extern void giveup_fpu(struct task_struct *prev)
  835. *
  836. * Not all FSL Book-E cores have an FPU
  837. */
  838. #ifndef CONFIG_PPC_FPU
  839. _GLOBAL(giveup_fpu)
  840. blr
  841. #endif
  842. /*
  843. * extern void abort(void)
  844. *
  845. * At present, this routine just applies a system reset.
  846. */
  847. _GLOBAL(abort)
  848. li r13,0
  849. mtspr SPRN_DBCR0,r13 /* disable all debug events */
  850. isync
  851. mfmsr r13
  852. ori r13,r13,MSR_DE@l /* Enable Debug Events */
  853. mtmsr r13
  854. isync
  855. mfspr r13,SPRN_DBCR0
  856. lis r13,(DBCR0_IDM|DBCR0_RST_CHIP)@h
  857. mtspr SPRN_DBCR0,r13
  858. isync
  859. _GLOBAL(set_context)
  860. #ifdef CONFIG_BDI_SWITCH
  861. /* Context switch the PTE pointer for the Abatron BDI2000.
  862. * The PGDIR is the second parameter.
  863. */
  864. lis r5, abatron_pteptrs@h
  865. ori r5, r5, abatron_pteptrs@l
  866. stw r4, 0x4(r5)
  867. #endif
  868. mtspr SPRN_PID,r3
  869. isync /* Force context change */
  870. blr
  871. _GLOBAL(flush_dcache_L1)
  872. mfspr r3,SPRN_L1CFG0
  873. rlwinm r5,r3,9,3 /* Extract cache block size */
  874. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  875. * are currently defined.
  876. */
  877. li r4,32
  878. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  879. * log2(number of ways)
  880. */
  881. slw r5,r4,r5 /* r5 = cache block size */
  882. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  883. mulli r7,r7,13 /* An 8-way cache will require 13
  884. * loads per set.
  885. */
  886. slw r7,r7,r6
  887. /* save off HID0 and set DCFA */
  888. mfspr r8,SPRN_HID0
  889. ori r9,r8,HID0_DCFA@l
  890. mtspr SPRN_HID0,r9
  891. isync
  892. lis r4,KERNELBASE@h
  893. mtctr r7
  894. 1: lwz r3,0(r4) /* Load... */
  895. add r4,r4,r5
  896. bdnz 1b
  897. msync
  898. lis r4,KERNELBASE@h
  899. mtctr r7
  900. 1: dcbf 0,r4 /* ...and flush. */
  901. add r4,r4,r5
  902. bdnz 1b
  903. /* restore HID0 */
  904. mtspr SPRN_HID0,r8
  905. isync
  906. blr
  907. #ifdef CONFIG_SMP
  908. /* When we get here, r24 needs to hold the CPU # */
  909. .globl __secondary_start
  910. __secondary_start:
  911. lis r3,__secondary_hold_acknowledge@h
  912. ori r3,r3,__secondary_hold_acknowledge@l
  913. stw r24,0(r3)
  914. li r3,0
  915. mr r4,r24 /* Why? */
  916. bl call_setup_cpu
  917. lis r3,tlbcam_index@ha
  918. lwz r3,tlbcam_index@l(r3)
  919. mtctr r3
  920. li r26,0 /* r26 safe? */
  921. /* Load each CAM entry */
  922. 1: mr r3,r26
  923. bl loadcam_entry
  924. addi r26,r26,1
  925. bdnz 1b
  926. /* get current_thread_info and current */
  927. lis r1,secondary_ti@ha
  928. lwz r1,secondary_ti@l(r1)
  929. lwz r2,TI_TASK(r1)
  930. /* stack */
  931. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  932. li r0,0
  933. stw r0,0(r1)
  934. /* ptr to current thread */
  935. addi r4,r2,THREAD /* address of our thread_struct */
  936. mtspr SPRN_SPRG_THREAD,r4
  937. /* Setup the defaults for TLB entries */
  938. li r4,(MAS4_TSIZED(BOOK3E_PAGESZ_4K))@l
  939. mtspr SPRN_MAS4,r4
  940. /* Jump to start_secondary */
  941. lis r4,MSR_KERNEL@h
  942. ori r4,r4,MSR_KERNEL@l
  943. lis r3,start_secondary@h
  944. ori r3,r3,start_secondary@l
  945. mtspr SPRN_SRR0,r3
  946. mtspr SPRN_SRR1,r4
  947. sync
  948. rfi
  949. sync
  950. .globl __secondary_hold_acknowledge
  951. __secondary_hold_acknowledge:
  952. .long -1
  953. #endif
  954. /*
  955. * We put a few things here that have to be page-aligned. This stuff
  956. * goes at the beginning of the data segment, which is page-aligned.
  957. */
  958. .data
  959. .align 12
  960. .globl sdata
  961. sdata:
  962. .globl empty_zero_page
  963. empty_zero_page:
  964. .space 4096
  965. .globl swapper_pg_dir
  966. swapper_pg_dir:
  967. .space PGD_TABLE_SIZE
  968. /*
  969. * Room for two PTE pointers, usually the kernel and current user pointers
  970. * to their respective root page table.
  971. */
  972. abatron_pteptrs:
  973. .space 8