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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sim/] [verilator/] [pdump.cpp] - Blame information for rev 209

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 204 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    pdump.cpp
4
//
5 209 dgisselq
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6 204 dgisselq
//
7
// Purpose:     Disassemble machine code files onto the stdout file.  Unlike
8
//              the zip-objdump program that is part of the binutils suite, this
9
//      program takes the pfile.bin output of the bench test suite and adds
10
//      profiling information to the output.  It's useful for finding out where,
11
//      at least in simulation, your time is being spent.  It can also be used,
12
//      after the fact, to get a trace of what instructions the CPU executed.
13
//
14
// Creator:     Dan Gisselquist, Ph.D.
15
//              Gisselquist Technology, LLC
16
//
17
////////////////////////////////////////////////////////////////////////////////
18
//
19
// Copyright (C) 2015,2017, Gisselquist Technology, LLC
20
//
21
// This program is free software (firmware): you can redistribute it and/or
22
// modify it under the terms of  the GNU General Public License as published
23
// by the Free Software Foundation, either version 3 of the License, or (at
24
// your option) any later version.
25
//
26
// This program is distributed in the hope that it will be useful, but WITHOUT
27
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
28
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29
// for more details.
30
//
31
// You should have received a copy of the GNU General Public License along
32 209 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
33 204 dgisselq
// target there if the PDF file isn't present.)  If not, see
34
// <http://www.gnu.org/licenses/> for a copy.
35
//
36
// License:     GPL, v3, as defined and found on www.gnu.org,
37
//              http://www.gnu.org/licenses/gpl.html
38
//
39
//
40
////////////////////////////////////////////////////////////////////////////////
41 209 dgisselq
//
42
//
43 204 dgisselq
#include <algorithm>
44 209 dgisselq
#include <map>
45 204 dgisselq
#include <stdio.h>
46
#include <unistd.h>
47
#include <ctype.h>
48
 
49
#include "zipelf.h"
50
#include "zopcodes.h"
51
#include "byteswap.h"
52
 
53
typedef uint32_t        ZIPI;   // A ZipCPU instruction word
54
 
55
typedef struct  { unsigned clks, addr; } ALT;
56
bool    altcmp(const ALT &a, const ALT &b) {
57
        return a.clks < b.clks;
58
}
59
 
60 209 dgisselq
typedef struct { unsigned clks, hits, addr; } insn_stat;
61 204 dgisselq
 
62 209 dgisselq
typedef std::map<unsigned, insn_stat *> vcd_profile;
63
 
64 204 dgisselq
void    dump_file(const char *fn) {
65
        const   int     NZIP = 4096;
66
        char    lna[NZIP], lnb[NZIP];
67
        FILE    *pf;
68 209 dgisselq
        unsigned        addr=0x0100000;
69
        vcd_profile     vp;
70 204 dgisselq
 
71
        pf = fopen("pfile.bin","rb");
72
        if (pf) {
73 209 dgisselq
                unsigned        buf[2];
74 204 dgisselq
                while(2 == fread(buf, sizeof(unsigned), 2, pf)) {
75 209 dgisselq
                        addr = buf[0];
76
                        if (vp.count(addr)>0) {
77
                                vp[addr]->hits++;
78
                                vp[addr]->clks += buf[1];
79
                        } else {
80
                                insn_stat       *is;
81
 
82
                                is = new insn_stat;
83
                                is->hits = 1;
84
                                is->clks = buf[1];
85
                                is->addr = addr;
86
                                vp[addr] = is;
87
                        }
88 204 dgisselq
                }
89
        }
90
 
91
        printf("%s:\n", fn);
92
        if (iself(fn)) {
93
                ELFSECTION **secpp=NULL, *secp;
94 209 dgisselq
                double          cpi;
95
                unsigned        entry;
96
 
97 204 dgisselq
                elfread(fn, entry, secpp);
98
                for(int i=0; secpp[i]->m_len; i++) {
99
                        secp = secpp[i];
100
                        for(unsigned j=0; j<secp->m_len; j+=4) {
101
                                uint32_t        w, a;
102
 
103 209 dgisselq
                                a = secp->m_vaddr+j;
104
                                w = buildword((const unsigned char *)&secp->m_data[j]);
105 204 dgisselq
                                zipi_to_double_string(a, w, lna, lnb);
106
                                // printf("%s\n", ln);
107 209 dgisselq
                                printf("%08x: (0x%08x %c%c%c%c) ", a, w,
108 204 dgisselq
                                        isgraph((w>>24)&0x0ff)?((w>>24)&0x0ff) : '.',
109
                                        isgraph((w>>16)&0x0ff)?((w>>16)&0x0ff) : '.',
110
                                        isgraph((w>> 8)&0x0ff)?((w>> 8)&0x0ff) : '.',
111
                                        isgraph((w    )&0x0ff)?((w    )&0x0ff) : '.'
112
                                        );
113 209 dgisselq
                                if (vp.count(a)>0) {
114
                                        insn_stat *is = vp[a];
115
                                        cpi = is->clks / (double)is->hits;
116
 
117
                                        printf("%8d %8d %4.1f ", is->hits, is->clks, cpi);
118
                                } else
119
                                        printf("%23s", "");
120
 
121 204 dgisselq
                                printf("%s\n", lna);
122
                                if (lnb[0])
123 209 dgisselq
                                        printf("-%50s%s\n", "", lnb);
124 204 dgisselq
                        }
125
                }
126
        }
127
}
128
 
129
int main(int argc, char **argv) {
130
        if (argc <= 1)
131
                printf("USAGE: pdump <dump-file> | less\n");
132
        for(int argn=1; argn<argc; argn++) {
133
                if(access(argv[argn], R_OK)==0)
134
                        dump_file(argv[argn]);
135
        }
136
 
137
        return 0;
138
}
139
 

powered by: WebSVN 2.1.0

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