head_fsl_booke.S 24 KB

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