diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-02-28 19:15:38 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-17 16:42:22 +0100 |
| commit | 47d94c6e1c0c46a9c5cdce528c8dca588a531595 (patch) | |
| tree | 78850a86a11406bc9abcc8179ec0ab2f43a688f1 | |
| parent | d22f98cb70587dc451db5cfc0abd4b7fd89ee602 (diff) | |
| download | teachos-47d94c6e1c0c46a9c5cdce528c8dca588a531595.tar.xz teachos-47d94c6e1c0c46a9c5cdce528c8dca588a531595.zip | |
implement first draft of RAMDiskDevice
4 files changed, 66 insertions, 6 deletions
diff --git a/kernel/devices/include/devices/BlockDevice.hpp b/kernel/devices/include/devices/BlockDevice.hpp index db66683..69d7f81 100644 --- a/kernel/devices/include/devices/BlockDevice.hpp +++ b/kernel/devices/include/devices/BlockDevice.hpp @@ -1,10 +1,15 @@ #ifndef TEACH_OS_KERNEL_DEVICES_BLOCK_DEVICE_HPP #define TEACH_OS_KERNEL_DEVICES_BLOCK_DEVICE_HPP +#include <cstddef> + namespace devices { struct block_device { + virtual ~block_device() = default; + + virtual auto read_block(size_t block_index, void * buffer) const -> void = 0; }; } // namespace devices diff --git a/kernel/devices/include/devices/storage/RAMDisk/RAMDiskDevice.hpp b/kernel/devices/include/devices/storage/RAMDisk/RAMDiskDevice.hpp index 98471cf..aa736a4 100644 --- a/kernel/devices/include/devices/storage/RAMDisk/RAMDiskDevice.hpp +++ b/kernel/devices/include/devices/storage/RAMDisk/RAMDiskDevice.hpp @@ -1,10 +1,26 @@ #ifndef TEACH_OS_KERNEL_DEVICES_STORAGE_RAM_DISK_DEVICE_HPP #define TEACH_OS_KERNEL_DEVICES_STORAGE_RAM_DISK_DEVICE_HPP +#include "kapi/memory.hpp" + +#include "devices/BlockDevice.hpp" + +#include <cstddef> + namespace devices::storage::ram_disk { - struct ram_disk_device + struct ram_disk_device : block_device { + constexpr size_t static block_size = 512uz; // TODO BA-FS26 really correct / good?? + + ram_disk_device() = default; + ram_disk_device(kapi::memory::linear_address data_start, size_t data_size); + + auto read_block(size_t block_index, void * buffer) const -> void override; + + private: + kapi::memory::linear_address m_data_start{}; + size_t m_data_size{}; }; } // namespace devices::storage::ram_disk diff --git a/kernel/devices/src/storage/RAMDisk/RAMDiskController.cpp b/kernel/devices/src/storage/RAMDisk/RAMDiskController.cpp index 3e12e0d..48b9116 100644 --- a/kernel/devices/src/storage/RAMDisk/RAMDiskController.cpp +++ b/kernel/devices/src/storage/RAMDisk/RAMDiskController.cpp @@ -3,6 +3,8 @@ #include "kapi/boot_module/boot_module.hpp" #include "kapi/boot_module/boot_module_registry.hpp" +#include "devices/storage/RAMDisk/RAMDiskDevice.hpp" + #include <kstd/print> #include <algorithm> @@ -18,16 +20,21 @@ namespace devices::storage::ram_disk { std::ranges::for_each(*m_boot_module_registry, [this](auto const & module) { create_device_from_boot_module(module); }); - } - auto ram_disk_controller::devices_count() -> size_t - { - return m_devices.size(); + // TODO BA-FS26 just for testing, remove again + std::ranges::for_each(m_devices, [](auto const & device) { device.read_block(0, nullptr); }); } auto ram_disk_controller::create_device_from_boot_module(kapi::boot_modules::boot_module const & module) -> void { + m_devices.at(0) = ram_disk_device{module.start_address, module.size}; + kstd::println("[RAM DISK CONTROLLER] Found boot module: {} at address {} with size {} bytes", module.name, module.start_address, module.size); } + + auto ram_disk_controller::devices_count() -> size_t + { + return m_devices.size(); + } } // namespace devices::storage::ram_disk
\ No newline at end of file diff --git a/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp b/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp index 8d8f51e..1e650d8 100644 --- a/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp +++ b/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp @@ -1,6 +1,38 @@ #include "devices/storage/RAMDisk/RAMDiskDevice.hpp" +#include "kapi/memory.hpp" +#include "kapi/system.hpp" + +#include <kstd/print> + +#include <cstddef> + namespace devices::storage::ram_disk { - // TODO BA-FS26 implement ram disk device functionality + ram_disk_device::ram_disk_device(kapi::memory::linear_address data_start, size_t data_size) + : m_data_start(data_start) + , m_data_size(data_size) + {} + + auto ram_disk_device::read_block(size_t block_index, void * /*buffer*/) const -> void + { + // if (buffer == nullptr) + // { + // kapi::system::panic("[RAM DISK DEVICE] read_block called with null buffer."); + // } + + auto const offset = block_index * block_size; + if (offset + block_size > + m_data_size) // TODO BA-FS26 really correct, what if block_size doesn't divide m_data_size? + { + kapi::system::panic("[RAM DISK DEVICE] read_block out of bounds."); + } + + auto const source = static_cast<std::byte *>(m_data_start) + offset; + for (size_t i = 0; i < block_size; ++i) + { + kstd::println("address: {}, value: {}", source + i, std::to_integer<unsigned int>(*(source + i))); + } + // std::memcpy(buffer, source, block_size); + } } // namespace devices::storage::ram_disk
\ No newline at end of file |
