OVP: save/restore registers using protocol buffer

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1206 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
sirozipp
2012-05-05 07:57:43 +00:00
parent 238aafde3e
commit 084ff6eb99
10 changed files with 120 additions and 5 deletions

View File

@ -43,6 +43,7 @@ include_directories($ENV{IMPERAS_HOME}/ImpPublic/include/host)
#add_subdirectory(ovpworld.org/mmc/flakyMemory/1.0/model)
add_subdirectory(cortexM3)
add_subdirectory(statusmsg)
include(ExternalProject)
#### Put resulting (model) library file in <your_build_dir>/lib ####

View File

@ -86,10 +86,22 @@ class OVPCpu {
*/
virtual void makeCallbackMemory(size_t sizeText, size_t offText, size_t sizeMem, size_t offMem) = 0;
/**
* Saves cpu status in file at given path
* @param path path to store file
*/
virtual void save(const string& path) = 0;
/**
* Restore cpu status from file at given path
* @param path path to store file
*/
virtual void restore(const string& path) = 0;
/**
* Returns the private icmProcessorObject pointer needed for some OVP action
* @return icmProcessorObject
*/
icmProcessorObject *getProcessor() {
return cpu;
}

View File

@ -47,3 +47,11 @@ uint32_t OVPPlatform::getSP() {
return res;
}
void OVPPlatform::save(const string& path) {
platform->save(path);
}
void OVPPlatform::restore(const string& path) {
platform->restore(path);
}

View File

@ -48,6 +48,16 @@ public:
*/
uint32_t getSP();
/**
* Save cpu status
*/
void save(const string&);
/**
* Restore cpu status
*/
void restore(const string&);
};
#endif

View File

@ -7,9 +7,9 @@ set(SRCS
)
add_executable(ovp_cortexM3 ${SRCS})
add_dependencies(ovp_cortexM3 ovpstatusmessages )
add_dependencies(ovp_cortexM3 protomessages )
target_link_libraries(ovp_cortexM3 ${SIM_LDFLAGS} SAL controller jobserver util )
target_link_libraries(ovp_cortexM3 ${SIM_LDFLAGS} SAL controller jobserver util ovpstatusmessages)
## OVP links all needed shared libraries via a runtimeloader
set_target_properties(ovp_cortexM3 PROPERTIES LINK_FLAGS "-L${CMAKE_BINARY_DIR}/lib -lpcl -m32 ")
set_target_properties(ovp_cortexM3 PROPERTIES LINK_FLAGS "-L${CMAKE_BINARY_DIR}/lib -lpcl -lprotobuf -m32 ")

View File

@ -332,6 +332,61 @@ void ARM_Cortex_M3::makeCallbackMemory(size_t sizeText, size_t offText, size_t s
textMemSize = sizeText;
}
void ARM_Cortex_M3::save(const string& path) {
OVPStatusMessage ovpstat;
// save registers
// FIXME: what about reg with id 16? should be status register
for(unsigned int i = 0; i < 16; ++i) {
uint32_t tmp = 0;
icmRegInfoP reg = icmGetRegByIndex(processorP, i);
icmReadRegInfoValue(processorP, reg, (void *)&tmp);
OVPStatusMessage::Register *msgReg = ovpstat.add_reg();
switch(i) {
case 13: msgReg->set_name("sp");
break;
case 14: msgReg->set_name("lr");
break;
case 15: msgReg->set_name("pc");
break;
case 16: msgReg->set_name("sr");
break;
default: char num[3];
sprintf(num, "r%d", i);
msgReg->set_name(num);
}
msgReg->set_value(tmp);
// std::cerr << "save " << i << ": " << tmp << std::endl;
}
string stmp;
ovpstat.SerializeToString(&stmp);
ofstream file;
file.open(path.c_str(), ios::out);
file << stmp;
file.close();
/* ofstream file(path.c_str(), ios::out | ios::trunc);
if(!ovpstat.SerializeToOstream(&file)) {
std::cerr << "Error writing to file " << path << "!" << std::endl;
}*/
}
void ARM_Cortex_M3::restore(const string& path) {
fstream input(path.c_str(), ios::in);
OVPStatusMessage ovpstat;
ovpstat.ParseFromIstream(&input);
for(int i = 0; i < ovpstat.reg_size(); ++i) {
const OVPStatusMessage::Register& ovpreg = ovpstat.reg(i);
uint32_t val = ovpreg.value();
// std::cerr << "restore "<<ovpreg.name()<<": " << val << std::endl;
icmRegInfoP reg = icmGetRegByIndex(processorP, i);
icmWriteRegInfoValue(processorP, reg, (void *)&val);
}
}
int main(int argc, char **argv) {
if(argc != 2) {
@ -356,7 +411,5 @@ int main(int argc, char **argv) {
arm.makeSTRegister();
arm.makePCRegister();
// sal::simulator.finishedRegisterCreation();
arm.startSimulation(argv[1]);
}

View File

@ -3,6 +3,7 @@
#include "../../OVPCpu.hpp"
#include "ovp/statusmsg/OVPStatusMessage.pb.h"
using namespace icmCpuManager;
@ -26,6 +27,9 @@ class ARM_Cortex_M3 : public OVPCpu {
void makePCRegister();
void makeCallbackMemory(size_t, size_t, size_t, size_t);
void save(const string&);
void restore(const string&);
};

View File

@ -0,0 +1,15 @@
## Setup desired protobuf descriptions HERE ##
set(MY_PROTOS
OVPStatusMessage.proto
)
#### PROTOBUFS ####
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${MY_PROTOS} )
## Build library
add_library(ovpstatusmessages ${PROTO_SRCS} ${PROTO_HDRS} )

View File

@ -0,0 +1,10 @@
message OVPStatusMessage {
// Registers
message Register {
required string name = 1;
required uint32 value = 2;
}
repeated Register reg = 1;
}

2
ovp/statusmsg/protogen.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
protoc --cpp_out=. FailControlMessage.proto