head_8xx.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * PowerPC version
  4. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  5. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  6. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Low-level exception handlers and MMU support
  8. * rewritten by Paul Mackerras.
  9. * Copyright (C) 1996 Paul Mackerras.
  10. * MPC8xx modifications by Dan Malek
  11. * Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
  12. *
  13. * This file contains low-level support and setup for PowerPC 8xx
  14. * embedded processors, including trap and interrupt dispatch.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/magic.h>
  18. #include <linux/pgtable.h>
  19. #include <linux/sizes.h>
  20. #include <linux/linkage.h>
  21. #include <asm/processor.h>
  22. #include <asm/page.h>
  23. #include <asm/mmu.h>
  24. #include <asm/cache.h>
  25. #include <asm/cputable.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/ppc_asm.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/ptrace.h>
  30. #include <asm/code-patching-asm.h>
  31. #include <asm/interrupt.h>
  32. /*
  33. * Value for the bits that have fixed value in RPN entries.
  34. * Also used for tagging DAR for DTLBerror.
  35. */
  36. #define RPN_PATTERN 0x00f0
  37. #include "head_32.h"
  38. #define PAGE_SHIFT_512K 19
  39. #define PAGE_SHIFT_8M 23
  40. __HEAD
  41. _GLOBAL(_stext);
  42. _GLOBAL(_start);
  43. /* MPC8xx
  44. * This port was done on an MBX board with an 860. Right now I only
  45. * support an ELF compressed (zImage) boot from EPPC-Bug because the
  46. * code there loads up some registers before calling us:
  47. * r3: ptr to board info data
  48. * r4: initrd_start or if no initrd then 0
  49. * r5: initrd_end - unused if r4 is 0
  50. * r6: Start of command line string
  51. * r7: End of command line string
  52. *
  53. * I decided to use conditional compilation instead of checking PVR and
  54. * adding more processor specific branches around code I don't need.
  55. * Since this is an embedded processor, I also appreciate any memory
  56. * savings I can get.
  57. *
  58. * The MPC8xx does not have any BATs, but it supports large page sizes.
  59. * We first initialize the MMU to support 8M byte pages, then load one
  60. * entry into each of the instruction and data TLBs to map the first
  61. * 8M 1:1. I also mapped an additional I/O space 1:1 so we can get to
  62. * the "internal" processor registers before MMU_init is called.
  63. *
  64. * -- Dan
  65. */
  66. .globl __start
  67. __start:
  68. mr r31,r3 /* save device tree ptr */
  69. /* We have to turn on the MMU right away so we get cache modes
  70. * set correctly.
  71. */
  72. bl initial_mmu
  73. /* We now have the lower 8 Meg mapped into TLB entries, and the caches
  74. * ready to work.
  75. */
  76. turn_on_mmu:
  77. mfmsr r0
  78. ori r0,r0,MSR_DR|MSR_IR
  79. mtspr SPRN_SRR1,r0
  80. lis r0,start_here@h
  81. ori r0,r0,start_here@l
  82. mtspr SPRN_SRR0,r0
  83. rfi /* enables MMU */
  84. #ifdef CONFIG_PERF_EVENTS
  85. .align 4
  86. .globl itlb_miss_counter
  87. itlb_miss_counter:
  88. .space 4
  89. .globl dtlb_miss_counter
  90. dtlb_miss_counter:
  91. .space 4
  92. .globl instruction_counter
  93. instruction_counter:
  94. .space 4
  95. #endif
  96. /* System reset */
  97. EXCEPTION(INTERRUPT_SYSTEM_RESET, Reset, system_reset_exception)
  98. /* Machine check */
  99. START_EXCEPTION(INTERRUPT_MACHINE_CHECK, MachineCheck)
  100. EXCEPTION_PROLOG INTERRUPT_MACHINE_CHECK MachineCheck handle_dar_dsisr=1
  101. prepare_transfer_to_handler
  102. bl machine_check_exception
  103. b interrupt_return
  104. /* External interrupt */
  105. EXCEPTION(INTERRUPT_EXTERNAL, HardwareInterrupt, do_IRQ)
  106. /* Alignment exception */
  107. START_EXCEPTION(INTERRUPT_ALIGNMENT, Alignment)
  108. EXCEPTION_PROLOG INTERRUPT_ALIGNMENT Alignment handle_dar_dsisr=1
  109. prepare_transfer_to_handler
  110. bl alignment_exception
  111. REST_NVGPRS(r1)
  112. b interrupt_return
  113. /* Program check exception */
  114. START_EXCEPTION(INTERRUPT_PROGRAM, ProgramCheck)
  115. EXCEPTION_PROLOG INTERRUPT_PROGRAM ProgramCheck
  116. prepare_transfer_to_handler
  117. bl program_check_exception
  118. REST_NVGPRS(r1)
  119. b interrupt_return
  120. /* Decrementer */
  121. EXCEPTION(INTERRUPT_DECREMENTER, Decrementer, timer_interrupt)
  122. /* System call */
  123. START_EXCEPTION(INTERRUPT_SYSCALL, SystemCall)
  124. SYSCALL_ENTRY INTERRUPT_SYSCALL
  125. /* Single step - not used on 601 */
  126. EXCEPTION(INTERRUPT_TRACE, SingleStep, single_step_exception)
  127. /* On the MPC8xx, this is a software emulation interrupt. It occurs
  128. * for all unimplemented and illegal instructions.
  129. */
  130. START_EXCEPTION(INTERRUPT_SOFT_EMU_8xx, SoftEmu)
  131. EXCEPTION_PROLOG INTERRUPT_SOFT_EMU_8xx SoftEmu
  132. prepare_transfer_to_handler
  133. bl emulation_assist_interrupt
  134. REST_NVGPRS(r1)
  135. b interrupt_return
  136. /*
  137. * For the MPC8xx, this is a software tablewalk to load the instruction
  138. * TLB. The task switch loads the M_TWB register with the pointer to the first
  139. * level table.
  140. * If there is no second level table (value is zero) or if there
  141. * is an invalid pte, we load that into the TLB, which causes another fault
  142. * into the TLB Error interrupt where we can handle such problems.
  143. * We have to use the MD_xxx registers for the tablewalk because the
  144. * equivalent MI_xxx registers only perform the attribute functions.
  145. */
  146. #ifdef CONFIG_8xx_CPU15
  147. #define INVALIDATE_ADJACENT_PAGES_CPU15(addr, tmp) \
  148. addi tmp, addr, PAGE_SIZE; \
  149. tlbie tmp; \
  150. addi tmp, addr, -PAGE_SIZE; \
  151. tlbie tmp
  152. #else
  153. #define INVALIDATE_ADJACENT_PAGES_CPU15(addr, tmp)
  154. #endif
  155. START_EXCEPTION(INTERRUPT_INST_TLB_MISS_8xx, InstructionTLBMiss)
  156. mtspr SPRN_SPRG_SCRATCH2, r10
  157. mtspr SPRN_M_TW, r11
  158. mfspr r10, SPRN_SRR0 /* Get effective address of fault */
  159. INVALIDATE_ADJACENT_PAGES_CPU15(r10, r11)
  160. mtspr SPRN_MD_EPN, r10
  161. mfspr r10, SPRN_M_TWB /* Get level 1 table */
  162. lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r10) /* Get level 1 entry */
  163. mtspr SPRN_MD_TWC, r11
  164. mfspr r10, SPRN_MD_TWC
  165. lwz r10, 0(r10) /* Get the pte */
  166. rlwimi r11, r10, 0, _PAGE_GUARDED | _PAGE_ACCESSED
  167. rlwimi r11, r10, 32 - 9, _PMD_PAGE_512K
  168. mtspr SPRN_MI_TWC, r11
  169. /* The Linux PTE won't go exactly into the MMU TLB.
  170. * Software indicator bits 20 and 23 must be clear.
  171. * Software indicator bits 22, 24, 25, 26, and 27 must be
  172. * set. All other Linux PTE bits control the behavior
  173. * of the MMU.
  174. */
  175. rlwinm r10, r10, 0, ~0x0f00 /* Clear bits 20-23 */
  176. rlwimi r10, r10, 4, 0x0400 /* Copy _PAGE_EXEC into bit 21 */
  177. ori r10, r10, RPN_PATTERN | 0x200 /* Set 22 and 24-27 */
  178. mtspr SPRN_MI_RPN, r10 /* Update TLB entry */
  179. /* Restore registers */
  180. 0: mfspr r10, SPRN_SPRG_SCRATCH2
  181. mfspr r11, SPRN_M_TW
  182. rfi
  183. patch_site 0b, patch__itlbmiss_exit_1
  184. #ifdef CONFIG_PERF_EVENTS
  185. patch_site 0f, patch__itlbmiss_perf
  186. 0: lwz r10, (itlb_miss_counter - PAGE_OFFSET)@l(0)
  187. addi r10, r10, 1
  188. stw r10, (itlb_miss_counter - PAGE_OFFSET)@l(0)
  189. mfspr r10, SPRN_SPRG_SCRATCH2
  190. mfspr r11, SPRN_M_TW
  191. rfi
  192. #endif
  193. START_EXCEPTION(INTERRUPT_DATA_TLB_MISS_8xx, DataStoreTLBMiss)
  194. mtspr SPRN_SPRG_SCRATCH2, r10
  195. mtspr SPRN_M_TW, r11
  196. mfspr r10, SPRN_M_TWB /* Get level 1 table */
  197. lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r10) /* Get level 1 entry */
  198. mtspr SPRN_MD_TWC, r11
  199. mfspr r10, SPRN_MD_TWC
  200. lwz r10, 0(r10) /* Get the pte */
  201. /* Insert Guarded and Accessed flags into the TWC from the Linux PTE.
  202. * It is bit 27 of both the Linux PTE and the TWC (at least
  203. * I got that right :-). It will be better when we can put
  204. * this into the Linux pgd/pmd and load it in the operation
  205. * above.
  206. */
  207. rlwimi r11, r10, 0, _PAGE_GUARDED | _PAGE_ACCESSED
  208. rlwimi r11, r10, 32 - 9, _PMD_PAGE_512K
  209. mtspr SPRN_MD_TWC, r11
  210. /* The Linux PTE won't go exactly into the MMU TLB.
  211. * Software indicator bits 24, 25, 26, and 27 must be
  212. * set. All other Linux PTE bits control the behavior
  213. * of the MMU.
  214. */
  215. li r11, RPN_PATTERN
  216. rlwimi r10, r11, 0, 24, 27 /* Set 24-27 */
  217. mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
  218. mtspr SPRN_DAR, r11 /* Tag DAR */
  219. /* Restore registers */
  220. 0: mfspr r10, SPRN_SPRG_SCRATCH2
  221. mfspr r11, SPRN_M_TW
  222. rfi
  223. patch_site 0b, patch__dtlbmiss_exit_1
  224. #ifdef CONFIG_PERF_EVENTS
  225. patch_site 0f, patch__dtlbmiss_perf
  226. 0: lwz r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
  227. addi r10, r10, 1
  228. stw r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
  229. mfspr r10, SPRN_SPRG_SCRATCH2
  230. mfspr r11, SPRN_M_TW
  231. rfi
  232. #endif
  233. /* This is an instruction TLB error on the MPC8xx. This could be due
  234. * to many reasons, such as executing guarded memory or illegal instruction
  235. * addresses. There is nothing to do but handle a big time error fault.
  236. */
  237. START_EXCEPTION(INTERRUPT_INST_TLB_ERROR_8xx, InstructionTLBError)
  238. /* 0x400 is InstructionAccess exception, needed by bad_page_fault() */
  239. EXCEPTION_PROLOG INTERRUPT_INST_STORAGE InstructionTLBError
  240. andis. r5,r9,DSISR_SRR1_MATCH_32S@h /* Filter relevant SRR1 bits */
  241. andis. r10,r9,SRR1_ISI_NOPT@h
  242. beq+ .Litlbie
  243. tlbie r12
  244. .Litlbie:
  245. stw r12, _DAR(r11)
  246. stw r5, _DSISR(r11)
  247. prepare_transfer_to_handler
  248. bl do_page_fault
  249. b interrupt_return
  250. /* This is the data TLB error on the MPC8xx. This could be due to
  251. * many reasons, including a dirty update to a pte. We bail out to
  252. * a higher level function that can handle it.
  253. */
  254. START_EXCEPTION(INTERRUPT_DATA_TLB_ERROR_8xx, DataTLBError)
  255. EXCEPTION_PROLOG_0 handle_dar_dsisr=1
  256. mfspr r11, SPRN_DAR
  257. cmpwi cr1, r11, RPN_PATTERN
  258. beq- cr1, FixupDAR /* must be a buggy dcbX, icbi insn. */
  259. DARFixed:/* Return from dcbx instruction bug workaround */
  260. mfspr r11, SPRN_DSISR
  261. rlwinm r11, r11, 0, DSISR_NOHPTE
  262. cmpwi cr1, r11, 0
  263. beq+ cr1, .Ldtlbie
  264. mfspr r11, SPRN_DAR
  265. tlbie r11
  266. rlwinm r11, r11, 16, 0xffff
  267. cmplwi cr1, r11, TASK_SIZE@h
  268. bge- cr1, FixupPGD
  269. .Ldtlbie:
  270. EXCEPTION_PROLOG_1
  271. /* 0x300 is DataAccess exception, needed by bad_page_fault() */
  272. EXCEPTION_PROLOG_2 INTERRUPT_DATA_STORAGE DataTLBError handle_dar_dsisr=1
  273. prepare_transfer_to_handler
  274. bl do_page_fault
  275. b interrupt_return
  276. #ifdef CONFIG_VMAP_STACK
  277. vmap_stack_overflow_exception
  278. #endif
  279. /* On the MPC8xx, these next four traps are used for development
  280. * support of breakpoints and such. Someday I will get around to
  281. * using them.
  282. */
  283. START_EXCEPTION(INTERRUPT_DATA_BREAKPOINT_8xx, DataBreakpoint)
  284. EXCEPTION_PROLOG_0 handle_dar_dsisr=1
  285. mfspr r11, SPRN_SRR0
  286. cmplwi cr1, r11, (.Ldtlbie - PAGE_OFFSET)@l
  287. cmplwi cr7, r11, (.Litlbie - PAGE_OFFSET)@l
  288. cror 4*cr1+eq, 4*cr1+eq, 4*cr7+eq
  289. bne cr1, 1f
  290. mtcr r10
  291. mfspr r10, SPRN_SPRG_SCRATCH0
  292. mfspr r11, SPRN_SPRG_SCRATCH1
  293. rfi
  294. 1: EXCEPTION_PROLOG_1
  295. EXCEPTION_PROLOG_2 INTERRUPT_DATA_BREAKPOINT_8xx DataBreakpoint handle_dar_dsisr=1
  296. mfspr r4,SPRN_BAR
  297. stw r4,_DAR(r11)
  298. prepare_transfer_to_handler
  299. bl do_break
  300. REST_NVGPRS(r1)
  301. b interrupt_return
  302. #ifdef CONFIG_PERF_EVENTS
  303. START_EXCEPTION(INTERRUPT_INST_BREAKPOINT_8xx, InstructionBreakpoint)
  304. mtspr SPRN_SPRG_SCRATCH0, r10
  305. lwz r10, (instruction_counter - PAGE_OFFSET)@l(0)
  306. addi r10, r10, -1
  307. stw r10, (instruction_counter - PAGE_OFFSET)@l(0)
  308. lis r10, 0xffff
  309. ori r10, r10, 0x01
  310. mtspr SPRN_COUNTA, r10
  311. mfspr r10, SPRN_SPRG_SCRATCH0
  312. rfi
  313. #else
  314. EXCEPTION(INTERRUPT_INST_BREAKPOINT_8xx, Trap_1d, unknown_exception)
  315. #endif
  316. EXCEPTION(0x1e00, Trap_1e, unknown_exception)
  317. EXCEPTION(0x1f00, Trap_1f, unknown_exception)
  318. __HEAD
  319. . = 0x2000
  320. FixupPGD:
  321. mtspr SPRN_M_TW, r10
  322. mfspr r10, SPRN_DAR
  323. mtspr SPRN_MD_EPN, r10
  324. mfspr r11, SPRN_M_TWB /* Get level 1 table */
  325. lwz r10, (swapper_pg_dir - PAGE_OFFSET)@l(r11) /* Get the level 1 entry */
  326. cmpwi cr1, r10, 0
  327. bne cr1, 1f
  328. rlwinm r10, r11, 0, 20, 31
  329. oris r10, r10, (swapper_pg_dir - PAGE_OFFSET)@ha
  330. lwz r10, (swapper_pg_dir - PAGE_OFFSET)@l(r10) /* Get the level 1 entry */
  331. cmpwi cr1, r10, 0
  332. beq cr1, 1f
  333. stw r10, (swapper_pg_dir - PAGE_OFFSET)@l(r11) /* Set the level 1 entry */
  334. mfspr r10, SPRN_M_TW
  335. mtcr r10
  336. mfspr r10, SPRN_SPRG_SCRATCH0
  337. mfspr r11, SPRN_SPRG_SCRATCH1
  338. rfi
  339. 1:
  340. mfspr r10, SPRN_M_TW
  341. b .Ldtlbie
  342. /* This is the procedure to calculate the data EA for buggy dcbx,dcbi instructions
  343. * by decoding the registers used by the dcbx instruction and adding them.
  344. * DAR is set to the calculated address.
  345. */
  346. FixupDAR:/* Entry point for dcbx workaround. */
  347. mtspr SPRN_M_TW, r10
  348. /* fetch instruction from memory. */
  349. mfspr r10, SPRN_SRR0
  350. mtspr SPRN_MD_EPN, r10
  351. rlwinm r11, r10, 16, 0xfff8
  352. cmpli cr1, r11, TASK_SIZE@h
  353. mfspr r11, SPRN_M_TWB /* Get level 1 table */
  354. blt+ cr1, 3f
  355. /* create physical page address from effective address */
  356. tophys(r11, r10)
  357. mfspr r11, SPRN_M_TWB /* Get level 1 table */
  358. rlwinm r11, r11, 0, 20, 31
  359. oris r11, r11, (swapper_pg_dir - PAGE_OFFSET)@ha
  360. 3:
  361. lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r11) /* Get the level 1 entry */
  362. rlwinm r11, r11, 0, ~_PMD_PAGE_8M
  363. mtspr SPRN_MD_TWC, r11
  364. mfspr r11, SPRN_MD_TWC
  365. lwz r11, 0(r11) /* Get the pte */
  366. /* concat physical page address(r11) and page offset(r10) */
  367. rlwimi r11, r10, 0, 32 - PAGE_SHIFT, 31
  368. lwz r11,0(r11)
  369. /* Check if it really is a dcbx instruction. */
  370. /* dcbt and dcbtst does not generate DTLB Misses/Errors,
  371. * no need to include them here */
  372. xoris r10, r11, 0x7c00 /* check if major OP code is 31 */
  373. rlwinm r10, r10, 0, 21, 5
  374. cmpwi cr1, r10, 2028 /* Is dcbz? */
  375. beq+ cr1, 142f
  376. cmpwi cr1, r10, 940 /* Is dcbi? */
  377. beq+ cr1, 142f
  378. cmpwi cr1, r10, 108 /* Is dcbst? */
  379. beq+ cr1, 144f /* Fix up store bit! */
  380. cmpwi cr1, r10, 172 /* Is dcbf? */
  381. beq+ cr1, 142f
  382. cmpwi cr1, r10, 1964 /* Is icbi? */
  383. beq+ cr1, 142f
  384. 141: mfspr r10,SPRN_M_TW
  385. b DARFixed /* Nope, go back to normal TLB processing */
  386. 144: mfspr r10, SPRN_DSISR
  387. rlwinm r10, r10,0,7,5 /* Clear store bit for buggy dcbst insn */
  388. mtspr SPRN_DSISR, r10
  389. 142: /* continue, it was a dcbx, dcbi instruction. */
  390. mfctr r10
  391. mtdar r10 /* save ctr reg in DAR */
  392. rlwinm r10, r11, 24, 24, 28 /* offset into jump table for reg RB */
  393. addi r10, r10, 150f@l /* add start of table */
  394. mtctr r10 /* load ctr with jump address */
  395. xor r10, r10, r10 /* sum starts at zero */
  396. bctr /* jump into table */
  397. 150:
  398. add r10, r10, r0 ;b 151f
  399. add r10, r10, r1 ;b 151f
  400. add r10, r10, r2 ;b 151f
  401. add r10, r10, r3 ;b 151f
  402. add r10, r10, r4 ;b 151f
  403. add r10, r10, r5 ;b 151f
  404. add r10, r10, r6 ;b 151f
  405. add r10, r10, r7 ;b 151f
  406. add r10, r10, r8 ;b 151f
  407. add r10, r10, r9 ;b 151f
  408. mtctr r11 ;b 154f /* r10 needs special handling */
  409. mtctr r11 ;b 153f /* r11 needs special handling */
  410. add r10, r10, r12 ;b 151f
  411. add r10, r10, r13 ;b 151f
  412. add r10, r10, r14 ;b 151f
  413. add r10, r10, r15 ;b 151f
  414. add r10, r10, r16 ;b 151f
  415. add r10, r10, r17 ;b 151f
  416. add r10, r10, r18 ;b 151f
  417. add r10, r10, r19 ;b 151f
  418. add r10, r10, r20 ;b 151f
  419. add r10, r10, r21 ;b 151f
  420. add r10, r10, r22 ;b 151f
  421. add r10, r10, r23 ;b 151f
  422. add r10, r10, r24 ;b 151f
  423. add r10, r10, r25 ;b 151f
  424. add r10, r10, r26 ;b 151f
  425. add r10, r10, r27 ;b 151f
  426. add r10, r10, r28 ;b 151f
  427. add r10, r10, r29 ;b 151f
  428. add r10, r10, r30 ;b 151f
  429. add r10, r10, r31
  430. 151:
  431. rlwinm r11,r11,19,24,28 /* offset into jump table for reg RA */
  432. cmpwi cr1, r11, 0
  433. beq cr1, 152f /* if reg RA is zero, don't add it */
  434. addi r11, r11, 150b@l /* add start of table */
  435. mtctr r11 /* load ctr with jump address */
  436. rlwinm r11,r11,0,16,10 /* make sure we don't execute this more than once */
  437. bctr /* jump into table */
  438. 152:
  439. mfdar r11
  440. mtdar r10
  441. mtctr r11 /* restore ctr reg from DAR */
  442. mfspr r11, SPRN_SPRG_THREAD
  443. stw r10, DAR(r11)
  444. mfspr r10, SPRN_DSISR
  445. stw r10, DSISR(r11)
  446. mfspr r10,SPRN_M_TW
  447. b DARFixed /* Go back to normal TLB handling */
  448. /* special handling for r10,r11 since these are modified already */
  449. 153: mfspr r11, SPRN_SPRG_SCRATCH1 /* load r11 from SPRN_SPRG_SCRATCH1 */
  450. add r10, r10, r11 /* add it */
  451. mfctr r11 /* restore r11 */
  452. b 151b
  453. 154: mfspr r11, SPRN_SPRG_SCRATCH0 /* load r10 from SPRN_SPRG_SCRATCH0 */
  454. add r10, r10, r11 /* add it */
  455. mfctr r11 /* restore r11 */
  456. b 151b
  457. /*
  458. * This is where the main kernel code starts.
  459. */
  460. start_here:
  461. /* ptr to current */
  462. lis r2,init_task@h
  463. ori r2,r2,init_task@l
  464. /* ptr to phys current thread */
  465. tophys(r4,r2)
  466. addi r4,r4,THREAD /* init task's THREAD */
  467. mtspr SPRN_SPRG_THREAD,r4
  468. /* stack */
  469. lis r1,init_thread_union@ha
  470. addi r1,r1,init_thread_union@l
  471. lis r0, STACK_END_MAGIC@h
  472. ori r0, r0, STACK_END_MAGIC@l
  473. stw r0, 0(r1)
  474. li r0,0
  475. stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
  476. lis r6, swapper_pg_dir@ha
  477. tophys(r6,r6)
  478. mtspr SPRN_M_TWB, r6
  479. bl early_init /* We have to do this with MMU on */
  480. /*
  481. * Decide what sort of machine this is and initialize the MMU.
  482. */
  483. #ifdef CONFIG_KASAN
  484. bl kasan_early_init
  485. #endif
  486. li r3,0
  487. mr r4,r31
  488. bl machine_init
  489. bl MMU_init
  490. /*
  491. * Go back to running unmapped so we can load up new values
  492. * and change to using our exception vectors.
  493. * On the 8xx, all we have to do is invalidate the TLB to clear
  494. * the old 8M byte TLB mappings and load the page table base register.
  495. */
  496. /* The right way to do this would be to track it down through
  497. * init's THREAD like the context switch code does, but this is
  498. * easier......until someone changes init's static structures.
  499. */
  500. lis r4,2f@h
  501. ori r4,r4,2f@l
  502. tophys(r4,r4)
  503. li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  504. mtspr SPRN_SRR0,r4
  505. mtspr SPRN_SRR1,r3
  506. rfi
  507. /* Load up the kernel context */
  508. 2:
  509. #ifdef CONFIG_PIN_TLB_IMMR
  510. lis r0, MD_TWAM@h
  511. oris r0, r0, 0x1f00
  512. mtspr SPRN_MD_CTR, r0
  513. LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID)
  514. tlbie r0
  515. mtspr SPRN_MD_EPN, r0
  516. LOAD_REG_IMMEDIATE(r0, MD_SVALID | MD_PS512K | MD_GUARDED)
  517. mtspr SPRN_MD_TWC, r0
  518. mfspr r0, SPRN_IMMR
  519. rlwinm r0, r0, 0, 0xfff80000
  520. ori r0, r0, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \
  521. _PAGE_NO_CACHE | _PAGE_PRESENT
  522. mtspr SPRN_MD_RPN, r0
  523. lis r0, (MD_TWAM | MD_RSV4I)@h
  524. mtspr SPRN_MD_CTR, r0
  525. #endif
  526. #ifndef CONFIG_PIN_TLB_TEXT
  527. li r0, 0
  528. mtspr SPRN_MI_CTR, r0
  529. #endif
  530. #if !defined(CONFIG_PIN_TLB_DATA) && !defined(CONFIG_PIN_TLB_IMMR)
  531. lis r0, MD_TWAM@h
  532. mtspr SPRN_MD_CTR, r0
  533. #endif
  534. tlbia /* Clear all TLB entries */
  535. sync /* wait for tlbia/tlbie to finish */
  536. /* set up the PTE pointers for the Abatron bdiGDB.
  537. */
  538. lis r5, abatron_pteptrs@h
  539. ori r5, r5, abatron_pteptrs@l
  540. stw r5, 0xf0(0) /* Must match your Abatron config file */
  541. tophys(r5,r5)
  542. lis r6, swapper_pg_dir@h
  543. ori r6, r6, swapper_pg_dir@l
  544. stw r6, 0(r5)
  545. /* Now turn on the MMU for real! */
  546. li r4,MSR_KERNEL
  547. lis r3,start_kernel@h
  548. ori r3,r3,start_kernel@l
  549. mtspr SPRN_SRR0,r3
  550. mtspr SPRN_SRR1,r4
  551. rfi /* enable MMU and jump to start_kernel */
  552. /* Set up the initial MMU state so we can do the first level of
  553. * kernel initialization. This maps the first 8 MBytes of memory 1:1
  554. * virtual to physical. Also, set the cache mode since that is defined
  555. * by TLB entries and perform any additional mapping (like of the IMMR).
  556. * If configured to pin some TLBs, we pin the first 8 Mbytes of kernel,
  557. * 24 Mbytes of data, and the 512k IMMR space. Anything not covered by
  558. * these mappings is mapped by page tables.
  559. */
  560. SYM_FUNC_START_LOCAL(initial_mmu)
  561. li r8, 0
  562. mtspr SPRN_MI_CTR, r8 /* remove PINNED ITLB entries */
  563. lis r10, MD_TWAM@h
  564. mtspr SPRN_MD_CTR, r10 /* remove PINNED DTLB entries */
  565. tlbia /* Invalidate all TLB entries */
  566. lis r8, MI_APG_INIT@h /* Set protection modes */
  567. ori r8, r8, MI_APG_INIT@l
  568. mtspr SPRN_MI_AP, r8
  569. lis r8, MD_APG_INIT@h
  570. ori r8, r8, MD_APG_INIT@l
  571. mtspr SPRN_MD_AP, r8
  572. /* Map the lower RAM (up to 32 Mbytes) into the ITLB and DTLB */
  573. lis r8, MI_RSV4I@h
  574. ori r8, r8, 0x1c00
  575. oris r12, r10, MD_RSV4I@h
  576. ori r12, r12, 0x1c00
  577. li r9, 4 /* up to 4 pages of 8M */
  578. mtctr r9
  579. lis r9, KERNELBASE@h /* Create vaddr for TLB */
  580. li r10, MI_PS8MEG | _PMD_ACCESSED | MI_SVALID
  581. li r11, MI_BOOTINIT /* Create RPN for address 0 */
  582. 1:
  583. mtspr SPRN_MI_CTR, r8 /* Set instruction MMU control */
  584. addi r8, r8, 0x100
  585. ori r0, r9, MI_EVALID /* Mark it valid */
  586. mtspr SPRN_MI_EPN, r0
  587. mtspr SPRN_MI_TWC, r10
  588. mtspr SPRN_MI_RPN, r11 /* Store TLB entry */
  589. mtspr SPRN_MD_CTR, r12
  590. addi r12, r12, 0x100
  591. mtspr SPRN_MD_EPN, r0
  592. mtspr SPRN_MD_TWC, r10
  593. mtspr SPRN_MD_RPN, r11
  594. addis r9, r9, 0x80
  595. addis r11, r11, 0x80
  596. bdnz 1b
  597. /* Since the cache is enabled according to the information we
  598. * just loaded into the TLB, invalidate and enable the caches here.
  599. * We should probably check/set other modes....later.
  600. */
  601. lis r8, IDC_INVALL@h
  602. mtspr SPRN_IC_CST, r8
  603. mtspr SPRN_DC_CST, r8
  604. lis r8, IDC_ENABLE@h
  605. mtspr SPRN_IC_CST, r8
  606. mtspr SPRN_DC_CST, r8
  607. /* Disable debug mode entry on breakpoints */
  608. mfspr r8, SPRN_DER
  609. #ifdef CONFIG_PERF_EVENTS
  610. rlwinm r8, r8, 0, ~0xc
  611. #else
  612. rlwinm r8, r8, 0, ~0x8
  613. #endif
  614. mtspr SPRN_DER, r8
  615. blr
  616. SYM_FUNC_END(initial_mmu)
  617. #ifdef CONFIG_PIN_TLB
  618. _GLOBAL(mmu_pin_tlb)
  619. lis r9, (1f - PAGE_OFFSET)@h
  620. ori r9, r9, (1f - PAGE_OFFSET)@l
  621. mfmsr r10
  622. mflr r11
  623. li r12, MSR_KERNEL & ~(MSR_IR | MSR_DR | MSR_RI)
  624. rlwinm r0, r10, 0, ~MSR_RI
  625. rlwinm r0, r0, 0, ~MSR_EE
  626. mtmsr r0
  627. isync
  628. .align 4
  629. mtspr SPRN_SRR0, r9
  630. mtspr SPRN_SRR1, r12
  631. rfi
  632. 1:
  633. li r5, 0
  634. lis r6, MD_TWAM@h
  635. mtspr SPRN_MI_CTR, r5
  636. mtspr SPRN_MD_CTR, r6
  637. tlbia
  638. #ifdef CONFIG_PIN_TLB_TEXT
  639. LOAD_REG_IMMEDIATE(r5, 28 << 8)
  640. LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET)
  641. LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG | _PMD_ACCESSED)
  642. LOAD_REG_IMMEDIATE(r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT)
  643. LOAD_REG_ADDR(r9, _sinittext)
  644. li r0, 4
  645. mtctr r0
  646. 2: ori r0, r6, MI_EVALID
  647. mtspr SPRN_MI_CTR, r5
  648. mtspr SPRN_MI_EPN, r0
  649. mtspr SPRN_MI_TWC, r7
  650. mtspr SPRN_MI_RPN, r8
  651. addi r5, r5, 0x100
  652. addis r6, r6, SZ_8M@h
  653. addis r8, r8, SZ_8M@h
  654. cmplw r6, r9
  655. bdnzt lt, 2b
  656. lis r0, MI_RSV4I@h
  657. mtspr SPRN_MI_CTR, r0
  658. #endif
  659. LOAD_REG_IMMEDIATE(r5, 28 << 8 | MD_TWAM)
  660. #ifdef CONFIG_PIN_TLB_DATA
  661. LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET)
  662. LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG | _PMD_ACCESSED)
  663. li r8, 0
  664. #ifdef CONFIG_PIN_TLB_IMMR
  665. li r0, 3
  666. #else
  667. li r0, 4
  668. #endif
  669. mtctr r0
  670. cmpwi r4, 0
  671. beq 4f
  672. LOAD_REG_ADDR(r9, _sinittext)
  673. 2: ori r0, r6, MD_EVALID
  674. ori r12, r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT
  675. mtspr SPRN_MD_CTR, r5
  676. mtspr SPRN_MD_EPN, r0
  677. mtspr SPRN_MD_TWC, r7
  678. mtspr SPRN_MD_RPN, r12
  679. addi r5, r5, 0x100
  680. addis r6, r6, SZ_8M@h
  681. addis r8, r8, SZ_8M@h
  682. cmplw r6, r9
  683. bdnzt lt, 2b
  684. 4:
  685. 2: ori r0, r6, MD_EVALID
  686. ori r12, r8, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT
  687. mtspr SPRN_MD_CTR, r5
  688. mtspr SPRN_MD_EPN, r0
  689. mtspr SPRN_MD_TWC, r7
  690. mtspr SPRN_MD_RPN, r12
  691. addi r5, r5, 0x100
  692. addis r6, r6, SZ_8M@h
  693. addis r8, r8, SZ_8M@h
  694. cmplw r6, r3
  695. bdnzt lt, 2b
  696. #endif
  697. #ifdef CONFIG_PIN_TLB_IMMR
  698. LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID)
  699. LOAD_REG_IMMEDIATE(r7, MD_SVALID | MD_PS512K | MD_GUARDED | _PMD_ACCESSED)
  700. mfspr r8, SPRN_IMMR
  701. rlwinm r8, r8, 0, 0xfff80000
  702. ori r8, r8, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \
  703. _PAGE_NO_CACHE | _PAGE_PRESENT
  704. mtspr SPRN_MD_CTR, r5
  705. mtspr SPRN_MD_EPN, r0
  706. mtspr SPRN_MD_TWC, r7
  707. mtspr SPRN_MD_RPN, r8
  708. #endif
  709. #if defined(CONFIG_PIN_TLB_IMMR) || defined(CONFIG_PIN_TLB_DATA)
  710. lis r0, (MD_RSV4I | MD_TWAM)@h
  711. mtspr SPRN_MD_CTR, r0
  712. #endif
  713. mtspr SPRN_SRR1, r10
  714. mtspr SPRN_SRR0, r11
  715. rfi
  716. #endif