1 // See LICENSE for license details.
2 
3 #include <iostream>
4 #include "htif_hexwriter.h"
5 #include "memif.h"
6 #include "elfloader.h"
7 
main(int argc,char ** argv)8 int main(int argc, char** argv)
9 {
10   if(argc < 4 || argc > 5)
11   {
12     std::cerr << "Usage: " << argv[0] << " <width> <depth> <elf_file> [base]" << std::endl;
13     return 1;
14   }
15 
16   unsigned width = atoi(argv[1]);
17   if(width == 0 || (width & (width-1)))
18   {
19     std::cerr << "width must be a power of 2" << std::endl;
20     return 1;
21   }
22 
23   unsigned long long int base = 0;
24   if(argc==5) {
25     base = atoll(argv[4]);
26     if(base & (width-1))
27     {
28       std::cerr << "base must be divisible by width" << std::endl;
29       return 1;
30     }
31   }
32 
33   unsigned depth = atoi(argv[2]);
34   if(depth == 0 || (depth & (depth-1)))
35   {
36     std::cerr << "depth must be a power of 2" << std::endl;
37     return 1;
38   }
39 
40   htif_hexwriter_t htif(base, width, depth);
41   memif_t memif(&htif);
42   reg_t entry;
43   load_elf(argv[3], &memif, &entry);
44   std::cout << htif;
45 
46   return 0;
47 }
48