MemoryMappedComponent.cc Source File

Back to the index.

MemoryMappedComponent.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2010 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
29 
30 
32  const string& visibleClassName)
33  : Component(className, visibleClassName)
34  , m_memoryMappedBase(0)
35  , m_memoryMappedSize(0)
36  , m_memoryMappedAddrMul(1)
37 {
38  AddVariable("memoryMappedBase", &m_memoryMappedBase);
39  AddVariable("memoryMappedSize", &m_memoryMappedSize);
40  AddVariable("memoryMappedAddrMul", &m_memoryMappedAddrMul);
41 }
42 
44 {
45  stringstream ss;
47 
48  const StateVariable* memoryMappedBase = GetVariable("memoryMappedBase");
49  const StateVariable* memoryMappedSize = GetVariable("memoryMappedSize");
50  const StateVariable* memoryMappedAddrMul =
51  GetVariable("memoryMappedAddrMul");
52  if (memoryMappedBase != NULL && memoryMappedSize != NULL) {
53  if (!ss.str().empty())
54  ss << ", ";
55 
56  uint64_t nBytes = memoryMappedSize->ToInteger();
57  if (nBytes >= (1 << 30))
58  ss << (nBytes >> 30) << " GB";
59  else if (nBytes >= (1 << 20))
60  ss << (nBytes >> 20) << " MB";
61  else if (nBytes >= (1 << 10))
62  ss << (nBytes >> 10) << " KB";
63  else if (nBytes != 1)
64  ss << nBytes << " bytes";
65  else
66  ss << nBytes << " byte";
67 
68  ss << " at offset ";
69  ss.flags(std::ios::hex | std::ios::showbase);
70  ss << memoryMappedBase->ToInteger();
71 
72  if (memoryMappedAddrMul != NULL &&
73  memoryMappedAddrMul->ToInteger() != 1)
74  ss << ", addrmul " << memoryMappedAddrMul->ToInteger();
75  }
76 
77  return ss.str();
78 }
79 
MemoryMappedComponent::GenerateDetails
string GenerateDetails() const
Generate details about the component.
Definition: MemoryMappedComponent.cc:43
Component::GenerateDetails
virtual string GenerateDetails() const
Generate details about the component.
Definition: Component.cc:417
Component::AddVariable
bool AddVariable(const string &name, T *variablePointer)
Adds a state variable of type T to the Component.
Definition: Component.h:563
StateVariable
StateVariables make up the persistent state of Component objects.
Definition: StateVariable.h:69
StateVariable::ToInteger
uint64_t ToInteger() const
Returns the variable as an unsignedinteger value.
Definition: StateVariable.cc:280
MemoryMappedComponent::MemoryMappedComponent
MemoryMappedComponent(const string &className, const string &visibleClassName)
Constructs a MemoryMappedComponent.
Definition: MemoryMappedComponent.cc:31
Component
A Component is a node in the configuration tree that makes up an emulation setup.
Definition: Component.h:64
Component::GetVariable
StateVariable * GetVariable(const string &name)
Gets a pointer to a state variable.
Definition: Component.cc:949
MemoryMappedComponent.h

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18