Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 1 | #include "simulator.hpp" |
| 2 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 3 | #include <util/hei_includes.hpp> |
| 4 | |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 5 | #include <fstream> // std::ifstream |
| 6 | |
| 7 | namespace libhei |
| 8 | { |
| 9 | |
| 10 | //------------------------------------------------------------------------------ |
| 11 | |
| 12 | // Paths are relative from the build/ directory |
Zane Shelley | 8c093d8 | 2020-05-04 22:06:52 -0500 | [diff] [blame] | 13 | const std::map<SimulatorData::SimChipType, const char*> |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 14 | SimulatorData::cv_chipPath = { |
Zane Shelley | aadf3bf | 2020-04-30 21:25:29 -0500 | [diff] [blame] | 15 | {SAMPLE, "../test/simulator/sample_data/sample.cdb"}, |
Zane Shelley | 2215d23 | 2023-04-07 14:43:40 -0500 | [diff] [blame] | 16 | {EXPLORER_11, "chip_data/chip_data_explorer_11.cdb"}, |
| 17 | {EXPLORER_20, "chip_data/chip_data_explorer_20.cdb"}, |
| 18 | {P10_10, "chip_data/chip_data_p10_10.cdb"}, |
| 19 | {P10_20, "chip_data/chip_data_p10_20.cdb"}, |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 20 | }; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 21 | |
| 22 | //------------------------------------------------------------------------------ |
| 23 | |
| 24 | void SimulatorData::addChip(const Chip& i_chip) |
| 25 | { |
| 26 | // First check if this entry already exists. |
Zane Shelley | 8c093d8 | 2020-05-04 22:06:52 -0500 | [diff] [blame] | 27 | auto chip_itr = std::find(iv_chipList.begin(), iv_chipList.end(), i_chip); |
| 28 | ASSERT_EQ(iv_chipList.end(), chip_itr); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 29 | |
| 30 | // Add the new entry. |
| 31 | iv_chipList.push_back(i_chip); |
| 32 | |
Zane Shelley | 8c093d8 | 2020-05-04 22:06:52 -0500 | [diff] [blame] | 33 | // Check if this chip type has been initialized. |
| 34 | ChipType_t chipType = i_chip.getType(); |
| 35 | auto type_itr = std::find(iv_typeList.begin(), iv_typeList.end(), chipType); |
| 36 | if (iv_typeList.end() != type_itr) |
| 37 | { |
| 38 | return; // No need to continue. |
| 39 | } |
| 40 | |
| 41 | // Add the new entry. |
| 42 | iv_typeList.push_back(chipType); |
| 43 | |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 44 | // Look for the file path |
Zane Shelley | 8c093d8 | 2020-05-04 22:06:52 -0500 | [diff] [blame] | 45 | auto itr2 = cv_chipPath.find(static_cast<SimChipType>(chipType)); |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 46 | ASSERT_NE(cv_chipPath.end(), itr2); |
| 47 | const char* path = itr2->second; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 48 | |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 49 | // Open the Chip Data File |
| 50 | std::ifstream cdf{path, std::ifstream::binary}; |
| 51 | ASSERT_TRUE(cdf.good()); |
| 52 | |
| 53 | // Get the length of file |
| 54 | cdf.seekg(0, cdf.end); |
| 55 | size_t sz_buffer = cdf.tellg(); |
| 56 | cdf.seekg(0, cdf.beg); |
| 57 | |
| 58 | // Allocate memory |
| 59 | char* buffer = new char[sz_buffer]; |
| 60 | |
| 61 | // Read data as a block |
| 62 | cdf.read(buffer, sz_buffer); |
| 63 | |
| 64 | // Close the Chip Data File |
| 65 | cdf.close(); |
| 66 | |
| 67 | // Initilize the chip with this Chip Data File. |
Zane Shelley | dd109cc | 2020-04-30 21:41:41 -0500 | [diff] [blame] | 68 | initialize(buffer, sz_buffer); |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 69 | |
| 70 | // Clean up the buffer |
| 71 | delete[] buffer; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | //------------------------------------------------------------------------------ |
| 75 | |
Zane Shelley | 2215d23 | 2023-04-07 14:43:40 -0500 | [diff] [blame] | 76 | const char* __attn(AttentionType_t i_type) |
| 77 | { |
| 78 | const char* str = ""; |
| 79 | switch (i_type) |
| 80 | { |
| 81 | case ATTN_TYPE_CHIP_CS: |
| 82 | str = "CHIP_CS"; |
| 83 | break; |
| 84 | case ATTN_TYPE_UNIT_CS: |
| 85 | str = "UNIT_CS"; |
| 86 | break; |
| 87 | case ATTN_TYPE_RECOVERABLE: |
| 88 | str = "RECOVERABLE"; |
| 89 | break; |
| 90 | case ATTN_TYPE_SP_ATTN: |
| 91 | str = "SP_ATTN"; |
| 92 | break; |
| 93 | case ATTN_TYPE_HOST_ATTN: |
| 94 | str = "HOST_ATTN"; |
| 95 | break; |
| 96 | default: |
| 97 | HEI_ERR("Unsupported attention type: %u", i_type); |
| 98 | assert(0); |
| 99 | } |
| 100 | return str; |
| 101 | } |
| 102 | |
| 103 | //------------------------------------------------------------------------------ |
| 104 | |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 105 | void SimulatorData::endIteration() |
| 106 | { |
| 107 | // Start by calling libhei::isolate(). |
| 108 | IsolationData isoData{}; |
Zane Shelley | 229c155 | 2020-05-04 22:44:15 -0500 | [diff] [blame] | 109 | isolate(iv_chipList, isoData); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 110 | |
Zane Shelley | 88eb202 | 2022-01-20 14:25:14 -0600 | [diff] [blame] | 111 | /* TODO: Currently used for debug. Eventually, we want this written to file. |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 112 | for (const auto& e : isoData.getRegisterDump()) |
| 113 | { |
| 114 | HEI_INF("Chip: %s", (const char*)e.first.getChip()); |
| 115 | |
| 116 | for (const auto& r : e.second) |
| 117 | { |
| 118 | HEI_INF(" Reg: 0x%06x %d 0x%016" PRIx64, r.regId, r.regInst, |
| 119 | r.data->getFieldRight(0, 64)); |
| 120 | } |
| 121 | } |
| 122 | */ |
| 123 | |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 124 | // Get the list of signatures found in isolation. |
| 125 | std::vector<Signature> givenSigList = isoData.getSignatureList(); |
| 126 | |
Zane Shelley | 2215d23 | 2023-04-07 14:43:40 -0500 | [diff] [blame] | 127 | // Print out the expected signature list and verify matches with given list. |
| 128 | HEI_INF("Signature summary:") |
| 129 | bool mismatch = false; |
| 130 | for (const auto& e : iv_expSigList) |
Zane Shelley | 88eb202 | 2022-01-20 14:25:14 -0600 | [diff] [blame] | 131 | { |
Zane Shelley | 2215d23 | 2023-04-07 14:43:40 -0500 | [diff] [blame] | 132 | auto gItr = std::find(givenSigList.begin(), givenSigList.end(), e); |
| 133 | if (givenSigList.end() != gItr) |
| 134 | { |
| 135 | HEI_INF(" Match: %s 0x%04x %2u %2u %s", |
| 136 | (const char*)e.getChip().getChip(), e.getId(), |
| 137 | e.getInstance(), e.getBit(), __attn(e.getAttnType())); |
Zane Shelley | 88eb202 | 2022-01-20 14:25:14 -0600 | [diff] [blame] | 138 | |
Zane Shelley | 2215d23 | 2023-04-07 14:43:40 -0500 | [diff] [blame] | 139 | // Remove from given signature list so we can determine if there are |
| 140 | // any leftovers at the end. |
| 141 | givenSigList.erase(gItr); |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | HEI_INF(" No match: %s 0x%04x %2u %2u %s", |
| 146 | (const char*)e.getChip().getChip(), e.getId(), |
| 147 | e.getInstance(), e.getBit(), __attn(e.getAttnType())); |
| 148 | |
| 149 | mismatch = true; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Print out any leftover signatures from the given list. |
| 154 | for (const auto& g : givenSigList) |
| 155 | { |
| 156 | HEI_INF(" Unexpected: %s 0x%04x %2u %2u %s", |
| 157 | (const char*)g.getChip().getChip(), g.getId(), g.getInstance(), |
| 158 | g.getBit(), __attn(g.getAttnType())); |
| 159 | |
| 160 | mismatch = true; |
| 161 | } |
| 162 | |
| 163 | // Final check for mismatches. |
| 164 | ASSERT_FALSE(mismatch); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 165 | |
| 166 | // The iteration is complete so we can flush the data. |
| 167 | flushIterationData(); |
| 168 | } |
Zane Shelley | 1be4c3c | 2020-04-17 15:55:07 -0500 | [diff] [blame] | 169 | |
| 170 | } // end namespace libhei |