sh_mmu.cpp revision 1.1 1 /* $NetBSD: sh_mmu.cpp,v 1.1 2001/02/09 18:35:19 uch Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sh3/sh_arch.h>
40 #include <sh3/sh_mmu.h>
41
42 BOOL
43 MemoryManager_SHMMU::init(void)
44 {
45 _kmode = SetKMode(1);
46
47 _asid = VOLATILE_REF(MMUPTEH) & MMUPTEH_ASID_MASK;
48 DPRINTF((TEXT("ASID = %d\n"), _asid));
49
50 return TRUE;
51 }
52
53 MemoryManager_SHMMU::~MemoryManager_SHMMU(void)
54 {
55 SetKMode(_kmode);
56 }
57
58 // get physical address from memory mapped TLB.
59 paddr_t
60 MemoryManager_SHMMU::searchPage(vaddr_t vaddr)
61 {
62 u_int32_t vpn, idx, s, dum, aae, dae, entry_idx;
63 paddr_t paddr = ~0;
64 int way;
65
66 vpn = vaddr & PAGE_MASK;
67 // Windows CE uses VPN-only index-mode.
68 idx = vaddr & MMUAA_VPN_MASK;
69
70 // to avoid another TLB access, disable external interrupt.
71 s = suspendIntr();
72
73 do {
74 // load target address page to TLB
75 dum = VOLATILE_REF(vaddr);
76 VOLATILE_REF(vaddr) = dum;
77
78 for (way = 0; way < MMU_WAY; way++) {
79 entry_idx = idx | (way << MMUAA_WAY_SHIFT);
80 // inquire MMU address array.
81 aae = VOLATILE_REF(MMUAA | entry_idx);
82
83 if (!(aae & MMUAA_D_VALID) ||
84 ((aae & MMUAA_D_ASID_MASK) != _asid) ||
85 (((aae | idx) & PAGE_MASK) != vpn))
86 continue;
87
88 // entry found.
89 // inquire MMU data array to get its physical address.
90 dae = VOLATILE_REF(MMUDA | entry_idx);
91 paddr = (dae & PAGE_MASK) | (vaddr & ~PAGE_MASK);
92 break;
93 }
94 } while (paddr == ~0);
95
96 resumeIntr(s);
97
98 return paddr;
99 }
100
101