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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [cpuscope.cpp] - Blame information for rev 113

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 105 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 5 dgisselq
//
3
// Filename:    cpuscope.cpp
4
//
5 105 dgisselq
// Project:     XuLA2-LX25 SoC based upon the ZipCPU
6 5 dgisselq
//
7
// Purpose:     To read out, and decompose, the results of the wishbone scope
8
//              as applied to the ICAPE2 interaction.
9
//
10 105 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12 5 dgisselq
//
13 105 dgisselq
////////////////////////////////////////////////////////////////////////////////
14 5 dgisselq
//
15 105 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
16 5 dgisselq
//
17 105 dgisselq
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// You should have received a copy of the GNU General Public License along
28
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
29
// target there if the PDF file isn't present.)  If not, see
30
// <http://www.gnu.org/licenses/> for a copy.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
//
38
//
39 5 dgisselq
#include <stdio.h>
40
#include <stdlib.h>
41
#include <unistd.h>
42
#include <strings.h>
43
#include <ctype.h>
44
#include <string.h>
45
#include <signal.h>
46
#include <assert.h>
47
 
48
#include "usbi.h"
49
#include "port.h"
50
#include "llcomms.h"
51
#include "regdefs.h"
52 113 dgisselq
#include "scopecls.h"
53 5 dgisselq
 
54
#define WBSCOPE         R_CPUSCOPE
55
#define WBSCOPEDATA     R_CPUSCOPED
56
 
57
#include "zopcodes.h"
58
 
59
FPGA    *m_fpga;
60
void    closeup(int v) {
61
        m_fpga->kill();
62
        exit(0);
63
}
64
 
65
unsigned brev(const unsigned v) {
66
        unsigned int r, a;
67
        a = v;
68
        r = 0;
69
        for(int i=0; i<8; i++) {
70
                r <<= 1;
71
                r |= (a&1);
72
                a >>= 1;
73
        } return r;
74
}
75
 
76
unsigned wrev(const unsigned v) {
77
        unsigned r = brev(v&0x0ff);
78
        r |= brev((v>>8)&0x0ff)<<8;
79
        return r;
80
}
81
 
82 113 dgisselq
const char *opcodestr[] = {
83
        "SUB","AND","ADD","OR","XOR","LSR","LSL","ASR",
84
        "MPY","LDILO","MPYUHI","MPYSHI","BREV","POPC","ROL","MOV",
85
        "CMP","TEST","LOD","STO","DIVU","DIVS","LDI","LDI",
86
        "NOOP","BREAK","LOCK","(rsrvd)","(rsrvd)","(rsrvd)","(rsrvd)","(rsrvd)"
87
};
88
const char *regstr[] = {
89
        "R0","R1","R2","R3","R4","R5","R6","R7","R8","R9","RA","RB","RC",
90
        "SP","CC","PC"
91
};
92
 
93
class   CPUSCOPE : public SCOPE {
94
public:
95
        CPUSCOPE(FPGA *fpga, unsigned addr, bool vecread)
96
                : SCOPE(fpga, addr, false, false) {};
97
        ~CPUSCOPE(void) {}
98
        virtual void    decode(DEVBUS::BUSW val) const {
99
                int     i_wb_err, gie, alu_illegal, newpc, mem_busy, stb, we,
100
                        maddr, ins, pfval, alu_pc;
101
                int     pfcyc, pfstb, pfaddr;
102
 
103
                i_wb_err    = (val>>31)&1;
104
                gie         = (val>>30)&1;
105
                alu_illegal = (val>>29)&1;
106
                newpc       = (val>>28)&1;
107
                mem_busy    = (val>>27)&1;
108
                stb         = (val>>26)&1;
109
                we          = (val>>25)&1;
110
                maddr       = (val>>16)&0x01ff;
111
                ins         = (val>>16)&0x07ff;
112
                pfval       = (val>>15)&1;
113
                pfcyc       = (val>>14)&1;
114
                pfstb       = (val>>13)&1;
115
                pfaddr      = (val & 0x1fff);
116
                alu_pc      = (val & 0x7fff);
117
 
118
                printf("%s%s%s%s%s ",
119
                        (i_wb_err)?"E ":"  ",
120
                        (gie)?"GIE":"   ",
121
                        (alu_illegal)?"ILL":"   ",
122
                        (newpc)?"NPC":"   ",
123
                        (mem_busy)?"MBSY":"    ");
124
                if (mem_busy)
125
                        printf("M:%s%s@..%4x", (stb)?"STB":"   ",(we)?"W":"R",
126
                                maddr);
127
                else {
128
                        int     inreg = (ins>>6)&0x0f;
129
                        int     opcode = ((ins>>1)&0x1f);
130
                        const char *incode = opcodestr[opcode];
131
                        printf("I:%03x %5s,%s", (ins<<1), incode, regstr[inreg]);
132
                }
133
 
134
                if (pfval)
135
                        printf(" V: %04x%4s", alu_pc, "");
136
                else
137
                        printf(" %s%s@%04x",
138
                                (pfcyc)?"CYC":"   ",
139
                                (pfstb)?"STB":"   ",
140
                                pfaddr);
141
        }
142
};
143
 
144 5 dgisselq
int main(int argc, char **argv) {
145 105 dgisselq
        int     skp=0, port = FPGAPORT;
146
        bool    use_usb = true;
147 5 dgisselq
 
148 105 dgisselq
        skp=1;
149
        for(int argn=0; argn<argc-skp; argn++) {
150
                if (argv[argn+skp][0] == '-') {
151
                        if (argv[argn+skp][1] == 'u')
152
                                use_usb = true;
153
                        else if (argv[argn+skp][1] == 'p') {
154
                                use_usb = false;
155
                                if (isdigit(argv[argn+skp][2]))
156
                                        port = atoi(&argv[argn+skp][2]);
157
                        }
158
                        skp++; argn--;
159
                } else
160
                        argv[argn] = argv[argn+skp];
161
        } argc -= skp;
162
 
163
        if (use_usb)
164
                m_fpga = new FPGA(new USBI());
165
        else
166
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
167
 
168 5 dgisselq
        signal(SIGSTOP, closeup);
169
        signal(SIGHUP, closeup);
170
 
171 113 dgisselq
        CPUSCOPE *scope = new CPUSCOPE(m_fpga, WBSCOPE, false);
172
        if (!scope->ready()) {
173 5 dgisselq
                printf("Scope is not yet ready:\n");
174 113 dgisselq
                scope->decode_control();
175
        } else
176
                scope->read();
177 5 dgisselq
        delete  m_fpga;
178
}
179
 

powered by: WebSVN 2.1.0

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