From eafbf23b6e2419595eeee3ca08e0f7a714126ec1 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 8 Feb 2014 17:24:49 +0100 Subject: [PATCH] Prepare malloc support --- userlib/include/malloc.hpp | 20 +++++++++++++++++ userlib/src/malloc.cpp | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 userlib/include/malloc.hpp create mode 100644 userlib/src/malloc.cpp diff --git a/userlib/include/malloc.hpp b/userlib/include/malloc.hpp new file mode 100644 index 00000000..1e7fcf6f --- /dev/null +++ b/userlib/include/malloc.hpp @@ -0,0 +1,20 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#ifndef USERLIB_MALLOC_H +#define USERLIB_MALLOC_H + +#include "types.hpp" + +void* malloc(size_t size); +void free(void* pointer); + +size_t brk_start(); +size_t brk_end(); +size_t sbrk(size_t inc); + +#endif diff --git a/userlib/src/malloc.cpp b/userlib/src/malloc.cpp new file mode 100644 index 00000000..385d981a --- /dev/null +++ b/userlib/src/malloc.cpp @@ -0,0 +1,45 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include "malloc.hpp" + +void* malloc(size_t size){ + //TODO + + return nullptr; +} + +void free(void* pointer){ + //TODO +} + +size_t brk_start(){ + size_t value; + asm volatile("mov rax, 7; int 50; mov %0, rax" + : "=m" (value) + : //No inputs + : "rax"); + return value; +} + +size_t brk_end(){ + size_t value; + asm volatile("mov rax, 8; int 50; mov %0, rax" + : "=m" (value) + : //No inputs + : "rax"); + return value; +} + +size_t sbrk(size_t inc){ + size_t value; + asm volatile("mov rax, 9; int 50; mov %0, rax" + : "=m" (value) + : "b" (inc) + : "rax"); + return value; +}