From f163a5d5f6802f63092229f0f9326e5fb44b7908 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 9 Aug 2020 21:55:42 +0200 Subject: Added malloc/free syscall --- lib/inc/mem.h | 13 +++++++++++-- lib/inc/sys.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/inc') diff --git a/lib/inc/mem.h b/lib/inc/mem.h index e2d574f..9399b54 100644 --- a/lib/inc/mem.h +++ b/lib/inc/mem.h @@ -5,8 +5,17 @@ #include -#define malloc(n) ((void *)((HEAP += n) - n)) // TODO: Implement real/better malloc/free -#define free(x) +// Huh +#ifdef kernel +#define malloc(n) (void *)((HEAP += n) - n) // TODO: Implement real/better malloc/free +#define free(ptr) +#elif defined(userspace) +#include +#define malloc(n) (void *)sys1(SYS_MALLOC, n) +#define free(ptr) (void)(sys1(SYS_FREE, (int)ptr)) +#else +#error "No lib target specified. Please use -Dkernel or -Duserspace" +#endif // TODO: Use malloc as syscall u32 HEAP; diff --git a/lib/inc/sys.h b/lib/inc/sys.h index aaeb6ca..aefaead 100644 --- a/lib/inc/sys.h +++ b/lib/inc/sys.h @@ -4,7 +4,7 @@ #ifndef SYS_H #define SYS_H -enum sys { SYS_HALT, SYS_EXEC }; +enum sys { SYS_LOOP, SYS_MALLOC, SYS_FREE, SYS_EXEC }; int sys0(enum sys num); int sys1(enum sys num, int d1); -- cgit v1.2.3