Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Zane Shelley | 3a02e24 | 2020-05-08 16:25:36 -0500 | [diff] [blame] | 3 | #include <hei_signature.hpp> |
Zane Shelley | 995be6c | 2021-02-24 15:48:55 -0600 | [diff] [blame] | 4 | #include <util/hei_bit_string.hpp> |
Zane Shelley | 3a02e24 | 2020-05-08 16:25:36 -0500 | [diff] [blame] | 5 | |
Zane Shelley | 47ca5c2 | 2021-06-22 11:44:02 -0500 | [diff] [blame] | 6 | #include <algorithm> |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <memory> |
Zane Shelley | 3a02e24 | 2020-05-08 16:25:36 -0500 | [diff] [blame] | 9 | #include <vector> |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 10 | |
| 11 | namespace libhei |
| 12 | { |
| 13 | |
| 14 | /** |
Zane Shelley | b406de4 | 2019-09-09 16:10:38 -0500 | [diff] [blame] | 15 | * @brief The main isolate() API is given a list of chips to analyze. This class |
| 16 | * will contain a list of all active hardware errors found on those |
| 17 | * chips, the contents of any registers associated with the active |
| 18 | * errors, and any other data that can be useful for debug. |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 19 | */ |
| 20 | class IsolationData |
| 21 | { |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 22 | public: // Constructors, destructor, assignment, etc. |
Zane Shelley | b406de4 | 2019-09-09 16:10:38 -0500 | [diff] [blame] | 23 | /** @brief Default constructor. */ |
| 24 | IsolationData() = default; |
Zane Shelley | 5a26661 | 2019-08-15 16:23:53 -0500 | [diff] [blame] | 25 | |
| 26 | /** @brief Destructor. */ |
| 27 | ~IsolationData() = default; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 28 | |
| 29 | /** @brief Copy constructor. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 30 | IsolationData(const IsolationData&) = default; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 31 | |
| 32 | /** @brief Assignment operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 33 | IsolationData& operator=(const IsolationData&) = default; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 34 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 35 | public: |
| 36 | /** The data stored in each entry of the register dump. */ |
| 37 | struct RegDumpEntry |
| 38 | { |
| 39 | RegDumpEntry(RegisterId_t i_regId, Instance_t i_regInst, |
| 40 | std::shared_ptr<BitStringBuffer> i_data) : |
Patrick Williams | 8db65db | 2024-08-16 15:22:30 -0400 | [diff] [blame] | 41 | regId(i_regId), regInst(i_regInst), data(i_data) |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 42 | {} |
| 43 | |
| 44 | RegisterId_t regId; ///< 3-byte register ID |
| 45 | Instance_t regInst; ///< 1-byte register instance |
| 46 | std::shared_ptr<BitStringBuffer> data; ///< register data |
Zane Shelley | 47ca5c2 | 2021-06-22 11:44:02 -0500 | [diff] [blame] | 47 | |
| 48 | bool operator==(const RegDumpEntry& r) const |
| 49 | { |
| 50 | return regId == r.regId && regInst == r.regInst && *data == *r.data; |
| 51 | } |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 52 | }; |
| 53 | |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 54 | private: // Instance variables |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 55 | /** A list of all signatures found during isolation. */ |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 56 | std::vector<Signature> iv_sigList; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 57 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 58 | /** |
| 59 | * This intended to be a snapshot of the register values read from hardware |
| 60 | * as the isolator iterates the isolation tree. Therefore, it cannot share |
| 61 | * the values stored in the hardware register cache. Instead, it must be a |
| 62 | * copy of the data. |
| 63 | */ |
| 64 | std::map<Chip, std::vector<RegDumpEntry>> iv_regDump; |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 65 | |
| 66 | public: // Member functions |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 67 | /** |
| 68 | * @brief Adds a signature to the signature list. |
| 69 | * @param i_signature The target signature. |
| 70 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 71 | void addSignature(const Signature& i_signature) |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 72 | { |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 73 | iv_sigList.push_back(i_signature); |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 76 | /** |
| 77 | * @brief Adds the contents of a register to the register dump. |
| 78 | * @param i_chip The chip associated with this register. |
| 79 | * @param i_regId The register ID. |
| 80 | * @param i_regInst The register instance. |
| 81 | * @param i_data A BitString containing the contents of the register. |
| 82 | * Note that this function will make a copy of the data, |
| 83 | * which will be stored separately from the hardware |
| 84 | * register cache. |
| 85 | */ |
| 86 | void addRegister(const Chip& i_chip, RegisterId_t i_regId, |
| 87 | Instance_t i_regInst, const BitString* i_data) |
| 88 | { |
| 89 | if (!i_data->isZero()) // Only add non-zero values to save space. |
| 90 | { |
| 91 | // Make a copy of the register value. |
| 92 | auto data = std::make_shared<BitStringBuffer>(*i_data); |
| 93 | |
Zane Shelley | 47ca5c2 | 2021-06-22 11:44:02 -0500 | [diff] [blame] | 94 | // We'll want to avoid adding duplicate data if possible. |
| 95 | if (iv_regDump.end() == iv_regDump.find(i_chip)) |
| 96 | { |
| 97 | // The chip doesn't exist in the map. Therefore, the data |
| 98 | // doesn't currently exist. So, add it. |
| 99 | iv_regDump[i_chip].emplace_back(i_regId, i_regInst, data); |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | // Search this chip for the data. |
| 104 | RegDumpEntry entry{i_regId, i_regInst, data}; |
| 105 | auto itr = std::find(iv_regDump[i_chip].begin(), |
| 106 | iv_regDump[i_chip].end(), entry); |
| 107 | |
| 108 | if (iv_regDump[i_chip].end() == itr) |
| 109 | { |
| 110 | // The data doesn't currently exist. So, add it. |
| 111 | iv_regDump[i_chip].push_back(entry); |
| 112 | } |
| 113 | } |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 117 | /** @brief Allows access to the signature list. */ |
Zane Shelley | 2e38ae5 | 2020-11-05 22:21:30 -0600 | [diff] [blame] | 118 | const std::vector<Signature>& getSignatureList() const |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 119 | { |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 120 | return iv_sigList; |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 123 | /** @brief Allows access to the register dump. */ |
| 124 | const std::map<Chip, std::vector<RegDumpEntry>>& getRegisterDump() const |
| 125 | { |
| 126 | return iv_regDump; |
| 127 | } |
| 128 | |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 129 | /** @brief Flushes the data to ensure a clean slate for isolation. */ |
| 130 | void flush() |
| 131 | { |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 132 | iv_sigList.clear(); |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 133 | iv_regDump.clear(); |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 134 | } |
Zane Shelley | 5a26661 | 2019-08-15 16:23:53 -0500 | [diff] [blame] | 135 | |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 136 | }; // end class IsolationData |
| 137 | |
| 138 | } // end namespace libhei |