diff options
Diffstat (limited to 'dev/kernel/src/BitMapMgr.cc')
| -rw-r--r-- | dev/kernel/src/BitMapMgr.cc | 55 |
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) |
