added placeholder malloc_stack as malloc precursor

master
Anton Lydike 3 years ago
parent 1e472d2a4a
commit a0c3a57921

@ -33,10 +33,10 @@ CFLAGS += -DTEXT_IO_ADDR=0xff0000 -DTEXT_IO_BUFLEN=64
CFLAGS += -march=$(ARCH)
# dependencies that need to be built:
_DEPS = ecall.c csr.c sched.c io.o
_DEPS = ecall.c csr.c sched.c io.c malloc.c
# dependencies as object files:
_OBJ = ecall.o sched.o boot.o csr.o io.o
_OBJ = ecall.o sched.o boot.o csr.o io.o malloc.o
DEPS = $(patsubst %,$(KLIBDIR)/%,$(_DEPS))

@ -0,0 +1,33 @@
#include "malloc.h"
#include "ecall.h"
malloc_info global_malloc_info = { 0 };
void* allocate_memory_end;
void malloc_init(malloc_info* given_info)
{
global_malloc_info = *given_info;
allocate_memory_end = given_info->allocate_memory_end;
}
void* malloc(size_t size)
{
return (void*) ENOMEM;
}
int free(void* ptr)
{
return EINVAL;
}
// allocate stack and return a pointer to the *end* of the allocated region
void* malloc_stack(size_t size)
{
void* new_alloc_end = (void*) (((int) allocate_memory_end) - size);
if (new_alloc_end < global_malloc_info.allocate_memory_start)
return (void*) ENOMEM;
void* stack_top = allocate_memory_end;
allocate_memory_end = new_alloc_end;
return stack_top;
}

@ -0,0 +1,18 @@
#ifndef H_MALLOC
#define H_MALLOC
typedef unsigned int size_t;
typedef struct malloc_info {
void* allocate_memory_end;
void* allocate_memory_start;
} malloc_info;
void* malloc(size_t size);
// int free(void* ptr);
void* malloc_stack(size_t size);
void malloc_init(malloc_info* info);
#endif
Loading…
Cancel
Save