2006-01-29 23:28:04 +01:00
|
|
|
/*
|
2014-04-01 19:18:12 +02:00
|
|
|
* Copyright (c) 2014 Advanced Micro Devices, Inc.
|
2006-01-29 23:28:04 +01:00
|
|
|
* Copyright (c) 2003 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Steve Reinhardt
|
2006-01-29 23:28:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2014-04-01 19:18:12 +02:00
|
|
|
* Declarations of a non-full system Page Table.
|
2006-01-29 23:28:04 +01:00
|
|
|
*/
|
|
|
|
|
2009-05-17 23:34:52 +02:00
|
|
|
#ifndef __MEM_PAGE_TABLE_HH__
|
|
|
|
#define __MEM_PAGE_TABLE_HH__
|
2006-01-29 23:28:04 +01:00
|
|
|
|
|
|
|
#include <string>
|
2015-10-12 10:07:59 +02:00
|
|
|
#include <unordered_map>
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2006-03-10 01:21:35 +01:00
|
|
|
#include "arch/isa_traits.hh"
|
2007-08-27 05:33:57 +02:00
|
|
|
#include "arch/tlb.hh"
|
2009-05-17 23:34:50 +02:00
|
|
|
#include "base/types.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2009-05-17 23:34:52 +02:00
|
|
|
#include "mem/request.hh"
|
2007-08-27 05:33:57 +02:00
|
|
|
#include "sim/serialize.hh"
|
2014-04-01 19:18:12 +02:00
|
|
|
#include "sim/system.hh"
|
|
|
|
|
|
|
|
class ThreadContext;
|
2006-01-29 23:28:04 +01:00
|
|
|
|
|
|
|
/**
|
2014-04-01 19:18:12 +02:00
|
|
|
* Declaration of base class for page table
|
2006-01-29 23:28:04 +01:00
|
|
|
*/
|
2015-07-07 10:51:03 +02:00
|
|
|
class PageTableBase : public Serializable
|
2006-01-29 23:28:04 +01:00
|
|
|
{
|
|
|
|
protected:
|
2006-06-27 21:04:11 +02:00
|
|
|
struct cacheElement {
|
2013-04-23 15:47:52 +02:00
|
|
|
bool valid;
|
2006-06-27 21:04:11 +02:00
|
|
|
Addr vaddr;
|
2007-08-27 05:33:57 +02:00
|
|
|
TheISA::TlbEntry entry;
|
|
|
|
};
|
2006-06-27 21:04:11 +02:00
|
|
|
|
|
|
|
struct cacheElement pTableCache[3];
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2006-02-21 02:53:38 +01:00
|
|
|
const Addr pageSize;
|
|
|
|
const Addr offsetMask;
|
|
|
|
|
2011-10-23 07:30:08 +02:00
|
|
|
const uint64_t pid;
|
|
|
|
const std::string _name;
|
2006-01-29 23:28:04 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-04-01 19:18:12 +02:00
|
|
|
PageTableBase(const std::string &__name, uint64_t _pid,
|
2014-09-03 13:42:21 +02:00
|
|
|
Addr _pageSize = TheISA::PageBytes)
|
2014-04-01 19:18:12 +02:00
|
|
|
: pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))),
|
|
|
|
pid(_pid), _name(__name)
|
|
|
|
{
|
|
|
|
assert(isPowerOf2(pageSize));
|
|
|
|
pTableCache[0].valid = false;
|
|
|
|
pTableCache[1].valid = false;
|
|
|
|
pTableCache[2].valid = false;
|
|
|
|
}
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2014-04-01 19:18:12 +02:00
|
|
|
virtual ~PageTableBase() {};
|
|
|
|
|
2014-11-24 03:01:09 +01:00
|
|
|
/* generic page table mapping flags
|
|
|
|
* unset | set
|
|
|
|
* bit 0 - no-clobber | clobber
|
|
|
|
* bit 1 - present | not-present
|
|
|
|
* bit 2 - cacheable | uncacheable
|
|
|
|
* bit 3 - read-write | read-only
|
|
|
|
*/
|
|
|
|
enum MappingFlags : uint32_t {
|
2016-01-11 11:52:20 +01:00
|
|
|
Zero = 0,
|
2014-11-24 03:01:09 +01:00
|
|
|
Clobber = 1,
|
|
|
|
NotPresent = 2,
|
|
|
|
Uncacheable = 4,
|
|
|
|
ReadOnly = 8,
|
|
|
|
};
|
|
|
|
|
2014-04-01 19:18:12 +02:00
|
|
|
virtual void initState(ThreadContext* tc) = 0;
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2011-10-23 07:30:08 +02:00
|
|
|
// for DPRINTF compatibility
|
|
|
|
const std::string name() const { return _name; }
|
|
|
|
|
2006-02-21 02:53:38 +01:00
|
|
|
Addr pageAlign(Addr a) { return (a & ~offsetMask); }
|
|
|
|
Addr pageOffset(Addr a) { return (a & offsetMask); }
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2014-11-24 03:01:09 +01:00
|
|
|
/**
|
|
|
|
* Maps a virtual memory region to a physical memory region.
|
|
|
|
* @param vaddr The starting virtual address of the region.
|
|
|
|
* @param paddr The starting physical address where the region is mapped.
|
|
|
|
* @param size The length of the region.
|
|
|
|
* @param flags Generic mapping flags that can be set by or-ing values
|
|
|
|
* from MappingFlags enum.
|
|
|
|
*/
|
2014-11-24 03:01:09 +01:00
|
|
|
virtual void map(Addr vaddr, Addr paddr, int64_t size,
|
2014-11-24 03:01:09 +01:00
|
|
|
uint64_t flags = 0) = 0;
|
2014-04-01 19:18:12 +02:00
|
|
|
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr) = 0;
|
|
|
|
virtual void unmap(Addr vaddr, int64_t size) = 0;
|
2006-02-21 02:53:38 +01:00
|
|
|
|
2011-10-23 07:30:07 +02:00
|
|
|
/**
|
|
|
|
* Check if any pages in a region are already allocated
|
|
|
|
* @param vaddr The starting virtual address of the region.
|
|
|
|
* @param size The length of the region.
|
|
|
|
* @return True if no pages in the region are mapped.
|
|
|
|
*/
|
2014-04-01 19:18:12 +02:00
|
|
|
virtual bool isUnmapped(Addr vaddr, int64_t size) = 0;
|
2011-10-23 07:30:07 +02:00
|
|
|
|
2007-08-27 05:33:57 +02:00
|
|
|
/**
|
|
|
|
* Lookup function
|
|
|
|
* @param vaddr The virtual address.
|
|
|
|
* @return entry The page table entry corresponding to vaddr.
|
|
|
|
*/
|
2014-04-01 19:18:12 +02:00
|
|
|
virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry) = 0;
|
2007-08-27 05:33:57 +02:00
|
|
|
|
2006-01-29 23:28:04 +01:00
|
|
|
/**
|
|
|
|
* Translate function
|
|
|
|
* @param vaddr The virtual address.
|
2008-11-15 18:30:10 +01:00
|
|
|
* @param paddr Physical address from translation.
|
|
|
|
* @return True if translation exists
|
2006-01-29 23:28:04 +01:00
|
|
|
*/
|
2006-02-21 02:53:38 +01:00
|
|
|
bool translate(Addr vaddr, Addr &paddr);
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2008-11-15 18:30:10 +01:00
|
|
|
/**
|
|
|
|
* Simplified translate function (just check for translation)
|
|
|
|
* @param vaddr The virtual address.
|
|
|
|
* @return True if translation exists
|
|
|
|
*/
|
|
|
|
bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
|
|
|
|
|
2006-01-29 23:28:04 +01:00
|
|
|
/**
|
2006-02-21 02:53:38 +01:00
|
|
|
* Perform a translation on the memory request, fills in paddr
|
2007-08-27 05:33:57 +02:00
|
|
|
* field of req.
|
2006-01-29 23:28:04 +01:00
|
|
|
* @param req The memory request.
|
|
|
|
*/
|
2007-08-27 05:33:57 +02:00
|
|
|
Fault translate(RequestPtr req);
|
2006-01-29 23:28:04 +01:00
|
|
|
|
2007-06-05 07:03:35 +02:00
|
|
|
/**
|
|
|
|
* Update the page table cache.
|
|
|
|
* @param vaddr virtual address (page aligned) to check
|
2007-08-27 05:33:57 +02:00
|
|
|
* @param pte page table entry to return
|
2007-06-05 07:03:35 +02:00
|
|
|
*/
|
2007-08-27 05:33:57 +02:00
|
|
|
inline void updateCache(Addr vaddr, TheISA::TlbEntry entry)
|
2007-06-05 07:03:35 +02:00
|
|
|
{
|
2007-08-27 05:33:57 +02:00
|
|
|
pTableCache[2].entry = pTableCache[1].entry;
|
2007-06-05 07:03:35 +02:00
|
|
|
pTableCache[2].vaddr = pTableCache[1].vaddr;
|
2013-04-23 15:47:52 +02:00
|
|
|
pTableCache[2].valid = pTableCache[1].valid;
|
|
|
|
|
2007-08-27 05:33:57 +02:00
|
|
|
pTableCache[1].entry = pTableCache[0].entry;
|
2007-06-05 07:03:35 +02:00
|
|
|
pTableCache[1].vaddr = pTableCache[0].vaddr;
|
2013-04-23 15:47:52 +02:00
|
|
|
pTableCache[1].valid = pTableCache[0].valid;
|
|
|
|
|
2007-08-27 05:33:57 +02:00
|
|
|
pTableCache[0].entry = entry;
|
2007-06-05 07:03:35 +02:00
|
|
|
pTableCache[0].vaddr = vaddr;
|
2013-04-23 15:47:52 +02:00
|
|
|
pTableCache[0].valid = true;
|
2007-06-05 07:03:35 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 15:47:52 +02:00
|
|
|
/**
|
|
|
|
* Erase an entry from the page table cache.
|
|
|
|
* @param vaddr virtual address (page aligned) to check
|
|
|
|
*/
|
|
|
|
inline void eraseCacheEntry(Addr vaddr)
|
|
|
|
{
|
|
|
|
// Invalidate cached entries if necessary
|
|
|
|
if (pTableCache[0].valid && pTableCache[0].vaddr == vaddr) {
|
|
|
|
pTableCache[0].valid = false;
|
|
|
|
} else if (pTableCache[1].valid && pTableCache[1].vaddr == vaddr) {
|
|
|
|
pTableCache[1].valid = false;
|
|
|
|
} else if (pTableCache[2].valid && pTableCache[2].vaddr == vaddr) {
|
|
|
|
pTableCache[2].valid = false;
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 19:18:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declaration of functional page table.
|
|
|
|
*/
|
|
|
|
class FuncPageTable : public PageTableBase
|
|
|
|
{
|
|
|
|
private:
|
2015-10-12 10:07:59 +02:00
|
|
|
typedef std::unordered_map<Addr, TheISA::TlbEntry> PTable;
|
2014-04-01 19:18:12 +02:00
|
|
|
typedef PTable::iterator PTableItr;
|
|
|
|
PTable pTable;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
FuncPageTable(const std::string &__name, uint64_t _pid,
|
2014-09-03 13:42:21 +02:00
|
|
|
Addr _pageSize = TheISA::PageBytes);
|
2014-04-01 19:18:12 +02:00
|
|
|
|
|
|
|
~FuncPageTable();
|
|
|
|
|
2015-10-12 10:08:01 +02:00
|
|
|
void initState(ThreadContext* tc) override
|
2014-04-01 19:18:12 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-24 03:01:09 +01:00
|
|
|
void map(Addr vaddr, Addr paddr, int64_t size,
|
2015-10-12 10:08:01 +02:00
|
|
|
uint64_t flags = 0) override;
|
|
|
|
void remap(Addr vaddr, int64_t size, Addr new_vaddr) override;
|
|
|
|
void unmap(Addr vaddr, int64_t size) override;
|
2014-04-01 19:18:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if any pages in a region are already allocated
|
|
|
|
* @param vaddr The starting virtual address of the region.
|
|
|
|
* @param size The length of the region.
|
|
|
|
* @return True if no pages in the region are mapped.
|
|
|
|
*/
|
2015-10-12 10:08:01 +02:00
|
|
|
bool isUnmapped(Addr vaddr, int64_t size) override;
|
2014-04-01 19:18:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup function
|
|
|
|
* @param vaddr The virtual address.
|
|
|
|
* @return entry The page table entry corresponding to vaddr.
|
|
|
|
*/
|
2015-10-12 10:08:01 +02:00
|
|
|
bool lookup(Addr vaddr, TheISA::TlbEntry &entry) override;
|
2014-04-01 19:18:12 +02:00
|
|
|
|
2015-10-12 10:07:59 +02:00
|
|
|
void serialize(CheckpointOut &cp) const override;
|
|
|
|
void unserialize(CheckpointIn &cp) override;
|
2006-01-29 23:28:04 +01:00
|
|
|
};
|
|
|
|
|
2014-04-01 19:18:12 +02:00
|
|
|
/**
|
|
|
|
* Faux page table class indended to stop the usage of
|
|
|
|
* an architectural page table, when there is none defined
|
|
|
|
* for a particular ISA.
|
|
|
|
*/
|
|
|
|
class NoArchPageTable : public FuncPageTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NoArchPageTable(const std::string &__name, uint64_t _pid, System *_sys,
|
2014-09-03 13:42:21 +02:00
|
|
|
Addr _pageSize = TheISA::PageBytes) : FuncPageTable(__name, _pid)
|
2014-04-01 19:18:12 +02:00
|
|
|
{
|
|
|
|
fatal("No architectural page table defined for this ISA.\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-17 23:34:52 +02:00
|
|
|
#endif // __MEM_PAGE_TABLE_HH__
|