gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tlb.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2005 The Regents of The University of Michigan
3  * Copyright (c) 2007 MIPS Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Nathan Binkert
30  * Steve Reinhardt
31  * Jaidev Patwardhan
32  * Korey Sewell
33  */
34 
35 #ifndef __ARCH_RISCV_TLB_HH__
36 #define __ARCH_RISCV_TLB_HH__
37 
38 #include <map>
39 
40 #include "arch/generic/tlb.hh"
41 #include "arch/riscv/isa_traits.hh"
42 #include "arch/riscv/pagetable.hh"
43 #include "arch/riscv/utility.hh"
44 #include "arch/riscv/vtophys.hh"
45 #include "base/statistics.hh"
46 #include "mem/request.hh"
47 #include "params/RiscvTLB.hh"
48 #include "sim/sim_object.hh"
49 
50 class ThreadContext;
51 
52 /* To maintain compatibility with other architectures, we'll
53  simply create an ITLB and DTLB that will point to the real TLB */
54 namespace RiscvISA {
55 
56 class TLB : public BaseTLB
57 {
58  protected:
59  typedef std::multimap<Addr, int> PageTable;
60  PageTable lookupTable; // Quick lookup into page table
61 
62  RiscvISA::PTE *table; // the Page Table
63  int size; // TLB Size
64  int nlu; // not last used entry (for replacement)
65 
66  void nextnlu() { if (++nlu >= size) nlu = 0; }
67  RiscvISA::PTE *lookup(Addr vpn, uint8_t asn) const;
68 
80 
81  public:
82  typedef RiscvTLBParams Params;
83  TLB(const Params *p);
84 
85  int probeEntry(Addr vpn,uint8_t) const;
86  RiscvISA::PTE *getEntry(unsigned) const;
87  virtual ~TLB();
88 
89  void takeOverFrom(BaseTLB *otlb) override {}
90 
92  int getsize() const { return size; }
93 
94  RiscvISA::PTE &index(bool advance = true);
95  void insert(Addr vaddr, RiscvISA::PTE &pte);
96  void insertAt(RiscvISA::PTE &pte, unsigned Index, int _smallPages);
97  void flushAll() override;
98  void demapPage(Addr vaddr, uint64_t asn) override
99  {
100  panic("demapPage unimplemented.\n");
101  }
102 
103  // static helper functions... really
104  static bool validVirtualAddress(Addr vaddr);
105 
106  static Fault checkCacheability(const RequestPtr &req);
107 
108  // Checkpointing
109  void serialize(CheckpointOut &cp) const override;
110  void unserialize(CheckpointIn &cp) override;
111 
112  void regStats() override;
113 
115  const RequestPtr &req, ThreadContext *tc, Mode mode) override;
116  void translateTiming(
117  const RequestPtr &req, ThreadContext *tc,
118  Translation *translation, Mode mode) override;
120  const RequestPtr &req,
121  ThreadContext *tc, Mode mode) const override;
122 
123  private:
124  Fault translateInst(const RequestPtr &req, ThreadContext *tc);
125  Fault translateData(const RequestPtr &req, ThreadContext *tc, bool write);
126 };
127 
128 }
129 
130 
131 
132 #endif // __RISCV_MEMORY_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Stats::Scalar write_accesses
Definition: tlb.hh:76
void insert(Addr vaddr, RiscvISA::PTE &pte)
Definition: tlb.cc:188
void insertAt(RiscvISA::PTE &pte, unsigned Index, int _smallPages)
Definition: tlb.cc:160
int smallPages
Definition: tlb.hh:91
void demapPage(Addr vaddr, uint64_t asn) override
Definition: tlb.hh:98
static Fault checkCacheability(const RequestPtr &req)
Definition: tlb.cc:147
PageTable lookupTable
Definition: tlb.hh:60
Stats::Formula accesses
Definition: tlb.hh:79
Stats::Formula misses
Definition: tlb.hh:78
void nextnlu()
Definition: tlb.hh:66
Stats::Scalar write_acv
Definition: tlb.hh:75
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
int getsize() const
Definition: tlb.hh:92
Definition: cprintf.cc:42
Bitfield< 4, 0 > mode
RiscvISA::PTE * lookup(Addr vpn, uint8_t asn) const
Definition: tlb.cc:81
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:203
Declaration of Statistics objects.
RiscvISA::PTE * table
Definition: tlb.hh:62
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
Bitfield< 0 > p
int size
Definition: tlb.hh:63
Stats::Formula hits
Definition: tlb.hh:77
Definition: tlb.hh:52
Fault translateInst(const RequestPtr &req, ThreadContext *tc)
Definition: tlb.cc:287
void flushAll() override
Remove all entries from the TLB.
Definition: tlb.cc:194
static bool validVirtualAddress(Addr vaddr)
void regStats() override
Callback to set stat parameters.
Definition: tlb.cc:230
Stats::Scalar read_accesses
Definition: tlb.hh:72
RiscvISA::PTE & index(bool advance=true)
Definition: tlb.cc:393
void takeOverFrom(BaseTLB *otlb) override
Take over from an old tlb context.
Definition: tlb.hh:89
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
RiscvTLBParams Params
Definition: tlb.hh:82
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3012
Mode
Definition: tlb.hh:59
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition: tlb.cc:377
std::multimap< Addr, int > PageTable
Definition: tlb.hh:59
Stats::Scalar read_misses
Definition: tlb.hh:70
Stats::Scalar read_hits
Definition: tlb.hh:69
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:215
int probeEntry(Addr vpn, uint8_t) const
Definition: tlb.cc:119
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition: tlb.cc:368
Stats::Scalar read_acv
Definition: tlb.hh:71
std::ostream CheckpointOut
Definition: serialize.hh:68
int nlu
Definition: tlb.hh:64
virtual ~TLB()
Definition: tlb.cc:73
TLB(const Params *p)
Definition: tlb.cc:65
Stats::Scalar write_hits
Definition: tlb.hh:73
RiscvISA::PTE * getEntry(unsigned) const
Definition: tlb.cc:111
Fault translateData(const RequestPtr &req, ThreadContext *tc, bool write)
Definition: tlb.cc:322
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
Stats::Scalar write_misses
Definition: tlb.hh:74
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Do post-translation physical address finalization.
Definition: tlb.cc:385

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13