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