head_fsl_booke.S 24 KB

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