diff options
author | Marvin Borner | 2020-08-09 21:55:42 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-09 21:55:42 +0200 |
commit | f163a5d5f6802f63092229f0f9326e5fb44b7908 (patch) | |
tree | f24ccfe1b9bd340875d534e1aa19ef8676fd4d7b /lib/inc | |
parent | b6d3d341c19440f8447d8d6c6567b7ff78db3174 (diff) |
Added malloc/free syscall
Diffstat (limited to 'lib/inc')
-rw-r--r-- | lib/inc/mem.h | 13 | ||||
-rw-r--r-- | lib/inc/sys.h | 2 |
2 files changed, 12 insertions, 3 deletions
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 <def.h> -#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 <sys.h> +#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); |