I am writing an early kernel heap to manage some memory allocations before the final heap is operational. When I assign an address(not used by anything else) to my struct pointer it works, the problem comes when I try to assign values to the struct members.
Before you answer, take in mind that I do not have any kind of C library which I can use. Debugging was done with QEMU and gdb through remote.
//The struct
typedef struct mem_block{
mblock_t *prev;
boolean used;
size_t size;
mblock_t *next;
} mblock_t;
//The file-local pointer(before its init)
mblock_t *eheap=NULL;
//Function that assigns the values
mblock_t *init_early_heap(address_t start, size_t size){
if(eheap==NULL){
if(size < sizeof(mblock_t)){
PANIC("Available memory below EHEAP requirement");
}
eheap = (mblock_t*)HEAP_START_ADDRESS;
eheap->prev = NULL;
eheap->next = NULL;
eheap->size = (size_t)(size - sizeof(mblock_t));
eheap->used = false;
print("\nCreated Early Heap at ");
print_hex_long(eheap);
print("\nSize in bytes: ");
print(itos(eheap->size));NL;
}
return eheap;
}
After the function returns, I get a pointer pointing at address 0xC0000000 and untouched members as eheap->size is 0(size parameter in the function is NOT 0).