summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/BitMapMgr.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-03-25 15:35:28 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-03-25 15:35:28 +0100
commit0ead895f52d24dad009f738037a7795d4e3d840a (patch)
tree863fd1c881fc7bf26ab78b932421e6416bbef288 /dev/kernel/src/BitMapMgr.cc
parent59dbe4cffc7c633709ef8b45f49c46daf7f74e92 (diff)
kernel: Refactor AHCI I/O path, enhance memory allocators, and cleanup obsolete script
- Removed unused `build_gcc.sh` script. - Namespaced CPU feature flags under `NeOS` and transitioned from enum to unnamed enum for scoping. - Renamed `drv_std_input_output` to `drv_std_input_output_ahci` for clarity. - Improved AHCI driver documentation and added zeroing for read buffers. - Added optional `pad` parameter to memory allocators: `mm_alloc_bitmap`, `mm_new_heap`, `PageMgr::Request`, etc. - Updated bitmap allocator to correctly handle and align with padded sizes. - Added `fPad` field to memory header block. - Fixed `ATA-DMA` mode comment, corrected PRD usage and logic. - Improved code documentation and formatting in `UserProcessScheduler`, `PageMgr`, and related components. - Enhanced safety in process memory cleanup (e.g., `StackReserve` cleanup). Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/src/BitMapMgr.cc')
-rw-r--r--dev/kernel/src/BitMapMgr.cc55
1 files changed, 35 insertions, 20 deletions
diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc
index 18b1a156..f65df8c6 100644
--- a/dev/kernel/src/BitMapMgr.cc
+++ b/dev/kernel/src/BitMapMgr.cc
@@ -28,7 +28,9 @@ namespace NeOS
{
namespace Detail
{
- /// \brief Proxy Interface to allocate a bitmap.
+ /***********************************************************************************/
+ /// \brief Proxy Interface to manage a bitmap allocator.
+ /***********************************************************************************/
class IBitMapProxy final
{
public:
@@ -79,27 +81,36 @@ namespace NeOS
return flags;
}
- /// @brief Iterate over availables pages for a free one.
- /// @return The new address which was found.
- auto FindBitMap(VoidPtr base_ptr, SizeT size, Bool wr, Bool user) -> VoidPtr
+ /***********************************************************************************/
+ /// @brief Iterate over availables bitmap, until we find a free entry.
+ /// @param base_ptr base pointer to look on.
+ /// @param size the size of the requested data structure.
+ /// @param wr is writable flag?
+ /// @param user is user flag?
+ /// @param pad additional padding added to **size**
+ /// @return The new free address, or nullptr.
+ /***********************************************************************************/
+ auto FindBitMap(VoidPtr base_ptr, const SizeT size, const Bool wr, const Bool user, const SizeT pad) -> VoidPtr
{
if (!size)
return nullptr;
- VoidPtr base = reinterpret_cast<VoidPtr>(((UIntPtr)base_ptr) + kPageSize);
+ constexpr const UInt32 kStartOffset = 0x1000;
- static SizeT biggest_block = 0UL;
+ VoidPtr base = reinterpret_cast<VoidPtr>(((UIntPtr)base_ptr) + kStartOffset);
+
+ static SizeT biggest = 0UL;
while (YES)
{
UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base);
if (ptr_bit_set[kBitMapMagIdx] == kBitMapMagic &&
- ptr_bit_set[kBitMapSizeIdx] == size)
+ ptr_bit_set[kBitMapSizeIdx] == (size + pad))
{
if (ptr_bit_set[kBitMapUsedIdx] == No)
{
- ptr_bit_set[kBitMapSizeIdx] = size;
+ ptr_bit_set[kBitMapSizeIdx] = size + pad;
ptr_bit_set[kBitMapUsedIdx] = Yes;
this->GetBitMapStatus(ptr_bit_set);
@@ -107,8 +118,8 @@ namespace NeOS
UInt32 flags = this->MakeMMFlags(wr, user);
mm_map_page(ptr_bit_set, ptr_bit_set, flags);
- if (biggest_block < size)
- biggest_block = size;
+ if (biggest < (size + pad))
+ biggest = size + pad;
return (VoidPtr)ptr_bit_set;
}
@@ -116,7 +127,7 @@ namespace NeOS
else if (ptr_bit_set[kBitMapMagIdx] != kBitMapMagic)
{
ptr_bit_set[kBitMapMagIdx] = kBitMapMagic;
- ptr_bit_set[kBitMapSizeIdx] = size;
+ ptr_bit_set[kBitMapSizeIdx] = (size + pad);
ptr_bit_set[kBitMapUsedIdx] = Yes;
this->GetBitMapStatus(ptr_bit_set);
@@ -124,13 +135,13 @@ namespace NeOS
UInt32 flags = this->MakeMMFlags(wr, user);
mm_map_page(ptr_bit_set, ptr_bit_set, flags);
- if (biggest_block < size)
- biggest_block = size;
+ if (biggest < (size + pad))
+ biggest = (size + pad);
return (VoidPtr)ptr_bit_set;
}
- base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base) + ((ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) ? (size) : ptr_bit_set[kBitMapSizeIdx]));
+ base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base) + ((ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) ? (size + pad) : ptr_bit_set[kBitMapSizeIdx]));
}
return nullptr;
@@ -145,42 +156,46 @@ namespace NeOS
return;
}
- kout << "Magic Number: " << hex_number(ptr_bit_set[kBitMapMagIdx]) << kendl;
- kout << "Is Allocated: " << (ptr_bit_set[kBitMapUsedIdx] ? "Yes" : "No") << kendl;
+ kout << "Magic: " << hex_number(ptr_bit_set[kBitMapMagIdx]) << kendl;
+ kout << "Is Allocated? " << (ptr_bit_set[kBitMapUsedIdx] ? "YES" : "NO") << kendl;
kout << "Size of BitMap (B): " << number(ptr_bit_set[kBitMapSizeIdx]) << kendl;
kout << "Size of BitMap (KIB): " << number(KIB(ptr_bit_set[kBitMapSizeIdx])) << kendl;
kout << "Size of BitMap (MIB): " << number(MIB(ptr_bit_set[kBitMapSizeIdx])) << kendl;
kout << "Size of BitMap (GIB): " << number(GIB(ptr_bit_set[kBitMapSizeIdx])) << kendl;
kout << "Size of BitMap (TIB): " << number(TIB(ptr_bit_set[kBitMapSizeIdx])) << kendl;
- kout << "Address Of BitMap Header: " << hex_number((UIntPtr)ptr_bit_set) << kendl;
+ kout << "BitMap Address: " << hex_number((UIntPtr)ptr_bit_set) << kendl;
}
};
} // namespace Detail
- auto mm_is_bitmap(VoidPtr ptr) -> Bool
+ auto mm_is_bitmap(VoidPtr ptr) -> BOOL
{
Detail::IBitMapProxy bitmp;
return bitmp.IsBitMap(ptr);
}
+ /***********************************************************************************/
/// @brief Allocate a new page to be used by the OS.
/// @param wr read/write bit.
/// @param user user bit.
/// @return a new bitmap allocated pointer.
- auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page) -> VoidPtr
+ /***********************************************************************************/
+ auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, const SizeT pad) -> VoidPtr
{
VoidPtr ptr_new = nullptr;
Detail::IBitMapProxy bitmp;
- ptr_new = bitmp.FindBitMap(kKernelBitMpStart, size, wr, user);
+ ptr_new = bitmp.FindBitMap(kKernelBitMpStart, size, wr, user, pad);
MUST_PASS(ptr_new);
return (UIntPtr*)ptr_new;
}
+ /***********************************************************************************/
/// @brief Free Bitmap, and mark it as absent.
/// @param ptr the pointer to free.
+ /***********************************************************************************/
auto mm_free_bitmap(VoidPtr ptr) -> Bool
{
if (!ptr)