[SOLVED] Stuck on passing grub memory map into my allocator
Posted: Thu Mar 03, 2016 11:43 pm
Hey all.
Im writing a basic allocator for my kernel.
I made a awesome allocate function that works great.
I use linked structs that contain infomation about free space for my allocator, here is the struct:
That all works fine, but I want to be able to load free memory areas into seperate free_loc's.
I am using grub to get the memory map. Here is my memory allocator init function:
It loops through the memory map, checking if a area is useable.
Heres the issue: I need to somehow leave a reference to the last area for the next area to attach its 'prev' too.
I am trying to use the pointer 'last' to acheive this.
It does what it needs to do fine, but it modifies the last area at this line:
I basicly want to change the 'free_loc' the pointer points too, but it is overwriting the data instead.
Im terrible at explaining so hopefully you can understand.
Thanks, Harry
Im writing a basic allocator for my kernel.
I made a awesome allocate function that works great.
I use linked structs that contain infomation about free space for my allocator, here is the struct:
Code: Select all
typedef struct
{
void* next;
void* prev;
uint32_t size;
void* base;
} free_loc;
I am using grub to get the memory map. Here is my memory allocator init function:
Code: Select all
void pmm_init(void* mmloc, unsigned long mmsize)
{
mmap_entry_t* cmap=(mmap_entry_t*)mmloc;
int i=0;
free_loc* last;
while(cmap < (mmap_entry_t*) mmloc + mmsize)
{
if(cmap->type == 1)
{
if(i==0)
{
first->size = cmap->len;
first->base = cmap->base;
first->prev = 0;
last = first;
}else{
free_loc* append;
append->size = cmap->len;
append->base = cmap->base;
append->prev = last;
last->next = append;
last = append;
}
i++;
}
cmap = (mmap_entry_t*) ( (unsigned int)cmap + cmap->size + sizeof(uint32_t));
}
}
Heres the issue: I need to somehow leave a reference to the last area for the next area to attach its 'prev' too.
I am trying to use the pointer 'last' to acheive this.
It does what it needs to do fine, but it modifies the last area at this line:
Code: Select all
last = append;
Im terrible at explaining so hopefully you can understand.
Thanks, Harry