idk we're trying out pmm
This commit is contained in:
66
kernel/arch/pmm/pmm.c
Normal file
66
kernel/arch/pmm/pmm.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <kernel/pmm.h>
|
||||
|
||||
/**
|
||||
* What i want to do is create a linked list of all the memory structures
|
||||
*
|
||||
* Theres one at the very start of the memory
|
||||
*
|
||||
* one at 1MB
|
||||
*
|
||||
* and then one provided by ram.
|
||||
*
|
||||
*
|
||||
* So the idea is to create a way to access memory through this such that,
|
||||
* when you give a bit block number, it'll go through the first item in the linked list, if the block is out of that range, it
|
||||
* traverses to the next node, tries to find it there, and then continues until it either runs out of memory, or finds a location
|
||||
*/
|
||||
|
||||
#define PMM_PAGE_SIZE 4096
|
||||
|
||||
struct pmm_mem_info {
|
||||
uint64_t startaddr;
|
||||
uint64_t len; // in kb
|
||||
uint32_t* bitmap;
|
||||
};
|
||||
|
||||
#define PMM_GET_MEM_BLOCKS(x) x.len / PMM_PAGE_SIZE
|
||||
|
||||
struct pmm_mem_info main_mem;
|
||||
|
||||
void __pmm_set(int bit, uint32_t* bitmap)
|
||||
{
|
||||
bitmap[bit / 32] |= (1 << (bit % 32));
|
||||
}
|
||||
|
||||
void __pmm_unset(int bit, uint32_t* bitmap)
|
||||
{
|
||||
bitmap[bit / 32] &= ~(1 << (bit % 32));
|
||||
}
|
||||
|
||||
void __pmm_first_free(struct pmm_mem_info mem_block)
|
||||
{
|
||||
for (uint32_t i = 0; i < PMM_GET_MEM_BLOCKS(mem_block) / 32; i++) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void pmm_set(int bit)
|
||||
{
|
||||
/**
|
||||
* Here we want to calculate if the bit is over the length
|
||||
* subtract the length and bit amount so that we compensate for the bit map
|
||||
*
|
||||
* i.e. (length / 4096) == amount of blocks in that specific mem region
|
||||
* if (bit > amt of blocks),
|
||||
* go to next node, subtract amt of blocks from bit, and pass that
|
||||
*
|
||||
* below is merely a temporary solution
|
||||
*/
|
||||
__pmm_set(bit, main_mem.bitmap);
|
||||
}
|
||||
|
||||
void pmm_unset(int bit)
|
||||
{
|
||||
// TODO: same as above
|
||||
__pmm_unset(bit, main_mem.bitmap);
|
||||
}
|
Reference in New Issue
Block a user