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

Subversion Repositories xulalx25soc

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

Go to most recent revision | 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
// Copyright (C) 2015, Gisselquist Technology, LLC
19
//
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
// License:     GPL, v3, as defined and found on www.gnu.org,
31
//              http://www.gnu.org/licenses/gpl.html
32
//
33
//
34
////////////////////////////////////////////////////////////////////////////////
35
//
36
//
37
//
38
#include <stdio.h>
39
#include <stdlib.h>
40
#include <unistd.h>
41
#include <strings.h>
42
#include <ctype.h>
43
#include <string.h>
44
#include <signal.h>
45
#include <assert.h>
46
 
47
#include "llcomms.h"
48
#include "usbi.h"
49
#include "port.h"
50
#include "regdefs.h"
51
 
52
FPGA    *m_fpga;
53
void    closeup(int v) {
54
        m_fpga->kill();
55
        exit(0);
56
}
57
 
58
unsigned int    cmd_read(FPGA *fpga, int r) {
59
        const unsigned int      MAXERR = 1000;
60
        unsigned int    errcount = 0;
61
        unsigned int    s;
62
 
63
        fpga->writeio(R_ZIPCTRL, CPU_HALT|(r&0x03f));
64
        while((((s = fpga->readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount<MAXERR))
65
                errcount++;
66
        if (errcount >= MAXERR) {
67
                printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%02x)\n",
68
                        errcount, r);
69
                printf("ZIPCTRL = 0x%08x", s);
70
                if ((s & 0x0200)==0) printf(" STALL");
71
                if  (s & 0x0400)     printf(" HALTED");
72
                if ((s & 0x03000)==0x01000)
73
                        printf(" SW-HALT");
74
                else {
75
                        if (s & 0x01000) printf(" SLEEPING");
76
                        if (s & 0x02000) printf(" GIE(UsrMode)");
77
                } printf("\n");
78
                exit(EXIT_FAILURE);
79
        } return fpga->readio(R_ZIPDATA);
80
}
81
 
82
void    usage(void) {
83
        printf("USAGE: zipstate\n");
84
}
85
 
86
int main(int argc, char **argv) {
87
        int     skp=0, port = FPGAPORT;
88
        bool    use_usb = true, long_state = false;
89
        unsigned int    v;
90
 
91
        skp=1;
92
        for(int argn=0; argn<argc-skp; argn++) {
93
                if (argv[argn+skp][0] == '-') {
94
                        if (argv[argn+skp][1] == 'u')
95
                                use_usb = true;
96
                        else if (argv[argn+skp][1] == 'l')
97
                                long_state = true;
98
                        else if (argv[argn+skp][1] == 'p') {
99
                                use_usb = false;
100
                                if (isdigit(argv[argn+skp][2]))
101
                                        port = atoi(&argv[argn+skp][2]);
102
                        }
103
                        skp++; argn--;
104
                } else
105
                        argv[argn] = argv[argn+skp];
106
        } argc -= skp;
107
 
108
        if (use_usb)
109
                m_fpga = new FPGA(new USBI());
110
        else
111
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
112
 
113
        if (!long_state) {
114
                v = m_fpga->readio(R_ZIPCTRL);
115
 
116
                printf("0x%08x: ", v);
117
                if (v & 0x0080) printf("PINT ");
118
                // if (v & 0x0100) printf("STEP "); // self resetting
119
                if((v & 0x00200)==0) printf("STALL ");
120
                if (v & 0x00400) printf("HALTED ");
121
                if((v & 0x03000)==0x01000) {
122
                        printf("SW-HALT");
123
                } else {
124
                        if (v & 0x01000) printf("SLEEPING ");
125
                        if (v & 0x02000) printf("GIE(UsrMode) ");
126
                }
127
                // if (v & 0x0800) printf("CLR-CACHE ");
128
                printf("\n");
129
        } else {
130
                printf("Reading the long-state ...\n");
131
                for(int i=0; i<14; i++) {
132
                        printf("sR%-2d: 0x%08x ", i, cmd_read(m_fpga, i));
133
                        if ((i&3)==3)
134
                                printf("\n");
135
                } printf("sCC : 0x%08x ", cmd_read(m_fpga, 14));
136
                printf("sPC : 0x%08x ", cmd_read(m_fpga, 15));
137
                printf("\n\n");
138
 
139
                for(int i=0; i<14; i++) {
140
                        printf("uR%-2d: 0x%08x ", i, cmd_read(m_fpga, i+16));
141
                        if ((i&3)==3)
142
                                printf("\n");
143
                } printf("uCC : 0x%08x ", cmd_read(m_fpga, 14+16));
144
                printf("uPC : 0x%08x ", cmd_read(m_fpga, 15+16));
145
                printf("\n\n");
146
        }
147
 
148
        delete  m_fpga;
149
}
150
 

powered by: WebSVN 2.1.0

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