Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 1 | #include <analyzer/analyzer_main.hpp> |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 2 | #include <attention.hpp> |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 3 | #include <attn_config.hpp> |
Ben Tyner | dbeaf79 | 2020-05-14 08:27:18 -0500 | [diff] [blame] | 4 | #include <attn_handler.hpp> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 5 | #include <attn_logging.hpp> |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 6 | #include <bp_handler.hpp> |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 7 | #include <ti_handler.hpp> |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 8 | |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 9 | #include <algorithm> |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 10 | #include <iomanip> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 11 | #include <map> |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 12 | #include <sstream> |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 13 | #include <vector> |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 14 | |
| 15 | namespace attn |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * @brief Handle SBE vital attention |
| 20 | * |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 21 | * @param i_attention Attention object |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 22 | * @return 0 indicates that the vital attention was successfully handled |
| 23 | * 1 indicates that the vital attention was NOT successfully handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 24 | */ |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 25 | int handleVital(Attention* i_attention); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * @brief Handle checkstop attention |
| 29 | * |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 30 | * @param i_attention Attention object |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 31 | * @return 0 indicates that the checkstop attention was successfully handled |
| 32 | * 1 indicates that the checkstop attention was NOT successfully |
| 33 | * handled. |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 34 | */ |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 35 | int handleCheckstop(Attention* i_attention); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * @brief Handle special attention |
| 39 | * |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 40 | * @param i_attention Attention object |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 41 | * @return 0 indicates that the special attention was successfully handled |
| 42 | * 1 indicates that the special attention was NOT successfully handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 43 | */ |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 44 | int handleSpecial(Attention* i_attention); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 45 | |
| 46 | /** |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 47 | * @brief The main attention handler logic |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 48 | * |
| 49 | * @param i_breakpoints true = breakpoint special attn handling enabled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 50 | */ |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 51 | void attnHandler(Config* i_config) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 52 | { |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 53 | // Vector of active attentions to be handled |
| 54 | std::vector<Attention> active_attentions; |
| 55 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 56 | uint32_t isr_val, isr_mask; |
| 57 | uint32_t proc; |
| 58 | |
| 59 | // loop through processors looking for active attentions |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 60 | trace<level::INFO>("Attention handler started"); |
Ben Tyner | 117af99 | 2020-05-22 13:32:11 -0500 | [diff] [blame] | 61 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 62 | pdbg_target* target; |
| 63 | pdbg_for_each_class_target("fsi", target) |
| 64 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 65 | trace<level::INFO>("iterating targets"); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 66 | if (PDBG_TARGET_ENABLED == pdbg_target_probe(target)) |
| 67 | { |
| 68 | proc = pdbg_target_index(target); // get processor number |
| 69 | |
| 70 | std::stringstream ss; // log message stream |
Ben Tyner | 9dbab8b | 2020-03-31 08:55:23 -0500 | [diff] [blame] | 71 | ss << "checking processor " << proc; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 72 | trace<level::INFO>(ss.str().c_str()); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 73 | |
| 74 | // get active attentions on processor |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 75 | if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val)) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 76 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 77 | // event |
| 78 | eventAttentionFail(RC_CFAM_ERROR); |
| 79 | |
| 80 | // trace |
| 81 | trace<level::INFO>("Error! cfam read 0x1007 FAILED"); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 82 | } |
| 83 | else |
| 84 | { |
| 85 | std::stringstream ss; // log message stream |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 86 | ss << "cfam 0x1007 = 0x"; |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 87 | ss << std::hex << std::setw(8) << std::setfill('0'); |
Ben Tyner | 9dbab8b | 2020-03-31 08:55:23 -0500 | [diff] [blame] | 88 | ss << isr_val; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 89 | trace<level::INFO>(ss.str().c_str()); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 90 | |
| 91 | // get interrupt enabled special attentions mask |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 92 | if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask)) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 93 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 94 | // event |
| 95 | eventAttentionFail(RC_CFAM_ERROR); |
| 96 | |
| 97 | // trace |
| 98 | trace<level::INFO>("Error! cfam read 0x100d FAILED"); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 99 | } |
| 100 | else |
| 101 | { |
| 102 | std::stringstream ss; // log message stream |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 103 | ss << "cfam 0x100d = 0x"; |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 104 | ss << std::hex << std::setw(8) << std::setfill('0'); |
Ben Tyner | 9dbab8b | 2020-03-31 08:55:23 -0500 | [diff] [blame] | 105 | ss << isr_mask; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 106 | trace<level::INFO>(ss.str().c_str()); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 107 | |
| 108 | // bit 0 on "left": bit 30 = SBE vital attention |
| 109 | if (isr_val & isr_mask & 0x00000002) |
| 110 | { |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 111 | active_attentions.emplace_back( |
| 112 | Attention::Vital, handleVital, target, i_config); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // bit 0 on "left": bit 1 = checkstop |
| 116 | if (isr_val & isr_mask & 0x40000000) |
| 117 | { |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 118 | active_attentions.emplace_back(Attention::Checkstop, |
| 119 | handleCheckstop, target, |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 120 | i_config); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // bit 0 on "left": bit 2 = special attention |
| 124 | if (isr_val & isr_mask & 0x20000000) |
| 125 | { |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 126 | active_attentions.emplace_back(Attention::Special, |
| 127 | handleSpecial, target, |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 128 | i_config); |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 129 | } |
| 130 | } // cfam 0x100d valid |
| 131 | } // cfam 0x1007 valid |
| 132 | } // fsi target enabled |
| 133 | } // next processor |
| 134 | |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 135 | // convert to heap, highest priority is at front |
| 136 | if (!std::is_heap(active_attentions.begin(), active_attentions.end())) |
| 137 | { |
| 138 | std::make_heap(active_attentions.begin(), active_attentions.end()); |
| 139 | } |
| 140 | |
| 141 | // call the attention handler until one is handled or all were attempted |
| 142 | while (false == active_attentions.empty()) |
| 143 | { |
| 144 | // handle highest priority attention, done if successful |
| 145 | if (RC_SUCCESS == active_attentions.front().handle()) |
| 146 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 147 | // an attention was handled so we are done |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 148 | break; |
| 149 | } |
| 150 | |
| 151 | // move attention to back of vector |
| 152 | std::pop_heap(active_attentions.begin(), active_attentions.end()); |
| 153 | |
| 154 | // remove attention from vector |
| 155 | active_attentions.pop_back(); |
| 156 | } |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @brief Handle SBE vital attention |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 161 | * |
| 162 | * @param i_attention Attention object |
| 163 | * @return 0 indicates that the vital attention was successfully handled |
| 164 | * 1 indicates that the vital attention was NOT successfully handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 165 | */ |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 166 | int handleVital(Attention* i_attention) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 167 | { |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 168 | int rc = RC_SUCCESS; // assume vital handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 169 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 170 | trace<level::INFO>("vital handler started"); |
| 171 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 172 | // if vital handling enabled, handle vital attention |
| 173 | if (false == (i_attention->getConfig()->getFlag(enVital))) |
| 174 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 175 | trace<level::INFO>("vital handling disabled"); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 176 | } |
| 177 | else |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 178 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 179 | // TODO need vital attention handling |
| 180 | |
| 181 | // FIXME TEMP CODE - begin |
| 182 | if (0) |
| 183 | { |
| 184 | eventVital(); |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | trace<level::INFO>("vital NOT handled"); // enabled but not handled |
| 189 | rc = RC_NOT_HANDLED; |
| 190 | } |
| 191 | // FIXME TEMP CODE -end |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | return rc; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @brief Handle checkstop attention |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 199 | * |
| 200 | * @param i_attention Attention object |
| 201 | * @return 0 indicates that the checkstop attention was successfully handled |
| 202 | * 1 indicates that the checkstop attention was NOT successfully |
| 203 | * handled. |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 204 | */ |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 205 | int handleCheckstop(Attention* i_attention) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 206 | { |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 207 | int rc = RC_SUCCESS; // assume checkstop handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 208 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 209 | trace<level::INFO>("checkstop handler started"); |
| 210 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 211 | // if checkstop handling enabled, handle checkstop attention |
| 212 | if (false == (i_attention->getConfig()->getFlag(enCheckstop))) |
| 213 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 214 | trace<level::INFO>("Checkstop handling disabled"); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 215 | } |
| 216 | else |
| 217 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 218 | // errors that were isolated |
| 219 | std::map<std::string, std::string> errors; |
| 220 | |
Ben Tyner | dbeaf79 | 2020-05-14 08:27:18 -0500 | [diff] [blame] | 221 | // analyze errors |
| 222 | if (true != analyzer::analyzeHardware(errors)) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 223 | { |
| 224 | rc = RC_ANALYZER_ERROR; |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | std::stringstream ss; |
| 229 | ss << "Analyzer isolated " << errors.size() << " error(s)"; |
| 230 | trace<level::INFO>(ss.str().c_str()); |
| 231 | |
| 232 | // add checkstop event to log |
| 233 | eventCheckstop(errors); |
| 234 | } |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 235 | } |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 236 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 237 | return rc; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @brief Handle special attention |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 242 | * |
| 243 | * @param i_attention Attention object |
| 244 | * @return 0 indicates that the special attention was successfully handled |
| 245 | * 1 indicates that the special attention was NOT successfully handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 246 | */ |
Ben Tyner | b481d90 | 2020-03-05 10:24:23 -0600 | [diff] [blame] | 247 | int handleSpecial(Attention* i_attention) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 248 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 249 | int rc = RC_SUCCESS; // assume special attention handled |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 250 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 251 | trace<level::INFO>("special attention handler started"); |
| 252 | |
| 253 | // TODO |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 254 | // Until the special attention chipop is availabe we will treat the special |
| 255 | // attention as a TI. If TI handling is disabled we will treat the special |
| 256 | // attention as a breakpopint. |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 257 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 258 | // TI attention gets priority over breakpoints, if enabled then handle |
| 259 | if (true == (i_attention->getConfig()->getFlag(enTerminate))) |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 260 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 261 | trace<level::INFO>("TI (terminate immediately)"); |
Ben Tyner | 7e6611f | 2020-02-13 16:42:56 -0600 | [diff] [blame] | 262 | |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 263 | // Call TI special attention handler |
| 264 | tiHandler(); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 265 | |
| 266 | // generate log event |
| 267 | eventTerminate(); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 268 | } |
| 269 | else |
| 270 | { |
| 271 | if (true == (i_attention->getConfig()->getFlag(enBreakpoints))) |
| 272 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 273 | trace<level::INFO>("breakpoint"); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 274 | |
| 275 | // Call the breakpoint special attention handler |
| 276 | bpHandler(); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 277 | } |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 278 | } |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 279 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 280 | if (RC_SUCCESS != rc) |
| 281 | { |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 282 | trace<level::INFO>("Special attn handling disabled"); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 283 | } |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 284 | |
| 285 | return rc; |
| 286 | } |
| 287 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 288 | } // namespace attn |