jtag: Apply Martin Strubel JTAG implementation for ZPU
[zpu.git] / zpu / hdl / example / zpuromgen.c
blob1c7f19c5748db650395c9ff4e8af517d00fd0236
1 // zpuromgen.c
2 //
3 // Program to turn a binary file into a VHDL lookup table.
4 // by Adam Pierce
5 // 29-Feb-2008
6 //
7 // This software is free to use by anyone for any purpose.
8 //
10 #include <stdint.h>
11 #include <unistd.h>
12 #include <stdio.h>
14 typedef uint8_t BYTE;
16 main(int argc, char **argv)
18 BYTE opcode[4];
19 int fd;
20 int addr = 0;
21 ssize_t s;
23 // Check the user has given us an input file.
24 if(argc < 2)
26 printf("Usage: %s <binary_file>\n\n", argv[0]);
27 return 1;
30 // Open the input file.
31 fd = open(argv[1], 0);
32 if(fd == -1)
34 perror("File Open");
35 return 2;
38 while(1)
40 // Read 32 bits.
41 s = read(fd, opcode, 4);
42 if(s == -1)
44 perror("File read");
45 return 3;
48 if(s == 0)
49 break; // End of file.
51 // Output to STDOUT.
52 printf("%6d => x\"%02x%02x%02x%02x\",\n",
53 addr++, opcode[0], opcode[1],
54 opcode[2], opcode[3]);
57 close(fd);
58 return 0;