78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
|
|
#include <cstdio>
|
|
|
|
#include "drivers/pci.hpp"
|
|
#include "drivers/ps2.hpp"
|
|
|
|
namespace
|
|
{
|
|
void cmdLspci() noexcept
|
|
{
|
|
using namespace baos::pci;
|
|
|
|
std::puts("Enumerating PCI devices.");
|
|
GeneralDeviceHeader generalDeviceHeader = {};
|
|
for (const Header& header : enumerateDevices())
|
|
{
|
|
std::printf("Bus %d, Port %d, Function %d: VendorID: 0x%X, DeviceID: 0x%X, Base Class: 0x%X, Sub Class: 0x%X\n",
|
|
header.bus, header.device, header.function, header.vendorID, header.deviceID,
|
|
static_cast<unsigned>(header.baseClass), static_cast<unsigned>(header.subClass));
|
|
|
|
if (header.headerType == HeaderType::GENERAL_DEVICE && getGeneralDeviceHeader(header, generalDeviceHeader))
|
|
{
|
|
std::printf(" BAR0: 0x%X, BAR1: 0x%X, BAR2: 0x%X\n"
|
|
" BAR3: 0x%X, BAR4: 0x%X, BAR5: 0x%X\n"
|
|
" Subsystem Vendor ID: 0x%X, Subsystem ID: 0x%X\n",
|
|
generalDeviceHeader.bar0, generalDeviceHeader.bar1, generalDeviceHeader.bar2,
|
|
generalDeviceHeader.bar3, generalDeviceHeader.bar4, generalDeviceHeader.bar5,
|
|
generalDeviceHeader.subsystemVendorID, generalDeviceHeader.subsystemID);
|
|
}
|
|
}
|
|
}
|
|
|
|
void cmdShowKeys() noexcept
|
|
{
|
|
std::puts("Press CTRL-C to quit.");
|
|
while (true)
|
|
{
|
|
baos::ps2::KeyEvent event;
|
|
while (!baos::ps2::readKey(event));
|
|
std::printf(
|
|
"Key event: scancode=%s(0x%X), down=%s, repeat=%s\n",
|
|
baos::ps2::keyName(event.scancode),
|
|
static_cast<unsigned>(event.scancode),
|
|
event.down ? "true" : "false",
|
|
event.repeat ? "true" : "false"
|
|
);
|
|
if (event.scancode == baos::ps2::Scancode::C && baos::ps2::isKeyDown(baos::ps2::Scancode::LEFT_CONTROL)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
extern "C" void main()
|
|
{
|
|
|
|
// __asm__ __volatile__("cli");
|
|
std::string cmd;
|
|
while(true)
|
|
{
|
|
std::printf("> ");
|
|
std::getline(cmd);
|
|
cmd.pop_back(); // pop the \n
|
|
|
|
if (cmd == "lspci")
|
|
{
|
|
cmdLspci();
|
|
continue;
|
|
}
|
|
else if (cmd == "show-keys")
|
|
{
|
|
cmdShowKeys();
|
|
continue;
|
|
}
|
|
std::printf("Unknown command: %s.\n", cmd.c_str());
|
|
}
|
|
}
|