Kernel: Reorder boot initialization

We now create the TTY as soon as possible so we can show console
output without serial port.
This commit is contained in:
Bananymous 2023-04-14 23:55:05 +03:00
parent 1aac3a0425
commit 2614437ba0
5 changed files with 44 additions and 37 deletions

View File

@ -17,9 +17,11 @@ namespace Kernel
BAN_NON_MOVABLE(DeviceManager); BAN_NON_MOVABLE(DeviceManager);
public: public:
static void initialize();
static DeviceManager& get(); static DeviceManager& get();
void initialize_pci_devices();
void initialize_updater();
ino_t get_next_ino() const; ino_t get_next_ino() const;
dev_t get_next_rdev() const; dev_t get_next_rdev() const;
uint8_t get_next_input_dev() const; uint8_t get_next_input_dev() const;

View File

@ -28,6 +28,8 @@ namespace Kernel
static bool is_initialized(); static bool is_initialized();
static TTY* current(); static TTY* current();
void initialize_device();
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override; virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override; virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
@ -110,8 +112,8 @@ namespace Kernel
virtual BAN::StringView name() const { return m_name; } virtual BAN::StringView name() const { return m_name; }
private: private:
const dev_t m_rdev; dev_t m_rdev;
const BAN::String m_name; BAN::String m_name;
}; };
} }

View File

@ -7,15 +7,14 @@
namespace Kernel namespace Kernel
{ {
static DeviceManager* s_instance = nullptr; DeviceManager& DeviceManager::get()
void DeviceManager::initialize()
{ {
ASSERT(s_instance == nullptr); static DeviceManager instance;
return instance;
s_instance = new DeviceManager; }
ASSERT(s_instance != nullptr);
void DeviceManager::initialize_pci_devices()
{
for (const auto& pci_device : PCI::get().devices()) for (const auto& pci_device : PCI::get().devices())
{ {
switch (pci_device.class_code()) switch (pci_device.class_code())
@ -38,16 +37,16 @@ namespace Kernel
if (controller) if (controller)
{ {
s_instance->add_device(controller); add_device(controller);
for (auto* device : controller->devices()) for (auto* device : controller->devices())
{ {
s_instance->add_device(device); add_device(device);
if (auto res = device->initialize_partitions(); res.is_error()) if (auto res = device->initialize_partitions(); res.is_error())
dprintln("{}", res.error()); dprintln("{}", res.error());
else else
{ {
for (auto* partition : device->partitions()) for (auto* partition : device->partitions())
s_instance->add_device(partition); add_device(partition);
} }
} }
} }
@ -57,7 +56,10 @@ namespace Kernel
break; break;
} }
} }
}
void DeviceManager::initialize_updater()
{
MUST(Process::create_kernel( MUST(Process::create_kernel(
[](void*) [](void*)
{ {
@ -70,12 +72,6 @@ namespace Kernel
); );
} }
DeviceManager& DeviceManager::get()
{
ASSERT(s_instance);
return *s_instance;
}
ino_t DeviceManager::get_next_ino() const ino_t DeviceManager::get_next_ino() const
{ {
static ino_t next_ino = 1; static ino_t next_ino = 1;

View File

@ -33,8 +33,6 @@ namespace Kernel
TTY::TTY(TerminalDriver* driver) TTY::TTY(TerminalDriver* driver)
: m_terminal_driver(driver) : m_terminal_driver(driver)
, m_rdev(next_tty_rdev())
, m_name(BAN::String::formatted("tty{}", minor(m_rdev)))
{ {
m_width = m_terminal_driver->width(); m_width = m_terminal_driver->width();
m_height = m_terminal_driver->height(); m_height = m_terminal_driver->height();
@ -44,6 +42,18 @@ namespace Kernel
if (s_tty == nullptr) if (s_tty == nullptr)
s_tty = this; s_tty = this;
}
TTY* TTY::current()
{
return s_tty;
}
void TTY::initialize_device()
{
m_rdev = next_tty_rdev();
m_name = BAN::String::formatted("tty{}", minor(m_rdev));
DeviceManager::get().add_device(this);
MUST(Process::create_kernel( MUST(Process::create_kernel(
[](void* tty_) [](void* tty_)
@ -60,11 +70,6 @@ namespace Kernel
); );
} }
TTY* TTY::current()
{
return s_tty;
}
void TTY::on_key(Input::KeyEvent event) void TTY::on_key(Input::KeyEvent event)
{ {
LockGuard _(m_lock); LockGuard _(m_lock);

View File

@ -137,6 +137,13 @@ extern "C" void kernel_main()
MMU::intialize(); MMU::intialize();
dprintln("MMU initialized"); dprintln("MMU initialized");
TerminalDriver* terminal_driver = VesaTerminalDriver::create();
ASSERT(terminal_driver);
dprintln("VESA initialized");
TTY* tty1 = new TTY(terminal_driver);
ASSERT(tty1);
Memory::Heap::initialize(); Memory::Heap::initialize();
dprintln("Heap initialzed"); dprintln("Heap initialzed");
@ -146,10 +153,6 @@ extern "C" void kernel_main()
PCI::initialize(); PCI::initialize();
dprintln("PCI initialized"); dprintln("PCI initialized");
TerminalDriver* terminal_driver = VesaTerminalDriver::create();
ASSERT(terminal_driver);
dprintln("VESA initialized");
MUST(ACPI::initialize()); MUST(ACPI::initialize());
dprintln("ACPI initialized"); dprintln("ACPI initialized");
@ -161,27 +164,26 @@ extern "C" void kernel_main()
MUST(Scheduler::initialize()); MUST(Scheduler::initialize());
Scheduler& scheduler = Scheduler::get(); Scheduler& scheduler = Scheduler::get();
MUST(scheduler.add_thread(MUST(Thread::create(init2, terminal_driver)))); MUST(scheduler.add_thread(MUST(Thread::create(init2, tty1))));
scheduler.start(); scheduler.start();
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
static void init2(void* terminal_driver) static void init2(void* tty1)
{ {
using namespace Kernel; using namespace Kernel;
using namespace Kernel::Input; using namespace Kernel::Input;
DeviceManager::initialize(); DeviceManager::get().initialize_pci_devices();
DeviceManager::get().initialize_updater();
MUST(VirtualFileSystem::initialize(cmdline.root)); MUST(VirtualFileSystem::initialize(cmdline.root));
if (auto res = PS2Controller::initialize(); res.is_error()) if (auto res = PS2Controller::initialize(); res.is_error())
dprintln("{}", res.error()); dprintln("{}", res.error());
TTY* tty1 = new TTY((TerminalDriver*)terminal_driver); ((TTY*)tty1)->initialize_device();
ASSERT(tty1);
DeviceManager::get().add_device(tty1);
MUST(Process::create_kernel( MUST(Process::create_kernel(
[](void*) [](void*)