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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [zipstate.cpp] - Blame information for rev 118

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    zipstate.v
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     To get a quick (understandable) peek at what the ZipCPU
8
//              is up to without stopping the CPU.  This is basically
9
//      identical to a "wbregs cpu" command, save that the bit fields of the
10
//      result are broken out into something more human readable.
11
//
12
//
13
// Creator:     Dan Gisselquist, Ph.D.
14
//              Gisselquist Technology, LLC
15
//
16
////////////////////////////////////////////////////////////////////////////////
17
//
18 118 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
19 17 dgisselq
//
20
// This program is free software (firmware): you can redistribute it and/or
21
// modify it under the terms of  the GNU General Public License as published
22
// by the Free Software Foundation, either version 3 of the License, or (at
23
// your option) any later version.
24
//
25
// This program is distributed in the hope that it will be useful, but WITHOUT
26
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
27
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28
// for more details.
29
//
30 118 dgisselq
// You should have received a copy of the GNU General Public License along
31
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
32
// target there if the PDF file isn't present.)  If not, see
33
// <http://www.gnu.org/licenses/> for a copy.
34
//
35 17 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
36
//              http://www.gnu.org/licenses/gpl.html
37
//
38
//
39
////////////////////////////////////////////////////////////////////////////////
40
//
41
//
42
//
43
#include <stdio.h>
44
#include <stdlib.h>
45
#include <unistd.h>
46
#include <strings.h>
47
#include <ctype.h>
48
#include <string.h>
49
#include <signal.h>
50
#include <assert.h>
51
 
52
#include "llcomms.h"
53
#include "usbi.h"
54
#include "port.h"
55
#include "regdefs.h"
56
 
57
FPGA    *m_fpga;
58
void    closeup(int v) {
59
        m_fpga->kill();
60
        exit(0);
61
}
62
 
63
unsigned int    cmd_read(FPGA *fpga, int r) {
64
        const unsigned int      MAXERR = 1000;
65
        unsigned int    errcount = 0;
66
        unsigned int    s;
67
 
68
        fpga->writeio(R_ZIPCTRL, CPU_HALT|(r&0x03f));
69
        while((((s = fpga->readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount<MAXERR))
70
                errcount++;
71
        if (errcount >= MAXERR) {
72
                printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%02x)\n",
73
                        errcount, r);
74
                printf("ZIPCTRL = 0x%08x", s);
75 118 dgisselq
                if ((s & 0x0200)==0) printf(" BUSY");
76 17 dgisselq
                if  (s & 0x0400)     printf(" HALTED");
77
                if ((s & 0x03000)==0x01000)
78
                        printf(" SW-HALT");
79
                else {
80
                        if (s & 0x01000) printf(" SLEEPING");
81
                        if (s & 0x02000) printf(" GIE(UsrMode)");
82
                } printf("\n");
83
                exit(EXIT_FAILURE);
84
        } return fpga->readio(R_ZIPDATA);
85
}
86
 
87
void    usage(void) {
88
        printf("USAGE: zipstate\n");
89
}
90
 
91
int main(int argc, char **argv) {
92
        int     skp=0, port = FPGAPORT;
93
        bool    use_usb = true, long_state = false;
94
        unsigned int    v;
95
 
96
        skp=1;
97
        for(int argn=0; argn<argc-skp; argn++) {
98
                if (argv[argn+skp][0] == '-') {
99
                        if (argv[argn+skp][1] == 'u')
100
                                use_usb = true;
101
                        else if (argv[argn+skp][1] == 'l')
102
                                long_state = true;
103
                        else if (argv[argn+skp][1] == 'p') {
104
                                use_usb = false;
105
                                if (isdigit(argv[argn+skp][2]))
106
                                        port = atoi(&argv[argn+skp][2]);
107
                        }
108
                        skp++; argn--;
109
                } else
110
                        argv[argn] = argv[argn+skp];
111
        } argc -= skp;
112
 
113
        if (use_usb)
114
                m_fpga = new FPGA(new USBI());
115
        else
116
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
117
 
118
        if (!long_state) {
119
                v = m_fpga->readio(R_ZIPCTRL);
120
 
121
                printf("0x%08x: ", v);
122
                if (v & 0x0080) printf("PINT ");
123
                // if (v & 0x0100) printf("STEP "); // self resetting
124 118 dgisselq
                if((v & 0x00200)==0) printf("BUSY ");
125 17 dgisselq
                if (v & 0x00400) printf("HALTED ");
126
                if((v & 0x03000)==0x01000) {
127
                        printf("SW-HALT");
128
                } else {
129
                        if (v & 0x01000) printf("SLEEPING ");
130
                        if (v & 0x02000) printf("GIE(UsrMode) ");
131
                }
132
                // if (v & 0x0800) printf("CLR-CACHE ");
133
                printf("\n");
134
        } else {
135
                printf("Reading the long-state ...\n");
136
                for(int i=0; i<14; i++) {
137
                        printf("sR%-2d: 0x%08x ", i, cmd_read(m_fpga, i));
138
                        if ((i&3)==3)
139
                                printf("\n");
140
                } printf("sCC : 0x%08x ", cmd_read(m_fpga, 14));
141
                printf("sPC : 0x%08x ", cmd_read(m_fpga, 15));
142
                printf("\n\n");
143
 
144
                for(int i=0; i<14; i++) {
145
                        printf("uR%-2d: 0x%08x ", i, cmd_read(m_fpga, i+16));
146
                        if ((i&3)==3)
147
                                printf("\n");
148
                } printf("uCC : 0x%08x ", cmd_read(m_fpga, 14+16));
149
                printf("uPC : 0x%08x ", cmd_read(m_fpga, 15+16));
150
                printf("\n\n");
151
        }
152
 
153
        delete  m_fpga;
154
}
155
 

powered by: WebSVN 2.1.0

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