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