blob: 4a5382d48b0e79bd0cf436e1b0de3a6c45e322e4 [file] [log] [blame]
Ben Tyneref320152020-01-09 10:31:23 -06001#include <libpdbg.h>
2
Ben Tyner0205f3b2020-02-24 10:24:47 -06003#include <analyzer/analyzer_main.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
8#include <iomanip>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06009#include <sstream>
Ben Tyneref320152020-01-09 10:31:23 -060010
11namespace attn
12{
13
14/**
15 * @brief Handle SBE vital attention
16 *
17 * @return 0 = success
18 */
19int handleVital();
20
21/**
22 * @brief Handle checkstop attention
23 *
24 * @return 0 = success
25 */
26int handleCheckstop();
27
28/**
29 * @brief Handle special attention
30 *
Ben Tyner970fd4f2020-02-19 13:46:42 -060031 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060032 * @return 0 = success
33 */
Ben Tyner970fd4f2020-02-19 13:46:42 -060034int handleSpecial(bool i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -060035
36/**
Ben Tyneref320152020-01-09 10:31:23 -060037 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060038 *
39 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060040 */
Ben Tyner970fd4f2020-02-19 13:46:42 -060041void attnHandler(bool i_breakpoints)
Ben Tyneref320152020-01-09 10:31:23 -060042{
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 Tyner9ae5ca42020-02-28 13:13:50 -060055 ss << "checking processor " << proc << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -060056 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 Tyner9ae5ca42020-02-28 13:13:50 -060062 ss << "Error! cfam read 0x1007 FAILED" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -060063 log<level::INFO>(ss.str().c_str());
64 }
65 else
66 {
67 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060068 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060069 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 Tyner9ae5ca42020-02-28 13:13:50 -060077 ss << "Error! cfam read 0x100d FAILED" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -060078 log<level::INFO>(ss.str().c_str());
79 }
80 else
81 {
82 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060083 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060084 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 Tyner9ae5ca42020-02-28 13:13:50 -060097 if (0 == handleCheckstop())
98 {
99 break;
100 }
Ben Tyneref320152020-01-09 10:31:23 -0600101 }
102
103 // bit 0 on "left": bit 2 = special attention
104 if (isr_val & isr_mask & 0x20000000)
105 {
Ben Tyner970fd4f2020-02-19 13:46:42 -0600106 handleSpecial(i_breakpoints);
Ben Tyneref320152020-01-09 10:31:23 -0600107 }
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 */
119int handleVital()
120{
121 int rc = 1; // vital attention handling not yet supported
122
123 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600124 ss << "vital" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600125 log<level::INFO>(ss.str().c_str());
126
127 if (0 != rc)
128 {
129 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600130 ss << "vital NOT handled" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600131 log<level::INFO>(ss.str().c_str());
132 }
133
134 return rc;
135}
136
137/**
138 * @brief Handle checkstop attention
139 */
140int handleCheckstop()
141{
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600142 int rc = 0; // checkstop handling supported
Ben Tyneref320152020-01-09 10:31:23 -0600143
144 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600145 ss << "checkstop" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600146 log<level::INFO>(ss.str().c_str());
147
Ben Tyner0205f3b2020-02-24 10:24:47 -0600148 analyzer::analyzeHardware();
Ben Tyneref320152020-01-09 10:31:23 -0600149
150 // TODO recoverable errors?
151
152 return rc;
153}
154
155/**
156 * @brief Handle special attention
Ben Tyner970fd4f2020-02-19 13:46:42 -0600157 *
158 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -0600159 */
Ben Tyner970fd4f2020-02-19 13:46:42 -0600160int handleSpecial(bool i_breakpoints)
Ben Tyneref320152020-01-09 10:31:23 -0600161{
162 int rc = 0; // special attention handling supported
163
164 std::stringstream ss; // log message stream
165
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600166 ss << "special" << std::endl;
Ben Tyneref320152020-01-09 10:31:23 -0600167
Ben Tyner970fd4f2020-02-19 13:46:42 -0600168 // 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 Tyner9ae5ca42020-02-28 13:13:50 -0600173 ss << "breakpoint" << std::endl;
Ben Tyner970fd4f2020-02-19 13:46:42 -0600174 log<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -0600175
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600176 // Call the breakpoint special attention handler
177 bpHandler();
Ben Tyner970fd4f2020-02-19 13:46:42 -0600178 }
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 Tyner9ae5ca42020-02-28 13:13:50 -0600185 ss << "TI (terminate immediately)" << std::endl;
Ben Tyner970fd4f2020-02-19 13:46:42 -0600186 log<level::INFO>(ss.str().c_str());
Ben Tyner7e6611f2020-02-13 16:42:56 -0600187
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600188 // Call TI special attention handler
189 tiHandler();
Ben Tyner970fd4f2020-02-19 13:46:42 -0600190 }
Ben Tyneref320152020-01-09 10:31:23 -0600191
192 // TODO recoverable errors?
193
194 return rc;
195}
196
Ben Tyneref320152020-01-09 10:31:23 -0600197} // namespace attn