added #include <stdlib.h> to get rid of errors building with gcc-4.4 on ubuntu
[riscv-isa-sim.git] / riscv / riscv-isa-run.cc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "sim.h"
4 #include "htif.h"
5
6 static void help()
7 {
8 fprintf(stderr, "usage: riscv-isa-run -f <fd> -t <fd> [additional options]\n");
9 fprintf(stderr, "Options:\n");
10 fprintf(stderr, " -f <fd> From-host pipe file descriptor\n");
11 fprintf(stderr, " -t <fd> To-host pipe file descriptor\n");
12 fprintf(stderr, " -p <n> Simulate <n> processors\n");
13 fprintf(stderr, " -d Interactive debug mode\n");
14 exit(1);
15 }
16
17 int main(int argc, char** argv)
18 {
19 bool debug = false;
20 int nprocs = 1;
21 int fromhost_fd = -1, tohost_fd = -1;
22
23 // parse command-line arguments
24 for(int c; (c = getopt(argc,argv,"hdp:f:t:")) != -1; )
25 {
26 switch(c)
27 {
28 case 'd':
29 debug = true;
30 break;
31 case 'p':
32 nprocs = atoi(optarg);
33 break;
34 case 'f':
35 fromhost_fd = atoi(optarg);
36 break;
37 case 't':
38 tohost_fd = atoi(optarg);
39 break;
40 default:
41 fprintf(stderr, "unknown option: -%c", optopt);
42 case 'h':
43 help();
44 }
45 }
46
47 // we require -f and -t to be specified so we can communicate with the host
48 if(fromhost_fd == -1 || tohost_fd == -1)
49 help();
50
51 // initialize host-target interface
52 htif_t htif(tohost_fd, fromhost_fd);
53
54 // initalize simulator and run to completion
55 sim_t s(nprocs, &htif);
56 s.run(debug);
57 }