head_40x.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 1995-1996 Gary Thomas <[email protected]>
  4. * Initial PowerPC version.
  5. * Copyright (c) 1996 Cort Dougan <[email protected]>
  6. * Rewritten for PReP
  7. * Copyright (c) 1996 Paul Mackerras <[email protected]>
  8. * Low-level exception handers, MMU support, and rewrite.
  9. * Copyright (c) 1997 Dan Malek <[email protected]>
  10. * PowerPC 8xx modifications.
  11. * Copyright (c) 1998-1999 TiVo, Inc.
  12. * PowerPC 403GCX modifications.
  13. * Copyright (c) 1999 Grant Erickson <[email protected]>
  14. * PowerPC 403GCX/405GP modifications.
  15. * Copyright 2000 MontaVista Software Inc.
  16. * PPC405 modifications
  17. * PowerPC 403GCX/405GP modifications.
  18. * Author: MontaVista Software, Inc.
  19. * [email protected] or [email protected]
  20. * [email protected]
  21. *
  22. * Module name: head_4xx.S
  23. *
  24. * Description:
  25. * Kernel execution entry point code.
  26. */
  27. #include <linux/init.h>
  28. #include <linux/pgtable.h>
  29. #include <linux/sizes.h>
  30. #include <asm/processor.h>
  31. #include <asm/page.h>
  32. #include <asm/mmu.h>
  33. #include <asm/cputable.h>
  34. #include <asm/thread_info.h>
  35. #include <asm/ppc_asm.h>
  36. #include <asm/asm-offsets.h>
  37. #include <asm/ptrace.h>
  38. #include <asm/export.h>
  39. #include "head_32.h"
  40. /* As with the other PowerPC ports, it is expected that when code
  41. * execution begins here, the following registers contain valid, yet
  42. * optional, information:
  43. *
  44. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  45. * r4 - Starting address of the init RAM disk
  46. * r5 - Ending address of the init RAM disk
  47. * r6 - Start of kernel command line string (e.g. "mem=96m")
  48. * r7 - End of kernel command line string
  49. *
  50. * This is all going to change RSN when we add bi_recs....... -- Dan
  51. */
  52. __HEAD
  53. _GLOBAL(_stext);
  54. _GLOBAL(_start);
  55. mr r31,r3 /* save device tree ptr */
  56. /* We have to turn on the MMU right away so we get cache modes
  57. * set correctly.
  58. */
  59. bl initial_mmu
  60. /* We now have the lower 16 Meg mapped into TLB entries, and the caches
  61. * ready to work.
  62. */
  63. turn_on_mmu:
  64. lis r0,MSR_KERNEL@h
  65. ori r0,r0,MSR_KERNEL@l
  66. mtspr SPRN_SRR1,r0
  67. lis r0,start_here@h
  68. ori r0,r0,start_here@l
  69. mtspr SPRN_SRR0,r0
  70. rfi /* enables MMU */
  71. b . /* prevent prefetch past rfi */
  72. /*
  73. * This area is used for temporarily saving registers during the
  74. * critical exception prolog.
  75. */
  76. . = 0xc0
  77. crit_save:
  78. _GLOBAL(crit_r10)
  79. .space 4
  80. _GLOBAL(crit_r11)
  81. .space 4
  82. _GLOBAL(crit_srr0)
  83. .space 4
  84. _GLOBAL(crit_srr1)
  85. .space 4
  86. _GLOBAL(crit_r1)
  87. .space 4
  88. _GLOBAL(crit_dear)
  89. .space 4
  90. _GLOBAL(crit_esr)
  91. .space 4
  92. /*
  93. * Exception prolog for critical exceptions. This is a little different
  94. * from the normal exception prolog above since a critical exception
  95. * can potentially occur at any point during normal exception processing.
  96. * Thus we cannot use the same SPRG registers as the normal prolog above.
  97. * Instead we use a couple of words of memory at low physical addresses.
  98. * This is OK since we don't support SMP on these processors.
  99. */
  100. .macro CRITICAL_EXCEPTION_PROLOG trapno name
  101. stw r10,crit_r10@l(0) /* save two registers to work with */
  102. stw r11,crit_r11@l(0)
  103. mfspr r10,SPRN_SRR0
  104. mfspr r11,SPRN_SRR1
  105. stw r10,crit_srr0@l(0)
  106. stw r11,crit_srr1@l(0)
  107. mfspr r10,SPRN_DEAR
  108. mfspr r11,SPRN_ESR
  109. stw r10,crit_dear@l(0)
  110. stw r11,crit_esr@l(0)
  111. mfcr r10 /* save CR in r10 for now */
  112. mfspr r11,SPRN_SRR3 /* check whether user or kernel */
  113. andi. r11,r11,MSR_PR
  114. lis r11,(critirq_ctx-PAGE_OFFSET)@ha
  115. lwz r11,(critirq_ctx-PAGE_OFFSET)@l(r11)
  116. beq 1f
  117. /* COMING FROM USER MODE */
  118. mfspr r11,SPRN_SPRG_THREAD /* if from user, start at top of */
  119. lwz r11,TASK_STACK-THREAD(r11) /* this thread's kernel stack */
  120. 1: stw r1,crit_r1@l(0)
  121. addi r1,r11,THREAD_SIZE-INT_FRAME_SIZE /* Alloc an excpt frm */
  122. LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)) /* re-enable MMU */
  123. mtspr SPRN_SRR1, r11
  124. lis r11, 1f@h
  125. ori r11, r11, 1f@l
  126. mtspr SPRN_SRR0, r11
  127. rfi
  128. .text
  129. 1:
  130. \name\()_virt:
  131. lwz r11,crit_r1@l(0)
  132. stw r11,GPR1(r1)
  133. stw r11,0(r1)
  134. mr r11,r1
  135. stw r10,_CCR(r11) /* save various registers */
  136. stw r12,GPR12(r11)
  137. stw r9,GPR9(r11)
  138. mflr r10
  139. stw r10,_LINK(r11)
  140. lis r9,PAGE_OFFSET@ha
  141. lwz r10,crit_r10@l(r9)
  142. lwz r12,crit_r11@l(r9)
  143. stw r10,GPR10(r11)
  144. stw r12,GPR11(r11)
  145. lwz r12,crit_dear@l(r9)
  146. lwz r9,crit_esr@l(r9)
  147. stw r12,_DEAR(r11) /* since they may have had stuff */
  148. stw r9,_ESR(r11) /* exception was taken */
  149. mfspr r12,SPRN_SRR2
  150. mfspr r9,SPRN_SRR3
  151. rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */
  152. COMMON_EXCEPTION_PROLOG_END \trapno + 2
  153. _ASM_NOKPROBE_SYMBOL(\name\()_virt)
  154. .endm
  155. /*
  156. * State at this point:
  157. * r9 saved in stack frame, now saved SRR3 & ~MSR_WE
  158. * r10 saved in crit_r10 and in stack frame, trashed
  159. * r11 saved in crit_r11 and in stack frame,
  160. * now phys stack/exception frame pointer
  161. * r12 saved in stack frame, now saved SRR2
  162. * CR saved in stack frame, CR0.EQ = !SRR3.PR
  163. * LR, DEAR, ESR in stack frame
  164. * r1 saved in stack frame, now virt stack/excframe pointer
  165. * r0, r3-r8 saved in stack frame
  166. */
  167. /*
  168. * Exception vectors.
  169. */
  170. #define CRITICAL_EXCEPTION(n, label, hdlr) \
  171. START_EXCEPTION(n, label); \
  172. CRITICAL_EXCEPTION_PROLOG n label; \
  173. prepare_transfer_to_handler; \
  174. bl hdlr; \
  175. b ret_from_crit_exc
  176. /*
  177. * 0x0100 - Critical Interrupt Exception
  178. */
  179. CRITICAL_EXCEPTION(0x0100, CriticalInterrupt, unknown_exception)
  180. /*
  181. * 0x0200 - Machine Check Exception
  182. */
  183. CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  184. /*
  185. * 0x0300 - Data Storage Exception
  186. * This happens for just a few reasons. U0 set (but we don't do that),
  187. * or zone protection fault (user violation, write to protected page).
  188. * The other Data TLB exceptions bail out to this point
  189. * if they can't resolve the lightweight TLB fault.
  190. */
  191. START_EXCEPTION(0x0300, DataStorage)
  192. EXCEPTION_PROLOG 0x300 DataStorage handle_dar_dsisr=1
  193. prepare_transfer_to_handler
  194. bl do_page_fault
  195. b interrupt_return
  196. /*
  197. * 0x0400 - Instruction Storage Exception
  198. * This is caused by a fetch from non-execute or guarded pages.
  199. */
  200. START_EXCEPTION(0x0400, InstructionAccess)
  201. EXCEPTION_PROLOG 0x400 InstructionAccess
  202. li r5,0
  203. stw r5, _ESR(r11) /* Zero ESR */
  204. stw r12, _DEAR(r11) /* SRR0 as DEAR */
  205. prepare_transfer_to_handler
  206. bl do_page_fault
  207. b interrupt_return
  208. /* 0x0500 - External Interrupt Exception */
  209. EXCEPTION(0x0500, HardwareInterrupt, do_IRQ)
  210. /* 0x0600 - Alignment Exception */
  211. START_EXCEPTION(0x0600, Alignment)
  212. EXCEPTION_PROLOG 0x600 Alignment handle_dar_dsisr=1
  213. prepare_transfer_to_handler
  214. bl alignment_exception
  215. REST_NVGPRS(r1)
  216. b interrupt_return
  217. /* 0x0700 - Program Exception */
  218. START_EXCEPTION(0x0700, ProgramCheck)
  219. EXCEPTION_PROLOG 0x700 ProgramCheck handle_dar_dsisr=1
  220. prepare_transfer_to_handler
  221. bl program_check_exception
  222. REST_NVGPRS(r1)
  223. b interrupt_return
  224. EXCEPTION(0x0800, Trap_08, unknown_exception)
  225. EXCEPTION(0x0900, Trap_09, unknown_exception)
  226. EXCEPTION(0x0A00, Trap_0A, unknown_exception)
  227. EXCEPTION(0x0B00, Trap_0B, unknown_exception)
  228. /* 0x0C00 - System Call Exception */
  229. START_EXCEPTION(0x0C00, SystemCall)
  230. SYSCALL_ENTRY 0xc00
  231. /* Trap_0D is commented out to get more space for system call exception */
  232. /* EXCEPTION(0x0D00, Trap_0D, unknown_exception) */
  233. EXCEPTION(0x0E00, Trap_0E, unknown_exception)
  234. EXCEPTION(0x0F00, Trap_0F, unknown_exception)
  235. /* 0x1000 - Programmable Interval Timer (PIT) Exception */
  236. START_EXCEPTION(0x1000, DecrementerTrap)
  237. b Decrementer
  238. /* 0x1010 - Fixed Interval Timer (FIT) Exception */
  239. START_EXCEPTION(0x1010, FITExceptionTrap)
  240. b FITException
  241. /* 0x1020 - Watchdog Timer (WDT) Exception */
  242. START_EXCEPTION(0x1020, WDTExceptionTrap)
  243. b WDTException
  244. /* 0x1100 - Data TLB Miss Exception
  245. * As the name implies, translation is not in the MMU, so search the
  246. * page tables and fix it. The only purpose of this function is to
  247. * load TLB entries from the page table if they exist.
  248. */
  249. START_EXCEPTION(0x1100, DTLBMiss)
  250. mtspr SPRN_SPRG_SCRATCH5, r10 /* Save some working registers */
  251. mtspr SPRN_SPRG_SCRATCH6, r11
  252. mtspr SPRN_SPRG_SCRATCH3, r12
  253. mtspr SPRN_SPRG_SCRATCH4, r9
  254. mfcr r12
  255. mfspr r9, SPRN_PID
  256. rlwimi r12, r9, 0, 0xff
  257. mfspr r10, SPRN_DEAR /* Get faulting address */
  258. /* If we are faulting a kernel address, we have to use the
  259. * kernel page tables.
  260. */
  261. lis r11, PAGE_OFFSET@h
  262. cmplw r10, r11
  263. blt+ 3f
  264. lis r11, swapper_pg_dir@h
  265. ori r11, r11, swapper_pg_dir@l
  266. li r9, 0
  267. mtspr SPRN_PID, r9 /* TLB will have 0 TID */
  268. b 4f
  269. /* Get the PGD for the current thread.
  270. */
  271. 3:
  272. mfspr r11,SPRN_SPRG_THREAD
  273. lwz r11,PGDIR(r11)
  274. #ifdef CONFIG_PPC_KUAP
  275. rlwinm. r9, r9, 0, 0xff
  276. beq 5f /* Kuap fault */
  277. #endif
  278. 4:
  279. tophys(r11, r11)
  280. rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */
  281. lwz r11, 0(r11) /* Get L1 entry */
  282. andi. r9, r11, _PMD_PRESENT /* Check if it points to a PTE page */
  283. beq 2f /* Bail if no table */
  284. rlwimi r11, r10, 22, 20, 29 /* Compute PTE address */
  285. lwz r11, 0(r11) /* Get Linux PTE */
  286. li r9, _PAGE_PRESENT | _PAGE_ACCESSED
  287. andc. r9, r9, r11 /* Check permission */
  288. bne 5f
  289. rlwinm r9, r11, 1, _PAGE_RW /* dirty => rw */
  290. and r9, r9, r11 /* hwwrite = dirty & rw */
  291. rlwimi r11, r9, 0, _PAGE_RW /* replace rw by hwwrite */
  292. /* Create TLB tag. This is the faulting address plus a static
  293. * set of bits. These are size, valid, E, U0.
  294. */
  295. li r9, 0x00c0
  296. rlwimi r10, r9, 0, 20, 31
  297. b finish_tlb_load
  298. 2: /* Check for possible large-page pmd entry */
  299. rlwinm. r9, r11, 2, 22, 24
  300. beq 5f
  301. /* Create TLB tag. This is the faulting address, plus a static
  302. * set of bits (valid, E, U0) plus the size from the PMD.
  303. */
  304. ori r9, r9, 0x40
  305. rlwimi r10, r9, 0, 20, 31
  306. b finish_tlb_load
  307. 5:
  308. /* The bailout. Restore registers to pre-exception conditions
  309. * and call the heavyweights to help us out.
  310. */
  311. mtspr SPRN_PID, r12
  312. mtcrf 0x80, r12
  313. mfspr r9, SPRN_SPRG_SCRATCH4
  314. mfspr r12, SPRN_SPRG_SCRATCH3
  315. mfspr r11, SPRN_SPRG_SCRATCH6
  316. mfspr r10, SPRN_SPRG_SCRATCH5
  317. b DataStorage
  318. /* 0x1200 - Instruction TLB Miss Exception
  319. * Nearly the same as above, except we get our information from different
  320. * registers and bailout to a different point.
  321. */
  322. START_EXCEPTION(0x1200, ITLBMiss)
  323. mtspr SPRN_SPRG_SCRATCH5, r10 /* Save some working registers */
  324. mtspr SPRN_SPRG_SCRATCH6, r11
  325. mtspr SPRN_SPRG_SCRATCH3, r12
  326. mtspr SPRN_SPRG_SCRATCH4, r9
  327. mfcr r12
  328. mfspr r9, SPRN_PID
  329. rlwimi r12, r9, 0, 0xff
  330. mfspr r10, SPRN_SRR0 /* Get faulting address */
  331. /* If we are faulting a kernel address, we have to use the
  332. * kernel page tables.
  333. */
  334. lis r11, PAGE_OFFSET@h
  335. cmplw r10, r11
  336. blt+ 3f
  337. lis r11, swapper_pg_dir@h
  338. ori r11, r11, swapper_pg_dir@l
  339. li r9, 0
  340. mtspr SPRN_PID, r9 /* TLB will have 0 TID */
  341. b 4f
  342. /* Get the PGD for the current thread.
  343. */
  344. 3:
  345. mfspr r11,SPRN_SPRG_THREAD
  346. lwz r11,PGDIR(r11)
  347. #ifdef CONFIG_PPC_KUAP
  348. rlwinm. r9, r9, 0, 0xff
  349. beq 5f /* Kuap fault */
  350. #endif
  351. 4:
  352. tophys(r11, r11)
  353. rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */
  354. lwz r11, 0(r11) /* Get L1 entry */
  355. andi. r9, r11, _PMD_PRESENT /* Check if it points to a PTE page */
  356. beq 2f /* Bail if no table */
  357. rlwimi r11, r10, 22, 20, 29 /* Compute PTE address */
  358. lwz r11, 0(r11) /* Get Linux PTE */
  359. li r9, _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  360. andc. r9, r9, r11 /* Check permission */
  361. bne 5f
  362. rlwinm r9, r11, 1, _PAGE_RW /* dirty => rw */
  363. and r9, r9, r11 /* hwwrite = dirty & rw */
  364. rlwimi r11, r9, 0, _PAGE_RW /* replace rw by hwwrite */
  365. /* Create TLB tag. This is the faulting address plus a static
  366. * set of bits. These are size, valid, E, U0.
  367. */
  368. li r9, 0x00c0
  369. rlwimi r10, r9, 0, 20, 31
  370. b finish_tlb_load
  371. 2: /* Check for possible large-page pmd entry */
  372. rlwinm. r9, r11, 2, 22, 24
  373. beq 5f
  374. /* Create TLB tag. This is the faulting address, plus a static
  375. * set of bits (valid, E, U0) plus the size from the PMD.
  376. */
  377. ori r9, r9, 0x40
  378. rlwimi r10, r9, 0, 20, 31
  379. b finish_tlb_load
  380. 5:
  381. /* The bailout. Restore registers to pre-exception conditions
  382. * and call the heavyweights to help us out.
  383. */
  384. mtspr SPRN_PID, r12
  385. mtcrf 0x80, r12
  386. mfspr r9, SPRN_SPRG_SCRATCH4
  387. mfspr r12, SPRN_SPRG_SCRATCH3
  388. mfspr r11, SPRN_SPRG_SCRATCH6
  389. mfspr r10, SPRN_SPRG_SCRATCH5
  390. b InstructionAccess
  391. EXCEPTION(0x1300, Trap_13, unknown_exception)
  392. EXCEPTION(0x1400, Trap_14, unknown_exception)
  393. EXCEPTION(0x1500, Trap_15, unknown_exception)
  394. EXCEPTION(0x1600, Trap_16, unknown_exception)
  395. EXCEPTION(0x1700, Trap_17, unknown_exception)
  396. EXCEPTION(0x1800, Trap_18, unknown_exception)
  397. EXCEPTION(0x1900, Trap_19, unknown_exception)
  398. EXCEPTION(0x1A00, Trap_1A, unknown_exception)
  399. EXCEPTION(0x1B00, Trap_1B, unknown_exception)
  400. EXCEPTION(0x1C00, Trap_1C, unknown_exception)
  401. EXCEPTION(0x1D00, Trap_1D, unknown_exception)
  402. EXCEPTION(0x1E00, Trap_1E, unknown_exception)
  403. EXCEPTION(0x1F00, Trap_1F, unknown_exception)
  404. /* Check for a single step debug exception while in an exception
  405. * handler before state has been saved. This is to catch the case
  406. * where an instruction that we are trying to single step causes
  407. * an exception (eg ITLB/DTLB miss) and thus the first instruction of
  408. * the exception handler generates a single step debug exception.
  409. *
  410. * If we get a debug trap on the first instruction of an exception handler,
  411. * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
  412. * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
  413. * The exception handler was handling a non-critical interrupt, so it will
  414. * save (and later restore) the MSR via SPRN_SRR1, which will still have
  415. * the MSR_DE bit set.
  416. */
  417. /* 0x2000 - Debug Exception */
  418. START_EXCEPTION(0x2000, DebugTrap)
  419. CRITICAL_EXCEPTION_PROLOG 0x2000 DebugTrap
  420. /*
  421. * If this is a single step or branch-taken exception in an
  422. * exception entry sequence, it was probably meant to apply to
  423. * the code where the exception occurred (since exception entry
  424. * doesn't turn off DE automatically). We simulate the effect
  425. * of turning off DE on entry to an exception handler by turning
  426. * off DE in the SRR3 value and clearing the debug status.
  427. */
  428. mfspr r10,SPRN_DBSR /* check single-step/branch taken */
  429. andis. r10,r10,DBSR_IC@h
  430. beq+ 2f
  431. andi. r10,r9,MSR_IR|MSR_PR /* check supervisor + MMU off */
  432. beq 1f /* branch and fix it up */
  433. mfspr r10,SPRN_SRR2 /* Faulting instruction address */
  434. cmplwi r10,0x2100
  435. bgt+ 2f /* address above exception vectors */
  436. /* here it looks like we got an inappropriate debug exception. */
  437. 1: rlwinm r9,r9,0,~MSR_DE /* clear DE in the SRR3 value */
  438. lis r10,DBSR_IC@h /* clear the IC event */
  439. mtspr SPRN_DBSR,r10
  440. /* restore state and get out */
  441. lwz r10,_CCR(r11)
  442. lwz r0,GPR0(r11)
  443. lwz r1,GPR1(r11)
  444. mtcrf 0x80,r10
  445. mtspr SPRN_SRR2,r12
  446. mtspr SPRN_SRR3,r9
  447. lwz r9,GPR9(r11)
  448. lwz r12,GPR12(r11)
  449. lwz r10,crit_r10@l(0)
  450. lwz r11,crit_r11@l(0)
  451. rfci
  452. b .
  453. /* continue normal handling for a critical exception... */
  454. 2: mfspr r4,SPRN_DBSR
  455. stw r4,_ESR(r11) /* DebugException takes DBSR in _ESR */
  456. prepare_transfer_to_handler
  457. bl DebugException
  458. b ret_from_crit_exc
  459. /* Programmable Interval Timer (PIT) Exception. (from 0x1000) */
  460. __HEAD
  461. Decrementer:
  462. EXCEPTION_PROLOG 0x1000 Decrementer
  463. lis r0,TSR_PIS@h
  464. mtspr SPRN_TSR,r0 /* Clear the PIT exception */
  465. prepare_transfer_to_handler
  466. bl timer_interrupt
  467. b interrupt_return
  468. /* Fixed Interval Timer (FIT) Exception. (from 0x1010) */
  469. __HEAD
  470. FITException:
  471. EXCEPTION_PROLOG 0x1010 FITException
  472. prepare_transfer_to_handler
  473. bl unknown_exception
  474. b interrupt_return
  475. /* Watchdog Timer (WDT) Exception. (from 0x1020) */
  476. __HEAD
  477. WDTException:
  478. CRITICAL_EXCEPTION_PROLOG 0x1020 WDTException
  479. prepare_transfer_to_handler
  480. bl WatchdogException
  481. b ret_from_crit_exc
  482. /* Other PowerPC processors, namely those derived from the 6xx-series
  483. * have vectors from 0x2100 through 0x2F00 defined, but marked as reserved.
  484. * However, for the 4xx-series processors these are neither defined nor
  485. * reserved.
  486. */
  487. __HEAD
  488. /* Damn, I came up one instruction too many to fit into the
  489. * exception space :-). Both the instruction and data TLB
  490. * miss get to this point to load the TLB.
  491. * r10 - TLB_TAG value
  492. * r11 - Linux PTE
  493. * r9 - available to use
  494. * PID - loaded with proper value when we get here
  495. * Upon exit, we reload everything and RFI.
  496. * Actually, it will fit now, but oh well.....a common place
  497. * to load the TLB.
  498. */
  499. tlb_4xx_index:
  500. .long 0
  501. finish_tlb_load:
  502. /*
  503. * Clear out the software-only bits in the PTE to generate the
  504. * TLB_DATA value. These are the bottom 2 bits of the RPM, the
  505. * top 3 bits of the zone field, and M.
  506. */
  507. li r9, 0x0ce2
  508. andc r11, r11, r9
  509. /* load the next available TLB index. */
  510. lwz r9, tlb_4xx_index@l(0)
  511. addi r9, r9, 1
  512. andi. r9, r9, PPC40X_TLB_SIZE - 1
  513. stw r9, tlb_4xx_index@l(0)
  514. tlbwe r11, r9, TLB_DATA /* Load TLB LO */
  515. tlbwe r10, r9, TLB_TAG /* Load TLB HI */
  516. /* Done...restore registers and get out of here.
  517. */
  518. mtspr SPRN_PID, r12
  519. mtcrf 0x80, r12
  520. mfspr r9, SPRN_SPRG_SCRATCH4
  521. mfspr r12, SPRN_SPRG_SCRATCH3
  522. mfspr r11, SPRN_SPRG_SCRATCH6
  523. mfspr r10, SPRN_SPRG_SCRATCH5
  524. rfi /* Should sync shadow TLBs */
  525. b . /* prevent prefetch past rfi */
  526. /* This is where the main kernel code starts.
  527. */
  528. start_here:
  529. /* ptr to current */
  530. lis r2,init_task@h
  531. ori r2,r2,init_task@l
  532. /* ptr to phys current thread */
  533. tophys(r4,r2)
  534. addi r4,r4,THREAD /* init task's THREAD */
  535. mtspr SPRN_SPRG_THREAD,r4
  536. /* stack */
  537. lis r1,init_thread_union@ha
  538. addi r1,r1,init_thread_union@l
  539. li r0,0
  540. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  541. bl early_init /* We have to do this with MMU on */
  542. /*
  543. * Decide what sort of machine this is and initialize the MMU.
  544. */
  545. #ifdef CONFIG_KASAN
  546. bl kasan_early_init
  547. #endif
  548. li r3,0
  549. mr r4,r31
  550. bl machine_init
  551. bl MMU_init
  552. /* Go back to running unmapped so we can load up new values
  553. * and change to using our exception vectors.
  554. * On the 4xx, all we have to do is invalidate the TLB to clear
  555. * the old 16M byte TLB mappings.
  556. */
  557. lis r4,2f@h
  558. ori r4,r4,2f@l
  559. tophys(r4,r4)
  560. lis r3,(MSR_KERNEL & ~(MSR_IR|MSR_DR))@h
  561. ori r3,r3,(MSR_KERNEL & ~(MSR_IR|MSR_DR))@l
  562. mtspr SPRN_SRR0,r4
  563. mtspr SPRN_SRR1,r3
  564. rfi
  565. b . /* prevent prefetch past rfi */
  566. /* Load up the kernel context */
  567. 2:
  568. sync /* Flush to memory before changing TLB */
  569. tlbia
  570. isync /* Flush shadow TLBs */
  571. /* set up the PTE pointers for the Abatron bdiGDB.
  572. */
  573. lis r6, swapper_pg_dir@h
  574. ori r6, r6, swapper_pg_dir@l
  575. lis r5, abatron_pteptrs@h
  576. ori r5, r5, abatron_pteptrs@l
  577. stw r5, 0xf0(0) /* Must match your Abatron config file */
  578. tophys(r5,r5)
  579. stw r6, 0(r5)
  580. /* Now turn on the MMU for real! */
  581. lis r4,MSR_KERNEL@h
  582. ori r4,r4,MSR_KERNEL@l
  583. lis r3,start_kernel@h
  584. ori r3,r3,start_kernel@l
  585. mtspr SPRN_SRR0,r3
  586. mtspr SPRN_SRR1,r4
  587. rfi /* enable MMU and jump to start_kernel */
  588. b . /* prevent prefetch past rfi */
  589. /* Set up the initial MMU state so we can do the first level of
  590. * kernel initialization. This maps the first 32 MBytes of memory 1:1
  591. * virtual to physical and more importantly sets the cache mode.
  592. */
  593. initial_mmu:
  594. tlbia /* Invalidate all TLB entries */
  595. isync
  596. /* We should still be executing code at physical address 0x0000xxxx
  597. * at this point. However, start_here is at virtual address
  598. * 0xC000xxxx. So, set up a TLB mapping to cover this once
  599. * translation is enabled.
  600. */
  601. lis r3,KERNELBASE@h /* Load the kernel virtual address */
  602. ori r3,r3,KERNELBASE@l
  603. tophys(r4,r3) /* Load the kernel physical address */
  604. iccci r0,r3 /* Invalidate the i-cache before use */
  605. /* Load the kernel PID.
  606. */
  607. li r0,0
  608. mtspr SPRN_PID,r0
  609. sync
  610. /* Configure and load one entry into TLB slots 63 */
  611. clrrwi r4,r4,10 /* Mask off the real page number */
  612. ori r4,r4,(TLB_WR | TLB_EX) /* Set the write and execute bits */
  613. clrrwi r3,r3,10 /* Mask off the effective page number */
  614. ori r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_16M))
  615. li r0,63 /* TLB slot 63 */
  616. tlbwe r4,r0,TLB_DATA /* Load the data portion of the entry */
  617. tlbwe r3,r0,TLB_TAG /* Load the tag portion of the entry */
  618. li r0,62 /* TLB slot 62 */
  619. addis r4,r4,SZ_16M@h
  620. addis r3,r3,SZ_16M@h
  621. tlbwe r4,r0,TLB_DATA /* Load the data portion of the entry */
  622. tlbwe r3,r0,TLB_TAG /* Load the tag portion of the entry */
  623. isync
  624. /* Establish the exception vector base
  625. */
  626. lis r4,KERNELBASE@h /* EVPR only uses the high 16-bits */
  627. tophys(r0,r4) /* Use the physical address */
  628. mtspr SPRN_EVPR,r0
  629. blr
  630. _GLOBAL(abort)
  631. mfspr r13,SPRN_DBCR0
  632. oris r13,r13,DBCR0_RST_SYSTEM@h
  633. mtspr SPRN_DBCR0,r13