| 1 |
31 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: zipstate.cpp
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
| 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 |
51 |
dgisselq |
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
|
| 19 |
31 |
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 |
|
|
// You should have received a copy of the GNU General Public License along
|
| 31 |
51 |
dgisselq |
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
| 32 |
31 |
dgisselq |
// target there if the PDF file isn't present.) If not, see
|
| 33 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 34 |
|
|
//
|
| 35 |
|
|
// 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 |
|
|
#include <stdio.h>
|
| 43 |
|
|
#include <stdlib.h>
|
| 44 |
|
|
#include <unistd.h>
|
| 45 |
|
|
#include <strings.h>
|
| 46 |
|
|
#include <ctype.h>
|
| 47 |
|
|
#include <string.h>
|
| 48 |
|
|
#include <signal.h>
|
| 49 |
|
|
#include <assert.h>
|
| 50 |
|
|
|
| 51 |
|
|
#include "port.h"
|
| 52 |
|
|
#include "llcomms.h"
|
| 53 |
|
|
#include "regdefs.h"
|
| 54 |
|
|
|
| 55 |
|
|
FPGA *m_fpga;
|
| 56 |
|
|
void closeup(int v) {
|
| 57 |
|
|
m_fpga->kill();
|
| 58 |
|
|
exit(0);
|
| 59 |
|
|
}
|
| 60 |
|
|
|
| 61 |
|
|
unsigned int cmd_read(FPGA *fpga, int r) {
|
| 62 |
|
|
const unsigned int MAXERR = 1000;
|
| 63 |
|
|
unsigned int errcount = 0;
|
| 64 |
|
|
unsigned int s;
|
| 65 |
|
|
|
| 66 |
|
|
fpga->writeio(R_ZIPCTRL, CPU_HALT|(r&0x03f));
|
| 67 |
|
|
while((((s = fpga->readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount<MAXERR))
|
| 68 |
|
|
errcount++;
|
| 69 |
|
|
if (errcount >= MAXERR) {
|
| 70 |
|
|
printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%02x)\n",
|
| 71 |
|
|
errcount, r);
|
| 72 |
|
|
printf("ZIPCTRL = 0x%08x", s);
|
| 73 |
36 |
dgisselq |
if ((s & 0x0200)==0) printf(" BUSY");
|
| 74 |
31 |
dgisselq |
if (s & 0x0400) printf(" HALTED");
|
| 75 |
|
|
if ((s & 0x03000)==0x01000)
|
| 76 |
|
|
printf(" SW-HALT");
|
| 77 |
|
|
else {
|
| 78 |
|
|
if (s & 0x01000) printf(" SLEEPING");
|
| 79 |
|
|
if (s & 0x02000) printf(" GIE(UsrMode)");
|
| 80 |
|
|
} printf("\n");
|
| 81 |
|
|
exit(EXIT_FAILURE);
|
| 82 |
|
|
} return fpga->readio(R_ZIPDATA);
|
| 83 |
|
|
}
|
| 84 |
|
|
|
| 85 |
|
|
void usage(void) {
|
| 86 |
|
|
printf("USAGE: zipstate\n");
|
| 87 |
|
|
}
|
| 88 |
|
|
|
| 89 |
|
|
int main(int argc, char **argv) {
|
| 90 |
|
|
bool long_state = false;
|
| 91 |
|
|
unsigned int v;
|
| 92 |
51 |
dgisselq |
int skp;
|
| 93 |
31 |
dgisselq |
|
| 94 |
|
|
skp=1;
|
| 95 |
|
|
for(int argn=0; argn<argc-skp; argn++) {
|
| 96 |
|
|
if (argv[argn+skp][0] == '-') {
|
| 97 |
|
|
if (argv[argn+skp][1] == 'l')
|
| 98 |
|
|
long_state = true;
|
| 99 |
|
|
skp++; argn--;
|
| 100 |
|
|
} else
|
| 101 |
|
|
argv[argn] = argv[argn+skp];
|
| 102 |
|
|
} argc -= skp;
|
| 103 |
|
|
|
| 104 |
|
|
FPGAOPEN(m_fpga);
|
| 105 |
|
|
|
| 106 |
|
|
if (!long_state) {
|
| 107 |
|
|
v = m_fpga->readio(R_ZIPCTRL);
|
| 108 |
|
|
|
| 109 |
|
|
printf("0x%08x: ", v);
|
| 110 |
|
|
if (v & 0x0080) printf("PINT ");
|
| 111 |
|
|
// if (v & 0x0100) printf("STEP "); // self resetting
|
| 112 |
36 |
dgisselq |
if((v & 0x00200)==0) printf("BUSY ");
|
| 113 |
31 |
dgisselq |
if (v & 0x00400) printf("HALTED ");
|
| 114 |
|
|
if((v & 0x03000)==0x01000) {
|
| 115 |
|
|
printf("SW-HALT");
|
| 116 |
|
|
} else {
|
| 117 |
|
|
if (v & 0x01000) printf("SLEEPING ");
|
| 118 |
|
|
if (v & 0x02000) printf("GIE(UsrMode) ");
|
| 119 |
|
|
}
|
| 120 |
|
|
// if (v & 0x0800) printf("CLR-CACHE ");
|
| 121 |
|
|
printf("\n");
|
| 122 |
|
|
} else {
|
| 123 |
|
|
printf("Reading the long-state ...\n");
|
| 124 |
|
|
for(int i=0; i<14; i++) {
|
| 125 |
|
|
printf("sR%-2d: 0x%08x ", i, cmd_read(m_fpga, i));
|
| 126 |
|
|
if ((i&3)==3)
|
| 127 |
|
|
printf("\n");
|
| 128 |
|
|
} printf("sCC : 0x%08x ", cmd_read(m_fpga, 14));
|
| 129 |
|
|
printf("sPC : 0x%08x ", cmd_read(m_fpga, 15));
|
| 130 |
|
|
printf("\n\n");
|
| 131 |
|
|
|
| 132 |
|
|
for(int i=0; i<14; i++) {
|
| 133 |
|
|
printf("uR%-2d: 0x%08x ", i, cmd_read(m_fpga, i+16));
|
| 134 |
|
|
if ((i&3)==3)
|
| 135 |
|
|
printf("\n");
|
| 136 |
|
|
} printf("uCC : 0x%08x ", cmd_read(m_fpga, 14+16));
|
| 137 |
|
|
printf("uPC : 0x%08x ", cmd_read(m_fpga, 15+16));
|
| 138 |
|
|
printf("\n\n");
|
| 139 |
|
|
}
|
| 140 |
|
|
|
| 141 |
|
|
delete m_fpga;
|
| 142 |
|
|
}
|
| 143 |
|
|
|