Nigel
b07b4f0d38
Problem: As our kernel grows we need more complex datastructures and functions these would come from the standard C/C++ library with normal programs. The kernel is a freestanding programme and has no access to standard libraries. Solution: We build a mini version of the standard C/C++ library which will contain the datastructures and functions we want. This library can then be statically linked into our kernel binary. Making it a statically linked library also gives more structure to the project. Keeping these random functions and datastructures in the kernel just clutters the kernel source code with less relevant source code.
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#pragma once
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
#include "memoryinfo.h"
|
|
#include "../prekernel/multiboot.h"
|
|
#include "../terminal/kterm.h"
|
|
#include <CoreLib/Memory.h>
|
|
|
|
#include "../bitmap.h"
|
|
|
|
#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);
|