page_table.hh revision 8600
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
495184Sgblack@eecs.umich.educlass Process;
502379SN/A
512379SN/A/**
522982Sstever@eecs.umich.edu * Page Table Declaration.
532379SN/A */
542399SN/Aclass PageTable
552379SN/A{
562379SN/A  protected:
575004Sgblack@eecs.umich.edu    typedef m5::hash_map<Addr, TheISA::TlbEntry> PTable;
585004Sgblack@eecs.umich.edu    typedef PTable::iterator PTableItr;
595004Sgblack@eecs.umich.edu    PTable pTable;
602809Ssaidi@eecs.umich.edu
612809Ssaidi@eecs.umich.edu    struct cacheElement {
622809Ssaidi@eecs.umich.edu        Addr vaddr;
635004Sgblack@eecs.umich.edu        TheISA::TlbEntry entry;
645004Sgblack@eecs.umich.edu    };
652809Ssaidi@eecs.umich.edu
662809Ssaidi@eecs.umich.edu    struct cacheElement pTableCache[3];
672379SN/A
682399SN/A    const Addr pageSize;
692399SN/A    const Addr offsetMask;
702399SN/A
715184Sgblack@eecs.umich.edu    Process *process;
722379SN/A
732379SN/A  public:
742379SN/A
755184Sgblack@eecs.umich.edu    PageTable(Process *_process, Addr _pageSize = TheISA::VMPageSize);
762379SN/A
772379SN/A    ~PageTable();
782379SN/A
792399SN/A    Addr pageAlign(Addr a)  { return (a & ~offsetMask); }
802399SN/A    Addr pageOffset(Addr a) { return (a &  offsetMask); }
812379SN/A
828600Ssteve.reinhardt@amd.com    void allocate(Addr vaddr, int64_t size, bool clobber = false);
835877Shsul@eecs.umich.edu    void remap(Addr vaddr, int64_t size, Addr new_vaddr);
845877Shsul@eecs.umich.edu    void deallocate(Addr vaddr, int64_t size);
852379SN/A
865004Sgblack@eecs.umich.edu    /**
878600Ssteve.reinhardt@amd.com     * Check if any pages in a region are already allocated
888600Ssteve.reinhardt@amd.com     * @param vaddr The starting virtual address of the region.
898600Ssteve.reinhardt@amd.com     * @param size The length of the region.
908600Ssteve.reinhardt@amd.com     * @return True if no pages in the region are mapped.
918600Ssteve.reinhardt@amd.com     */
928600Ssteve.reinhardt@amd.com    bool isUnmapped(Addr vaddr, int64_t size);
938600Ssteve.reinhardt@amd.com
948600Ssteve.reinhardt@amd.com    /**
955004Sgblack@eecs.umich.edu     * Lookup function
965004Sgblack@eecs.umich.edu     * @param vaddr The virtual address.
975004Sgblack@eecs.umich.edu     * @return entry The page table entry corresponding to vaddr.
985004Sgblack@eecs.umich.edu     */
995004Sgblack@eecs.umich.edu    bool lookup(Addr vaddr, TheISA::TlbEntry &entry);
1002399SN/A
1012379SN/A    /**
1022379SN/A     * Translate function
1032379SN/A     * @param vaddr The virtual address.
1045748SSteve.Reinhardt@amd.com     * @param paddr Physical address from translation.
1055748SSteve.Reinhardt@amd.com     * @return True if translation exists
1062379SN/A     */
1072399SN/A    bool translate(Addr vaddr, Addr &paddr);
1082379SN/A
1092379SN/A    /**
1105748SSteve.Reinhardt@amd.com     * Simplified translate function (just check for translation)
1115748SSteve.Reinhardt@amd.com     * @param vaddr The virtual address.
1125748SSteve.Reinhardt@amd.com     * @return True if translation exists
1135748SSteve.Reinhardt@amd.com     */
1145748SSteve.Reinhardt@amd.com    bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
1155748SSteve.Reinhardt@amd.com
1165748SSteve.Reinhardt@amd.com    /**
1172399SN/A     * Perform a translation on the memory request, fills in paddr
1185004Sgblack@eecs.umich.edu     * field of req.
1192379SN/A     * @param req The memory request.
1202379SN/A     */
1215004Sgblack@eecs.umich.edu    Fault translate(RequestPtr req);
1222379SN/A
1234521Ssaidi@eecs.umich.edu    /**
1244521Ssaidi@eecs.umich.edu     * Update the page table cache.
1254521Ssaidi@eecs.umich.edu     * @param vaddr virtual address (page aligned) to check
1265004Sgblack@eecs.umich.edu     * @param pte page table entry to return
1274521Ssaidi@eecs.umich.edu     */
1285004Sgblack@eecs.umich.edu    inline void updateCache(Addr vaddr, TheISA::TlbEntry entry)
1294521Ssaidi@eecs.umich.edu    {
1305004Sgblack@eecs.umich.edu        pTableCache[2].entry = pTableCache[1].entry;
1314521Ssaidi@eecs.umich.edu        pTableCache[2].vaddr = pTableCache[1].vaddr;
1325004Sgblack@eecs.umich.edu        pTableCache[1].entry = pTableCache[0].entry;
1334521Ssaidi@eecs.umich.edu        pTableCache[1].vaddr = pTableCache[0].vaddr;
1345004Sgblack@eecs.umich.edu        pTableCache[0].entry = entry;
1354521Ssaidi@eecs.umich.edu        pTableCache[0].vaddr = vaddr;
1364521Ssaidi@eecs.umich.edu    }
1374521Ssaidi@eecs.umich.edu
1384521Ssaidi@eecs.umich.edu
1393311Ssaidi@eecs.umich.edu    void serialize(std::ostream &os);
1405004Sgblack@eecs.umich.edu
1413311Ssaidi@eecs.umich.edu    void unserialize(Checkpoint *cp, const std::string &section);
1422379SN/A};
1432379SN/A
1446216Snate@binkert.org#endif // __MEM_PAGE_TABLE_HH__
145