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