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

Subversion Repositories zipcpu

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

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 69 dgisselq
//              Gisselquist Technology, LLC
11 2 dgisselq
//
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 52 dgisselq
#include <ctype.h>
39 2 dgisselq
 
40
#include "zopcodes.h"
41
 
42
void    dump_file(const char *fn) {
43
        const   int     NZIP = 4096;
44
        char    ln[NZIP];
45
        ZIPI    ibuf[NZIP];
46
        FILE    *fp;
47
        int     nr;
48 12 dgisselq
        int     addr=0x08000;
49 2 dgisselq
 
50
        fp = fopen(fn, "r");
51
        if (!fp)
52
                return;
53
        printf("%s:\n", fn);
54
        while((nr=fread(ibuf, sizeof(ZIPI), NZIP, fp))>0) {
55
                for(int i=0; i<nr; i++) {
56
                        zipi_to_string(ibuf[i], ln);
57
                        // printf("%s\n", ln);
58 52 dgisselq
                        printf("%08x: (0x%08x %c%c%c%c) %s\n", addr++,
59
                                ibuf[i],
60
                                isgraph((ibuf[i]>>24)&0x0ff)?((ibuf[i]>>24)&0x0ff) : '.',
61
                                isgraph((ibuf[i]>>16)&0x0ff)?((ibuf[i]>>16)&0x0ff) : '.',
62
                                isgraph((ibuf[i]>> 8)&0x0ff)?((ibuf[i]>> 8)&0x0ff) : '.',
63
                                isgraph((ibuf[i]    )&0x0ff)?((ibuf[i]    )&0x0ff) : '.',
64
                                ln);
65 2 dgisselq
                }
66
        } fclose(fp);
67
}
68
 
69
int main(int argc, char **argv) {
70
        for(int argn=1; argn<argc; argn++) {
71
                if(access(argv[argn], R_OK)==0)
72
                        dump_file(argv[argn]);
73
        }
74
 
75
        return 0;
76
}
77
 

powered by: WebSVN 2.1.0

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