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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zdump.cpp] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    zdump.cpp
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU core
6
//
7
// Purpose:     Disassemble machine code files onto the stdout file.
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Tecnology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
#include <stdio.h>
37
#include <unistd.h>
38
 
39
#include "zopcodes.h"
40
 
41
void    dump_file(const char *fn) {
42
        const   int     NZIP = 4096;
43
        char    ln[NZIP];
44
        ZIPI    ibuf[NZIP];
45
        FILE    *fp;
46
        int     nr;
47
        int     lineno=0;
48
 
49
        fp = fopen(fn, "r");
50
        if (!fp)
51
                return;
52
        printf("%s:\n", fn);
53
        while((nr=fread(ibuf, sizeof(ZIPI), NZIP, fp))>0) {
54
                for(int i=0; i<nr; i++) {
55
                        zipi_to_string(ibuf[i], ln);
56
                        // printf("%s\n", ln);
57
                        printf("%08x: (0x%08x) %s\n", lineno, ibuf[i], ln);
58
                }
59
        } fclose(fp);
60
}
61
 
62
int main(int argc, char **argv) {
63
        for(int argn=1; argn<argc; argn++) {
64
                if(access(argv[argn], R_OK)==0)
65
                        dump_file(argv[argn]);
66
        }
67
 
68
        return 0;
69
}
70
 

powered by: WebSVN 2.1.0

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