aboutsummaryrefslogtreecommitdiff
path: root/fesvr/elf2hex.cc
blob: 2638823b0870452a481b1a62fc41bf78a50bdad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// See LICENSE for license details.

#include <iostream>
#include "htif_hexwriter.h"
#include "memif.h"
#include "elfloader.h"

int main(int argc, char** argv)
{
  if(argc < 4 || argc > 5)
  {
    std::cerr << "Usage: " << argv[0] << " <width> <depth> <elf_file> [base]" << std::endl;
    return 1;
  }

  unsigned width = atoi(argv[1]);
  if(width == 0 || (width & (width-1)))
  {
    std::cerr << "width must be a power of 2" << std::endl;
    return 1;
  }

  unsigned long long int base = 0;
  if(argc==5) {
    base = atoll(argv[4]);
    if(base & (width-1))
    {
      std::cerr << "base must be divisible by width" << std::endl;
      return 1;
    }
  }

  unsigned depth = atoi(argv[2]);
  if(depth == 0 || (depth & (depth-1)))
  {
    std::cerr << "depth must be a power of 2" << std::endl;
    return 1;
  }

  htif_hexwriter_t htif(base, width, depth);
  memif_t memif(&htif);
  reg_t entry;
  load_elf(argv[3], &memif, &entry, 0);
  std::cout << htif;

  return 0;
}