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

Subversion Repositories xulalx25soc

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 dgisselq
//
2
//
3
// Filename:    cpuscope.cpp
4
//
5
// Project:     FPGA library development (Basys-3 development board)
6
//
7
// Purpose:     To read out, and decompose, the results of the wishbone scope
8
//              as applied to the ICAPE2 interaction.
9
//
10
// Creator:     Dan Gisselquist
11
//              Gisselquist Tecnology, LLC
12
//
13
// Copyright:   2015
14
//
15
//
16
#include <stdio.h>
17
#include <stdlib.h>
18
#include <unistd.h>
19
#include <strings.h>
20
#include <ctype.h>
21
#include <string.h>
22
#include <signal.h>
23
#include <assert.h>
24
 
25
#include "usbi.h"
26
#include "port.h"
27
#include "llcomms.h"
28
#include "regdefs.h"
29
 
30
#define WBSCOPE         R_CPUSCOPE
31
#define WBSCOPEDATA     R_CPUSCOPED
32
 
33
#include "zopcodes.h"
34
 
35
FPGA    *m_fpga;
36
void    closeup(int v) {
37
        m_fpga->kill();
38
        exit(0);
39
}
40
 
41
unsigned brev(const unsigned v) {
42
        unsigned int r, a;
43
        a = v;
44
        r = 0;
45
        for(int i=0; i<8; i++) {
46
                r <<= 1;
47
                r |= (a&1);
48
                a >>= 1;
49
        } return r;
50
}
51
 
52
unsigned wrev(const unsigned v) {
53
        unsigned r = brev(v&0x0ff);
54
        r |= brev((v>>8)&0x0ff)<<8;
55
        return r;
56
}
57
 
58
int main(int argc, char **argv) {
59
        FPGAOPEN(m_fpga);
60
 
61
        signal(SIGSTOP, closeup);
62
        signal(SIGHUP, closeup);
63
 
64
        unsigned        v, lgln, scoplen;
65
        printf("Attempting to read address %08x\n", WBSCOPE);
66
        v = m_fpga->readio(WBSCOPE);
67
        if (0x60000000 != (v & 0x60000000)) {
68
                printf("Scope is not yet ready:\n");
69
                printf("\tRESET:\t\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
70
                printf("\tSTOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
71
                printf("\tTRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
72
                printf("\tPRIMED:\t\t%s\n", (v&0x10000000)?"Yes":"No");
73
                printf("\tMANUAL:\t\t%s\n", (v&0x08000000)?"Yes":"No");
74
                printf("\tDISABLED:\t%s\n", (v&0x04000000)?"Yes":"No");
75
                printf("\tZERO:\t\t%s\n", (v&0x02000000)?"Yes":"No");
76
                exit(0);
77
        } else printf("SCOPD = %08x\n", v);
78
 
79
        lgln = (v>>20) & 0x1f;
80
        scoplen = (1<<lgln);
81
 
82
        DEVBUS::BUSW    *buf;
83
        buf = new DEVBUS::BUSW[scoplen];
84
 
85
        if (false) {
86
                printf("Attempting vector read\n");
87
                m_fpga->readz(WBSCOPEDATA, scoplen, buf);
88
 
89
                printf("Vector read complete\n");
90
        } else {
91
                for(unsigned int i=0; i<scoplen; i++)
92
                        buf[i] = m_fpga->readio(WBSCOPEDATA);
93
        }
94
 
95
        for(unsigned int i=0; i<scoplen; i++) {
96
                char    sbuf[64];
97
 
98
                if ((i>0)&&(buf[i] == buf[i-1])&&
99
                                (i<scoplen-1)&&(buf[i] == buf[i+1]))
100
                        continue;
101
                printf("%6d %08x:", i, buf[i]);
102
 
103
                unsigned addr = (buf[i]>>24)&0x0ff;
104
                zipi_to_string(m_fpga->readio(0x02000+addr),sbuf);
105
                printf(" %2x %-24s", (buf[i]>>24)&0x0ff, sbuf);
106
                printf(" %s%s%s%s%s %s%s%s",
107
                        ((buf[i]>>23)&1)?"P":" ",
108
                        ((buf[i]>>22)&1)?"D":" ",
109
                        ((buf[i]>>21)&1)?"O":" ",
110
                        ((buf[i]>>20)&1)?"A":" ",
111
                        ((buf[i]>>19)&1)?"M":" ",
112
                        ((buf[i]>>18)&1)?"o":" ",
113
                        ((buf[i]>>17)&1)?"a":" ",
114
                        ((buf[i]>>16)&1)?"m":" ");
115
                printf(" A=%02x ", (buf[i]>>8)&0x0ff);
116
                printf(" %s%02x ",
117
                        (((buf[i]>>16)&3)!=0)?"W->":"(w)",
118
                        (buf[i]&0x0ff));
119
                /*
120
                printf("%s", ((buf[i]>>31)&1)?"OpV":"   ");
121
                printf("%s", ((buf[i]>>30)&1)?"opA":"   ");
122
                printf("%s", ((buf[i]>>29)&1)?"AlV":"   ");
123
                printf("%s", ((buf[i]>>28)&1)?"AlW":"   ");
124
                printf("%s", ((buf[i]>>27)&1)?"opM":"   ");
125
                printf("%s", ((buf[i]>>26)&1)?"MmV":"   ");
126
                if (true) {
127
                        int     op = (buf[i]>>22)&0x0f;
128
                        switch(op) {
129
                        case  0: printf("CMP "); break;
130
                        case  1: printf("TST "); break;
131
                        case  2: printf("MOV "); break;
132
                        case  3: printf("LDI "); break;
133
                        case  4: printf("AUX "); break;
134
                        case  5: printf("ROL "); break;
135
                        case  6: printf("LOD "); break;
136
                        case  7: printf("STO "); break;
137
                        case  8: printf("SUB "); break;
138
                        case  9: printf("AND "); break;
139
                        case 10: printf("ADD "); break;
140
                        case 11: printf(" OR "); break;
141
                        case 12: printf("XOR "); break;
142
                        case 13: printf("LSL "); break;
143
                        case 14: printf("ASR "); break;
144
                        case 15: printf("LSR "); break;
145
                        default: printf("ILL "); break;
146
                        }
147
                } else
148
                        printf("%x", (buf[i]>>22)&0x0f);
149
                printf(" %s", ((buf[i]>>21)&1)?"W":" ");
150
                if ((buf[i]>>21)&1)
151
                        printf("[%X]", ((buf[i]>>17)&0x0f));
152
                else
153
                        printf("(%x)", ((buf[i]>>17)&0x0f));
154
                printf("D[%X]", ((buf[i]>>13)&0x0f));
155
                printf(" r_opA=..%02x", (buf[i]>>7)&0x3f);
156
                printf(" opA=..%02x", (buf[i]>>1)&0x3f);
157
                printf(" ALU=..%d", buf[i]&1);
158
                */
159
 
160
                printf("\n");
161
        }
162
 
163
        if (m_fpga->poll()) {
164
                printf("FPGA was interrupted\n");
165
                m_fpga->clear();
166
                m_fpga->writeio(R_ICONTROL, SCOPEN);
167
        }
168
        delete  m_fpga;
169
}
170
 

powered by: WebSVN 2.1.0

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