Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 1 | #include <chip_data/hei_chip_data.hpp> |
| 2 | #include <chip_data/hei_chip_data_stream.hpp> |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 3 | #include <register/hei_operator_register.hpp> |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 4 | #include <register/hei_scom_register.hpp> |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 5 | |
| 6 | namespace libhei |
| 7 | { |
| 8 | |
| 9 | //------------------------------------------------------------------------------ |
| 10 | |
| 11 | using FileKeyword_t = uint64_t; |
| 12 | |
| 13 | constexpr FileKeyword_t KW_CHIPDATA = 0x4348495044415441; // "CHIPDATA" ASCII |
| 14 | |
| 15 | using SectionKeyword_t = uint32_t; |
| 16 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 17 | constexpr SectionKeyword_t KW_REGS = 0x52454753; // "REGS" ASCII |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 18 | constexpr SectionKeyword_t KW_NODE = 0x4e4f4445; // "NODE" ASCII |
| 19 | constexpr SectionKeyword_t KW_ROOT = 0x524f4f54; // "ROOT" ASCII |
| 20 | |
| 21 | using Version_t = uint8_t; |
| 22 | |
| 23 | constexpr Version_t VERSION_1 = 0x01; |
| 24 | |
| 25 | //------------------------------------------------------------------------------ |
| 26 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 27 | void __readRegister(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip) |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 28 | { |
| 29 | // Read the register metadata. |
| 30 | RegisterId_t id; |
| 31 | RegisterType_t type; |
| 32 | RegisterAttributeFlags_t attr; |
| 33 | Instance_t numInsts; |
| 34 | io_stream >> id >> type >> attr >> numInsts; |
| 35 | |
| 36 | // Must have at least one instance. |
| 37 | HEI_ASSERT(0 != numInsts); |
| 38 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 39 | for (unsigned int i = 0; i < numInsts; i++) |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 40 | { |
| 41 | // Read the register instance metadata. |
| 42 | Instance_t inst; |
| 43 | io_stream >> inst; |
| 44 | |
| 45 | // The address size is dependent on the register type. |
| 46 | if (REG_TYPE_SCOM == type) |
| 47 | { |
| 48 | uint32_t addr; // 4-byte address. |
| 49 | io_stream >> addr; |
| 50 | |
| 51 | // Get this register from the flyweight factory. |
| 52 | auto& factory = Flyweight<const ScomRegister>::getSingleton(); |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 53 | auto hwReg = factory.get(id, inst, attr, addr); |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 54 | |
| 55 | // Add this register to the isolation chip. |
| 56 | io_isoChip->addHardwareRegister(hwReg); |
| 57 | } |
| 58 | else if (REG_TYPE_ID_SCOM == type) |
| 59 | { |
| 60 | uint64_t addr; // 8-byte address. |
| 61 | io_stream >> addr; |
| 62 | |
| 63 | // Get this register from the flyweight factory. |
| 64 | auto& factory = Flyweight<const IdScomRegister>::getSingleton(); |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 65 | auto hwReg = factory.get(id, inst, attr, addr); |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 66 | |
| 67 | // Add this register to the isolation chip. |
| 68 | io_isoChip->addHardwareRegister(hwReg); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | HEI_ASSERT(false); // Register type unsupported. |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | //------------------------------------------------------------------------------ |
| 78 | |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 79 | Register::ConstPtr __readExpr(ChipDataStream& io_stream, |
| 80 | const IsolationChip::Ptr& i_isoChip, |
| 81 | IsolationNode::Ptr& io_isoNode) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 82 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 83 | Register::ConstPtr expr{}; |
| 84 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 85 | uint8_t exprType; |
| 86 | io_stream >> exprType; |
| 87 | switch (exprType) |
| 88 | { |
| 89 | case 0x01: // register reference |
| 90 | { |
| 91 | RegisterId_t regId; |
| 92 | Instance_t regInst; |
| 93 | io_stream >> regId >> regInst; |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 94 | |
| 95 | // Find the hardware register that is stored in this isolation chip |
| 96 | // and add it to the list of capture registers. This ensures all |
| 97 | // registers referenced in the rules are are captured by default. |
| 98 | // Note that this will assert that the target register must exist in |
| 99 | // the isolation chip. |
| 100 | auto hwReg = i_isoChip->getHardwareRegister({regId, regInst}); |
| 101 | |
| 102 | // Add the register to the isolation node. |
| 103 | io_isoNode->addCaptureRegister(hwReg); |
| 104 | |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 105 | // Simply return this register. |
| 106 | expr = hwReg; |
| 107 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | case 0x02: // integer constant |
| 111 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 112 | auto& factory = Flyweight<const ConstantRegister>::getSingleton(); |
| 113 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 114 | if (REG_TYPE_SCOM == io_isoNode->getRegisterType() || |
| 115 | REG_TYPE_ID_SCOM == io_isoNode->getRegisterType()) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 116 | { |
| 117 | uint64_t constant; // 8-byte value |
| 118 | io_stream >> constant; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 119 | |
| 120 | // Create the constant register and put it in the flyweights. |
| 121 | expr = factory.get(constant); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 122 | } |
| 123 | else |
| 124 | { |
| 125 | HEI_ASSERT(false); // register type unsupported |
| 126 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 127 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | case 0x10: // AND operation |
| 131 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 132 | auto& factory = Flyweight<const AndRegister>::getSingleton(); |
| 133 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 134 | uint8_t numSubExpr; |
| 135 | io_stream >> numSubExpr; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 136 | |
| 137 | HEI_ASSERT(2 <= numSubExpr); // must be at least two |
| 138 | |
| 139 | // Read the first two sub-expressions. |
| 140 | auto e1 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 141 | auto e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 142 | HEI_ASSERT(e1 && e2); // Cannot be null |
| 143 | |
| 144 | // Create the AND register and put it in the flyweights. |
| 145 | expr = factory.get(e1, e2); |
| 146 | |
| 147 | // Iterate any remaining expressions. |
| 148 | for (uint8_t i = 2; i < numSubExpr; i++) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 149 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 150 | // Read the next sub-expressions. |
| 151 | e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 152 | HEI_ASSERT(e2); // Cannot be null |
| 153 | |
| 154 | // Create the AND register and put it in the flyweights. |
| 155 | expr = factory.get(expr, e2); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 156 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 157 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 158 | break; |
| 159 | } |
| 160 | case 0x11: // OR operation |
| 161 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 162 | auto& factory = Flyweight<const OrRegister>::getSingleton(); |
| 163 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 164 | uint8_t numSubExpr; |
| 165 | io_stream >> numSubExpr; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 166 | |
| 167 | HEI_ASSERT(2 <= numSubExpr); // must be at least two |
| 168 | |
| 169 | // Read the first two sub-expressions. |
| 170 | auto e1 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 171 | auto e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 172 | HEI_ASSERT(e1 && e2); // Cannot be null |
| 173 | |
| 174 | // Create the OR register and put it in the flyweights. |
| 175 | expr = factory.get(e1, e2); |
| 176 | |
| 177 | // Iterate any remaining expressions. |
| 178 | for (uint8_t i = 2; i < numSubExpr; i++) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 179 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 180 | // Read the next sub-expressions. |
| 181 | e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 182 | HEI_ASSERT(e2); // Cannot be null |
| 183 | |
| 184 | // Create the OR register and put it in the flyweights. |
| 185 | expr = factory.get(expr, e2); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 186 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 187 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | case 0x12: // NOT operation |
| 191 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 192 | auto& factory = Flyweight<const NotRegister>::getSingleton(); |
| 193 | |
| 194 | // Read the sub-expression |
| 195 | auto e = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 196 | HEI_ASSERT(e); // Cannot be null |
| 197 | |
| 198 | // Create the NOT register and put it in the flyweights. |
| 199 | expr = factory.get(e); |
| 200 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | case 0x13: // left shift operation |
| 204 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 205 | auto& factory = Flyweight<const LeftShiftRegister>::getSingleton(); |
| 206 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 207 | uint8_t shiftValue; |
| 208 | io_stream >> shiftValue; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 209 | |
| 210 | // Read the sub-expression |
| 211 | auto e = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 212 | HEI_ASSERT(e); // Cannot be null |
| 213 | |
| 214 | // Create the left shift register and put it in the flyweights. |
| 215 | expr = factory.get(e, shiftValue); |
| 216 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 217 | break; |
| 218 | } |
| 219 | case 0x14: // right shift operation |
| 220 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 221 | auto& factory = Flyweight<const RightShiftRegister>::getSingleton(); |
| 222 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 223 | uint8_t shiftValue; |
| 224 | io_stream >> shiftValue; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 225 | |
| 226 | // Read the sub-expression |
| 227 | auto e = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 228 | HEI_ASSERT(e); // Cannot be null |
| 229 | |
| 230 | // Create the right shift register and put it in the flyweights. |
| 231 | expr = factory.get(e, shiftValue); |
| 232 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 233 | break; |
| 234 | } |
| 235 | default: |
| 236 | HEI_ASSERT(false); // unsupported expression type |
| 237 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 238 | |
| 239 | return expr; |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | //------------------------------------------------------------------------------ |
| 243 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 244 | using TmpChildNodeMap = std::map<BitPosition_t, IsolationNode::Key>; |
| 245 | using TmpNodeData = std::pair<IsolationNode::Ptr, TmpChildNodeMap>; |
| 246 | using TmpNodeMap = std::map<IsolationNode::Key, TmpNodeData>; |
| 247 | |
| 248 | void __readNode(ChipDataStream& io_stream, const IsolationChip::Ptr& i_isoChip, |
| 249 | TmpNodeMap& io_tmpNodeMap) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 250 | { |
| 251 | // Read the node metadata. |
| 252 | NodeId_t nodeId; |
| 253 | RegisterType_t regType; |
| 254 | Instance_t numInsts; |
| 255 | io_stream >> nodeId >> regType >> numInsts; |
| 256 | |
| 257 | for (unsigned int i = 0; i < numInsts; i++) |
| 258 | { |
| 259 | // Read the node instance metadata. |
| 260 | Instance_t nodeInst; |
| 261 | uint8_t numCapRegs, numIsoRules, numChildNodes; |
| 262 | io_stream >> nodeInst >> numCapRegs >> numIsoRules >> numChildNodes; |
| 263 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 264 | // There must be at least one isolation rule defined. |
| 265 | HEI_ASSERT(0 != numIsoRules); |
| 266 | |
| 267 | // Allocate memory for this isolation node. |
| 268 | auto isoNode = |
| 269 | std::make_shared<IsolationNode>(nodeId, nodeInst, regType); |
| 270 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 271 | // Add capture registers. |
| 272 | for (unsigned int j = 0; j < numCapRegs; j++) |
| 273 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 274 | // Read the capture register metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 275 | RegisterId_t regId; |
| 276 | Instance_t regInst; |
| 277 | io_stream >> regId >> regInst; |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 278 | |
| 279 | // Find the hardware register that is stored in this isolation chip |
| 280 | // and add it to the list of capture registers. Note that this will |
| 281 | // assert that the target register must exist in the isolation chip. |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 282 | auto hwReg = i_isoChip->getHardwareRegister({regId, regInst}); |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 283 | |
| 284 | // Add the register to the isolation node. |
| 285 | isoNode->addCaptureRegister(hwReg); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | // Add isolation rules. |
| 289 | for (unsigned int j = 0; j < numIsoRules; j++) |
| 290 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 291 | // Read the rule metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 292 | AttentionType_t attnType; |
| 293 | io_stream >> attnType; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 294 | |
| 295 | // Read out the rule for this attention type. |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 296 | auto rule = __readExpr(io_stream, i_isoChip, isoNode); |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 297 | HEI_ASSERT(rule); // Cannot be null |
| 298 | |
| 299 | // Add the rule to the isolation node. |
| 300 | isoNode->addRule(attnType, rule); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 301 | } |
| 302 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 303 | // At this point, we will need to read out the child node metadata. |
| 304 | // However, we can't look up the child nodes and add them to this |
| 305 | // isolation node yet because we are still in the process of parsing |
| 306 | // them out of the Chip Data File. Therefore, we'll save a temporary map |
| 307 | // containing the child node information which will be used to look up |
| 308 | // the actual node objects later. |
| 309 | TmpChildNodeMap cMap{}; |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 310 | for (unsigned int j = 0; j < numChildNodes; j++) |
| 311 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 312 | // Read the child node metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 313 | BitPosition_t bit; |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame] | 314 | NodeId_t childId; |
| 315 | Instance_t childInst; |
| 316 | io_stream >> bit >> childId >> childInst; |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 317 | |
| 318 | auto ret = |
| 319 | cMap.emplace(bit, IsolationNode::Key{childId, childInst}); |
| 320 | HEI_ASSERT(ret.second); // Should not have duplicate entries |
| 321 | } |
| 322 | |
| 323 | // Add this isolation node with the temporary child node map to the |
| 324 | // returned map of nodes. |
| 325 | auto ret = io_tmpNodeMap.emplace(IsolationNode::Key{nodeId, nodeInst}, |
| 326 | TmpNodeData{isoNode, cMap}); |
| 327 | HEI_ASSERT(ret.second); // Should not have duplicate entries |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | //------------------------------------------------------------------------------ |
| 332 | |
| 333 | void __insertNodes(IsolationChip::Ptr& io_isoChip, |
| 334 | const TmpNodeMap& i_tmpNodeMap) |
| 335 | { |
| 336 | for (const auto& n : i_tmpNodeMap) |
| 337 | { |
| 338 | const IsolationNode::Ptr& node = n.second.first; |
| 339 | const TmpChildNodeMap& childMap = n.second.second; |
| 340 | |
| 341 | // Link the child nodes, if they exist. |
| 342 | for (const auto& c : childMap) |
| 343 | { |
| 344 | const BitPosition_t& bit = c.first; |
| 345 | const IsolationNode::Key& childKey = c.second; |
| 346 | |
| 347 | // Find the child node in the temporary map. |
| 348 | auto itr = i_tmpNodeMap.find(childKey); |
| 349 | HEI_ASSERT(i_tmpNodeMap.end() != itr); // Child node must exist. |
| 350 | |
| 351 | const IsolationNode::Ptr& child = itr->second.first; |
| 352 | |
| 353 | node->addChild(bit, child); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 354 | } |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 355 | |
| 356 | // Add this node to the isolation chip. |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 357 | io_isoChip->addIsolationNode(node); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
| 361 | //------------------------------------------------------------------------------ |
| 362 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 363 | void __readRoot(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 364 | { |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 365 | // Read the root node metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 366 | AttentionType_t attnType; |
| 367 | NodeId_t id; |
| 368 | Instance_t inst; |
| 369 | io_stream >> attnType >> id >> inst; |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 370 | |
| 371 | // Add the root node. |
| 372 | io_isoChip->addRootNode(attnType, io_isoChip->getIsolationNode({id, inst})); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | //------------------------------------------------------------------------------ |
| 376 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 377 | void parseChipDataFile(void* i_buffer, size_t i_bufferSize, |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 378 | IsolationChip::Map& io_isoChips) |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 379 | { |
| 380 | ChipDataStream stream{i_buffer, i_bufferSize}; |
| 381 | |
| 382 | // Read the file metadata. |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 383 | FileKeyword_t fileKeyword; |
| 384 | ChipType_t chipType; |
| 385 | Version_t version; |
| 386 | stream >> fileKeyword >> chipType >> version; |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 387 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 388 | // Check the file keyword. |
| 389 | HEI_ASSERT(KW_CHIPDATA == fileKeyword); |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 390 | |
| 391 | // This chip type should not already exist. |
| 392 | HEI_ASSERT(io_isoChips.end() == io_isoChips.find(chipType)); |
| 393 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 394 | // So far there is only one supported version type so check it here. |
| 395 | HEI_ASSERT(VERSION_1 == version); |
| 396 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 397 | // Allocate memory for the new isolation chip. |
| 398 | auto isoChip = std::make_unique<IsolationChip>(chipType); |
| 399 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 400 | // Read the register list metadata. |
| 401 | SectionKeyword_t regsKeyword; |
| 402 | RegisterId_t numRegs; |
| 403 | stream >> regsKeyword >> numRegs; |
| 404 | |
| 405 | // Check the register keyword. |
| 406 | HEI_ASSERT(KW_REGS == regsKeyword); |
| 407 | |
| 408 | // There must be at least one register defined. |
| 409 | HEI_ASSERT(0 != numRegs); |
| 410 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 411 | for (unsigned int i = 0; i < numRegs; i++) |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 412 | { |
| 413 | __readRegister(stream, isoChip); |
| 414 | } |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 415 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 416 | // Read the node list metadata. |
| 417 | SectionKeyword_t nodeKeyword; |
| 418 | NodeId_t numNodes; |
| 419 | stream >> nodeKeyword >> numNodes; |
| 420 | |
| 421 | // Check the node keyword. |
| 422 | HEI_ASSERT(KW_NODE == nodeKeyword); |
| 423 | |
| 424 | // There must be at least one node defined. |
| 425 | HEI_ASSERT(0 != numNodes); |
| 426 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 427 | TmpNodeMap tmpNodeMap; // Stores all nodes with child node map. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 428 | for (unsigned int i = 0; i < numNodes; i++) |
| 429 | { |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 430 | __readNode(stream, isoChip, tmpNodeMap); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 431 | } |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 432 | // Link all nodes with their child nodes. Then add them to isoChip. |
| 433 | __insertNodes(isoChip, tmpNodeMap); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 434 | |
| 435 | // Read the root node list metadata. |
| 436 | SectionKeyword_t rootKeyword; |
| 437 | AttentionType_t numRoots; |
| 438 | stream >> rootKeyword >> numRoots; |
| 439 | |
| 440 | // Check the root node keyword. |
| 441 | HEI_ASSERT(KW_ROOT == rootKeyword); |
| 442 | |
| 443 | // There must be at least one register defined. |
| 444 | HEI_ASSERT(0 != numRoots); |
| 445 | |
| 446 | for (unsigned int i = 0; i < numRoots; i++) |
| 447 | { |
| 448 | __readRoot(stream, isoChip); |
| 449 | } |
| 450 | |
| 451 | // At this point, the stream is done and it should be at the end of the |
| 452 | // file. |
| 453 | HEI_ASSERT(stream.eof()); |
| 454 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 455 | // Add this isolation chip to the collective list of isolation chips. |
| 456 | auto ret = io_isoChips.emplace(chipType, std::move(isoChip)); |
| 457 | HEI_ASSERT(ret.second); // Just in case. |
| 458 | } |
| 459 | |
| 460 | //------------------------------------------------------------------------------ |
| 461 | |
| 462 | } // namespace libhei |