31 if((!((9 == headerConstTextLength) && (
"\x0F\xF0\x0F\xF0\x0F\xF0\x0F\xF0" == headerConstText) && (1 == headerConstText2Length) && (
"a" == headerConstText2))))
32 warn(
".bit c0nstant header differs from expected.");
36 log(
"Name of design: " + designName);
37 for(
int headerDone = 0 ; !headerDone ; ){
43 log(
"FPGA part: " + partName);
49 log(
"Date: " + fileDate);
55 log(
"Time: " + fileTime);
61 int tmpPos = (int)fin.tellg();
62 fin.seekg (0, fin.end);
63 int fileSize = (int)fin.tellg();
64 fin.seekg (tmpPos, fin.beg);
65 if(fileSize != (tmpPos + reportedRemainingFileLength))
66 warn(
".bit header contained inaccurate file length field.");
70 warn(
".bit header contained unknown file field type.");
85 std::streamoff fileOffset = fin.tellg();
92 for(
int syncDetectionDone = 0 ; !syncDetectionDone ; ){
94 throw std::runtime_error(
"Was unable to find input bitstream's SYNC command.");
100 if(wordOld4 == 0x000000BB && wordOld3 == 0x11220044 && wordOld2 == 0xFFFFFFFF && wordOld1 == 0xFFFFFFFF && word ==
XCAP_getSyncInstruction()){
116 fin.seekg(-19, std::ios::cur);
120 fin.seekg(fileOffset, fin.beg);
142 fin.seekg(-3, std::ios::cur);
166 if(wordOld4 == 0x000000BB && wordOld3 == 0x11220044 && wordOld2 == 0xFFFFFFFF && wordOld1 == 0xFFFFFFFF && word ==
XCAP_getSyncInstruction()){
169 fin.seekg(-19, std::ios::cur);
183 std::streamoff fileOffset = fin.tellg();
188 for(
int syncDetectionDone = 0 ; !syncDetectionDone ; ){
190 throw std::runtime_error(
"Was unable to find input bitstream's IDCODE command.");
196 fin.seekg(-3, std::ios::cur);
199 fin.seekg(fileOffset, fin.beg);
208 char shadowFrame[WORDS_PER_FRAME*4];
209 bool shadowFrameValid =
false;
210 int b = 7, r = 0, c = 0, m = 0;
211 bool aligned =
false;
212 bool synched =
false;
214 if(bitstreamHasValidData){
217 loadedBitstreamEndianness = bitstreamFileEndianness;
236 uint32_t instruction =
FileIO::read32(fin, loadedBitstreamEndianness);
243 if(instructionType == 1) {
246 }
else if(instructionType == 2) {
247 wordCount = instructionPayload;
249 throw std::runtime_error(
"Bitstream has invalid instruction (" +
std::to_string(instruction) +
" @ " +
std::to_string(fin.tellg()) +
") (invalid type).");
254 shadowFrameValid =
false;
259 for( ; wordCount > 0 ; ){
261 uint32_t farValue =
FileIO::read32(fin, loadedBitstreamEndianness);
276 if(wordCount % WORDS_PER_FRAME != 0)
277 throw std::runtime_error(
"FDRI write of a partial frame was detected, which is currently not supported.");
278 if(shadowFrameValid){
283 if(b == BLOCKTYPE_LOGIC){
284 throwingAssertPrintVar_3(m, <, LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[r][c]], r, c, (
int)resourceString[r][c]);
285 memcpy(&bitstreamCLB[r][c][m*WORDS_PER_FRAME], &shadowFrame, WORDS_PER_FRAME*4);
286 }
else if(b == BLOCKTYPE_BLOCKRAM) {
288 memcpy(&bitstreamBRAM[r][c][m*WORDS_PER_FRAME], &shadowFrame, WORDS_PER_FRAME*4);
290 warn(
"Unknown BlockType(" +
std::to_string(b) +
") written while reading bitstream file.");
294 int forwardShadowReg = (wordCount/WORDS_PER_FRAME) - 1;
295 if(forwardShadowReg > 0){
296 if(b == BLOCKTYPE_LOGIC){
297 fin.read((
char*)&bitstreamCLB[r][c][m*WORDS_PER_FRAME], forwardShadowReg * WORDS_PER_FRAME * 4);
298 }
else if(b == BLOCKTYPE_BLOCKRAM){
299 fin.read((
char*)&bitstreamBRAM[r][c][m*WORDS_PER_FRAME], forwardShadowReg * WORDS_PER_FRAME * 4);
301 fin.ignore(forwardShadowReg * WORDS_PER_FRAME * 4);
302 warn(
"Unknown BlockType(" +
std::to_string(b) +
") written while reading bitstream file.");
304 for(
int i = 0 ; i < forwardShadowReg ; i++){
308 wordCount -= forwardShadowReg * WORDS_PER_FRAME;
309 shadowFrameValid =
true;
310 fin.read((
char*)&shadowFrame, WORDS_PER_FRAME*4);
311 wordCount -= WORDS_PER_FRAME;
316 shadowFrameValid =
false;
320 shadowFrameValid =
false;
331 bitstreamHasValidData =
true;
339 setDeviceByPartNameOrThrow();
340 ensureInitializedBitstreamArrays();
351 setDeviceByIDCODEOrThrow(idcode);
352 ensureInitializedBitstreamArrays();
361 if(bitstreamHasValidData){
364 loadedBitstreamEndianness = bitstreamFileEndianness;
367 for(
int i = 0 ; i < WORDS_PER_FRAME ; i++)
368 std::getline(fin,
str);
369 uint32_t* fromPtr = bitstreamBegin;
370 uint32_t* toPtr = bitstreamEnd;
371 for(uint32_t* bitstreamLoc = fromPtr ; bitstreamLoc < toPtr ; bitstreamLoc++){
372 std::getline(fin,
str);
373 uint32_t val = (uint32_t)(std::stoll(
str,
nullptr, 2) & 0xFFFFFFFF);
376 bitstreamHasValidData =
true;
383 ensureInitializedBitstreamArrays();
Endianness
< Endianness in byteman is represented not only by big/little endian, but also by potential bit swapp...
@ BE_BS
Big endian with bit swaps inside each byte.
@ LE_BS
Little endian with bit swaps inside each byte.
@ LE
Little endian ("LE" instead of full-er name, so it does not conflict with linux's reserved endianess ...
@ BE
Big endian ("BE" instead of full-er name, so it does not conflict with linux's reserved endianess wor...
@ NATIVE
System native will always be the fastest endianess to process.
#define throwingAssertPrintVar_1(left, operator,right, var1)
#define throwingAssert(left, operator,right)
#define throwingAssertPrintVar_3(left, operator,right, var1, var2, var3)
XCAP::Register XCAP_getInstructionRegister(uint32_t instruction)
Parses and returns instruction register. This is the register being addressed if the instruction is o...
XCAP::Operation XCAP_getInstructionOperation(uint32_t instruction)
Parses and returns instruction operation. Most Xil instructions will NOP or write.
uint32_t XCAP_getInstructionPayload(uint32_t instruction)
Parses and returns instruction payload. This is the immediate value after instruction type and operat...
uint32_t XCAP_getInstructionWordCount(uint32_t instruction)
Parses and returns instruction word count. This is the number of words to be read/written if the inst...
uint32_t XCAP_getSyncInstruction()
Generate and return the encoding for a SYNC instruction.
uint32_t XCAP_IDCODEInstruction()
Generate and return the encoding for a IDCODE writing instruction.
uint32_t XCAP_getInstructionType(uint32_t instruction)
Parses and returns instruction type. Valid Xil instructions will be of types 1 and 2.
void ensureSelectedEndianness(Endianness newEndianness)
void XCAP_parseFAR(int farValue, int slr, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
void XCAP_IncrementFAR(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
uint32_t NativeToLittleEndian32(uint32_t x)
uint32_t NativeToAnyEndianness32(uint32_t x, Endianness e)
uint32_t NativeToBigEndian32(uint32_t x)
std::string to_string(Endianness e)
uint32_t BitSwap32(uint32_t x)
uint8_t readNative8(std::ifstream &fin)
std::string readString(std::ifstream &fin, int stringSize)
uint16_t read16(std::ifstream &fin, Endianness e=Endianness::NATIVE)
uint32_t read32(std::ifstream &fin, Endianness e=Endianness::NATIVE)