#include "kapi/boot_modules.hpp" #include "kapi/cio.hpp" #include "kapi/cpu.hpp" #include "kapi/memory.hpp" #include "kapi/system.hpp" #include "kernel/cpu.hpp" #include "kernel/devices/storage/storage_management.hpp" #include "kernel/filesystem/device_file.hpp" #include "kernel/filesystem/file_descriptor_table.hpp" #include "kernel/filesystem/open_file_description.hpp" #include "kernel/filesystem/vfs.hpp" #include "kernel/memory.hpp" #include #include #include #include #include #include auto run_test_code() -> void { // setup auto fd_table = filesystem::file_descriptor_table::get(); auto storage_mgmt = devices::storage::storage_management::get(); auto device = storage_mgmt.device_by_major_minor(1, 0); auto dev_file = kstd::make_shared(device); filesystem::open_file_description ofd(dev_file); auto fd_index = fd_table.add_file(ofd); // use: read two bytes and write two again auto fd = fd_table.get_file(fd_index); if (!fd) { kstd::os::panic("test code failed"); } kstd::vector buffer{2}; auto number_of_read_bytes = fd->read(buffer.data(), buffer.size()); for (size_t i = 0; i < number_of_read_bytes; ++i) { kstd::print("{:02x} ", static_cast(buffer[i])); if ((i + 1) % 16 == 0) { kstd::println(""); } } kstd::println("---"); // write half of the file new auto const value1 = std::byte{0xAA}; auto const value2 = std::byte{0xBB}; kstd::vector write_buffer{value1, value2}; auto written_bytes = fd->write(write_buffer.data(), write_buffer.size()); kstd::println("written bytes: {}", written_bytes); fd_table.remove_file(fd_index); // use: read four bytes again -> two old bytes two new bytes filesystem::open_file_description ofd1(dev_file); fd_index = fd_table.add_file(ofd1); auto fd1 = fd_table.get_file(fd_index); if (!fd1) { kstd::os::panic("test code failed"); } kstd::vector buffer1{4}; number_of_read_bytes = fd1->read(buffer1.data(), buffer1.size()); for (size_t i = 0; i < number_of_read_bytes; ++i) { kstd::print("{:02x} ", static_cast(buffer1[i])); if ((i + 1) % 16 == 0) { kstd::println(""); } } kstd::println("---"); } auto main() -> int { kapi::cio::init(); kstd::println("[OS] IO subsystem initialized."); kapi::cpu::init(); kernel::cpu::init(); kapi::cpu::enable_interrupts(); kapi::memory::init(); kernel::memory::init_heap(kapi::memory::heap_base); kstd::println("[OS] Memory subsystem initialized."); kapi::system::memory_initialized(); kapi::boot_modules::init(); kstd::println("[OS] Boot module registry initialized."); devices::storage::storage_management::init(); kstd::println("[OS] Storage management initialized."); filesystem::file_descriptor_table::init(); kstd::println("[OS] Global file descriptor table initialized."); filesystem::vfs::init(); kstd::println("[OS] Virtual filesystem initialized."); run_test_code(); kapi::system::panic("Returning from kernel main!"); }