//  Copyright (C) 2016, mituhiromatuura all right reserved.

#include <kernel.h>
#include "tlsf.h"
#include "mem.h"

#define false 0
#define true 1

static bool_t	tlsf_initialized = false;
static unsigned char *mem_pool = (unsigned char *)0x2003a000;

void
init_mem(void)
{
	unsigned char *p = mem_pool;
	while(p < (unsigned char *)0x20048000)*(p++) = (unsigned char)0;

	if (init_memory_pool(0x20048000 - (int)mem_pool, mem_pool) >= 0) {
		tlsf_initialized = true;
	}
}

void *
malloc(SIZE size)
{
	if (tlsf_initialized) {
		return(tlsf_malloc(size));
	}
	else {
		return(NULL);
	}
}

void
free(void *ptr)
{
	if (tlsf_initialized) {
		tlsf_free(ptr);
	}
}
