aboutsummaryrefslogtreecommitdiff
path: root/kernel/src
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src')
-rw-r--r--kernel/src/acpi/manager.cpp48
-rw-r--r--kernel/src/test_support/filesystem/storage_boot_module_fixture.cpp105
-rw-r--r--kernel/src/test_support/filesystem/storage_boot_module_vfs_fixture.cpp7
3 files changed, 93 insertions, 67 deletions
diff --git a/kernel/src/acpi/manager.cpp b/kernel/src/acpi/manager.cpp
index 501ce92..5876799 100644
--- a/kernel/src/acpi/manager.cpp
+++ b/kernel/src/acpi/manager.cpp
@@ -8,8 +8,10 @@
#include <acpi/acpi.hpp>
+#include <algorithm>
#include <cstddef>
#include <cstdint>
+#include <ranges>
#include <string_view>
namespace kernel::acpi
@@ -32,7 +34,7 @@ namespace kernel::acpi
}
auto physical_extended_table_address = kapi::memory::physical_address{xsdp->table_address()};
auto linear_extended_table_address = kapi::memory::hhdm_to_linear(physical_extended_table_address);
- m_rsdt = static_cast<::acpi::sdt const *>(linear_extended_table_address);
+ m_rsdt = static_cast<::acpi::xsdt const *>(linear_extended_table_address);
m_extended = true;
}
else
@@ -43,7 +45,7 @@ namespace kernel::acpi
}
auto physical_root_table_address = kapi::memory::physical_address{m_sdp->table_address()};
auto linear_root_table_address = kapi::memory::hhdm_to_linear(physical_root_table_address);
- m_rsdt = static_cast<::acpi::sdt const *>(linear_root_table_address);
+ m_rsdt = static_cast<::acpi::rsdt const *>(linear_root_table_address);
}
}
@@ -54,29 +56,12 @@ namespace kernel::acpi
kapi::system::panic("[OS:ACPI] Invalid RSDT checksum!");
}
- auto entry_size = m_extended ? sizeof(std::uint64_t) : sizeof(std::uint32_t);
- auto entry_count = (m_rsdt->length().value - sizeof(::acpi::sdt)) / entry_size;
- auto entries_base = reinterpret_cast<std::byte const *>(m_rsdt) + sizeof(::acpi::sdt);
+ auto check_and_register_table = [&](auto table_address) -> void {
+ auto physical_table_address = kapi::memory::physical_address{reinterpret_cast<std::uintptr_t>(table_address)};
+ auto mapped_table = kapi::memory::hhdm_to_linear(physical_table_address);
+ auto table = static_cast<::acpi::table_header const *>(mapped_table);
- for (std::size_t i = 0; i < entry_count; ++i)
- {
- auto physical_table_address = kapi::memory::physical_address{};
-
- if (m_extended)
- {
- auto entry = reinterpret_cast<std::uint64_t const *>(entries_base + (i * entry_size));
- physical_table_address = kapi::memory::physical_address{*entry};
- }
- else
- {
- auto entry = reinterpret_cast<std::uint32_t const *>(entries_base + (i * entry_size));
- physical_table_address = kapi::memory::physical_address{*entry};
- }
-
- auto linear_table_address = kapi::memory::hhdm_to_linear(physical_table_address);
- auto table = static_cast<::acpi::sdt const *>(linear_table_address);
-
- if (!::acpi::validate_checksum({reinterpret_cast<std::byte const *>(table), table->length().value}))
+ if (!::acpi::validate_checksum({static_cast<std::byte const *>(mapped_table), table->length().value}))
{
kstd::println(kstd::print_sink::stderr, "[OS:ACPI] Invalid table checksum!");
}
@@ -85,12 +70,25 @@ namespace kernel::acpi
kstd::println("[OS:ACPI] Found '{}' ACPI table", table->signature());
m_tables.emplace(table->signature(), table);
}
+ };
+
+ if (m_extended)
+ {
+ auto xsdt = static_cast<::acpi::xsdt const *>(m_rsdt);
+ std::ranges::for_each(*xsdt | std::views::transform([](auto const & entry) { return entry.address(); }),
+ check_and_register_table);
+ }
+ else
+ {
+ auto rsdt = static_cast<::acpi::rsdt const *>(m_rsdt);
+ std::ranges::for_each(*rsdt | std::views::transform([](auto const & entry) { return entry.address(); }),
+ check_and_register_table);
}
return !m_tables.empty();
}
- auto manager::get_table(std::string_view signature) -> kstd::observer_ptr<::acpi::sdt const>
+ auto manager::get_table(std::string_view signature) -> kstd::observer_ptr<::acpi::table_header const>
{
if (m_tables.contains(signature))
{
diff --git a/kernel/src/test_support/filesystem/storage_boot_module_fixture.cpp b/kernel/src/test_support/filesystem/storage_boot_module_fixture.cpp
index a139f63..cd8360b 100644
--- a/kernel/src/test_support/filesystem/storage_boot_module_fixture.cpp
+++ b/kernel/src/test_support/filesystem/storage_boot_module_fixture.cpp
@@ -8,17 +8,72 @@
#include "kernel/test_support/boot_modules.hpp"
#include "kernel/test_support/devices/storage/management.hpp"
-#include <kstd/string>
-#include <kstd/vector>
-
#include <cstddef>
+#include <fcntl.h>
#include <filesystem>
-#include <fstream>
-#include <ios>
+#include <format>
#include <stdexcept>
+#include <string>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <utility>
+#include <vector>
namespace kernel::tests::filesystem
{
+ storage_boot_module_fixture::mapped_image::mapped_image(std::filesystem::path path)
+ : file_descriptor(::open(path.c_str(), O_RDWR))
+ {
+ if (file_descriptor < 0)
+ {
+ throw std::runtime_error{"Failed to open image file for test boot module: " + path.string()};
+ }
+
+ struct stat statistics{};
+ if (::fstat(file_descriptor, &statistics) < 0)
+ {
+ throw std::runtime_error{"Failed to get statistics for image file: " + path.string()};
+ }
+
+ size = static_cast<std::size_t>(statistics.st_size);
+
+ mapping = static_cast<std::byte *>(::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, file_descriptor, 0));
+ if (mapping == MAP_FAILED)
+ {
+ throw std::runtime_error{"Failed to map image file for test boot module: " + path.string()};
+ }
+ }
+
+ storage_boot_module_fixture::mapped_image::~mapped_image()
+ {
+ if (mapping != nullptr)
+ {
+ ::munmap(mapping, size);
+ }
+ if (file_descriptor >= 0)
+ {
+ ::close(file_descriptor);
+ }
+ }
+
+ storage_boot_module_fixture::mapped_image::mapped_image(mapped_image && other) noexcept
+ : file_descriptor{std::exchange(other.file_descriptor, -1)}
+ , mapping{std::exchange(other.mapping, nullptr)}
+ , size{std::exchange(other.size, 0)}
+ {}
+
+ auto storage_boot_module_fixture::mapped_image::operator=(mapped_image && other) noexcept -> mapped_image &
+ {
+ if (this != &other)
+ {
+ file_descriptor = std::exchange(other.file_descriptor, -1);
+ mapping = std::exchange(other.mapping, nullptr);
+ size = std::exchange(other.size, 0);
+ }
+ return *this;
+ }
+
storage_boot_module_fixture::~storage_boot_module_fixture()
{
kernel::tests::devices::storage::management::deinit();
@@ -36,23 +91,22 @@ namespace kernel::tests::filesystem
for (std::size_t i = 0; i < module_count; ++i)
{
- m_module_names.push_back("test_mod" + kstd::to_string(i));
+ m_module_names.push_back(std::format("test_mod{}", i));
m_module_data.emplace_back(module_size, std::byte{static_cast<unsigned char>(0x40 + (i % 16))});
}
for (std::size_t i = 0; i < module_count; ++i)
{
m_registry.add_boot_module(kapi::boot_modules::boot_module{
- m_module_names[i].view(), kapi::memory::linear_address{m_module_data[i].data()}, m_module_data[i].size()});
+ m_module_names[i].c_str(), kapi::memory::linear_address{m_module_data[i].data()}, m_module_data[i].size()});
}
kapi::boot_modules::set_boot_module_registry(m_registry);
kernel::devices::storage::management::init();
}
- auto storage_boot_module_fixture::setup_modules_from_img(kstd::vector<kstd::string> const & module_names,
- kstd::vector<std::filesystem::path> const & img_paths)
- -> void
+ auto storage_boot_module_fixture::setup_modules_from_img(std::vector<std::string> const & module_names,
+ std::vector<std::filesystem::path> const & img_paths) -> void
{
m_module_names.clear();
m_module_data.clear();
@@ -72,38 +126,13 @@ namespace kernel::tests::filesystem
kernel::devices::storage::management::init();
}
- auto storage_boot_module_fixture::setup_module_from_img(kstd::string const & module_name,
+ auto storage_boot_module_fixture::setup_module_from_img(std::string const & module_name,
std::filesystem::path const & img_path) -> void
{
- auto file = std::ifstream{img_path, std::ios::binary | std::ios::ate};
- if (!file)
- {
- throw std::runtime_error{"Failed to open image file for test boot module: " + img_path.string()};
- }
-
- auto const end_pos = file.tellg();
- if (end_pos < 0)
- {
- throw std::runtime_error{"Failed to determine image file size for test boot module: " + img_path.string()};
- }
-
- auto const size = static_cast<std::size_t>(end_pos);
- file.seekg(0, std::ios::beg);
-
m_module_names.push_back(module_name);
- m_module_data.emplace_back(size);
-
- if (size > 0)
- {
- file.read(reinterpret_cast<char *>(m_module_data.back().data()), static_cast<std::streamsize>(size));
- if (!file)
- {
- throw std::runtime_error{"Failed to read image file content for test boot module: " + img_path.string()};
- }
- }
+ auto & mapped_image = m_mapped_images.emplace_back(img_path);
m_registry.add_boot_module(kapi::boot_modules::boot_module{
- m_module_names.back().view(), kapi::memory::linear_address{m_module_data.back().data()},
- m_module_data.back().size()});
+ m_module_names.back().c_str(), kapi::memory::linear_address{mapped_image.mapping}, mapped_image.size});
}
} // namespace kernel::tests::filesystem \ No newline at end of file
diff --git a/kernel/src/test_support/filesystem/storage_boot_module_vfs_fixture.cpp b/kernel/src/test_support/filesystem/storage_boot_module_vfs_fixture.cpp
index cba7278..1a71b57 100644
--- a/kernel/src/test_support/filesystem/storage_boot_module_vfs_fixture.cpp
+++ b/kernel/src/test_support/filesystem/storage_boot_module_vfs_fixture.cpp
@@ -3,11 +3,10 @@
#include "kernel/filesystem/vfs.hpp"
#include "kernel/test_support/filesystem/vfs.hpp"
-#include <kstd/string>
-#include <kstd/vector>
-
#include <cstddef>
#include <filesystem>
+#include <string>
+#include <vector>
namespace kernel::tests::filesystem
{
@@ -24,7 +23,7 @@ namespace kernel::tests::filesystem
}
auto storage_boot_module_vfs_fixture::setup_modules_from_img_and_init_vfs(
- kstd::vector<kstd::string> const & module_names, kstd::vector<std::filesystem::path> const & img_paths) -> void
+ std::vector<std::string> const & module_names, std::vector<std::filesystem::path> const & img_paths) -> void
{
setup_modules_from_img(module_names, img_paths);
kernel::filesystem::vfs::init();