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