20 #include "pedigree/kernel/debugger/commands/DevicesCommand.h" 21 #include "pedigree/kernel/debugger/DebuggerIO.h" 22 #include "pedigree/kernel/machine/Device.h" 23 #include "pedigree/kernel/utilities/String.h" 24 #include "pedigree/kernel/utilities/utility.h" 44 pScreen->disableCli();
48 int nLines = ((pScreen->getHeight() - 2) * 3) / 4;
52 tree.resize(pScreen->
getWidth(), nLines);
53 tree.setScrollKeys(
'o',
'p');
56 info.move(0, nLines + 2);
57 info.resize(pScreen->
getWidth(), pScreen->getHeight() - nLines - 3);
58 info.setScrollKeys(
'j',
'k');
60 pScreen->disableRefreshes();
61 drawBackground(nLines, pScreen);
62 tree.refresh(pScreen);
63 info.refresh(pScreen);
67 bool bContinue =
true;
71 while ((c = pScreen->
getChar()) == 0)
79 tree.centreOn(tree.m_Line);
80 tree.refresh(pScreen);
81 info.setDevice(tree.getDevForIndex(tree.m_Line));
82 info.refresh(pScreen);
86 if (tree.m_Line < tree.getLineCount() - 1)
88 tree.centreOn(tree.m_Line);
89 tree.refresh(pScreen);
90 info.setDevice(tree.getDevForIndex(tree.m_Line));
91 info.refresh(pScreen);
96 info.refresh(pScreen);
101 info.refresh(pScreen);
107 info.getDevice()->
dump(str);
108 drawBackground(0, pScreen);
110 "Querying device - press any key to exit. ", 1, 0,
111 DebuggerIO::White, DebuggerIO::Black);
113 str, 2, 0, DebuggerIO::LightGrey, DebuggerIO::Black);
114 while ((c = pScreen->
getChar()) == 0)
116 drawBackground(nLines, pScreen);
117 tree.refresh(pScreen);
118 info.refresh(pScreen);
127 void DevicesCommand::drawBackground(
size_t nLines,
DebuggerIO *pScreen)
134 ' ', 0, 0, pScreen->
getWidth() - 1, DebuggerIO::White,
137 ' ', pScreen->getHeight() - 1, 0, pScreen->
getWidth() - 1,
138 DebuggerIO::White, DebuggerIO::Green);
141 "Pedigree debugger - Device tree", 0, 0, DebuggerIO::White,
145 "", pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
148 '-', nLines + 1, 0, pScreen->
getWidth(), DebuggerIO::DarkGrey,
152 DevicesCommand::DeviceTree::DeviceTree() : m_Line(0), m_LinearTree()
156 auto pusher = [
this](
Device *p) {
157 m_LinearTree.pushBack(p);
161 auto callback = pedigree_std::make_callable(pusher);
167 void DevicesCommand::DeviceTree::probeDev(
Device *pDev)
171 m_LinearTree.pushBack(pDev->
getChild(i));
176 const char *DevicesCommand::DeviceTree::getLine1(
182 Device *pDev = m_LinearTree[index];
185 colour = DebuggerIO::Yellow;
189 bgColour = DebuggerIO::Blue;
203 const char *DevicesCommand::DeviceTree::getLine2(
210 Device *pDev = m_LinearTree[index];
213 colour = DebuggerIO::White;
236 bgColour = DebuggerIO::Blue;
238 str.pad(m_width - colOffset);
243 size_t DevicesCommand::DeviceTree::getLineCount()
245 return m_LinearTree.count();
248 Device *DevicesCommand::DeviceTree::getDevForIndex(
size_t index)
250 return m_LinearTree[index];
253 DevicesCommand::DeviceInfo::DeviceInfo() : m_pDev(0)
257 void DevicesCommand::DeviceInfo::setDevice(
Device *dev)
262 const char *DevicesCommand::DeviceInfo::getLine1(
265 colour = DebuggerIO::Yellow;
271 return "(Abstract) type";
273 return "(Specific) type";
277 return "Openfirmware Handle";
285 const char *DevicesCommand::DeviceInfo::getLine2(
298 m_pDev->getName(str2);
303 str +=
static_cast<unsigned int>(m_pDev->getType());
306 str += m_pDev->getSpecificType();
309 str += m_pDev->getInterruptNumber();
313 str.append(reinterpret_cast<uintptr_t>(m_pDev->getOFHandle()), 16);
316 str +=
"Not applicable";
321 unsigned int i = index - 5;
322 if (i >= m_pDev->addresses().count())
339 size_t DevicesCommand::DeviceInfo::getLineCount()
342 return 5 + m_pDev->addresses().count();
virtual void dump(String &str)
Device * getChild(size_t n)
virtual size_t getWidth()=0
virtual void enableCli()=0
virtual void getName(String &str)
virtual String getSpecificType()
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
virtual void enableRefreshes()=0
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
static void foreach(Callback callback, Device *root=0)
virtual void drawString(const char *str, size_t row, size_t col, Colour foreColour, Colour backColour)=0
virtual void drawHorizontalLine(char c, size_t row, size_t colStart, size_t colEnd, Colour foreColour, Colour backColour)=0
Device * getParent() const