OpenCores
URL https://opencores.org/ocsvn/zpu/zpu/trunk

Subversion Repositories zpu

[/] [zpu/] [trunk/] [zpu/] [example/] [hello world/] [zpuromgen.c] - Blame information for rev 95

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 95 oharboe
// 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
//
9
// To build:
10
//
11
// gcc -Wall zpuromgen.c -o zpuromgen
12
 
13
#include <unistd.h>
14
#include <stdio.h>
15
#include <limits.h>
16
#include <sys/types.h>
17
#include <fcntl.h>
18
 
19
 
20
int main(int argc, char **argv)
21
{
22
       u_int8_t    opcode[4];
23
       int     fd;
24
       int     addr = 0;
25
       ssize_t s;
26
 
27
// Check the user has given us an input file.
28
       if(argc < 2)
29
       {
30
               printf("Usage: %s <binary_file>\n\n", argv[0]);
31
               return 1;
32
       }
33
 
34
// Open the input file.
35
       fd = open(argv[1], 0);
36
       if(fd == -1)
37
       {
38
               perror("File Open");
39
               return 2;
40
       }
41
 
42
       while(1)
43
       {
44
       // Read 32 bits.
45
               s = read(fd, opcode, 4);
46
               if(s == -1)
47
               {
48
                       perror("File read");
49
                       return 3;
50
               }
51
 
52
               if(s == 0)
53
                       break; // End of file.
54
 
55
       // Output to STDOUT.
56
               printf("%6d => x\"%02x%02x%02x%02x\",\n",
57
                      addr++, opcode[0], opcode[1],
58
                      opcode[2], opcode[3]);
59
       }
60
 
61
       close(fd);
62
       return 0;
63
}
64
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.