blob: a6bd46934217d3903bf8f356137f88cbb7795b89 [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
62 pdbg_target* target;
63 pdbg_for_each_class_target("fsi", target)
64 {
65 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
66 {
67 proc = pdbg_target_index(target); // get processor number
68
69 std::stringstream ss; // log message stream
Ben Tyner9dbab8b2020-03-31 08:55:23 -050070 ss << "checking processor " << proc;
Ben Tyneref320152020-01-09 10:31:23 -060071 log<level::INFO>(ss.str().c_str());
72
73 // get active attentions on processor
Ben Tynerb481d902020-03-05 10:24:23 -060074 if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060075 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -050076 log<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060077 }
78 else
79 {
80 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060081 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060082 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050083 ss << isr_val;
Ben Tyneref320152020-01-09 10:31:23 -060084 log<level::INFO>(ss.str().c_str());
85
86 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -060087 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -060088 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -050089 log<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060090 }
91 else
92 {
93 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060094 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060095 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050096 ss << isr_mask;
Ben Tyneref320152020-01-09 10:31:23 -060097 log<level::INFO>(ss.str().c_str());
98
99 // bit 0 on "left": bit 30 = SBE vital attention
100 if (isr_val & isr_mask & 0x00000002)
101 {
Ben Tyner3fb52e52020-03-31 10:10:07 -0500102 active_attentions.emplace_back(
103 Attention::Vital, handleVital, target, i_config);
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,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500111 i_config);
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,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500119 i_config);
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
Ben Tyner3fb52e52020-03-31 10:10:07 -0500151 *
152 * @param i_attention Attention object
153 * @return 0 indicates that the vital attention was successfully handled
154 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600155 */
Ben Tynerb481d902020-03-05 10:24:23 -0600156int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600157{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500158 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600159
Ben Tyner3fb52e52020-03-31 10:10:07 -0500160 // if vital handling enabled, handle vital attention
161 if (false == (i_attention->getConfig()->getFlag(enVital)))
162 {
163 log<level::INFO>("vital handling disabled");
164 rc = RC_NOT_SUCCESS;
165 }
166 else
Ben Tyneref320152020-01-09 10:31:23 -0600167 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500168 log<level::INFO>("vital NOT handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500169 rc = RC_NOT_SUCCESS;
Ben Tyneref320152020-01-09 10:31:23 -0600170 }
171
172 return rc;
173}
174
175/**
176 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500177 *
178 * @param i_attention Attention object
179 * @return 0 indicates that the checkstop attention was successfully handled
180 * 1 indicates that the checkstop attention was NOT successfully
181 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600182 */
Ben Tynerb481d902020-03-05 10:24:23 -0600183int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600184{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500185 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600186
Ben Tyner3fb52e52020-03-31 10:10:07 -0500187 // if checkstop handling enabled, handle checkstop attention
188 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
189 {
190 log<level::INFO>("Checkstop handling disabled");
191 rc = RC_NOT_SUCCESS;
192 }
193 else
194 {
195 analyzer::analyzeHardware();
196 rc = RC_SUCCESS;
197 }
Ben Tyneref320152020-01-09 10:31:23 -0600198
Ben Tyneref320152020-01-09 10:31:23 -0600199 return rc;
200}
201
202/**
203 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500204 *
205 * @param i_attention Attention object
206 * @return 0 indicates that the special attention was successfully handled
207 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600208 */
Ben Tynerb481d902020-03-05 10:24:23 -0600209int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600210{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500211 int rc = RC_NOT_SUCCESS; // assume special attention handling disabled
Ben Tyneref320152020-01-09 10:31:23 -0600212
Ben Tyner3fb52e52020-03-31 10:10:07 -0500213 // Until the special attention chipop is availabe we will treat the special
214 // attention as a TI. If TI handling is disabled we will treat the special
215 // attention as a breakpopint.
Ben Tyneref320152020-01-09 10:31:23 -0600216
Ben Tyner3fb52e52020-03-31 10:10:07 -0500217 // TI attention gets priority over breakpoints, if enabled then handle
218 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600219 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500220 log<level::INFO>("TI (terminate immediately)");
Ben Tyner7e6611f2020-02-13 16:42:56 -0600221
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600222 // Call TI special attention handler
223 tiHandler();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500224 rc = RC_SUCCESS;
225 }
226 else
227 {
228 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
229 {
230 log<level::INFO>("breakpoint");
231
232 // Call the breakpoint special attention handler
233 bpHandler();
234 rc = RC_SUCCESS;
235 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600236 }
Ben Tyneref320152020-01-09 10:31:23 -0600237
Ben Tyner3fb52e52020-03-31 10:10:07 -0500238 if (RC_SUCCESS != rc)
239 {
240 log<level::INFO>("Special attn handling disabled");
241 }
Ben Tyneref320152020-01-09 10:31:23 -0600242
243 return rc;
244}
245
Ben Tyneref320152020-01-09 10:31:23 -0600246} // namespace attn