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