Kernel: Move DEBUG_* macros to centralized Debug.h

This makes toggling debug info much easier
This commit is contained in:
Bananymous 2024-09-20 11:00:07 +03:00
parent bc0acc6f44
commit 23d6205659
17 changed files with 49 additions and 57 deletions

View File

@ -47,6 +47,27 @@
#define BOCHS_BREAK() asm volatile("xchgw %bx, %bx")
#define DEBUG_PCI 0
#define DEBUG_SCHEDULER 0
#define DEBUG_PS2 1
#define DEBUG_ARP 0
#define DEBUG_IPV4 0
#define DEBUG_ETHERTYPE 0
#define DEBUG_TCP 0
#define DEBUG_E1000 0
#define DEBUG_DISK_SYNC 0
#define DEBUG_NVMe 0
#define DEBUG_XHCI 0
#define DEBUG_USB 0
#define DEBUG_USB_HID 0
#define DEBUG_USB_KEYBOARD 0
#define DEBUG_USB_MOUSE 0
namespace Debug
{
void dump_stack_trace();

View File

@ -9,8 +9,6 @@
#include <kernel/IO.h>
#include <kernel/Timer/Timer.h>
#define DEBUG_PS2 1
namespace Kernel::Input
{

View File

@ -2,8 +2,6 @@
#include <kernel/Scheduler.h>
#include <kernel/Timer/Timer.h>
#define DEBUG_ARP 0
namespace Kernel
{

View File

@ -6,8 +6,6 @@
#include <kernel/Networking/E1000/E1000.h>
#include <kernel/Networking/NetworkManager.h>
#define DEBUG_E1000 1
namespace Kernel
{
@ -68,10 +66,8 @@ namespace Kernel
detect_eeprom();
TRY(read_mac_address());
#if DEBUG_E1000
dprintln("E1000 at PCI {}:{}.{}", m_pci_device.bus(), m_pci_device.dev(), m_pci_device.func());
dprintln(" MAC: {}", m_mac_address);
#endif
TRY(initialize_rx());
TRY(initialize_tx());
@ -81,14 +77,12 @@ namespace Kernel
m_link_up = !!(read32(REG_STATUS) & STATUS_LU);
#if DEBUG_E1000
dprintln(" link up: {}", link_up());
if (link_up())
{
int speed = link_speed();
dprintln(" link speed: {} Mbps", speed);
}
#endif
return {};
}
@ -285,6 +279,8 @@ namespace Kernel
while (descriptor.status == 0)
continue;
dprintln_if(DEBUG_E1000, "sent {} bytes", sizeof(EthernetHeader) + buffer.size());
return {};
}
@ -303,6 +299,8 @@ namespace Kernel
break;
ASSERT(descriptor.length <= E1000_RX_BUFFER_SIZE);
dprintln_if(DEBUG_E1000, "got {} bytes", (uint16_t)descriptor.length);
NetworkManager::get().on_receive(*this, BAN::ConstByteSpan {
reinterpret_cast<const uint8_t*>(m_rx_buffer_region->vaddr() + rx_current * E1000_RX_BUFFER_SIZE),
descriptor.length

View File

@ -9,8 +9,6 @@
#include <netinet/in.h>
#define DEBUG_IPV4 0
namespace Kernel
{

View File

@ -10,8 +10,6 @@
#include <kernel/Networking/UDPSocket.h>
#include <kernel/Networking/UNIX/Socket.h>
#define DEBUG_ETHERTYPE 0
namespace Kernel
{

View File

@ -7,8 +7,6 @@
#include <fcntl.h>
#include <netinet/in.h>
#define DEBUG_TCP 0
namespace Kernel
{

View File

@ -27,8 +27,6 @@
#define PCI_CMD_BUS_MASTER (1 << 2)
#define PCI_CMD_INTERRUPT_DISABLE (1 << 10)
#define DEBUG_PCI 0
namespace Kernel::PCI
{

View File

@ -6,7 +6,6 @@
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
#define DEBUG_SCHEDULER 0
#define SCHEDULER_ASSERT 1
#define SCHEDULER_LOAD_BALANCE 0

View File

@ -4,8 +4,6 @@
#include <kernel/Storage/DiskCache.h>
#include <kernel/Storage/StorageDevice.h>
#define DEBUG_SYNC 0
namespace Kernel
{
@ -127,7 +125,7 @@ namespace Kernel
sector_start++;
else
{
dprintln_if(DEBUG_SYNC, "syncing {}->{}", cache.first_sector + sector_start, cache.first_sector + sector_start + sector_count);
dprintln_if(DEBUG_DISK_SYNC, "syncing {}->{}", cache.first_sector + sector_start, cache.first_sector + sector_start + sector_count);
auto data_slice = m_sync_cache.span().slice(sector_start * m_sector_size, sector_count * m_sector_size);
TRY(m_device.write_sectors_impl(cache.first_sector + sector_start, sector_count, data_slice));
sector_start += sector_count + 1;
@ -137,7 +135,7 @@ namespace Kernel
if (sector_count > 0)
{
dprintln_if(DEBUG_SYNC, "syncing {}->{}", cache.first_sector + sector_start, cache.first_sector + sector_start + sector_count);
dprintln_if(DEBUG_DISK_SYNC, "syncing {}->{}", cache.first_sector + sector_start, cache.first_sector + sector_start + sector_count);
auto data_slice = m_sync_cache.span().slice(sector_start * m_sector_size, sector_count * m_sector_size);
TRY(m_device.write_sectors_impl(cache.first_sector + sector_start, sector_count, data_slice));
}

View File

@ -7,8 +7,6 @@
#include <sys/sysmacros.h>
#define DEBUG_NVMe 1
namespace Kernel
{
@ -65,8 +63,8 @@ namespace Kernel
return BAN::Error::from_errno(ENOTSUP);
}
dprintln_if(DEBUG_NVMe, "NVMe controller");
dprintln_if(DEBUG_NVMe, " version: {}.{}", (uint16_t)vs.major, (uint8_t)vs.minor);
dprintln("NVMe controller");
dprintln(" version: {}.{}", (uint16_t)vs.major, (uint8_t)vs.minor);
auto& cap = m_controller_registers->cap;
if (!(cap.css & NVMe::CAP_CSS_NVME))
@ -160,7 +158,7 @@ namespace Kernel
return BAN::Error::from_errno(EFAULT);
}
dprintln_if(DEBUG_NVMe, " model: '{}'", BAN::StringView { (char*)dma_page->vaddr() + 24, 20 });
dprintln(" model: '{}'", BAN::StringView { (char*)dma_page->vaddr() + 24, 20 });
return {};
}

View File

@ -2,7 +2,6 @@
#include <kernel/USB/Device.h>
#include <kernel/USB/HID/HIDDriver.h>
#define DEBUG_USB 0
#define USB_DUMP_DESCRIPTORS 0
namespace Kernel

View File

@ -5,7 +5,6 @@
#include <kernel/USB/HID/Keyboard.h>
#include <kernel/USB/HID/Mouse.h>
#define DEBUG_HID 0
#define DUMP_HID_REPORT 0
namespace Kernel
@ -135,12 +134,12 @@ namespace Kernel
}
const auto& hid_descriptor = *reinterpret_cast<const HIDDescriptor*>(m_interface.misc_descriptors[hid_descriptor_index].data());
dprintln_if(DEBUG_HID, "HID descriptor ({} bytes)", m_interface.misc_descriptors[hid_descriptor_index].size());
dprintln_if(DEBUG_HID, " bLength: {}", hid_descriptor.bLength);
dprintln_if(DEBUG_HID, " bDescriptorType: {}", hid_descriptor.bDescriptorType);
dprintln_if(DEBUG_HID, " bcdHID: {H}.{2H}", hid_descriptor.bcdHID >> 8, hid_descriptor.bcdHID & 0xFF);
dprintln_if(DEBUG_HID, " bCountryCode: {}", hid_descriptor.bCountryCode);
dprintln_if(DEBUG_HID, " bNumDescriptors: {}", hid_descriptor.bNumDescriptors);
dprintln_if(DEBUG_USB_HID, "HID descriptor ({} bytes)", m_interface.misc_descriptors[hid_descriptor_index].size());
dprintln_if(DEBUG_USB_HID, " bLength: {}", hid_descriptor.bLength);
dprintln_if(DEBUG_USB_HID, " bDescriptorType: {}", hid_descriptor.bDescriptorType);
dprintln_if(DEBUG_USB_HID, " bcdHID: {H}.{2H}", hid_descriptor.bcdHID >> 8, hid_descriptor.bcdHID & 0xFF);
dprintln_if(DEBUG_USB_HID, " bCountryCode: {}", hid_descriptor.bCountryCode);
dprintln_if(DEBUG_USB_HID, " bNumDescriptors: {}", hid_descriptor.bNumDescriptors);
uint32_t report_descriptor_index = 0;
BAN::Vector<Collection> collections;
@ -150,7 +149,7 @@ namespace Kernel
if (static_cast<HIDDescriptorType>(descriptor.bDescriptorType) != HIDDescriptorType::Report)
{
dprintln_if(DEBUG_HID, "Skipping HID descriptor type 0x{2H}", descriptor.bDescriptorType);
dprintln_if(DEBUG_USB_HID, "Skipping HID descriptor type 0x{2H}", descriptor.bDescriptorType);
continue;
}
@ -176,7 +175,7 @@ namespace Kernel
}
}
dprintln_if(DEBUG_HID, "Parsing {} byte report descriptor", +descriptor.wItemLength);
dprintln_if(DEBUG_USB_HID, "Parsing {} byte report descriptor", +descriptor.wItemLength);
auto report_data = BAN::ConstByteSpan(reinterpret_cast<uint8_t*>(dma_buffer->vaddr()), descriptor.wItemLength);
auto new_collections = TRY(parse_report_descriptor(report_data, m_uses_report_id));
@ -275,7 +274,7 @@ namespace Kernel
return;
}
if constexpr(DEBUG_HID)
if constexpr(DEBUG_USB_HID)
{
const auto nibble_to_hex = [](uint8_t x) -> char { return x + (x < 10 ? '0' : 'A' - 10); };
@ -289,7 +288,7 @@ namespace Kernel
}
*ptr = '\0';
dprintln_if(DEBUG_HID, "Received {} bytes from endpoint {}: {}", data.size(), endpoint_id, buffer);
dprintln_if(DEBUG_USB_HID, "Received {} bytes from endpoint {}: {}", data.size(), endpoint_id, buffer);
}
const auto extract_bits =

View File

@ -2,8 +2,6 @@
#include <kernel/USB/HID/Keyboard.h>
#include <LibInput/KeyEvent.h>
#define DEBUG_KEYBOARD 0
namespace Kernel
{
@ -66,7 +64,7 @@ namespace Kernel
const bool pressed = m_keyboard_state_temp[i];
if (pressed)
dprintln_if(DEBUG_KEYBOARD, "Pressed {2H}", i);
dprintln_if(DEBUG_USB_KEYBOARD, "Pressed {2H}", i);
auto opt_keycode = s_scancode_to_keycode[i];
if (opt_keycode.has_value())
@ -102,7 +100,7 @@ namespace Kernel
if (usage_page != 0x07)
{
dprintln_if(DEBUG_KEYBOARD, "Unsupported keyboard usage page {2H}", usage_page);
dprintln_if(DEBUG_USB_KEYBOARD, "Unsupported keyboard usage page {2H}", usage_page);
return;
}
if (!state)
@ -117,7 +115,7 @@ namespace Kernel
if (usage_page != 0x07)
{
dprintln_if(DEBUG_KEYBOARD, "Unsupported keyboard usage page {2H}", usage_page);
dprintln_if(DEBUG_USB_KEYBOARD, "Unsupported keyboard usage page {2H}", usage_page);
return;
}
if (usage >= 4 && usage < m_keyboard_state_temp.size())

View File

@ -1,8 +1,6 @@
#include <kernel/USB/HID/Mouse.h>
#include <LibInput/MouseEvent.h>
#define DEBUG_MOUSE 0
namespace Kernel
{
@ -16,7 +14,7 @@ namespace Kernel
{
if (m_pointer_x || m_pointer_y)
{
dprintln_if(DEBUG_MOUSE, "Mouse move event {}, {}", m_pointer_x, m_pointer_y);
dprintln_if(DEBUG_USB_MOUSE, "Mouse move event {}, {}", m_pointer_x, m_pointer_y);
LibInput::MouseEvent event;
event.type = LibInput::MouseEventType::MouseMoveEvent;
@ -30,7 +28,7 @@ namespace Kernel
if (m_wheel)
{
dprintln_if(DEBUG_MOUSE, "Mouse scroll event {}", m_wheel);
dprintln_if(DEBUG_USB_MOUSE, "Mouse scroll event {}", m_wheel);
LibInput::MouseEvent event;
event.type = LibInput::MouseEventType::MouseScrollEvent;
@ -47,7 +45,7 @@ namespace Kernel
const bool pressed = m_button_state_temp[i];
dprintln_if(DEBUG_MOUSE, "Mouse button event {}: {}", i, pressed);
dprintln_if(DEBUG_USB_MOUSE, "Mouse button event {}: {}", i, pressed);
LibInput::MouseEvent event;
event.type = LibInput::MouseEventType::MouseButtonEvent;
@ -76,7 +74,7 @@ namespace Kernel
m_wheel = state;
break;
default:
dprintln_if(DEBUG_MOUSE, "Unsupported mouse usage {2H} on page {2H}", usage, usage_page);
dprintln_if(DEBUG_USB_MOUSE, "Unsupported mouse usage {2H} on page {2H}", usage, usage_page);
break;
}
break;
@ -86,14 +84,14 @@ namespace Kernel
m_button_state_temp[usage - 1] = state;
break;
default:
dprintln_if(DEBUG_MOUSE, "Unsupported mouse usage page {2H}", usage_page);
dprintln_if(DEBUG_USB_MOUSE, "Unsupported mouse usage page {2H}", usage_page);
break;
}
}
void USBMouse::handle_array(uint16_t usage_page, uint16_t usage)
{
dprintln_if(DEBUG_MOUSE, "Unhandled array report {2H}:{2H}", usage_page, usage);
dprintln_if(DEBUG_USB_MOUSE, "Unhandled array report {2H}:{2H}", usage_page, usage);
}
}

View File

@ -7,8 +7,6 @@
#include <kernel/USB/XHCI/Controller.h>
#include <kernel/USB/XHCI/Device.h>
#define DEBUG_XHCI 0
namespace Kernel
{

View File

@ -5,8 +5,6 @@
#include <kernel/Timer/Timer.h>
#include <kernel/USB/XHCI/Device.h>
#define DEBUG_XHCI 0
namespace Kernel
{