page_table.hh revision 8601
12379SN/A/*
22379SN/A * Copyright (c) 2003 The Regents of The University of Michigan
32379SN/A * All rights reserved.
42379SN/A *
52379SN/A * Redistribution and use in source and binary forms, with or without
62379SN/A * modification, are permitted provided that the following conditions are
72379SN/A * met: redistributions of source code must retain the above copyright
82379SN/A * notice, this list of conditions and the following disclaimer;
92379SN/A * redistributions in binary form must reproduce the above copyright
102379SN/A * notice, this list of conditions and the following disclaimer in the
112379SN/A * documentation and/or other materials provided with the distribution;
122379SN/A * neither the name of the copyright holders nor the names of its
132379SN/A * contributors may be used to endorse or promote products derived from
142379SN/A * this software without specific prior written permission.
152379SN/A *
162379SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172379SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182379SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192379SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202379SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212379SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222379SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232379SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242379SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252379SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262379SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292379SN/A */
302379SN/A
312379SN/A/**
322379SN/A * @file
332379SN/A * Declaration of a non-full system Page Table.
342379SN/A */
352379SN/A
366216Snate@binkert.org#ifndef __MEM_PAGE_TABLE_HH__
376216Snate@binkert.org#define __MEM_PAGE_TABLE_HH__
382379SN/A
392379SN/A#include <string>
402379SN/A
412423SN/A#include "arch/isa_traits.hh"
425004Sgblack@eecs.umich.edu#include "arch/tlb.hh"
432809Ssaidi@eecs.umich.edu#include "base/hashmap.hh"
446216Snate@binkert.org#include "base/types.hh"
456658Snate@binkert.org#include "config/the_isa.hh"
462394SN/A#include "mem/request.hh"
475004Sgblack@eecs.umich.edu#include "sim/serialize.hh"
482379SN/A
492379SN/A/**
502982Sstever@eecs.umich.edu * Page Table Declaration.
512379SN/A */
522399SN/Aclass PageTable
532379SN/A{
542379SN/A  protected:
555004Sgblack@eecs.umich.edu    typedef m5::hash_map<Addr, TheISA::TlbEntry> PTable;
565004Sgblack@eecs.umich.edu    typedef PTable::iterator PTableItr;
575004Sgblack@eecs.umich.edu    PTable pTable;
582809Ssaidi@eecs.umich.edu
592809Ssaidi@eecs.umich.edu    struct cacheElement {
602809Ssaidi@eecs.umich.edu        Addr vaddr;
615004Sgblack@eecs.umich.edu        TheISA::TlbEntry entry;
625004Sgblack@eecs.umich.edu    };
632809Ssaidi@eecs.umich.edu
642809Ssaidi@eecs.umich.edu    struct cacheElement pTableCache[3];
652379SN/A
662399SN/A    const Addr pageSize;
672399SN/A    const Addr offsetMask;
682399SN/A
698601Ssteve.reinhardt@amd.com    const uint64_t pid;
708601Ssteve.reinhardt@amd.com    const std::string _name;
712379SN/A
722379SN/A  public:
732379SN/A
748601Ssteve.reinhardt@amd.com    PageTable(const std::string &__name, uint64_t _pid,
758601Ssteve.reinhardt@amd.com              Addr _pageSize = TheISA::VMPageSize);
762379SN/A
772379SN/A    ~PageTable();
782379SN/A
798601Ssteve.reinhardt@amd.com    // for DPRINTF compatibility
808601Ssteve.reinhardt@amd.com    const std::string name() const { return _name; }
818601Ssteve.reinhardt@amd.com
822399SN/A    Addr pageAlign(Addr a)  { return (a & ~offsetMask); }
832399SN/A    Addr pageOffset(Addr a) { return (a &  offsetMask); }
842379SN/A
858601Ssteve.reinhardt@amd.com    void map(Addr vaddr, Addr paddr, int64_t size, bool clobber = false);
865877Shsul@eecs.umich.edu    void remap(Addr vaddr, int64_t size, Addr new_vaddr);
878601Ssteve.reinhardt@amd.com    void unmap(Addr vaddr, int64_t size);
882379SN/A
895004Sgblack@eecs.umich.edu    /**
908600Ssteve.reinhardt@amd.com     * Check if any pages in a region are already allocated
918600Ssteve.reinhardt@amd.com     * @param vaddr The starting virtual address of the region.
928600Ssteve.reinhardt@amd.com     * @param size The length of the region.
938600Ssteve.reinhardt@amd.com     * @return True if no pages in the region are mapped.
948600Ssteve.reinhardt@amd.com     */
958600Ssteve.reinhardt@amd.com    bool isUnmapped(Addr vaddr, int64_t size);
968600Ssteve.reinhardt@amd.com
978600Ssteve.reinhardt@amd.com    /**
985004Sgblack@eecs.umich.edu     * Lookup function
995004Sgblack@eecs.umich.edu     * @param vaddr The virtual address.
1005004Sgblack@eecs.umich.edu     * @return entry The page table entry corresponding to vaddr.
1015004Sgblack@eecs.umich.edu     */
1025004Sgblack@eecs.umich.edu    bool lookup(Addr vaddr, TheISA::TlbEntry &entry);
1032399SN/A
1042379SN/A    /**
1052379SN/A     * Translate function
1062379SN/A     * @param vaddr The virtual address.
1075748SSteve.Reinhardt@amd.com     * @param paddr Physical address from translation.
1085748SSteve.Reinhardt@amd.com     * @return True if translation exists
1092379SN/A     */
1102399SN/A    bool translate(Addr vaddr, Addr &paddr);
1112379SN/A
1122379SN/A    /**
1135748SSteve.Reinhardt@amd.com     * Simplified translate function (just check for translation)
1145748SSteve.Reinhardt@amd.com     * @param vaddr The virtual address.
1155748SSteve.Reinhardt@amd.com     * @return True if translation exists
1165748SSteve.Reinhardt@amd.com     */
1175748SSteve.Reinhardt@amd.com    bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
1185748SSteve.Reinhardt@amd.com
1195748SSteve.Reinhardt@amd.com    /**
1202399SN/A     * Perform a translation on the memory request, fills in paddr
1215004Sgblack@eecs.umich.edu     * field of req.
1222379SN/A     * @param req The memory request.
1232379SN/A     */
1245004Sgblack@eecs.umich.edu    Fault translate(RequestPtr req);
1252379SN/A
1264521Ssaidi@eecs.umich.edu    /**
1274521Ssaidi@eecs.umich.edu     * Update the page table cache.
1284521Ssaidi@eecs.umich.edu     * @param vaddr virtual address (page aligned) to check
1295004Sgblack@eecs.umich.edu     * @param pte page table entry to return
1304521Ssaidi@eecs.umich.edu     */
1315004Sgblack@eecs.umich.edu    inline void updateCache(Addr vaddr, TheISA::TlbEntry entry)
1324521Ssaidi@eecs.umich.edu    {
1335004Sgblack@eecs.umich.edu        pTableCache[2].entry = pTableCache[1].entry;
1344521Ssaidi@eecs.umich.edu        pTableCache[2].vaddr = pTableCache[1].vaddr;
1355004Sgblack@eecs.umich.edu        pTableCache[1].entry = pTableCache[0].entry;
1364521Ssaidi@eecs.umich.edu        pTableCache[1].vaddr = pTableCache[0].vaddr;
1375004Sgblack@eecs.umich.edu        pTableCache[0].entry = entry;
1384521Ssaidi@eecs.umich.edu        pTableCache[0].vaddr = vaddr;
1394521Ssaidi@eecs.umich.edu    }
1404521Ssaidi@eecs.umich.edu
1414521Ssaidi@eecs.umich.edu
1423311Ssaidi@eecs.umich.edu    void serialize(std::ostream &os);
1435004Sgblack@eecs.umich.edu
1443311Ssaidi@eecs.umich.edu    void unserialize(Checkpoint *cp, const std::string &section);
1452379SN/A};
1462379SN/A
1476216Snate@binkert.org#endif // __MEM_PAGE_TABLE_HH__
148