I have designed a MIPS I simulator using Verilator which allows me to wrap verilog code into c++. I am attempting to run a c++ program on my processor but I've reached some problems. My goal is to:
- write a test program in c++
- compile this program using a cross compiler g++ (mips-linux)
- take generated ELF file and disassemble it using objdump
- store the entire binary object dump in a text file
- open text file in my simulator
- run some text manipulating functions to isolate the HEX dump portion of the objdump
- load entire elf hex dump into my processor's memory (a c++ memory map containing elements keyed by their address in memory as defined by the ELF file.)
- run the program by setting the program counter and letting it go until exit syscall of program.
The problem would be steps 7 and 8. I have a very rudimentary understanding of the ELF file format. As far as I can tell (readelf can be used to output a program starting point) the program ounter should be set initially at the address of the beginning of the .text section. Unfortunately doing this does not result in a proper program run on my processor.
I have verified proper program execution of my processor by writing assembly programs, loading them into MIPS assembly simulators, and verifying, instruction by instruction, that the register file and generated addressing matches. What I don't understand is why I can't get even a "helloworld" program to run by writing in c++, compiling, and loading into my "memory"? I'm not particularly knowledgeable in this field. I could really use some help figuring this out.
My understanding is that .text and .data contain everything needed for my program to run. This is obviously not the case because as I traverse the .text section, my program does not execute correctly. Is there something else I need to do with the ELF file before loading it into memory?