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