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);
public:
static void initialize();
static DeviceManager& get();
void initialize_pci_devices();
void initialize_updater();
ino_t get_next_ino() const;
dev_t get_next_rdev() const;
uint8_t get_next_input_dev() const;

View File

@ -28,6 +28,8 @@ namespace Kernel
static bool is_initialized();
static TTY* current();
void initialize_device();
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;
@ -110,8 +112,8 @@ namespace Kernel
virtual BAN::StringView name() const { return m_name; }
private:
const dev_t m_rdev;
const BAN::String m_name;
dev_t m_rdev;
BAN::String m_name;
};
}

View File

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

View File

@ -33,8 +33,6 @@ namespace Kernel
TTY::TTY(TerminalDriver* 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_height = m_terminal_driver->height();
@ -44,6 +42,18 @@ namespace Kernel
if (s_tty == nullptr)
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(
[](void* tty_)
@ -60,11 +70,6 @@ namespace Kernel
);
}
TTY* TTY::current()
{
return s_tty;
}
void TTY::on_key(Input::KeyEvent event)
{
LockGuard _(m_lock);

View File

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