[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  Schedule::Load
  SVN::S4
  Synopsys-modes
  SystemPerl
  Verilog-Pli
  Voneline
  Vregs
General Info
  Papers

Load Array With Binary Contents

Added by Dan Snyder over 1 year ago

I've written some C++ code, compiled it into a binary and I now want to load the instructions generated into an array contained within my verilator C++ file. I'm simulating a simple MIPS I structure and I would like to test it with a realistic instruction memory. Any ideas about how to go about doing this? I'm quite new at this so any incite would be helpful.


Replies (6)

RE: Load Array With Binary Contents - Added by Wilson Snyder over 1 year ago

You can just use standard verilog, for example initial $readmemh(filename, mem_array, 0, max_index);

RE: Load Array With Binary Contents - Added by Dan Snyder over 1 year ago

Thanks, I'll definitely capture my binary instructions that way.

RE: Load Array With Binary Contents - Added by Dan Snyder over 1 year ago

Here's a more specific description of my issue:

I'm trying to figure out how to load a program written in C++ onto a processor I've designed. The processor uses the MIPS I ISA and I wrote it using Verilator. This being said I have a C++ file that instantiates my processor module as an object.

The C++ file contains 2 arrays, one that represents instruction memory and another that represents data memory. I want to fill the instruction memory array with the instructions in my compiled binary file (made from a simple test program written in C++). To do this I require some knowledge of the MIPS ABI. I have the generic System V ABI and the processor specific MIPS32 ABI documents and I am attempting to determine where exactly in my binary file my program resides.

I need help figuring out exactly what instructions in my binary file I need and how I should use them. Can anyone supply me with some incite as to how I go about sorting through the binary I generated? I know I need the instructions that represent my sample program but what else do I need? The whole set of instructions or just a subset?

This isn't a Verilator question exactly so I don't expect it to be answered but if you have the time to, I'd greatly appreciate any help/direction I can get.

RE: Load Array With Binary Contents - Added by Wilson Snyder over 1 year ago

You need an "ELF loader", that takes all the "loader sections" and puts them into your array, or puts them into a hex file format that then gets to your array. Do a little googling and if you can't find anything you'll need to read up on the ELF format and sections, and use "libelf" or similar to pull out what you need.

RE: Load Array With Binary Contents - Added by Dan Snyder over 1 year ago

Thanks for the help, I ended up writing a quick C++ program that would take the output of readelf, extract the .text and .data segments and then convert each instruction to a decimal number to be loaded into my instruction array. 2 step process but it works okay.

RE: Load Array With Binary Contents - Added by Wilson Snyder over 1 year ago

Glad I could help. If you want to avoid two steps you can hide the first by using popen() instead of fopen() and thus your C program can call readelf itself.

(1-6/6)