2022-02-26 19:44:16 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "memoryinfo.h"
|
2023-02-03 20:47:05 +00:00
|
|
|
#include "../prekernel/multiboot.h"
|
|
|
|
#include "../terminal/kterm.h"
|
2023-02-03 19:01:31 +00:00
|
|
|
#include "../../lib/include/mem.h"
|
2023-02-03 20:47:05 +00:00
|
|
|
#include "../bitmap.h"
|
2022-02-26 19:44:16 +00:00
|
|
|
|
|
|
|
#define BLOCK_SIZE 4092
|
|
|
|
#define BLOCKS_PER_WORD 32 // A word is 16 bit in x86 machines according to my google search results!
|
|
|
|
|
|
|
|
#define KB_TO_BLOCKS(x) (x / BLOCK_SIZE)
|
|
|
|
#define IS_ALIGNED(addr, align) !((addr) & ~((align) - 1))
|
|
|
|
#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align))
|
|
|
|
|
|
|
|
void initialise_available_regions(uint32_t memoryMapAddr, uint32_t memoryMapLastAddr, uint32_t* memoryBitMap, int* used_blocks);
|
|
|
|
|
|
|
|
extern uint32_t* memoryBitMap;
|
|
|
|
|
|
|
|
class PhysicalMemory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setup(MemoryInfo* memory);
|
|
|
|
void destroy();
|
|
|
|
void free_block(void* ptr);
|
|
|
|
void* allocate_block();
|
|
|
|
void allocate_region(uint32_t, uint32_t);
|
|
|
|
void deallocate_region(uint32_t , uint32_t );
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t pmmap_size;
|
|
|
|
size_t max_blocks;
|
|
|
|
int used_blocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
void mapMultibootMemoryMap( MemoryInfo* memInfo , multiboot_info_t *mbt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Debug Verbose Functions
|
|
|
|
*
|
|
|
|
* @param mmap
|
|
|
|
*/
|
|
|
|
void print_Multiboot_memory_Map(multiboot_memory_map_t* mmap);
|