Riaz Ul Haque Mian
Riaz Ul Haque Mian

Reputation: 23

How to compile and run an C executable in gem-5 that use text file as input and output in gem5 SE mode with se.py?

I have a C code that takes value form two input file calculate multiplication and write the time into another text file. First I compile and make executable with GCC and the name is Method1_X86_BINARY_

gcc DecMulTimeMeasure.c decContext.c decDouble.c decQuad.c -o Method1_X86_BINARY_

The executable is working ./Method1_X86_BINARY_ file! Now I want to compile using gem5 SE mode by bellow command

./build/X86/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/x86/linux/Method1_X86_BINARY_

After that I receive following error

GEM5 SIMULATION START problem reading inputA.txt file Exiting @ tick 9053500 because exiting with last active thread context Simulated exit code not 0! Exit code is 1

The Message GEM5 SIMULATION START and problem reading inputA.txt file shows form my C code where bellow :

>FILE *ptr_file_read, *ptr_file_readB,*ptr_file_write , *Mptr_file_write;
 char fileNameA [40] = "final_result_a.txt";
 char fileNameB [40] = "final_result_b.txt";
 printf("GEM5 SIMULATION START");
ptr_file_read = fopen(fileNameA, "r"); //Name of the input file
if (!ptr_file_read)
{
     printf("problem reading inputA.txt file");
      return 1;
 }

So the message GEM5 SIMULATION START indicate that the executable is okay where as the message problem reading inputA.txt file indicates the problem is during reading form text file.

My question is how I can run the file in GEM-5 simulator.

Here I upload full project with little description in readme. github.com/riazcseiu/DecimalMultiplication.git

Upvotes: 2

Views: 2001

Answers (1)

Ciro Santilli
Ciro Santilli

Reputation: 4083

General compile and run shown at: How to compile and run an executable in gem5 syscall emulation mode with se.py?

Then, I test it in gem5 211869ea950f3cc3116655f06b1d46d3fa39fb3a (October 2019), and opening and closing or regular files just works normally: files can be read from host, and written to host filesystem normally.

I have tested this with this minimal C file write / read example.

The file src/doc/se-files.txt documents the implementation of this feature.

I believe gem5 then treats some special Linux files e.g. under /proc and /sys specially since those require more complex interactions with the kernel that gem5 is simulating in SE.

Upvotes: 0

Related Questions