From 23d620565972167f9feaf3848415d5937e388dc0 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 20 Sep 2024 11:00:07 +0300 Subject: [PATCH] Kernel: Move DEBUG_* macros to centralized Debug.h This makes toggling debug info much easier --- kernel/include/kernel/Debug.h | 21 +++++++++++++++++++++ kernel/kernel/Input/PS2/Controller.cpp | 2 -- kernel/kernel/Networking/ARPTable.cpp | 2 -- kernel/kernel/Networking/E1000/E1000.cpp | 10 ++++------ kernel/kernel/Networking/IPv4Layer.cpp | 2 -- kernel/kernel/Networking/NetworkManager.cpp | 2 -- kernel/kernel/Networking/TCPSocket.cpp | 2 -- kernel/kernel/PCI.cpp | 2 -- kernel/kernel/Scheduler.cpp | 1 - kernel/kernel/Storage/DiskCache.cpp | 6 ++---- kernel/kernel/Storage/NVMe/Controller.cpp | 8 +++----- kernel/kernel/USB/Device.cpp | 1 - kernel/kernel/USB/HID/HIDDriver.cpp | 21 ++++++++++----------- kernel/kernel/USB/HID/Keyboard.cpp | 8 +++----- kernel/kernel/USB/HID/Mouse.cpp | 14 ++++++-------- kernel/kernel/USB/XHCI/Controller.cpp | 2 -- kernel/kernel/USB/XHCI/Device.cpp | 2 -- 17 files changed, 49 insertions(+), 57 deletions(-) diff --git a/kernel/include/kernel/Debug.h b/kernel/include/kernel/Debug.h index 59df777a72..9bd8b90176 100644 --- a/kernel/include/kernel/Debug.h +++ b/kernel/include/kernel/Debug.h @@ -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(); diff --git a/kernel/kernel/Input/PS2/Controller.cpp b/kernel/kernel/Input/PS2/Controller.cpp index a16d2f6cfa..a927436314 100644 --- a/kernel/kernel/Input/PS2/Controller.cpp +++ b/kernel/kernel/Input/PS2/Controller.cpp @@ -9,8 +9,6 @@ #include #include -#define DEBUG_PS2 1 - namespace Kernel::Input { diff --git a/kernel/kernel/Networking/ARPTable.cpp b/kernel/kernel/Networking/ARPTable.cpp index 35abb7e149..d67b509861 100644 --- a/kernel/kernel/Networking/ARPTable.cpp +++ b/kernel/kernel/Networking/ARPTable.cpp @@ -2,8 +2,6 @@ #include #include -#define DEBUG_ARP 0 - namespace Kernel { diff --git a/kernel/kernel/Networking/E1000/E1000.cpp b/kernel/kernel/Networking/E1000/E1000.cpp index a7257e000d..4077a33e34 100644 --- a/kernel/kernel/Networking/E1000/E1000.cpp +++ b/kernel/kernel/Networking/E1000/E1000.cpp @@ -6,8 +6,6 @@ #include #include -#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(m_rx_buffer_region->vaddr() + rx_current * E1000_RX_BUFFER_SIZE), descriptor.length diff --git a/kernel/kernel/Networking/IPv4Layer.cpp b/kernel/kernel/Networking/IPv4Layer.cpp index b0990efbc2..116ae63a16 100644 --- a/kernel/kernel/Networking/IPv4Layer.cpp +++ b/kernel/kernel/Networking/IPv4Layer.cpp @@ -9,8 +9,6 @@ #include -#define DEBUG_IPV4 0 - namespace Kernel { diff --git a/kernel/kernel/Networking/NetworkManager.cpp b/kernel/kernel/Networking/NetworkManager.cpp index a80636cc5d..7aa519b8bb 100644 --- a/kernel/kernel/Networking/NetworkManager.cpp +++ b/kernel/kernel/Networking/NetworkManager.cpp @@ -10,8 +10,6 @@ #include #include -#define DEBUG_ETHERTYPE 0 - namespace Kernel { diff --git a/kernel/kernel/Networking/TCPSocket.cpp b/kernel/kernel/Networking/TCPSocket.cpp index c2a22909ae..93df156bc9 100644 --- a/kernel/kernel/Networking/TCPSocket.cpp +++ b/kernel/kernel/Networking/TCPSocket.cpp @@ -7,8 +7,6 @@ #include #include -#define DEBUG_TCP 0 - namespace Kernel { diff --git a/kernel/kernel/PCI.cpp b/kernel/kernel/PCI.cpp index 06e19b828e..2c76f43369 100644 --- a/kernel/kernel/PCI.cpp +++ b/kernel/kernel/PCI.cpp @@ -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 { diff --git a/kernel/kernel/Scheduler.cpp b/kernel/kernel/Scheduler.cpp index 7c52c7dcc9..c0706929da 100644 --- a/kernel/kernel/Scheduler.cpp +++ b/kernel/kernel/Scheduler.cpp @@ -6,7 +6,6 @@ #include #include -#define DEBUG_SCHEDULER 0 #define SCHEDULER_ASSERT 1 #define SCHEDULER_LOAD_BALANCE 0 diff --git a/kernel/kernel/Storage/DiskCache.cpp b/kernel/kernel/Storage/DiskCache.cpp index f72a4a1e03..f88ffb0f62 100644 --- a/kernel/kernel/Storage/DiskCache.cpp +++ b/kernel/kernel/Storage/DiskCache.cpp @@ -4,8 +4,6 @@ #include #include -#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)); } diff --git a/kernel/kernel/Storage/NVMe/Controller.cpp b/kernel/kernel/Storage/NVMe/Controller.cpp index 39d62ce176..50674a502f 100644 --- a/kernel/kernel/Storage/NVMe/Controller.cpp +++ b/kernel/kernel/Storage/NVMe/Controller.cpp @@ -7,8 +7,6 @@ #include -#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 {}; } diff --git a/kernel/kernel/USB/Device.cpp b/kernel/kernel/USB/Device.cpp index c16cac86de..b820f6947d 100644 --- a/kernel/kernel/USB/Device.cpp +++ b/kernel/kernel/USB/Device.cpp @@ -2,7 +2,6 @@ #include #include -#define DEBUG_USB 0 #define USB_DUMP_DESCRIPTORS 0 namespace Kernel diff --git a/kernel/kernel/USB/HID/HIDDriver.cpp b/kernel/kernel/USB/HID/HIDDriver.cpp index 736ce17643..5cecb99091 100644 --- a/kernel/kernel/USB/HID/HIDDriver.cpp +++ b/kernel/kernel/USB/HID/HIDDriver.cpp @@ -5,7 +5,6 @@ #include #include -#define DEBUG_HID 0 #define DUMP_HID_REPORT 0 namespace Kernel @@ -135,12 +134,12 @@ namespace Kernel } const auto& hid_descriptor = *reinterpret_cast(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 collections; @@ -150,7 +149,7 @@ namespace Kernel if (static_cast(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(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 = diff --git a/kernel/kernel/USB/HID/Keyboard.cpp b/kernel/kernel/USB/HID/Keyboard.cpp index d9bb5b7058..d5dd476ee1 100644 --- a/kernel/kernel/USB/HID/Keyboard.cpp +++ b/kernel/kernel/USB/HID/Keyboard.cpp @@ -2,8 +2,6 @@ #include #include -#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()) diff --git a/kernel/kernel/USB/HID/Mouse.cpp b/kernel/kernel/USB/HID/Mouse.cpp index 4412299685..8dfe50e3eb 100644 --- a/kernel/kernel/USB/HID/Mouse.cpp +++ b/kernel/kernel/USB/HID/Mouse.cpp @@ -1,8 +1,6 @@ #include #include -#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); } } diff --git a/kernel/kernel/USB/XHCI/Controller.cpp b/kernel/kernel/USB/XHCI/Controller.cpp index 6c503d2a62..3b71db56a6 100644 --- a/kernel/kernel/USB/XHCI/Controller.cpp +++ b/kernel/kernel/USB/XHCI/Controller.cpp @@ -7,8 +7,6 @@ #include #include -#define DEBUG_XHCI 0 - namespace Kernel { diff --git a/kernel/kernel/USB/XHCI/Device.cpp b/kernel/kernel/USB/XHCI/Device.cpp index 4860eb8abe..dfb5a3e522 100644 --- a/kernel/kernel/USB/XHCI/Device.cpp +++ b/kernel/kernel/USB/XHCI/Device.cpp @@ -5,8 +5,6 @@ #include #include -#define DEBUG_XHCI 0 - namespace Kernel {