From b817e1977ce61eea63add0d8ae3502a06b386f04 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 13 Aug 2021 15:24:03 +0200 Subject: [PATCH] base-hw: serial output as Main member Let the kernel's serial-output driver be a member of the one Kernel::Main object instead of having it as global static variable. Ref #4217 --- repos/base-hw/src/core/kernel/main.cc | 12 ++++++++++++ repos/base-hw/src/core/kernel/main.h | 4 ++++ repos/base-hw/src/core/kernel_log.cc | 13 +++---------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/repos/base-hw/src/core/kernel/main.cc b/repos/base-hw/src/core/kernel/main.cc index ed753cf56a..855d6dbb7c 100644 --- a/repos/base-hw/src/core/kernel/main.cc +++ b/repos/base-hw/src/core/kernel/main.cc @@ -42,6 +42,9 @@ class Kernel::Main friend void main_handle_kernel_entry(); friend void main_initialize_and_handle_kernel_entry(); friend time_t main_read_idle_thread_execution_time(unsigned cpu_idx); + friend void main_print_char(char c); + + enum { SERIAL_BAUD_RATE = 115200 }; static Main *_instance; @@ -52,6 +55,9 @@ class Kernel::Main Genode::Core_platform_pd _core_platform_pd { _addr_space_id_alloc }; Genode::Constructible _core_main_thread { }; Board::Global_interrupt_controller _global_irq_ctrl { }; + Board::Serial _serial { Genode::Platform::mmio_to_virt(Board::UART_BASE), + Board::UART_CLOCK, + SERIAL_BAUD_RATE }; void _handle_kernel_entry(); @@ -196,6 +202,12 @@ Genode::Platform_pd &Kernel::Main::core_platform_pd() } +void Kernel::main_print_char(char c) +{ + Main::_instance->_serial.put_char(c); +} + + Kernel::time_t Kernel::main_read_idle_thread_execution_time(unsigned cpu_idx) { return Main::_instance->_cpu_pool.cpu(cpu_idx).idle_thread().execution_time(); diff --git a/repos/base-hw/src/core/kernel/main.h b/repos/base-hw/src/core/kernel/main.h index b7046174d6..fe5a8d3367 100644 --- a/repos/base-hw/src/core/kernel/main.h +++ b/repos/base-hw/src/core/kernel/main.h @@ -19,11 +19,15 @@ namespace Kernel { + void main_print_char(char const c); + void main_handle_kernel_entry(); void main_initialize_and_handle_kernel_entry(); time_t main_read_idle_thread_execution_time(unsigned cpu_idx); + + void main_print_char(char c); } #endif /* _KERNEL__MAIN_H_ */ diff --git a/repos/base-hw/src/core/kernel_log.cc b/repos/base-hw/src/core/kernel_log.cc index cbeba18755..ba8a59c91e 100644 --- a/repos/base-hw/src/core/kernel_log.cc +++ b/repos/base-hw/src/core/kernel_log.cc @@ -13,26 +13,19 @@ */ /* base-hw Core includes */ -#include -#include +#include #include void Kernel::log(char const c) { - using namespace Board; - enum { ASCII_LINE_FEED = 10, ASCII_CARRIAGE_RETURN = 13, - BAUD_RATE = 115200 }; - static Serial serial { Genode::Platform::mmio_to_virt(UART_BASE), - UART_CLOCK, BAUD_RATE }; - if (c == ASCII_LINE_FEED) - serial.put_char(ASCII_CARRIAGE_RETURN); + main_print_char(ASCII_CARRIAGE_RETURN); - serial.put_char(c); + main_print_char(c); }