mmu.S 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * linux/arch/m32r/mm/mmu.S
  3. *
  4. * Copyright (C) 2001 by Hiroyuki Kondo
  5. */
  6. #include <linux/linkage.h>
  7. #include <asm/assembler.h>
  8. #include <asm/smp.h>
  9. .text
  10. #ifdef CONFIG_MMU
  11. #include <asm/mmu_context.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/m32r.h>
  15. /*
  16. * TLB Miss Exception handler
  17. */
  18. .balign 16
  19. ENTRY(tme_handler)
  20. .global tlb_entry_i_dat
  21. .global tlb_entry_d_dat
  22. SWITCH_TO_KERNEL_STACK
  23. #if defined(CONFIG_ISA_M32R2)
  24. st r0, @-sp
  25. st r1, @-sp
  26. st r2, @-sp
  27. st r3, @-sp
  28. seth r3, #high(MMU_REG_BASE)
  29. ld r1, @(MESTS_offset, r3) ; r1: status (MESTS reg.)
  30. ld r0, @(MDEVP_offset, r3) ; r0: PFN + ASID (MDEVP reg.)
  31. st r1, @(MESTS_offset, r3) ; clear status (MESTS reg.)
  32. and3 r1, r1, #(MESTS_IT)
  33. bnez r1, 1f ; instruction TLB miss?
  34. ;; data TLB miss
  35. ;; input
  36. ;; r0: PFN + ASID (MDEVP reg.)
  37. ;; r1 - r3: free
  38. ;; output
  39. ;; r0: PFN + ASID
  40. ;; r1: TLB entry base address
  41. ;; r2: &tlb_entry_{i|d}_dat
  42. ;; r3: free
  43. #ifndef CONFIG_SMP
  44. seth r2, #high(tlb_entry_d_dat)
  45. or3 r2, r2, #low(tlb_entry_d_dat)
  46. #else /* CONFIG_SMP */
  47. ldi r1, #-8192
  48. seth r2, #high(tlb_entry_d_dat)
  49. or3 r2, r2, #low(tlb_entry_d_dat)
  50. and r1, sp
  51. ld r1, @(16, r1) ; current_thread_info->cpu
  52. slli r1, #2
  53. add r2, r1
  54. #endif /* !CONFIG_SMP */
  55. seth r1, #high(DTLB_BASE)
  56. or3 r1, r1, #low(DTLB_BASE)
  57. bra 2f
  58. .balign 16
  59. .fillinsn
  60. 1:
  61. ;; instrucntion TLB miss
  62. ;; input
  63. ;; r0: MDEVP reg. (included ASID)
  64. ;; r1 - r3: free
  65. ;; output
  66. ;; r0: PFN + ASID
  67. ;; r1: TLB entry base address
  68. ;; r2: &tlb_entry_{i|d}_dat
  69. ;; r3: free
  70. ldi r3, #-4096
  71. and3 r0, r0, #(MMU_CONTEXT_ASID_MASK)
  72. mvfc r1, bpc
  73. and r1, r3
  74. or r0, r1 ; r0: PFN + ASID
  75. #ifndef CONFIG_SMP
  76. seth r2, #high(tlb_entry_i_dat)
  77. or3 r2, r2, #low(tlb_entry_i_dat)
  78. #else /* CONFIG_SMP */
  79. ldi r1, #-8192
  80. seth r2, #high(tlb_entry_i_dat)
  81. or3 r2, r2, #low(tlb_entry_i_dat)
  82. and r1, sp
  83. ld r1, @(16, r1) ; current_thread_info->cpu
  84. slli r1, #2
  85. add r2, r1
  86. #endif /* !CONFIG_SMP */
  87. seth r1, #high(ITLB_BASE)
  88. or3 r1, r1, #low(ITLB_BASE)
  89. .fillinsn
  90. 2:
  91. ;; select TLB entry
  92. ;; input
  93. ;; r0: PFN + ASID
  94. ;; r1: TLB entry base address
  95. ;; r2: &tlb_entry_{i|d}_dat
  96. ;; r3: free
  97. ;; output
  98. ;; r0: PFN + ASID
  99. ;; r1: TLB entry address
  100. ;; r2, r3: free
  101. #ifdef CONFIG_ISA_DUAL_ISSUE
  102. ld r3, @r2 || srli r1, #3
  103. #else
  104. ld r3, @r2
  105. srli r1, #3
  106. #endif
  107. add r1, r3
  108. ; tlb_entry_{d|i}_dat++;
  109. addi r3, #1
  110. and3 r3, r3, #(NR_TLB_ENTRIES - 1)
  111. #ifdef CONFIG_ISA_DUAL_ISSUE
  112. st r3, @r2 || slli r1, #3
  113. #else
  114. st r3, @r2
  115. slli r1, #3
  116. #endif
  117. ;; load pte
  118. ;; input
  119. ;; r0: PFN + ASID
  120. ;; r1: TLB entry address
  121. ;; r2, r3: free
  122. ;; output
  123. ;; r0: PFN + ASID
  124. ;; r1: TLB entry address
  125. ;; r2: pte_data
  126. ;; r3: free
  127. ; pgd = *(unsigned long *)MPTB;
  128. ld24 r2, #(-MPTB - 1)
  129. srl3 r3, r0, #22
  130. #ifdef CONFIG_ISA_DUAL_ISSUE
  131. not r2, r2 || slli r3, #2 ; r3: pgd offset
  132. #else
  133. not r2, r2
  134. slli r3, #2
  135. #endif
  136. ld r2, @r2 ; r2: pgd base addr (MPTB reg.)
  137. or r3, r2 ; r3: pmd addr
  138. ; pmd = pmd_offset(pgd, address);
  139. ld r3, @r3 ; r3: pmd data
  140. beqz r3, 3f ; pmd_none(*pmd) ?
  141. and3 r2, r3, #0xfff
  142. add3 r2, r2, #-355 ; _KERNPG_TABLE(=0x163)
  143. bnez r2, 3f ; pmd_bad(*pmd) ?
  144. ldi r2, #-4096
  145. ; pte = pte_offset(pmd, address);
  146. and r2, r3 ; r2: pte base addr
  147. srl3 r3, r0, #10
  148. and3 r3, r3, #0xffc ; r3: pte offset
  149. or r3, r2
  150. seth r2, #0x8000
  151. or r3, r2 ; r3: pte addr
  152. ; pte_data = (unsigned long)pte_val(*pte);
  153. ld r2, @r3 ; r2: pte data
  154. and3 r3, r2, #2 ; _PAGE_PRESENT(=2) check
  155. beqz r3, 3f
  156. .fillinsn
  157. 5:
  158. ;; set tlb
  159. ;; input
  160. ;; r0: PFN + ASID
  161. ;; r1: TLB entry address
  162. ;; r2: pte_data
  163. ;; r3: free
  164. st r0, @r1 ; set_tlb_tag(entry++, address);
  165. st r2, @+r1 ; set_tlb_data(entry, pte_data);
  166. .fillinsn
  167. 6:
  168. ld r3, @sp+
  169. ld r2, @sp+
  170. ld r1, @sp+
  171. ld r0, @sp+
  172. rte
  173. .fillinsn
  174. 3:
  175. ;; error
  176. ;; input
  177. ;; r0: PFN + ASID
  178. ;; r1: TLB entry address
  179. ;; r2, r3: free
  180. ;; output
  181. ;; r0: PFN + ASID
  182. ;; r1: TLB entry address
  183. ;; r2: pte_data
  184. ;; r3: free
  185. #ifdef CONFIG_ISA_DUAL_ISSUE
  186. bra 5b || ldi r2, #2
  187. #else
  188. ldi r2, #2 ; r2: pte_data = 0 | _PAGE_PRESENT(=2)
  189. bra 5b
  190. #endif
  191. #elif defined (CONFIG_ISA_M32R)
  192. st sp, @-sp
  193. st r0, @-sp
  194. st r1, @-sp
  195. st r2, @-sp
  196. st r3, @-sp
  197. st r4, @-sp
  198. seth r3, #high(MMU_REG_BASE)
  199. ld r0, @(MDEVA_offset,r3) ; r0: address (MDEVA reg.)
  200. mvfc r2, bpc ; r2: bpc
  201. ld r1, @(MESTS_offset,r3) ; r1: status (MESTS reg.)
  202. st r1, @(MESTS_offset,r3) ; clear status (MESTS reg.)
  203. and3 r1, r1, #(MESTS_IT)
  204. beqz r1, 1f ; data TLB miss?
  205. ;; instrucntion TLB miss
  206. mv r0, r2 ; address = bpc;
  207. ; entry = (unsigned long *)ITLB_BASE+tlb_entry_i*2;
  208. seth r3, #shigh(tlb_entry_i_dat)
  209. ld r4, @(low(tlb_entry_i_dat),r3)
  210. sll3 r2, r4, #3
  211. seth r1, #high(ITLB_BASE)
  212. or3 r1, r1, #low(ITLB_BASE)
  213. add r2, r1 ; r2: entry
  214. addi r4, #1 ; tlb_entry_i++;
  215. and3 r4, r4, #(NR_TLB_ENTRIES-1)
  216. st r4, @(low(tlb_entry_i_dat),r3)
  217. bra 2f
  218. .fillinsn
  219. 1:
  220. ;; data TLB miss
  221. ; entry = (unsigned long *)DTLB_BASE+tlb_entry_d*2;
  222. seth r3, #shigh(tlb_entry_d_dat)
  223. ld r4, @(low(tlb_entry_d_dat),r3)
  224. sll3 r2, r4, #3
  225. seth r1, #high(DTLB_BASE)
  226. or3 r1, r1, #low(DTLB_BASE)
  227. add r2, r1 ; r2: entry
  228. addi r4, #1 ; tlb_entry_d++;
  229. and3 r4, r4, #(NR_TLB_ENTRIES-1)
  230. st r4, @(low(tlb_entry_d_dat),r3)
  231. .fillinsn
  232. 2:
  233. ;; load pte
  234. ; r0: address, r2: entry
  235. ; r1,r3,r4: (free)
  236. ; pgd = *(unsigned long *)MPTB;
  237. ld24 r1, #(-MPTB-1)
  238. not r1, r1
  239. ld r1, @r1
  240. srl3 r4, r0, #22
  241. sll3 r3, r4, #2
  242. add r3, r1 ; r3: pgd
  243. ; pmd = pmd_offset(pgd, address);
  244. ld r1, @r3 ; r1: pmd
  245. beqz r1, 3f ; pmd_none(*pmd) ?
  246. ;
  247. and3 r1, r1, #0x3ff
  248. ldi r4, #0x163 ; _KERNPG_TABLE(=0x163)
  249. bne r1, r4, 3f ; pmd_bad(*pmd) ?
  250. .fillinsn
  251. 4:
  252. ; pte = pte_offset(pmd, address);
  253. ld r4, @r3 ; r4: pte
  254. ldi r3, #-4096
  255. and r4, r3
  256. srl3 r3, r0, #10
  257. and3 r3, r3, #0xffc
  258. add r4, r3
  259. seth r3, #0x8000
  260. add r4, r3 ; r4: pte
  261. ; pte_data = (unsigned long)pte_val(*pte);
  262. ld r1, @r4 ; r1: pte_data
  263. and3 r3, r1, #2 ; _PAGE_PRESENT(=2) check
  264. beqz r3, 3f
  265. .fillinsn
  266. ;; set tlb
  267. ; r0: address, r1: pte_data, r2: entry
  268. ; r3,r4: (free)
  269. 5:
  270. ldi r3, #-4096 ; set_tlb_tag(entry++, address);
  271. and r3, r0
  272. seth r4, #shigh(MASID)
  273. ld r4, @(low(MASID),r4) ; r4: MASID
  274. and3 r4, r4, #(MMU_CONTEXT_ASID_MASK)
  275. or r3, r4
  276. st r3, @r2
  277. st r1, @(4,r2) ; set_tlb_data(entry, pte_data);
  278. ld r4, @sp+
  279. ld r3, @sp+
  280. ld r2, @sp+
  281. ld r1, @sp+
  282. ld r0, @sp+
  283. ld sp, @sp+
  284. rte
  285. .fillinsn
  286. 3:
  287. ldi r1, #2 ; r1: pte_data = 0 | _PAGE_PRESENT(=2)
  288. bra 5b
  289. #else
  290. #error unknown isa configuration
  291. #endif
  292. ENTRY(init_tlb)
  293. ;; Set MMU Register
  294. seth r0, #high(MMU_REG_BASE) ; Set MMU_REG_BASE higher
  295. or3 r0, r0, #low(MMU_REG_BASE) ; Set MMU_REG_BASE lower
  296. ldi r1, #0
  297. st r1, @(MPSZ_offset,r0) ; Set MPSZ Reg(Page size 4KB:0 16KB:1 64KB:2)
  298. ldi r1, #0
  299. st r1, @(MASID_offset,r0) ; Set ASID Zero
  300. ;; Set TLB
  301. seth r0, #high(ITLB_BASE) ; Set ITLB_BASE higher
  302. or3 r0, r0, #low(ITLB_BASE) ; Set ITLB_BASE lower
  303. seth r1, #high(DTLB_BASE) ; Set DTLB_BASE higher
  304. or3 r1, r1, #low(DTLB_BASE) ; Set DTLB_BASE lower
  305. ldi r2, #0
  306. ldi r3, #NR_TLB_ENTRIES
  307. addi r0, #-4
  308. addi r1, #-4
  309. clear_tlb:
  310. st r2, @+r0 ; VPA <- 0
  311. st r2, @+r0 ; PPA <- 0
  312. st r2, @+r1 ; VPA <- 0
  313. st r2, @+r1 ; PPA <- 0
  314. addi r3, #-1
  315. bnez r3, clear_tlb
  316. ;;
  317. jmp r14
  318. ENTRY(m32r_itlb_entrys)
  319. ENTRY(m32r_otlb_entrys)
  320. #endif /* CONFIG_MMU */
  321. .end