vtophys.cc revision 8706
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
292665Ssaidi@eecs.umich.edu *          Steve Reinhardt
302665Ssaidi@eecs.umich.edu *          Ali Saidi
312SN/A */
322SN/A
332SN/A#include <string>
342SN/A
352521SN/A#include "arch/alpha/ev5.hh"
361110SN/A#include "arch/alpha/vtophys.hh"
372521SN/A#include "base/chunk_generator.hh"
381110SN/A#include "base/trace.hh"
392680Sktlim@umich.edu#include "cpu/thread_context.hh"
408232Snate@binkert.org#include "debug/VtoPhys.hh"
418706Sandreas.hansson@arm.com#include "mem/port_proxy.hh"
422SN/A
432SN/Ausing namespace std;
442SN/A
455568Snate@binkert.orgnamespace AlphaISA {
465568Snate@binkert.org
475568Snate@binkert.orgPageTableEntry
488706Sandreas.hansson@arm.comkernel_pte_lookup(PortProxy* mem, Addr ptbr, VAddr vaddr)
492SN/A{
501111SN/A    Addr level1_pte = ptbr + vaddr.level1();
515568Snate@binkert.org    PageTableEntry level1 = mem->read<uint64_t>(level1_pte);
521111SN/A    if (!level1.valid()) {
532SN/A        DPRINTF(VtoPhys, "level 1 PTE not valid, va = %#\n", vaddr);
542SN/A        return 0;
552SN/A    }
562SN/A
571111SN/A    Addr level2_pte = level1.paddr() + vaddr.level2();
585568Snate@binkert.org    PageTableEntry level2 = mem->read<uint64_t>(level2_pte);
591111SN/A    if (!level2.valid()) {
602SN/A        DPRINTF(VtoPhys, "level 2 PTE not valid, va = %#x\n", vaddr);
612SN/A        return 0;
622SN/A    }
632SN/A
641111SN/A    Addr level3_pte = level2.paddr() + vaddr.level3();
655568Snate@binkert.org    PageTableEntry level3 = mem->read<uint64_t>(level3_pte);
661111SN/A    if (!level3.valid()) {
671111SN/A        DPRINTF(VtoPhys, "level 3 PTE not valid, va = %#x\n", vaddr);
681111SN/A        return 0;
691111SN/A    }
701111SN/A    return level3;
712SN/A}
722SN/A
732SN/AAddr
745568Snate@binkert.orgvtophys(Addr vaddr)
752SN/A{
762SN/A    Addr paddr = 0;
775568Snate@binkert.org    if (IsUSeg(vaddr))
782SN/A        DPRINTF(VtoPhys, "vtophys: invalid vaddr %#x", vaddr);
795568Snate@binkert.org    else if (IsK0Seg(vaddr))
805568Snate@binkert.org        paddr = K0Seg2Phys(vaddr);
812SN/A    else
822SN/A        panic("vtophys: ptbr is not set on virtual lookup");
832SN/A
842SN/A    DPRINTF(VtoPhys, "vtophys(%#x) -> %#x\n", vaddr, paddr);
852SN/A
862SN/A    return paddr;
872SN/A}
882SN/A
892SN/AAddr
905568Snate@binkert.orgvtophys(ThreadContext *tc, Addr addr)
912SN/A{
925568Snate@binkert.org    VAddr vaddr = addr;
935568Snate@binkert.org    Addr ptbr = tc->readMiscRegNoEffect(IPR_PALtemp20);
942SN/A    Addr paddr = 0;
95924SN/A    //@todo Andrew couldn't remember why he commented some of this code
96924SN/A    //so I put it back in. Perhaps something to do with gdb debugging?
975568Snate@binkert.org    if (PcPAL(vaddr) && (vaddr < PalMax)) {
98924SN/A        paddr = vaddr & ~ULL(1);
99924SN/A    } else {
1005568Snate@binkert.org        if (IsK0Seg(vaddr)) {
1015568Snate@binkert.org            paddr = K0Seg2Phys(vaddr);
102973SN/A        } else if (!ptbr) {
103973SN/A            paddr = vaddr;
104547SN/A        } else {
1055568Snate@binkert.org            PageTableEntry pte =
1068706Sandreas.hansson@arm.com                kernel_pte_lookup(tc->getPhysProxy(), ptbr, vaddr);
1071111SN/A            if (pte.valid())
1081111SN/A                paddr = pte.paddr() | vaddr.offset();
109547SN/A        }
110924SN/A    }
111924SN/A
1122SN/A
1132SN/A    DPRINTF(VtoPhys, "vtophys(%#x) -> %#x\n", vaddr, paddr);
1142SN/A
1152SN/A    return paddr;
1162SN/A}
1172SN/A
1185568Snate@binkert.org} // namespace AlphaISA
119