summaryrefslogtreecommitdiff
path: root/src/dev/x86
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-07-07 09:51:03 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-07-07 09:51:03 +0100
commit76cd4393c08b83fa9006ee7bce1fb62457e053c1 (patch)
treef1d2d109f77a8cf31365143d6eb127b610d924f5 /src/dev/x86
parentd7a56ee524c976a41fa40e5382a28462de799645 (diff)
downloadgem5-76cd4393c08b83fa9006ee7bce1fb62457e053c1.tar.xz
sim: Refactor the serialization base class
Objects that are can be serialized are supposed to inherit from the Serializable class. This class is meant to provide a unified API for such objects. However, so far it has mainly been used by SimObjects due to some fundamental design limitations. This changeset redesigns to the serialization interface to make it more generic and hide the underlying checkpoint storage. Specifically: * Add a set of APIs to serialize into a subsection of the current object. Previously, objects that needed this functionality would use ad-hoc solutions using nameOut() and section name generation. In the new world, an object that implements the interface has the methods serializeSection() and unserializeSection() that serialize into a named /subsection/ of the current object. Calling serialize() serializes an object into the current section. * Move the name() method from Serializable to SimObject as it is no longer needed for serialization. The fully qualified section name is generated by the main serialization code on the fly as objects serialize sub-objects. * Add a scoped ScopedCheckpointSection helper class. Some objects need to serialize data structures, that are not deriving from Serializable, into subsections. Previously, this was done using nameOut() and manual section name generation. To simplify this, this changeset introduces a ScopedCheckpointSection() helper class. When this class is instantiated, it adds a new /subsection/ and subsequent serialization calls during the lifetime of this helper class happen inside this section (or a subsection in case of nested sections). * The serialize() call is now const which prevents accidental state manipulation during serialization. Objects that rely on modifying state can use the serializeOld() call instead. The default implementation simply calls serialize(). Note: The old-style calls need to be explicitly called using the serializeOld()/serializeSectionOld() style APIs. These are used by default when serializing SimObjects. * Both the input and output checkpoints now use their own named types. This hides underlying checkpoint implementation from objects that need checkpointing and makes it easier to change the underlying checkpoint storage code.
Diffstat (limited to 'src/dev/x86')
-rw-r--r--src/dev/x86/cmos.cc8
-rw-r--r--src/dev/x86/cmos.hh4
-rw-r--r--src/dev/x86/i8042.cc58
-rw-r--r--src/dev/x86/i8042.hh14
-rw-r--r--src/dev/x86/i82094aa.cc4
-rw-r--r--src/dev/x86/i82094aa.hh4
-rw-r--r--src/dev/x86/i8237.cc4
-rw-r--r--src/dev/x86/i8237.hh4
-rw-r--r--src/dev/x86/i8254.cc8
-rw-r--r--src/dev/x86/i8254.hh5
-rw-r--r--src/dev/x86/i8259.cc4
-rw-r--r--src/dev/x86/i8259.hh4
-rw-r--r--src/dev/x86/speaker.cc4
-rw-r--r--src/dev/x86/speaker.hh5
14 files changed, 63 insertions, 67 deletions
diff --git a/src/dev/x86/cmos.cc b/src/dev/x86/cmos.cc
index 6a778b758..73cfe853e 100644
--- a/src/dev/x86/cmos.cc
+++ b/src/dev/x86/cmos.cc
@@ -119,23 +119,23 @@ X86ISA::Cmos::startup()
}
void
-X86ISA::Cmos::serialize(std::ostream &os)
+X86ISA::Cmos::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(address);
SERIALIZE_ARRAY(regs, numRegs);
// Serialize the timer
- rtc.serialize("rtc", os);
+ rtc.serialize("rtc", cp);
}
void
-X86ISA::Cmos::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::Cmos::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(address);
UNSERIALIZE_ARRAY(regs, numRegs);
// Serialize the timer
- rtc.unserialize("rtc", cp, section);
+ rtc.unserialize("rtc", cp);
}
X86ISA::Cmos *
diff --git a/src/dev/x86/cmos.hh b/src/dev/x86/cmos.hh
index fa5865c0a..f0234da54 100644
--- a/src/dev/x86/cmos.hh
+++ b/src/dev/x86/cmos.hh
@@ -83,9 +83,9 @@ class Cmos : public BasicPioDevice
Tick write(PacketPtr pkt);
virtual void startup();
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
} // namespace X86ISA
diff --git a/src/dev/x86/i8042.cc b/src/dev/x86/i8042.cc
index a0a7c35ec..03b12dc14 100644
--- a/src/dev/x86/i8042.cc
+++ b/src/dev/x86/i8042.cc
@@ -463,7 +463,7 @@ X86ISA::I8042::write(PacketPtr pkt)
}
void
-X86ISA::I8042::serialize(std::ostream &os)
+X86ISA::I8042::serializeOld(CheckpointOut &cp)
{
uint8_t statusRegData = statusReg.__data;
uint8_t commandByteData = commandByte.__data;
@@ -474,12 +474,12 @@ X86ISA::I8042::serialize(std::ostream &os)
SERIALIZE_SCALAR(commandByteData);
SERIALIZE_SCALAR(dataReg);
SERIALIZE_SCALAR(lastCommand);
- mouse.serialize("mouse", os);
- keyboard.serialize("keyboard", os);
+ mouse.serialize("mouse", cp);
+ keyboard.serialize("keyboard", cp);
}
void
-X86ISA::I8042::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::I8042::unserialize(CheckpointIn &cp)
{
uint8_t statusRegData;
uint8_t commandByteData;
@@ -490,38 +490,37 @@ X86ISA::I8042::unserialize(Checkpoint *cp, const std::string &section)
UNSERIALIZE_SCALAR(commandByteData);
UNSERIALIZE_SCALAR(dataReg);
UNSERIALIZE_SCALAR(lastCommand);
- mouse.unserialize("mouse", cp, section);
- keyboard.unserialize("keyboard", cp, section);
+ mouse.unserialize("mouse", cp);
+ keyboard.unserialize("keyboard", cp);
statusReg.__data = statusRegData;
commandByte.__data = commandByteData;
}
void
-X86ISA::PS2Keyboard::serialize(const std::string &base, std::ostream &os)
+X86ISA::PS2Keyboard::serialize(const std::string &base, CheckpointOut &cp)
{
- paramOut(os, base + ".lastCommand", lastCommand);
+ paramOut(cp, base + ".lastCommand", lastCommand);
int bufferSize = outBuffer.size();
- paramOut(os, base + ".outBuffer.size", bufferSize);
+ paramOut(cp, base + ".outBuffer.size", bufferSize);
uint8_t *buffer = new uint8_t[bufferSize];
for (int i = 0; i < bufferSize; ++i) {
buffer[i] = outBuffer.front();
outBuffer.pop();
}
- arrayParamOut(os, base + ".outBuffer.elts", buffer,
+ arrayParamOut(cp, base + ".outBuffer.elts", buffer,
bufferSize*sizeof(uint8_t));
delete[] buffer;
}
void
-X86ISA::PS2Keyboard::unserialize(const std::string &base, Checkpoint *cp,
- const std::string &section)
+X86ISA::PS2Keyboard::unserialize(const std::string &base, CheckpointIn &cp)
{
- paramIn(cp, section, base + ".lastCommand", lastCommand);
+ paramIn(cp, base + ".lastCommand", lastCommand);
int bufferSize;
- paramIn(cp, section, base + ".outBuffer.size", bufferSize);
+ paramIn(cp, base + ".outBuffer.size", bufferSize);
uint8_t *buffer = new uint8_t[bufferSize];
- arrayParamIn(cp, section, base + ".outBuffer.elts", buffer,
+ arrayParamIn(cp, base + ".outBuffer.elts", buffer,
bufferSize*sizeof(uint8_t));
for (int i = 0; i < bufferSize; ++i) {
outBuffer.push(buffer[i]);
@@ -530,43 +529,42 @@ X86ISA::PS2Keyboard::unserialize(const std::string &base, Checkpoint *cp,
}
void
-X86ISA::PS2Mouse::serialize(const std::string &base, std::ostream &os)
+X86ISA::PS2Mouse::serialize(const std::string &base, CheckpointOut &cp)
{
uint8_t statusData = status.__data;
- paramOut(os, base + ".lastCommand", lastCommand);
+ paramOut(cp, base + ".lastCommand", lastCommand);
int bufferSize = outBuffer.size();
- paramOut(os, base + ".outBuffer.size", bufferSize);
+ paramOut(cp, base + ".outBuffer.size", bufferSize);
uint8_t *buffer = new uint8_t[bufferSize];
for (int i = 0; i < bufferSize; ++i) {
buffer[i] = outBuffer.front();
outBuffer.pop();
}
- arrayParamOut(os, base + ".outBuffer.elts", buffer,
+ arrayParamOut(cp, base + ".outBuffer.elts", buffer,
bufferSize*sizeof(uint8_t));
delete[] buffer;
- paramOut(os, base + ".status", statusData);
- paramOut(os, base + ".resolution", resolution);
- paramOut(os, base + ".sampleRate", sampleRate);
+ paramOut(cp, base + ".status", statusData);
+ paramOut(cp, base + ".resolution", resolution);
+ paramOut(cp, base + ".sampleRate", sampleRate);
}
void
-X86ISA::PS2Mouse::unserialize(const std::string &base, Checkpoint *cp,
- const std::string &section)
+X86ISA::PS2Mouse::unserialize(const std::string &base, CheckpointIn &cp)
{
uint8_t statusData;
- paramIn(cp, section, base + ".lastCommand", lastCommand);
+ paramIn(cp, base + ".lastCommand", lastCommand);
int bufferSize;
- paramIn(cp, section, base + ".outBuffer.size", bufferSize);
+ paramIn(cp, base + ".outBuffer.size", bufferSize);
uint8_t *buffer = new uint8_t[bufferSize];
- arrayParamIn(cp, section, base + ".outBuffer.elts", buffer,
+ arrayParamIn(cp, base + ".outBuffer.elts", buffer,
bufferSize*sizeof(uint8_t));
for (int i = 0; i < bufferSize; ++i) {
outBuffer.push(buffer[i]);
}
delete[] buffer;
- paramIn(cp, section, base + ".status", statusData);
- paramIn(cp, section, base + ".resolution", resolution);
- paramIn(cp, section, base + ".sampleRate", sampleRate);
+ paramIn(cp, base + ".status", statusData);
+ paramIn(cp, base + ".resolution", resolution);
+ paramIn(cp, base + ".sampleRate", sampleRate);
status.__data = statusData;
}
diff --git a/src/dev/x86/i8042.hh b/src/dev/x86/i8042.hh
index 791922142..9d2548857 100644
--- a/src/dev/x86/i8042.hh
+++ b/src/dev/x86/i8042.hh
@@ -117,9 +117,8 @@ class PS2Mouse : public PS2Device
bool processData(uint8_t data);
- void serialize(const std::string &base, std::ostream &os);
- void unserialize(const std::string &base, Checkpoint *cp,
- const std::string &section);
+ void serialize(const std::string &base, CheckpointOut &cp);
+ void unserialize(const std::string &base, CheckpointIn &cp);
};
class PS2Keyboard : public PS2Device
@@ -151,9 +150,8 @@ class PS2Keyboard : public PS2Device
public:
bool processData(uint8_t data);
- void serialize(const std::string &base, std::ostream &os);
- void unserialize(const std::string &base, Checkpoint *cp,
- const std::string &section);
+ void serialize(const std::string &base, CheckpointOut &cp);
+ void unserialize(const std::string &base, CheckpointIn &cp);
};
class I8042 : public BasicPioDevice
@@ -249,8 +247,8 @@ class I8042 : public BasicPioDevice
Tick write(PacketPtr pkt);
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serializeOld(CheckpointOut &cp) M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
} // namespace X86ISA
diff --git a/src/dev/x86/i82094aa.cc b/src/dev/x86/i82094aa.cc
index 12697ce62..44fa29154 100644
--- a/src/dev/x86/i82094aa.cc
+++ b/src/dev/x86/i82094aa.cc
@@ -260,7 +260,7 @@ X86ISA::I82094AA::lowerInterruptPin(int number)
}
void
-X86ISA::I82094AA::serialize(std::ostream &os)
+X86ISA::I82094AA::serialize(CheckpointOut &cp) const
{
uint64_t* redirTableArray = (uint64_t*)redirTable;
SERIALIZE_SCALAR(regSel);
@@ -273,7 +273,7 @@ X86ISA::I82094AA::serialize(std::ostream &os)
}
void
-X86ISA::I82094AA::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::I82094AA::unserialize(CheckpointIn &cp)
{
uint64_t redirTableArray[TableSize];
UNSERIALIZE_SCALAR(regSel);
diff --git a/src/dev/x86/i82094aa.hh b/src/dev/x86/i82094aa.hh
index 4fe927ae4..afa597e65 100644
--- a/src/dev/x86/i82094aa.hh
+++ b/src/dev/x86/i82094aa.hh
@@ -109,8 +109,8 @@ class I82094AA : public BasicPioDevice, public IntDevice
void raiseInterruptPin(int number);
void lowerInterruptPin(int number);
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
} // namespace X86ISA
diff --git a/src/dev/x86/i8237.cc b/src/dev/x86/i8237.cc
index a43c1ec91..b16f78883 100644
--- a/src/dev/x86/i8237.cc
+++ b/src/dev/x86/i8237.cc
@@ -126,13 +126,13 @@ X86ISA::I8237::write(PacketPtr pkt)
}
void
-X86ISA::I8237::serialize(std::ostream &os)
+X86ISA::I8237::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(maskReg);
}
void
-X86ISA::I8237::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::I8237::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(maskReg);
}
diff --git a/src/dev/x86/i8237.hh b/src/dev/x86/i8237.hh
index b1b11091b..481983b8e 100644
--- a/src/dev/x86/i8237.hh
+++ b/src/dev/x86/i8237.hh
@@ -59,8 +59,8 @@ class I8237 : public BasicPioDevice
Tick write(PacketPtr pkt);
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
} // namespace X86ISA
diff --git a/src/dev/x86/i8254.cc b/src/dev/x86/i8254.cc
index b80952237..f784a0107 100644
--- a/src/dev/x86/i8254.cc
+++ b/src/dev/x86/i8254.cc
@@ -78,15 +78,15 @@ X86ISA::I8254::write(PacketPtr pkt)
}
void
-X86ISA::I8254::serialize(std::ostream &os)
+X86ISA::I8254::serialize(CheckpointOut &cp) const
{
- pit.serialize("pit", os);
+ pit.serialize("pit", cp);
}
void
-X86ISA::I8254::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::I8254::unserialize(CheckpointIn &cp)
{
- pit.unserialize("pit", cp, section);
+ pit.unserialize("pit", cp);
}
void
diff --git a/src/dev/x86/i8254.hh b/src/dev/x86/i8254.hh
index 76521e73e..c4f04bd42 100644
--- a/src/dev/x86/i8254.hh
+++ b/src/dev/x86/i8254.hh
@@ -109,8 +109,9 @@ class I8254 : public BasicPioDevice
pit.writeControl(val);
}
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
+
virtual void startup();
};
diff --git a/src/dev/x86/i8259.cc b/src/dev/x86/i8259.cc
index d599ecef3..84f2d1321 100644
--- a/src/dev/x86/i8259.cc
+++ b/src/dev/x86/i8259.cc
@@ -305,7 +305,7 @@ X86ISA::I8259::getVector()
}
void
-X86ISA::I8259::serialize(std::ostream &os)
+X86ISA::I8259::serialize(CheckpointOut &cp) const
{
SERIALIZE_ARRAY(pinStates, NumLines);
SERIALIZE_ENUM(mode);
@@ -323,7 +323,7 @@ X86ISA::I8259::serialize(std::ostream &os)
}
void
-X86ISA::I8259::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::I8259::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_ARRAY(pinStates, NumLines);
UNSERIALIZE_ENUM(mode);
diff --git a/src/dev/x86/i8259.hh b/src/dev/x86/i8259.hh
index 2d6080cc3..567ad7a32 100644
--- a/src/dev/x86/i8259.hh
+++ b/src/dev/x86/i8259.hh
@@ -109,8 +109,8 @@ class I8259 : public BasicPioDevice, public IntDevice
void lowerInterruptPin(int number);
int getVector();
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
} // namespace X86ISA
diff --git a/src/dev/x86/speaker.cc b/src/dev/x86/speaker.cc
index 70f52dd1a..235860815 100644
--- a/src/dev/x86/speaker.cc
+++ b/src/dev/x86/speaker.cc
@@ -74,14 +74,14 @@ X86ISA::Speaker::write(PacketPtr pkt)
}
void
-X86ISA::Speaker::serialize(std::ostream &os)
+X86ISA::Speaker::serialize(CheckpointOut &cp) const
{
uint8_t controlValData = controlVal.__data;
SERIALIZE_SCALAR(controlValData);
}
void
-X86ISA::Speaker::unserialize(Checkpoint *cp, const std::string &section)
+X86ISA::Speaker::unserialize(CheckpointIn &cp)
{
uint8_t controlValData;
UNSERIALIZE_SCALAR(controlValData);
diff --git a/src/dev/x86/speaker.hh b/src/dev/x86/speaker.hh
index 22fc03e1c..3c879060f 100644
--- a/src/dev/x86/speaker.hh
+++ b/src/dev/x86/speaker.hh
@@ -73,9 +73,8 @@ class Speaker : public BasicPioDevice
Tick write(PacketPtr pkt);
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
-
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
} // namespace X86ISA