blob: 8c26bb386717e6ca2f33d198141b2075f40d2102 [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 Tyner3fb52e52020-03-31 10:10:07 -05003#include <attn_config.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06004#include <bp_handler.hpp>
5#include <logging.hpp>
6#include <ti_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -06007
Ben Tynerb481d902020-03-05 10:24:23 -06008#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -06009#include <iomanip>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060010#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060011#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060012
13namespace attn
14{
15
Ben Tynerb481d902020-03-05 10:24:23 -060016/** @brief Return codes */
17static constexpr int RC_SUCCESS = 0;
18static constexpr int RC_NOT_SUCCESS = 1;
19
Ben Tyneref320152020-01-09 10:31:23 -060020/**
21 * @brief Handle SBE vital attention
22 *
Ben Tynerb481d902020-03-05 10:24:23 -060023 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050024 * @return 0 indicates that the vital attention was successfully handled
25 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060026 */
Ben Tynerb481d902020-03-05 10:24:23 -060027int handleVital(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060028
29/**
30 * @brief Handle checkstop attention
31 *
Ben Tynerb481d902020-03-05 10:24:23 -060032 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050033 * @return 0 indicates that the checkstop attention was successfully handled
34 * 1 indicates that the checkstop attention was NOT successfully
35 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060036 */
Ben Tynerb481d902020-03-05 10:24:23 -060037int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060038
39/**
40 * @brief Handle special attention
41 *
Ben Tynerb481d902020-03-05 10:24:23 -060042 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050043 * @return 0 indicates that the special attention was successfully handled
44 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060045 */
Ben Tynerb481d902020-03-05 10:24:23 -060046int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060047
48/**
Ben Tyneref320152020-01-09 10:31:23 -060049 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060050 *
51 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060052 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050053void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060054{
Ben Tynerb481d902020-03-05 10:24:23 -060055 // Vector of active attentions to be handled
56 std::vector<Attention> active_attentions;
57
Ben Tyneref320152020-01-09 10:31:23 -060058 uint32_t isr_val, isr_mask;
59 uint32_t proc;
60
61 // loop through processors looking for active attentions
Ben Tyner117af992020-05-22 13:32:11 -050062 log<level::INFO>("Attention handler started");
63
Ben Tyneref320152020-01-09 10:31:23 -060064 pdbg_target* target;
65 pdbg_for_each_class_target("fsi", target)
66 {
Ben Tyner117af992020-05-22 13:32:11 -050067 log<level::INFO>("iterating targets");
Ben Tyneref320152020-01-09 10:31:23 -060068 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 Tyner9dbab8b2020-03-31 08:55:23 -050073 ss << "checking processor " << proc;
Ben Tyneref320152020-01-09 10:31:23 -060074 log<level::INFO>(ss.str().c_str());
75
76 // get active attentions on processor
Ben Tynerb481d902020-03-05 10:24:23 -060077 if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060078 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -050079 log<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060080 }
81 else
82 {
83 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060084 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060085 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050086 ss << isr_val;
Ben Tyneref320152020-01-09 10:31:23 -060087 log<level::INFO>(ss.str().c_str());
88
89 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -060090 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -060091 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -050092 log<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060093 }
94 else
95 {
96 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060097 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060098 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050099 ss << isr_mask;
Ben Tyneref320152020-01-09 10:31:23 -0600100 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 Tyner3fb52e52020-03-31 10:10:07 -0500105 active_attentions.emplace_back(
106 Attention::Vital, handleVital, target, i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600107 }
108
109 // bit 0 on "left": bit 1 = checkstop
110 if (isr_val & isr_mask & 0x40000000)
111 {
Ben Tynerb481d902020-03-05 10:24:23 -0600112 active_attentions.emplace_back(Attention::Checkstop,
113 handleCheckstop, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500114 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600115 }
116
117 // bit 0 on "left": bit 2 = special attention
118 if (isr_val & isr_mask & 0x20000000)
119 {
Ben Tynerb481d902020-03-05 10:24:23 -0600120 active_attentions.emplace_back(Attention::Special,
121 handleSpecial, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500122 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600123 }
124 } // cfam 0x100d valid
125 } // cfam 0x1007 valid
126 } // fsi target enabled
127 } // next processor
128
Ben Tynerb481d902020-03-05 10:24:23 -0600129 // 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 Tyneref320152020-01-09 10:31:23 -0600150}
151
152/**
153 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500154 *
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 Tyneref320152020-01-09 10:31:23 -0600158 */
Ben Tynerb481d902020-03-05 10:24:23 -0600159int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600160{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500161 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600162
Ben Tyner3fb52e52020-03-31 10:10:07 -0500163 // 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 Tyneref320152020-01-09 10:31:23 -0600170 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500171 log<level::INFO>("vital NOT handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500172 rc = RC_NOT_SUCCESS;
Ben Tyneref320152020-01-09 10:31:23 -0600173 }
174
175 return rc;
176}
177
178/**
179 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500180 *
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 Tyneref320152020-01-09 10:31:23 -0600185 */
Ben Tynerb481d902020-03-05 10:24:23 -0600186int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600187{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500188 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600189
Ben Tyner3fb52e52020-03-31 10:10:07 -0500190 // 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 Tyneref320152020-01-09 10:31:23 -0600201
Ben Tyneref320152020-01-09 10:31:23 -0600202 return rc;
203}
204
205/**
206 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500207 *
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 Tyneref320152020-01-09 10:31:23 -0600211 */
Ben Tynerb481d902020-03-05 10:24:23 -0600212int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600213{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500214 int rc = RC_NOT_SUCCESS; // assume special attention handling disabled
Ben Tyneref320152020-01-09 10:31:23 -0600215
Ben Tyner3fb52e52020-03-31 10:10:07 -0500216 // 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 Tyneref320152020-01-09 10:31:23 -0600219
Ben Tyner3fb52e52020-03-31 10:10:07 -0500220 // TI attention gets priority over breakpoints, if enabled then handle
221 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600222 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500223 log<level::INFO>("TI (terminate immediately)");
Ben Tyner7e6611f2020-02-13 16:42:56 -0600224
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600225 // Call TI special attention handler
226 tiHandler();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500227 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 Tyner970fd4f2020-02-19 13:46:42 -0600239 }
Ben Tyneref320152020-01-09 10:31:23 -0600240
Ben Tyner3fb52e52020-03-31 10:10:07 -0500241 if (RC_SUCCESS != rc)
242 {
243 log<level::INFO>("Special attn handling disabled");
244 }
Ben Tyneref320152020-01-09 10:31:23 -0600245
246 return rc;
247}
248
Ben Tyneref320152020-01-09 10:31:23 -0600249} // namespace attn