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 f132a6ce authored by Davide Pala's avatar Davide Pala

Refactored code that populates the stack into a function

parent 5c276141
......@@ -17,9 +17,6 @@ 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,
......@@ -57,6 +54,11 @@ protected:
ac_int<32, true> doGettimeofday(ac_int<32, false> timeValPtr);
ac_int<32, true> doUnlink(ac_int<32, false> path);
ac_int<32, true> doFstat(ac_int<32, false> file, ac_int<32, false> stataddr);
private:
void setByte(unsigned, ac_int<8, true>);
void readElf(const char*);
void pushArgsOnStack(const std::vector<std::string>);
};
#endif // __BASIC_SIMULATOR_H__
......@@ -51,25 +51,9 @@ BasicSimulator::BasicSimulator(const char* binaryFile, std::vector<std::string>
if(DEBUG){
printf("Start Symbol Reading done.\n");
}
//****************************************************************************
// Adding command line arguments on the stack
unsigned int argc = args.size();
mem[STACK_INIT >> 2] = argc;
auto currentPlaceStrings = STACK_INIT + 4 + 4 * argc;
for (unsigned oneArg = 0; oneArg < argc; oneArg++) {
mem[(STACK_INIT + 4 * oneArg + 4) >> 2] = currentPlaceStrings;
int oneCharIndex = 0;
for(const auto c : args[oneArg]){
setByte(currentPlaceStrings + oneCharIndex, c);
oneCharIndex++;
}
setByte(currentPlaceStrings + oneCharIndex, 0);
currentPlaceStrings += oneCharIndex + 1;
}
pushArgsOnStack(args);
if(DEBUG){
printf("Populate Data Memory done.\n");
}
......@@ -99,6 +83,25 @@ void BasicSimulator::readElf(const char *binaryFile){
}
}
void BasicSimulator::pushArgsOnStack(const std::vector<std::string> args){
unsigned int argc = args.size();
mem[STACK_INIT >> 2] = argc;
auto currentPlaceStrings = STACK_INIT + 4 + 4 * argc;
for (unsigned oneArg = 0; oneArg < argc; oneArg++) {
mem[(STACK_INIT + 4 * oneArg + 4) >> 2] = currentPlaceStrings;
int oneCharIndex = 0;
for(const auto c : args[oneArg]){
setByte(currentPlaceStrings + oneCharIndex, c);
oneCharIndex++;
}
setByte(currentPlaceStrings + oneCharIndex, 0);
currentPlaceStrings += oneCharIndex + 1;
}
}
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