byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
XilinxSeries7.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 Kristiyan Manev (University of Manchester)
3  *
4  * Licensed under the Apache License, Version 2.0(the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #include<iostream>
18 #include<stdio.h>
19 #include<string>
20 #include<cstring> //memset
21 #include<algorithm> //replace
22 #include<sstream>
23 #include<stdexcept>
24 #include<fstream>
25 
26 #include "XilinxSeries7.h"
27 #include "../../../Common/str.h"
28 
29 using namespace std;
30 
32 {
33  initFabric();
34 }
35 
37 {
38 }
39 
41  if(initializedResourceStringShortPartName == "")
42  throw runtime_error("The target device needs to be known, before you can manipulate any bitstream!");
43  if(initializedBitstreamParamsShortPartName != initializedResourceStringShortPartName){//The device is changed
44  initializedBitstreamParamsShortPartName = initializedResourceStringShortPartName;
45  for(int r = 0 ; r < numberOfRows ; r++){
46  for((numberOfCols[r] = 0, numberOfFramesBeforeCol[r][0] = 0, numberOfBRAMCols[r] = 0) ; (uint8_t)resourceString[r][numberOfCols[r]] ; numberOfCols[r]++){
47  numberOfFramesBeforeCol[r][numberOfCols[r] + 1] = numberOfFramesBeforeCol[r][numberOfCols[r]] + LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[r][numberOfCols[r]]];
48  numberOfBRAMsBeforeCol[r][numberOfCols[r]] = numberOfBRAMCols[r];
49  if(str::iff::charIs(resourceString[r][numberOfCols[r]], 'A','B','C','D','E','F','G','4')) //A-G are BlockRAM columns, '4' is empty blockram column
50  numberOfBRAMCols[r]++;
51  }
52  numberOfFramesPerRow[r] = numberOfFramesBeforeCol[r][numberOfCols[r]];
53  numberOfWordsPerRow[r] = numberOfFramesPerRow[r] * XS7_WORDS_PER_FRAME;
54  for(int c = numberOfCols[r] + 1 ; c < XS7_MAX_COLS ; c++){
55  numberOfFramesBeforeCol[r][c] = numberOfFramesBeforeCol[r][c - 1];
56  }
57  for(int c = numberOfCols[r] ; c < XS7_MAX_COLS ; c++){
58  numberOfBRAMsBeforeCol[r][c] = numberOfBRAMsBeforeCol[r][c - 1];
59  }
60  }
61 
62 
63  maxNumberOfCols = numberOfCols[0];
64  maxNumberOfBRAMCols = numberOfBRAMCols[0];
65  for(int r = 1 ; r < numberOfRows ; r++){
66  if(maxNumberOfCols < numberOfCols[r])
67  maxNumberOfCols = numberOfCols[r];
68  if(maxNumberOfBRAMCols < numberOfBRAMCols[r])
69  maxNumberOfBRAMCols = numberOfBRAMCols[r];
70  }
71  }
72 }
73 
75  if(initializedResourceStringShortPartName == "")
76  throw runtime_error("The target device needs to be known, before you can manipulate any bitstream!");
77  if(initializedBitstreamShortPartName != initializedResourceStringShortPartName){//The device is changed
78  initializedBitstreamShortPartName = initializedResourceStringShortPartName;
79  if(bitstreamBegin != nullptr)
80  delete bitstreamBegin;
81 
82  initializeResourceStringParameters();
83  //Allocate
84  int bramPlaneSize = 0;
85  int clbPlaneSize = 0;
86  for(int r = 0 ; r < numberOfRows ; r++){
87  bramPlaneSize += XS7_WORDS_PER_FRAME * (XS7_EXTRA_FRAMES_PER_ROW + numberOfBRAMCols[r] * XS7_FRAMES_PER_BRAM_CONTENT_COLUMN);
88  clbPlaneSize += numberOfWordsPerRow[r];
89  }
90  bitstreamBegin = new uint32_t[clbPlaneSize + bramPlaneSize];
91 
92  //Calc pointers
93  int offset = 0;
94 
95  for(int slr = 0 ; slr < numberOfSLRs ; slr++){
96  int fromGlobalRowTop = SLRinfo[slr].fromRow + SLRinfo[slr].rowsInBottomHalf;
97  int toGlobalRowTop = SLRinfo[slr].toRow;
98  int fromGlobalRowBottom = SLRinfo[slr].fromRow + SLRinfo[slr].rowsInBottomHalf - 1;
99  int toGlobalRowBottom = SLRinfo[slr].fromRow;
100  for(int r = fromGlobalRowTop ; r <= toGlobalRowTop ; r++){
101  for(int c = 0 ; c < numberOfCols[r] ; c++){
102  bitstreamCLB[r][c] = &bitstreamBegin[offset];
103  offset += LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[r][c]] * XS7_WORDS_PER_FRAME;
104  }
105  }
106  for(int r = fromGlobalRowBottom ; r >= toGlobalRowBottom ; r--){
107  for(int c = 0 ; c < numberOfCols[r] ; c++){
108  bitstreamCLB[r][c] = &bitstreamBegin[offset];
109  offset += LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[r][c]] * XS7_WORDS_PER_FRAME;
110  }
111  }
112  for(int r = fromGlobalRowTop ; r <= toGlobalRowTop ; r++){
113  for(int c = 0 ; c < numberOfBRAMCols[r] ; c++){
114  bitstreamBRAM[r][c] = &bitstreamBegin[offset];
116  }
117  bitstreamBRAM[r][numberOfBRAMCols[r]] = &bitstreamBegin[offset];
119  }
120  for(int r = fromGlobalRowBottom ; r >= toGlobalRowBottom ; r--){
121  for(int c = 0 ; c < numberOfBRAMCols[r] ; c++){
122  bitstreamBRAM[r][c] = &bitstreamBegin[offset];
124  }
125  bitstreamBRAM[r][numberOfBRAMCols[r]] = &bitstreamBegin[offset];
127  }
128  }
129 
130  bitstreamEnd = &bitstreamBegin[offset];
131  bitstreamHasValidData = false;
132  log("Reserved " + to_string(clbPlaneSize + bramPlaneSize) + " words for the bitstream buffers of device \"" + partName + "\"");
133  }
134 }
135 
136 string XilinxSeries7::getFrameType(int blockType, int rowAddress, int columnAddress){
137  if(XS7_BLOCKTYPE_BLOCKRAM == blockType)
138  return "BlockRAM Contents";
139  else if(XS7_BLOCKTYPE_LOGIC == blockType)
140  return LUT_typeOfFrameForResourceLetter[(uint8_t)resourceString[rowAddress][columnAddress]];
141  else
142  return "Unknown";
143 }
#define XS7_MAX_COLS
Definition: XS7_Fabric.h:27
#define XS7_EXTRA_FRAMES_PER_ROW
Definition: XS7_Fabric.h:46
#define XS7_WORDS_PER_FRAME
Definition: XS7_Fabric.h:41
#define XS7_FRAMES_PER_BRAM_CONTENT_COLUMN
Definition: XS7_Fabric.h:42
#define XS7_BLOCKTYPE_BLOCKRAM
Definition: XS7_Fabric.h:35
#define XS7_BLOCKTYPE_LOGIC
Definition: XS7_Fabric.h:34
std::string getFrameType(int, int, int) override
void ensureInitializedBitstreamArrays() override
virtual ~XilinxSeries7()
void initializeResourceStringParameters() override
std::string to_string(Endianness e)
Definition: Endianness.h:56
bool charIs(char checkedChar)
Returns false. End of recursion for template.
Definition: iff.h:101