Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 167 lines (165 sloc) 3.795 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
/*
* Copyright (C) 2009-2012 Chris McClelland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <makestuff.h>
#include <stdio.h>
#include <stdlib.h>
#include <libfpgalink.h>
#include "../xsvf.h"

#define bitsToBytes(x) ((x>>3) + (x&7 ? 1 : 0))
#define printAddrs() if ( wantAddrs ) printf("%08tX: ", p-buffer)

int main(int argc, const char *argv[]) {
const uint8 *buffer, *p, *savePtr;
uint32 length;
uint8 byte;
uint32 xsdrSize = 0;
uint32 numBytes, temp;
bool wantAddrs = true;
if ( argc != 2 && argc != 3 ) {
fprintf(stderr, "Synopsis: %s [-n] <xsvfFile>\n", argv[0]);
exit(1);
}
if ( argv[1][0] == '-' && argv[1][1] == 'n' && argv[1][2] == '\0' ) {
buffer = flLoadFile(argv[2], &length);
wantAddrs = false;
} else {
buffer = flLoadFile(argv[1], &length);
}
p = buffer;
byte = *p;
while ( byte != XCOMPLETE ) {
switch ( byte ) {
case XTDOMASK:
printAddrs();
printf("XTDOMASK(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *++p);
numBytes--;
}
printf(")\n");
break;
case XSDRTDO:
printAddrs();
printf("XSDRTDO(");
numBytes = temp = bitsToBytes(xsdrSize);
savePtr = p + 1;
while ( numBytes ) {
printf("%02X", *++p);
p++;
numBytes--;
}
printf(", ");
while ( temp ) {
printf("%02X", *++savePtr);
savePtr++;
temp--;
}
printf(")\n");
break;
case XREPEAT:
printAddrs();
printf("XREPEAT(%02X)\n", *++p);
break;
case XRUNTEST:
printAddrs();
printf("XRUNTEST(%02X%02X%02X%02X)\n", p[1], p[2], p[3], p[4]);
p += 4;
break;
case XSDRSIZE:
printAddrs();
xsdrSize = *++p;
xsdrSize <<= 8;
xsdrSize |= *++p;
xsdrSize <<= 8;
xsdrSize |= *++p;
xsdrSize <<= 8;
xsdrSize |= *++p;
printf("XSDRSIZE(%08X)\n", xsdrSize);
break;
case XSIR:
printAddrs();
printf("XSIR(");
byte = *++p;
printf("%02X, ", byte);
numBytes = bitsToBytes((uint32)byte);
while ( numBytes ) {
printf("%02X", *++p);
numBytes--;
}
printf(")\n");
break;
case XSDR:
printAddrs();
printf("XSDR(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *++p);
numBytes--;
}
printf(")\n");
break;
case XSDRB:
printAddrs();
printf("XSDRB(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *++p);
numBytes--;
}
printf(")\n");
break;
case XSDRC:
printAddrs();
printf("XSDRC(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *++p);
numBytes--;
}
printf(")\n");
break;
case XSDRE:
printAddrs();
printf("XSDRE(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *++p);
numBytes--;
}
printf(")\n");
break;
case XSTATE:
printAddrs();
printf("XSTATE(%02X)\n", *++p);
break;
case XENDIR:
printAddrs();
printf("XENDIR(%02X)\n", *++p);
break;
case XENDDR:
printAddrs();
printf("XENDDR(%02X)\n", *++p);
break;
default:
fprintf(stderr, "Unrecognised command %02X\n", byte);
exit(1);
}
byte = *++p;
}
printf("XCOMPLETE\n");
return 0;
}
Something went wrong with that request. Please try again.