pagetable.hh revision 5569
12984Sgblack@eecs.umich.edu/*
22984Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
32984Sgblack@eecs.umich.edu * All rights reserved.
42984Sgblack@eecs.umich.edu *
52984Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
62984Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
72984Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
82984Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
92984Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
102984Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
112984Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
122984Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
132984Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
142984Sgblack@eecs.umich.edu * this software without specific prior written permission.
152984Sgblack@eecs.umich.edu *
162984Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172984Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182984Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192984Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202984Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212984Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222984Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232984Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242984Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252984Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262984Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272984Sgblack@eecs.umich.edu *
282984Sgblack@eecs.umich.edu * Authors: Nathan Binkert
292984Sgblack@eecs.umich.edu *          Steve Reinhardt
302984Sgblack@eecs.umich.edu */
312984Sgblack@eecs.umich.edu
322984Sgblack@eecs.umich.edu#ifndef __ARCH_ALPHA_PAGETABLE_H__
332984Sgblack@eecs.umich.edu#define __ARCH_ALPHA_PAGETABLE_H__
342984Sgblack@eecs.umich.edu
352984Sgblack@eecs.umich.edu#include "arch/alpha/isa_traits.hh"
362984Sgblack@eecs.umich.edu#include "arch/alpha/utility.hh"
372984Sgblack@eecs.umich.edu#include "config/full_system.hh"
382984Sgblack@eecs.umich.edu
392984Sgblack@eecs.umich.edunamespace AlphaISA {
402984Sgblack@eecs.umich.edu
415569Snate@binkert.orgstruct VAddr
425569Snate@binkert.org{
435569Snate@binkert.org    static const int ImplBits = 43;
445569Snate@binkert.org    static const Addr ImplMask = (ULL(1) << ImplBits) - 1;
455569Snate@binkert.org    static const Addr UnImplMask = ~ImplMask;
465569Snate@binkert.org
475569Snate@binkert.org    Addr addr;
485569Snate@binkert.org
495569Snate@binkert.org    VAddr(Addr a) : addr(a) {}
505569Snate@binkert.org    operator Addr() const { return addr; }
515569Snate@binkert.org    const VAddr &operator=(Addr a) { addr = a; return *this; }
525569Snate@binkert.org
535569Snate@binkert.org    Addr vpn() const { return (addr & ImplMask) >> PageShift; }
545569Snate@binkert.org    Addr page() const { return addr & PageMask; }
555569Snate@binkert.org    Addr offset() const { return addr & PageOffset; }
565569Snate@binkert.org
575569Snate@binkert.org    Addr level3() const
585569Snate@binkert.org    { return PteAddr(addr >> PageShift); }
595569Snate@binkert.org    Addr level2() const
605569Snate@binkert.org    { return PteAddr(addr >> NPtePageShift + PageShift); }
615569Snate@binkert.org    Addr level1() const
625569Snate@binkert.org    { return PteAddr(addr >> 2 * NPtePageShift + PageShift); }
635569Snate@binkert.org};
645569Snate@binkert.org
655569Snate@binkert.orgstruct PageTableEntry
665569Snate@binkert.org{
675569Snate@binkert.org    PageTableEntry(uint64_t e) : entry(e) {}
685569Snate@binkert.org    uint64_t entry;
695569Snate@binkert.org    operator uint64_t() const { return entry; }
705569Snate@binkert.org    const PageTableEntry &operator=(uint64_t e) { entry = e; return *this; }
715569Snate@binkert.org    const PageTableEntry &operator=(const PageTableEntry &e)
725569Snate@binkert.org    { entry = e.entry; return *this; }
735569Snate@binkert.org
745569Snate@binkert.org    Addr _pfn()  const { return (entry >> 32) & 0xffffffff; }
755569Snate@binkert.org    Addr _sw()   const { return (entry >> 16) & 0xffff; }
765569Snate@binkert.org    int  _rsv0() const { return (entry >> 14) & 0x3; }
775569Snate@binkert.org    bool _uwe()  const { return (entry >> 13) & 0x1; }
785569Snate@binkert.org    bool _kwe()  const { return (entry >> 12) & 0x1; }
795569Snate@binkert.org    int  _rsv1() const { return (entry >> 10) & 0x3; }
805569Snate@binkert.org    bool _ure()  const { return (entry >>  9) & 0x1; }
815569Snate@binkert.org    bool _kre()  const { return (entry >>  8) & 0x1; }
825569Snate@binkert.org    bool _nomb() const { return (entry >>  7) & 0x1; }
835569Snate@binkert.org    int  _gh()   const { return (entry >>  5) & 0x3; }
845569Snate@binkert.org    bool _asm_()  const { return (entry >>  4) & 0x1; }
855569Snate@binkert.org    bool _foe()  const { return (entry >>  3) & 0x1; }
865569Snate@binkert.org    bool _fow()  const { return (entry >>  2) & 0x1; }
875569Snate@binkert.org    bool _for()  const { return (entry >>  1) & 0x1; }
885569Snate@binkert.org    bool valid() const { return (entry >>  0) & 0x1; }
895569Snate@binkert.org
905569Snate@binkert.org    Addr paddr() const { return _pfn() << PageShift; }
915569Snate@binkert.org};
925569Snate@binkert.org
935569Snate@binkert.org// ITB/DTB table entry
945569Snate@binkert.orgstruct TlbEntry
955569Snate@binkert.org{
965569Snate@binkert.org    Addr tag;               // virtual page number tag
975569Snate@binkert.org    Addr ppn;               // physical page number
985569Snate@binkert.org    uint8_t xre;            // read permissions - VMEM_PERM_* mask
995569Snate@binkert.org    uint8_t xwe;            // write permissions - VMEM_PERM_* mask
1005569Snate@binkert.org    uint8_t asn;            // address space number
1015569Snate@binkert.org    bool asma;              // address space match
1025569Snate@binkert.org    bool fonr;              // fault on read
1035569Snate@binkert.org    bool fonw;              // fault on write
1045569Snate@binkert.org    bool valid;             // valid page table entry
1055569Snate@binkert.org
1065569Snate@binkert.org
1075569Snate@binkert.org    //Construct an entry that maps to physical address addr.
1085569Snate@binkert.org    TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr)
1092984Sgblack@eecs.umich.edu    {
1105569Snate@binkert.org        VAddr vaddr(_vaddr);
1115569Snate@binkert.org        VAddr paddr(_paddr);
1125569Snate@binkert.org        tag = vaddr.vpn();
1135569Snate@binkert.org        ppn = paddr.vpn();
1145569Snate@binkert.org        xre = 15;
1155569Snate@binkert.org        xwe = 15;
1165569Snate@binkert.org        asn = _asn;
1175569Snate@binkert.org        asma = false;
1185569Snate@binkert.org        fonr = false;
1195569Snate@binkert.org        fonw = false;
1205569Snate@binkert.org        valid = true;
1215569Snate@binkert.org    }
1222984Sgblack@eecs.umich.edu
1235569Snate@binkert.org    TlbEntry()
1245569Snate@binkert.org    {}
1252984Sgblack@eecs.umich.edu
1265569Snate@binkert.org    Addr
1275569Snate@binkert.org    pageStart()
1285569Snate@binkert.org    {
1295569Snate@binkert.org        return ppn << PageShift;
1305569Snate@binkert.org    }
1312984Sgblack@eecs.umich.edu
1325569Snate@binkert.org    void serialize(std::ostream &os);
1335569Snate@binkert.org    void unserialize(Checkpoint *cp, const std::string &section);
1345569Snate@binkert.org};
1352984Sgblack@eecs.umich.edu
1365569Snate@binkert.org} // namespace AlphaISA
1372984Sgblack@eecs.umich.edu
1382984Sgblack@eecs.umich.edu#endif // __ARCH_ALPHA_PAGETABLE_H__
1392984Sgblack@eecs.umich.edu
140