head_8xx.S 22 KB

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