CacheComponent.h Source File

Back to the index.

CacheComponent.h
Go to the documentation of this file.
1 #ifndef CACHECOMPONENT_H
2 #define CACHECOMPONENT_H
3 
4 /*
5  * Copyright (C) 2010 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 // COMPONENT(cache)
32 
33 
34 #include "AddressDataBus.h"
35 #include "MemoryMappedComponent.h"
36 
37 #include "UnitTest.h"
38 
39 #include <string.h>
40 #include <iomanip>
41 
42 
43 /**
44  * \brief A memory Cache Component.
45  *
46  * TODO
47  *
48  * Note: This class does <i>not</i> handle unaligned access. It is up to the
49  * caller to make sure that e.g. ReadData(uint64_t&, Endianness) is only
50  * called when the selected address is 64-bit aligned.
51  *
52  * (The reason for this is that different emulated components want different
53  * semantics for unaligned access. For example, an x86 processor will
54  * transparently allow unaligned access, most RISC processors will cause
55  * an unaligned address exception, and some old ARM processors may even simply
56  * ignore the lowest bits of the address!)
57  */
59  : public Component
60  , public AddressDataBus
61  , public UnitTestable
62 {
63 public:
64  /**
65  * \brief Constructs a CacheComponent.
66  *
67  * @param visibleClassName The visible class name. Defaults to
68  * "cache". Useful alternatives may be "l1", "l2", or "l3".
69  */
70  CacheComponent(const string& visibleClassName = "cache");
71 
72  virtual ~CacheComponent();
73 
74  /**
75  * \brief Creates a CacheComponent.
76  */
78 
79  virtual void ResetState();
80 
81  string GenerateDetails() const;
82 
83  /**
84  * \brief Get attribute information about the CacheComponent class.
85  *
86  * @param attributeName The attribute name.
87  * @return A string representing the attribute value.
88  */
89  static string GetAttribute(const string& attributeName);
90 
91  virtual void GetMethodNames(vector<string>& names) const;
92 
93  virtual bool MethodMayBeReexecutedWithoutArgs(const string& methodName) const;
94 
95  virtual void ExecuteMethod(GXemul* gxemul,
96  const string& methodName,
97  const vector<string>& arguments);
98 
99  /**
100  * \brief Returns the component's AddressDataBus interface.
101  *
102  * @return A pointer to an AddressDataBus.
103  */
104  virtual AddressDataBus* AsAddressDataBus();
105 
106  /* Implementation of AddressDataBus: */
107  virtual void AddressSelect(uint64_t address);
108  virtual bool ReadData(uint8_t& data, Endianness endianness);
109  virtual bool ReadData(uint16_t& data, Endianness endianness);
110  virtual bool ReadData(uint32_t& data, Endianness endianness);
111  virtual bool ReadData(uint64_t& data, Endianness endianness);
112  virtual bool WriteData(const uint8_t& data, Endianness endianness);
113  virtual bool WriteData(const uint16_t& data, Endianness endianness);
114  virtual bool WriteData(const uint32_t& data, Endianness endianness);
115  virtual bool WriteData(const uint64_t& data, Endianness endianness);
116 
117 
118  /********************************************************************/
119 
120  static void RunUnitTests(int& nSucceeded, int& nFailures);
121 
122 private:
123 
124 private:
125  // State:
126  uint64_t m_size; // total cache size
127  uint64_t m_lineSize; // line size, in bytes
128  uint64_t m_lastDumpAddr;
129  int m_associativity;// 0 = fully. 1 = direct mapped. n = n-way.
130  // TODO: the actual data (cache lines)
131 
132  // Cached/runtime state:
133  uint64_t m_addressSelect; // For AddressDataBus read/write
134 };
135 
136 
137 #endif // CACHECOMPONENT_H
static void RunUnitTests(int &nSucceeded, int &nFailures)
CacheComponent(const string &visibleClassName="cache")
Constructs a CacheComponent.
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a CacheComponent.
Endianness
Definition: misc.h:156
virtual AddressDataBus * AsAddressDataBus()
Returns the component&#39;s AddressDataBus interface.
virtual bool ReadData(uint8_t &data, Endianness endianness)
Reads 8-bit data from the currently selected address.
virtual void ExecuteMethod(GXemul *gxemul, const string &methodName, const vector< string > &arguments)
Executes a method on the component.
An interface for implementing components that read/write data via an address bus. ...
A memory Cache Component.
The main emulator class.
Definition: GXemul.h:54
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
u_short data
Definition: siireg.h:79
static string GetAttribute(const string &attributeName)
Get attribute information about the CacheComponent class.
A Component is a node in the configuration tree that makes up an emulation setup. ...
Definition: Component.h:62
string GenerateDetails() const
Generate details about the component.
virtual ~CacheComponent()
virtual void AddressSelect(uint64_t address)
Place an address on the bus.
virtual void ResetState()
Resets the state variables of this component.
virtual bool WriteData(const uint8_t &data, Endianness endianness)
Writes 8-bit data to the currently selected address.
Base class for unit testable classes.
Definition: UnitTest.h:74
virtual void GetMethodNames(vector< string > &names) const
Retrieves a component&#39;s implemented method names.

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13