blob: 65d980aa03e10356f009804cb4bc00ec32293735 [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 Tyner9dbab8b2020-03-31 08:55:23 -050065 ss << "checking processor " << proc;
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 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -050071 log<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060072 }
73 else
74 {
75 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060076 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060077 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050078 ss << isr_val;
Ben Tyneref320152020-01-09 10:31:23 -060079 log<level::INFO>(ss.str().c_str());
80
81 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -060082 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -060083 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -050084 log<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060085 }
86 else
87 {
88 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060089 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060090 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050091 ss << isr_mask;
Ben Tyneref320152020-01-09 10:31:23 -060092 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 Tynerb481d902020-03-05 10:24:23 -060097 active_attentions.emplace_back(Attention::Vital,
98 handleVital, target,
99 i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600100 }
101
102 // bit 0 on "left": bit 1 = checkstop
103 if (isr_val & isr_mask & 0x40000000)
104 {
Ben Tynerb481d902020-03-05 10:24:23 -0600105 active_attentions.emplace_back(Attention::Checkstop,
106 handleCheckstop, target,
107 i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600108 }
109
110 // bit 0 on "left": bit 2 = special attention
111 if (isr_val & isr_mask & 0x20000000)
112 {
Ben Tynerb481d902020-03-05 10:24:23 -0600113 active_attentions.emplace_back(Attention::Special,
114 handleSpecial, target,
115 i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600116 }
117 } // cfam 0x100d valid
118 } // cfam 0x1007 valid
119 } // fsi target enabled
120 } // next processor
121
Ben Tynerb481d902020-03-05 10:24:23 -0600122 // 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 Tyneref320152020-01-09 10:31:23 -0600143}
144
145/**
146 * @brief Handle SBE vital attention
147 */
Ben Tynerb481d902020-03-05 10:24:23 -0600148int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600149{
Ben Tynerb481d902020-03-05 10:24:23 -0600150 int rc = RC_NOT_SUCCESS; // vital attention handling not yet supported
Ben Tyneref320152020-01-09 10:31:23 -0600151
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500152 log<level::INFO>("vital");
Ben Tyneref320152020-01-09 10:31:23 -0600153
Ben Tynerb481d902020-03-05 10:24:23 -0600154 if (RC_SUCCESS != rc)
Ben Tyneref320152020-01-09 10:31:23 -0600155 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500156 log<level::INFO>("vital NOT handled");
Ben Tyneref320152020-01-09 10:31:23 -0600157 }
158
159 return rc;
160}
161
162/**
163 * @brief Handle checkstop attention
164 */
Ben Tynerb481d902020-03-05 10:24:23 -0600165int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600166{
Ben Tynerb481d902020-03-05 10:24:23 -0600167 int rc = RC_SUCCESS; // checkstop handling supported
Ben Tyneref320152020-01-09 10:31:23 -0600168
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500169 log<level::INFO>("checkstop");
Ben Tyneref320152020-01-09 10:31:23 -0600170
Ben Tyner0205f3b2020-02-24 10:24:47 -0600171 analyzer::analyzeHardware();
Ben Tyneref320152020-01-09 10:31:23 -0600172
Ben Tyneref320152020-01-09 10:31:23 -0600173 return rc;
174}
175
176/**
177 * @brief Handle special attention
178 */
Ben Tynerb481d902020-03-05 10:24:23 -0600179int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600180{
Ben Tynerb481d902020-03-05 10:24:23 -0600181 int rc = RC_SUCCESS; // special attention handling supported
Ben Tyneref320152020-01-09 10:31:23 -0600182
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500183 log<level::INFO>("special");
Ben Tyneref320152020-01-09 10:31:23 -0600184
Ben Tyner970fd4f2020-02-19 13:46:42 -0600185 // 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 Tynerb481d902020-03-05 10:24:23 -0600188 if (0 != (i_attention->getFlags() & enableBreakpoints))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600189 {
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500190 log<level::INFO>("breakpoint");
Ben Tyneref320152020-01-09 10:31:23 -0600191
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600192 // Call the breakpoint special attention handler
193 bpHandler();
Ben Tyner970fd4f2020-02-19 13:46:42 -0600194 }
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 Tyner9dbab8b2020-03-31 08:55:23 -0500201 log<level::INFO>("TI (terminate immediately)");
Ben Tyner7e6611f2020-02-13 16:42:56 -0600202
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600203 // Call TI special attention handler
204 tiHandler();
Ben Tyner970fd4f2020-02-19 13:46:42 -0600205 }
Ben Tyneref320152020-01-09 10:31:23 -0600206
207 // TODO recoverable errors?
208
209 return rc;
210}
211
Ben Tyneref320152020-01-09 10:31:23 -0600212} // namespace attn