| 1 |
31 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: cpuscope.cpp
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: XuLA2-LX25 SoC based upon the ZipCPU
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose: To read out, and decompose, the results of the wishbone scope
|
| 8 |
|
|
// as applied to the ZipCPU internal operation.
|
| 9 |
|
|
//
|
| 10 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 11 |
|
|
// Gisselquist Technology, LLC
|
| 12 |
|
|
//
|
| 13 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 14 |
|
|
//
|
| 15 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
| 16 |
|
|
//
|
| 17 |
|
|
// 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 |
|
|
#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 "port.h"
|
| 49 |
|
|
#include "llcomms.h"
|
| 50 |
|
|
#include "regdefs.h"
|
| 51 |
|
|
#include "scopecls.h"
|
| 52 |
|
|
|
| 53 |
|
|
#define WBSCOPE R_CPUSCOPE
|
| 54 |
|
|
#define WBSCOPEDATA R_CPUSCOPED
|
| 55 |
|
|
|
| 56 |
|
|
FPGA *m_fpga;
|
| 57 |
|
|
void closeup(int v) {
|
| 58 |
|
|
m_fpga->kill();
|
| 59 |
|
|
exit(0);
|
| 60 |
|
|
}
|
| 61 |
|
|
|
| 62 |
|
|
const char *regstr[] = {
|
| 63 |
|
|
"R0","R1","R2","R3","R4","R5","R6","R7","R8","R9","RA","RB","RC",
|
| 64 |
|
|
"SP","CC","PC"
|
| 65 |
|
|
};
|
| 66 |
|
|
|
| 67 |
|
|
class CPUSCOPE : public SCOPE {
|
| 68 |
|
|
public:
|
| 69 |
|
|
CPUSCOPE(FPGA *fpga, unsigned addr, bool vecread)
|
| 70 |
|
|
: SCOPE(fpga, addr, false, false) {};
|
| 71 |
|
|
~CPUSCOPE(void) {}
|
| 72 |
|
|
virtual void decode(DEVBUS::BUSW val) const {
|
| 73 |
|
|
if (val & 0x80000000)
|
| 74 |
|
|
printf("TRIG ");
|
| 75 |
|
|
else
|
| 76 |
|
|
printf(" ");
|
| 77 |
|
|
if ((val & 0x40000000)==0) {
|
| 78 |
|
|
printf("%s <- 0x.%08x", regstr[(val>>32-6)&0xf], val&0x03ffffff);
|
| 79 |
|
|
} else if ((val & 0x60000000)==0x60000000) {
|
| 80 |
|
|
if (val&0x08000000)
|
| 81 |
|
|
printf("MEM-W[0x........] <- 0x.%07x %s",
|
| 82 |
|
|
(val&0x07ffffff),
|
| 83 |
|
|
(val&0x10000000)?"(GBL)":"");
|
| 84 |
|
|
else
|
| 85 |
|
|
printf("MEM-R[0x.%07x] -> (Not Givn) %s",
|
| 86 |
|
|
(val&0x07ffffff),
|
| 87 |
|
|
(val&0x10000000)?"(GBL)":"");
|
| 88 |
|
|
} else if ((val & 0x70000000)==0x40000000)
|
| 89 |
|
|
printf("JMP 0x%08x", (val&0x0fffffff));
|
| 90 |
|
|
else {
|
| 91 |
|
|
int master, halt, brk, sleep, gie, buserr, trap,
|
| 92 |
|
|
ill, clri, pfv, pfi, dcdce, dcdv, dcdstall,
|
| 93 |
|
|
opce, opvalid, oppipe, aluce, alubsy, aluwr,
|
| 94 |
|
|
aluill, aluwrf, memce, memwe, membsy;
|
| 95 |
|
|
master = (val>>27)&1;
|
| 96 |
|
|
halt = (val>>26)&1;
|
| 97 |
|
|
brk = (val>>25)&1;
|
| 98 |
|
|
sleep = (val>>24)&1;
|
| 99 |
|
|
gie = (val>>23)&1;
|
| 100 |
|
|
buserr = (val>>22)&1;
|
| 101 |
|
|
trap = (val>>21)&1;
|
| 102 |
|
|
ill = (val>>20)&1;
|
| 103 |
|
|
clri = (val>>19)&1;
|
| 104 |
|
|
pfv = (val>>18)&1;
|
| 105 |
|
|
pfi = (val>>17)&1;
|
| 106 |
|
|
dcdce = (val>>16)&1;
|
| 107 |
|
|
dcdv = (val>>15)&1;
|
| 108 |
|
|
dcdstall=(val>>14)&1;
|
| 109 |
|
|
opce = (val>>13)&1;
|
| 110 |
|
|
opvalid= (val>>12)&1;
|
| 111 |
|
|
oppipe = (val>>11)&1;
|
| 112 |
|
|
aluce = (val>>10)&1;
|
| 113 |
|
|
alubsy = (val>> 9)&1;
|
| 114 |
|
|
aluwr = (val>> 8)&1;
|
| 115 |
|
|
aluill = (val>> 7)&1;
|
| 116 |
|
|
aluwrf = (val>> 6)&1;
|
| 117 |
|
|
memce = (val>> 5)&1;
|
| 118 |
|
|
memwe = (val>> 4)&1;
|
| 119 |
|
|
membsy = (val>> 3)&1;
|
| 120 |
|
|
printf("FLAGS %08x", val);
|
| 121 |
|
|
printf(" CE[%c%c%c%c]",
|
| 122 |
|
|
(dcdce)?'D':' ',
|
| 123 |
|
|
(opce)?'O':' ',
|
| 124 |
|
|
(aluce)?'A':' ',
|
| 125 |
|
|
(memce)?'M':' ');
|
| 126 |
|
|
printf(" V[%c%c%c%c]",
|
| 127 |
|
|
(pfv)?'P':' ',
|
| 128 |
|
|
(dcdv)?'D':' ',
|
| 129 |
|
|
(opvalid)?'O':' ',
|
| 130 |
|
|
(aluwr)?'A':' ');
|
| 131 |
|
|
if (master) printf(" MCE");
|
| 132 |
|
|
if (halt) printf(" I-HALT");
|
| 133 |
|
|
if (brk) printf(" O-BREAK");
|
| 134 |
|
|
if (sleep) printf(" SLP");
|
| 135 |
|
|
if (GIE) printf(" GIE");
|
| 136 |
|
|
if (buserr) printf(" BE");
|
| 137 |
|
|
if (trap) printf(" TRAP");
|
| 138 |
|
|
if (ill) printf(" ILL");
|
| 139 |
|
|
if (clri) printf(" CLR-I");
|
| 140 |
|
|
if (pfi) printf(" PF-ILL");
|
| 141 |
|
|
if (dcdstall)printf(" DCD-STALL");
|
| 142 |
|
|
if (oppipe) printf(" OP-PIPE");
|
| 143 |
|
|
if (alubsy) printf(" ALU-BUSY");
|
| 144 |
|
|
if (memwe) printf(" MEM-WE");
|
| 145 |
|
|
if (membsy) printf(" MEM-BUSY");
|
| 146 |
|
|
//
|
| 147 |
|
|
}
|
| 148 |
|
|
}
|
| 149 |
|
|
};
|
| 150 |
|
|
|
| 151 |
|
|
int main(int argc, char **argv) {
|
| 152 |
|
|
FPGAOPEN(m_fpga);
|
| 153 |
|
|
|
| 154 |
|
|
signal(SIGSTOP, closeup);
|
| 155 |
|
|
signal(SIGHUP, closeup);
|
| 156 |
|
|
|
| 157 |
|
|
CPUSCOPE *scope = new CPUSCOPE(m_fpga, WBSCOPE, false);
|
| 158 |
|
|
if (!scope->ready()) {
|
| 159 |
|
|
printf("Scope is not yet ready:\n");
|
| 160 |
|
|
scope->decode_control();
|
| 161 |
|
|
scope->decode(WBSCOPEDATA);
|
| 162 |
|
|
printf("\n");
|
| 163 |
|
|
} else
|
| 164 |
|
|
scope->read();
|
| 165 |
|
|
delete m_fpga;
|
| 166 |
|
|
}
|
| 167 |
|
|
|