blob: af62771bbb45643e5e919bd8a89ef3f9f09a8a36 [file] [log] [blame]
Ben Tyner0205f3b2020-02-24 10:24:47 -06001#include <analyzer/analyzer_main.hpp>
Ben Tynerb481d902020-03-05 10:24:23 -06002#include <attention.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06003#include <bp_handler.hpp>
4#include <logging.hpp>
5#include <ti_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -06006
Ben Tynerb481d902020-03-05 10:24:23 -06007#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -06008#include <iomanip>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06009#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060010#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060011
12namespace attn
13{
14
Ben Tynerb481d902020-03-05 10:24:23 -060015/** @brief Return codes */
16static constexpr int RC_SUCCESS = 0;
17static constexpr int RC_NOT_SUCCESS = 1;
18
Ben Tyneref320152020-01-09 10:31:23 -060019/**
20 * @brief Handle SBE vital attention
21 *
Ben Tynerb481d902020-03-05 10:24:23 -060022 * @param i_attention Attention object
Ben Tyneref320152020-01-09 10:31:23 -060023 * @return 0 = success
24 */
Ben Tynerb481d902020-03-05 10:24:23 -060025int handleVital(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060026
27/**
28 * @brief Handle checkstop attention
29 *
Ben Tynerb481d902020-03-05 10:24:23 -060030 * @param i_attention Attention object
Ben Tyneref320152020-01-09 10:31:23 -060031 * @return 0 = success
32 */
Ben Tynerb481d902020-03-05 10:24:23 -060033int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060034
35/**
36 * @brief Handle special attention
37 *
Ben Tynerb481d902020-03-05 10:24:23 -060038 * @param i_attention Attention object
Ben Tyneref320152020-01-09 10:31:23 -060039 * @return 0 = success
40 */
Ben Tynerb481d902020-03-05 10:24:23 -060041int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060042
43/**
Ben Tyneref320152020-01-09 10:31:23 -060044 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060045 *
46 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060047 */
Ben Tynerb481d902020-03-05 10:24:23 -060048void attnHandler(const bool i_breakpoints)
Ben Tyneref320152020-01-09 10:31:23 -060049{
Ben Tynerb481d902020-03-05 10:24:23 -060050 // Vector of active attentions to be handled
51 std::vector<Attention> active_attentions;
52
Ben Tyneref320152020-01-09 10:31:23 -060053 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 Tyner9ae5ca42020-02-28 13:13:50 -060065 ss << "checking processor " << proc << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -060066 log<level::INFO>(ss.str().c_str());
67
68 // get active attentions on processor
Ben Tynerb481d902020-03-05 10:24:23 -060069 if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060070 {
71 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060072 ss << "Error! cfam read 0x1007 FAILED" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -060073 log<level::INFO>(ss.str().c_str());
74 }
75 else
76 {
77 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060078 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060079 ss << std::hex << std::setw(8) << std::setfill('0');
80 ss << isr_val << std::endl;
81 log<level::INFO>(ss.str().c_str());
82
83 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -060084 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -060085 {
86 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060087 ss << "Error! cfam read 0x100d FAILED" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -060088 log<level::INFO>(ss.str().c_str());
89 }
90 else
91 {
92 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060093 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060094 ss << std::hex << std::setw(8) << std::setfill('0');
95 ss << isr_mask << std::endl;
96 log<level::INFO>(ss.str().c_str());
97
98 // bit 0 on "left": bit 30 = SBE vital attention
99 if (isr_val & isr_mask & 0x00000002)
100 {
Ben Tynerb481d902020-03-05 10:24:23 -0600101 active_attentions.emplace_back(Attention::Vital,
102 handleVital, target,
103 i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600104 }
105
106 // bit 0 on "left": bit 1 = checkstop
107 if (isr_val & isr_mask & 0x40000000)
108 {
Ben Tynerb481d902020-03-05 10:24:23 -0600109 active_attentions.emplace_back(Attention::Checkstop,
110 handleCheckstop, target,
111 i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600112 }
113
114 // bit 0 on "left": bit 2 = special attention
115 if (isr_val & isr_mask & 0x20000000)
116 {
Ben Tynerb481d902020-03-05 10:24:23 -0600117 active_attentions.emplace_back(Attention::Special,
118 handleSpecial, target,
119 i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600120 }
121 } // cfam 0x100d valid
122 } // cfam 0x1007 valid
123 } // fsi target enabled
124 } // next processor
125
Ben Tynerb481d902020-03-05 10:24:23 -0600126 // convert to heap, highest priority is at front
127 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
128 {
129 std::make_heap(active_attentions.begin(), active_attentions.end());
130 }
131
132 // call the attention handler until one is handled or all were attempted
133 while (false == active_attentions.empty())
134 {
135 // handle highest priority attention, done if successful
136 if (RC_SUCCESS == active_attentions.front().handle())
137 {
138 break;
139 }
140
141 // move attention to back of vector
142 std::pop_heap(active_attentions.begin(), active_attentions.end());
143
144 // remove attention from vector
145 active_attentions.pop_back();
146 }
Ben Tyneref320152020-01-09 10:31:23 -0600147}
148
149/**
150 * @brief Handle SBE vital attention
151 */
Ben Tynerb481d902020-03-05 10:24:23 -0600152int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600153{
Ben Tynerb481d902020-03-05 10:24:23 -0600154 int rc = RC_NOT_SUCCESS; // vital attention handling not yet supported
Ben Tyneref320152020-01-09 10:31:23 -0600155
156 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600157 ss << "vital" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600158 log<level::INFO>(ss.str().c_str());
159
Ben Tynerb481d902020-03-05 10:24:23 -0600160 if (RC_SUCCESS != rc)
Ben Tyneref320152020-01-09 10:31:23 -0600161 {
162 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600163 ss << "vital NOT handled" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600164 log<level::INFO>(ss.str().c_str());
165 }
166
167 return rc;
168}
169
170/**
171 * @brief Handle checkstop attention
172 */
Ben Tynerb481d902020-03-05 10:24:23 -0600173int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600174{
Ben Tynerb481d902020-03-05 10:24:23 -0600175 int rc = RC_SUCCESS; // checkstop handling supported
Ben Tyneref320152020-01-09 10:31:23 -0600176
177 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600178 ss << "checkstop" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600179 log<level::INFO>(ss.str().c_str());
180
Ben Tyner0205f3b2020-02-24 10:24:47 -0600181 analyzer::analyzeHardware();
Ben Tyneref320152020-01-09 10:31:23 -0600182
183 // TODO recoverable errors?
184
185 return rc;
186}
187
188/**
189 * @brief Handle special attention
190 */
Ben Tynerb481d902020-03-05 10:24:23 -0600191int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600192{
Ben Tynerb481d902020-03-05 10:24:23 -0600193 int rc = RC_SUCCESS; // special attention handling supported
Ben Tyneref320152020-01-09 10:31:23 -0600194
195 std::stringstream ss; // log message stream
196
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600197 ss << "special" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600198
Ben Tyner970fd4f2020-02-19 13:46:42 -0600199 // Right now we always handle breakpoint special attentions if breakpoint
200 // attn handling is enabled. This will eventually check if breakpoint attn
201 // handing is enabled AND there is a breakpoint pending.
Ben Tynerb481d902020-03-05 10:24:23 -0600202 if (0 != (i_attention->getFlags() & enableBreakpoints))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600203 {
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600204 ss << "breakpoint" << std::endl;
Ben Tyner970fd4f2020-02-19 13:46:42 -0600205 log<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -0600206
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600207 // Call the breakpoint special attention handler
208 bpHandler();
Ben Tyner970fd4f2020-02-19 13:46:42 -0600209 }
210 // Right now if breakpoint attn handling is not enabled we will treat the
211 // special attention as a TI. This will eventually be changed to check
212 // whether a TI is active and handle it regardless of whether breakpoint
213 // handling is enbaled or not.
214 else
215 {
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600216 ss << "TI (terminate immediately)" << std::endl;
Ben Tyner970fd4f2020-02-19 13:46:42 -0600217 log<level::INFO>(ss.str().c_str());
Ben Tyner7e6611f2020-02-13 16:42:56 -0600218
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600219 // Call TI special attention handler
220 tiHandler();
Ben Tyner970fd4f2020-02-19 13:46:42 -0600221 }
Ben Tyneref320152020-01-09 10:31:23 -0600222
223 // TODO recoverable errors?
224
225 return rc;
226}
227
Ben Tyneref320152020-01-09 10:31:23 -0600228} // namespace attn