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

Subversion Repositories zipcpu

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

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 99 dgisselq
void    dump_file(const bool bigend, const char *fn) {
43 2 dgisselq
        const   int     NZIP = 4096;
44 70 dgisselq
        char    ln[NZIP], lb[NZIP];
45 2 dgisselq
        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 99 dgisselq
                        if (bigend) {
57
                                ZIPI bei, lei = ibuf[i];
58
                                bei  = lei&0x0ff; bei<<=8; lei>>= 8;
59
                                bei |= lei&0x0ff; bei<<=8; lei>>= 8;
60
                                bei |= lei&0x0ff; bei<<=8; lei>>= 8;
61
                                bei |= lei&0x0ff;
62
                                ibuf[i] = bei;
63
                        }
64 70 dgisselq
                        zipi_to_string(ibuf[i], ln, lb);
65 2 dgisselq
                        // printf("%s\n", ln);
66 52 dgisselq
                        printf("%08x: (0x%08x %c%c%c%c) %s\n", addr++,
67
                                ibuf[i],
68
                                isgraph((ibuf[i]>>24)&0x0ff)?((ibuf[i]>>24)&0x0ff) : '.',
69
                                isgraph((ibuf[i]>>16)&0x0ff)?((ibuf[i]>>16)&0x0ff) : '.',
70
                                isgraph((ibuf[i]>> 8)&0x0ff)?((ibuf[i]>> 8)&0x0ff) : '.',
71
                                isgraph((ibuf[i]    )&0x0ff)?((ibuf[i]    )&0x0ff) : '.',
72
                                ln);
73 70 dgisselq
                        if (lb[0])
74
                                printf("%28s%s\n", "", lb);
75 2 dgisselq
                }
76
        } fclose(fp);
77
}
78
 
79
int main(int argc, char **argv) {
80 99 dgisselq
        bool    bigend = false;
81 2 dgisselq
        for(int argn=1; argn<argc; argn++) {
82 99 dgisselq
                if (argv[argn][0] == '-') {
83
                        if (argv[argn][1] == 'B')
84
                                bigend = true;
85
                        else if (argv[argn][1] == 'L')
86
                                bigend = false;
87
                } else if(access(argv[argn], R_OK)==0)
88
                        dump_file(bigend, argv[argn]);
89 2 dgisselq
        }
90
 
91
        return 0;
92
}
93
 

powered by: WebSVN 2.1.0

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