This repository has been archived on 2020-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
Legacy-Sync/kheap.c
Jenny Curle f6ba6aa117 Legacy OS files. Have an i686-elf-gcc & -ld in your PATH,
and the Makefile will take care of the rest.
2019-04-01 01:38:50 +01:00

41 lines
772 B
C

#include "headers/kheap.h"
#include <stdint.h>
#include <stddef.h>
// end is defined in the linker
extern uint32_t end;
uint32_t placement_address = (uint32_t)&end;
uint32_t kmalloc(size_t sz, int align, uint32_t *phys)
{
if( align == 1 && (placement_address & 0xFFFFF000)) // if not page aligned
{
placement_address &= 0xFFFFF000;
placement_address += 0x1000;
}
if(phys)
{
*phys = placement_address;
}
uint32_t tmp = placement_address;
placement_address += sz;
return tmp;
}
uint32_t kmalloc_a(size_t sz)
{
return kmalloc(sz,1,0);
}
uint32_t kmalloc_p(size_t sz, uint32_t *phys)
{
return kmalloc(sz,0,phys);
}
uint32_t kmalloc_ap(size_t sz, uint32_t *phys)
{
return kmalloc(sz,1,phys);
}