Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 5c276141 authored by Davide Pala's avatar Davide Pala

Refactored elf reading into a function

parent 46d81fed
......@@ -17,6 +17,9 @@ class BasicSimulator : public Simulator {
FILE* outputFile;
FILE* traceFile;
FILE* signatureFile;
private:
void setByte(unsigned, ac_int<8, true>);
void readElf(const char*);
public:
BasicSimulator(const char* binaryFile, std::vector<std::string>, const char* inFile, const char* outFile,
......@@ -28,7 +31,6 @@ protected:
void printEnd();
void extend(){};
void setByte(unsigned, ac_int<8, true>);
// Functions for memory accesses
void stb(ac_int<32, false> addr, ac_int<8, true> value);
void sth(ac_int<32, false> addr, ac_int<16, true> value);
......
......@@ -46,27 +46,7 @@ BasicSimulator::BasicSimulator(const char* binaryFile, std::vector<std::string>
//****************************************************************************
// Populate memory using ELF file
ElfFile elfFile(binaryFile);
for(auto const &section : elfFile.sectionTable){
if(section.address != 0){
for (unsigned i = 0; i < section.size; i++)
setByte(section.address + i, elfFile.content[section.offset + i]);
// update the size of the heap
if (section.name != ".text" && section.name != ".text.init") {
if (section.address + section.size > heapAddress)
heapAddress = section.address + section.size;
}
}
}
//****************************************************************************
// Looking for start symbol
core.pc = find_by_name(elfFile.symbols, "_start").offset;
if (signatureFile != NULL){
begin_signature = find_by_name(elfFile.symbols, "begin_signature").offset;
end_signature = find_by_name(elfFile.symbols, "end_signature").offset;
}
readElf(binaryFile);
if(DEBUG){
printf("Start Symbol Reading done.\n");
......@@ -97,6 +77,28 @@ BasicSimulator::BasicSimulator(const char* binaryFile, std::vector<std::string>
core.regFile[2] = STACK_INIT;
}
void BasicSimulator::readElf(const char *binaryFile){
ElfFile elfFile(binaryFile);
for(auto const &section : elfFile.sectionTable){
if(section.address != 0){
for (unsigned i = 0; i < section.size; i++)
setByte(section.address + i, elfFile.content[section.offset + i]);
// update the size of the heap
if (section.name != ".text" && section.name != ".text.init") {
if (section.address + section.size > heapAddress)
heapAddress = section.address + section.size;
}
}
}
core.pc = find_by_name(elfFile.symbols, "_start").offset;
if (signatureFile != NULL){
begin_signature = find_by_name(elfFile.symbols, "begin_signature").offset;
end_signature = find_by_name(elfFile.symbols, "end_signature").offset;
}
}
BasicSimulator::~BasicSimulator()
{
if (inputFile)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment