head_fsl_booke.S 24 KB

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