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
382984Sgblack@eecs.umich.edunamespace AlphaISA {
392984Sgblack@eecs.umich.edu
405569Snate@binkert.orgstruct VAddr
415569Snate@binkert.org{
425569Snate@binkert.org    static const int ImplBits = 43;
435569Snate@binkert.org    static const Addr ImplMask = (ULL(1) << ImplBits) - 1;
445569Snate@binkert.org    static const Addr UnImplMask = ~ImplMask;
455569Snate@binkert.org
465569Snate@binkert.org    Addr addr;
475569Snate@binkert.org
485569Snate@binkert.org    VAddr(Addr a) : addr(a) {}
495569Snate@binkert.org    operator Addr() const { return addr; }
505569Snate@binkert.org    const VAddr &operator=(Addr a) { addr = a; return *this; }
515569Snate@binkert.org
525569Snate@binkert.org    Addr vpn() const { return (addr & ImplMask) >> PageShift; }
535569Snate@binkert.org    Addr page() const { return addr & PageMask; }
545569Snate@binkert.org    Addr offset() const { return addr & PageOffset; }
555569Snate@binkert.org
565569Snate@binkert.org    Addr level3() const
575569Snate@binkert.org    { return PteAddr(addr >> PageShift); }
585569Snate@binkert.org    Addr level2() const
595570Snate@binkert.org    { return PteAddr(addr >> (NPtePageShift + PageShift)); }
605569Snate@binkert.org    Addr level1() const
615570Snate@binkert.org    { return PteAddr(addr >> (2 * NPtePageShift + PageShift)); }
625569Snate@binkert.org};
635569Snate@binkert.org
645569Snate@binkert.orgstruct PageTableEntry
655569Snate@binkert.org{
665569Snate@binkert.org    PageTableEntry(uint64_t e) : entry(e) {}
675569Snate@binkert.org    uint64_t entry;
685569Snate@binkert.org    operator uint64_t() const { return entry; }
695569Snate@binkert.org    const PageTableEntry &operator=(uint64_t e) { entry = e; return *this; }
705569Snate@binkert.org    const PageTableEntry &operator=(const PageTableEntry &e)
715569Snate@binkert.org    { entry = e.entry; return *this; }
725569Snate@binkert.org
735569Snate@binkert.org    Addr _pfn()  const { return (entry >> 32) & 0xffffffff; }
745569Snate@binkert.org    Addr _sw()   const { return (entry >> 16) & 0xffff; }
755569Snate@binkert.org    int  _rsv0() const { return (entry >> 14) & 0x3; }
765569Snate@binkert.org    bool _uwe()  const { return (entry >> 13) & 0x1; }
775569Snate@binkert.org    bool _kwe()  const { return (entry >> 12) & 0x1; }
785569Snate@binkert.org    int  _rsv1() const { return (entry >> 10) & 0x3; }
795569Snate@binkert.org    bool _ure()  const { return (entry >>  9) & 0x1; }
805569Snate@binkert.org    bool _kre()  const { return (entry >>  8) & 0x1; }
815569Snate@binkert.org    bool _nomb() const { return (entry >>  7) & 0x1; }
825569Snate@binkert.org    int  _gh()   const { return (entry >>  5) & 0x3; }
835569Snate@binkert.org    bool _asm_()  const { return (entry >>  4) & 0x1; }
845569Snate@binkert.org    bool _foe()  const { return (entry >>  3) & 0x1; }
855569Snate@binkert.org    bool _fow()  const { return (entry >>  2) & 0x1; }
865569Snate@binkert.org    bool _for()  const { return (entry >>  1) & 0x1; }
875569Snate@binkert.org    bool valid() const { return (entry >>  0) & 0x1; }
885569Snate@binkert.org
895569Snate@binkert.org    Addr paddr() const { return _pfn() << PageShift; }
905569Snate@binkert.org};
915569Snate@binkert.org
925569Snate@binkert.org// ITB/DTB table entry
9310905Sandreas.sandberg@arm.comstruct TlbEntry : public Serializable
945569Snate@binkert.org{
955569Snate@binkert.org    Addr tag;               // virtual page number tag
965569Snate@binkert.org    Addr ppn;               // physical page number
975569Snate@binkert.org    uint8_t xre;            // read permissions - VMEM_PERM_* mask
985569Snate@binkert.org    uint8_t xwe;            // write permissions - VMEM_PERM_* mask
995569Snate@binkert.org    uint8_t asn;            // address space number
1005569Snate@binkert.org    bool asma;              // address space match
1015569Snate@binkert.org    bool fonr;              // fault on read
1025569Snate@binkert.org    bool fonw;              // fault on write
1035569Snate@binkert.org    bool valid;             // valid page table entry
1045569Snate@binkert.org
1055569Snate@binkert.org
1065569Snate@binkert.org    //Construct an entry that maps to physical address addr.
10710558Salexandru.dutu@amd.com    TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr,
10810558Salexandru.dutu@amd.com             bool uncacheable, bool read_only)
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;
12110558Salexandru.dutu@amd.com        if (uncacheable || read_only)
12210558Salexandru.dutu@amd.com            warn("Alpha TlbEntry does not support uncacheable"
12310558Salexandru.dutu@amd.com                 " or read-only mappings\n");
1245569Snate@binkert.org    }
1252984Sgblack@eecs.umich.edu
1265569Snate@binkert.org    TlbEntry()
12710905Sandreas.sandberg@arm.com        : tag(0), ppn(0), xre(0), xwe(0), asn(0),
12810905Sandreas.sandberg@arm.com          asma(false), fonr(0), fonw(0), valid(0)
12910905Sandreas.sandberg@arm.com    {
13010905Sandreas.sandberg@arm.com    }
1312984Sgblack@eecs.umich.edu
1325877Shsul@eecs.umich.edu    void
1335877Shsul@eecs.umich.edu    updateVaddr(Addr new_vaddr)
1345877Shsul@eecs.umich.edu    {
1355877Shsul@eecs.umich.edu        VAddr vaddr(new_vaddr);
1365877Shsul@eecs.umich.edu        tag = vaddr.vpn();
1375877Shsul@eecs.umich.edu    }
1385877Shsul@eecs.umich.edu
1395569Snate@binkert.org    Addr
1405569Snate@binkert.org    pageStart()
1415569Snate@binkert.org    {
1425569Snate@binkert.org        return ppn << PageShift;
1435569Snate@binkert.org    }
1442984Sgblack@eecs.umich.edu
14511168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
14611168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
1475569Snate@binkert.org};
1482984Sgblack@eecs.umich.edu
1495569Snate@binkert.org} // namespace AlphaISA
1502984Sgblack@eecs.umich.edu
1512984Sgblack@eecs.umich.edu#endif // __ARCH_ALPHA_PAGETABLE_H__
1522984Sgblack@eecs.umich.edu
153