mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-15 23:47:25 -04:00
Make buddy more dynamic
This commit is contained in:
parent
8b52ef4713
commit
f0006809b4
@ -15,16 +15,22 @@ inline constexpr T pow(T const& x, size_t n){
|
||||
return n > 0 ? x * pow(x, n - 1) : 1;
|
||||
}
|
||||
|
||||
template<size_t Levels, size_t First, size_t Last, size_t Unit>
|
||||
template<size_t Levels, size_t Unit>
|
||||
struct buddy_allocator {
|
||||
static constexpr const size_t levels = Levels;
|
||||
static constexpr const size_t max_block = pow(2, levels - 1);
|
||||
static constexpr const size_t first_address = First;
|
||||
static constexpr const size_t last_address = Last;
|
||||
|
||||
std::array<static_bitmap, levels> bitmaps;
|
||||
|
||||
size_t first_address;
|
||||
size_t last_address;
|
||||
|
||||
public:
|
||||
void set_memory_range(size_t first, size_t last){
|
||||
first_address = first;
|
||||
last_address = last;
|
||||
}
|
||||
|
||||
template<size_t I>
|
||||
void init(size_t words, uint64_t* data){
|
||||
bitmaps[I].init(words, data);
|
||||
|
@ -38,12 +38,14 @@ std::array<uint64_t, array_size(32)> data_bitmap_32;
|
||||
std::array<uint64_t, array_size(64)> data_bitmap_64;
|
||||
std::array<uint64_t, array_size(128)> data_bitmap_128;
|
||||
|
||||
typedef buddy_allocator<8, first_virtual_address, last_virtual_address, unit> buddy_type;
|
||||
typedef buddy_allocator<8, unit> buddy_type;
|
||||
buddy_type allocator;
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
void virtual_allocator::init(){
|
||||
allocator.set_memory_range(first_virtual_address, last_virtual_address);
|
||||
|
||||
//Give room to the bitmaps
|
||||
allocator.init<0>(array_size(1), data_bitmap_1.data());
|
||||
allocator.init<1>(array_size(2), data_bitmap_2.data());
|
||||
|
Loading…
x
Reference in New Issue
Block a user