Prepare malloc support

This commit is contained in:
Baptiste Wicht 2014-02-08 17:24:49 +01:00
parent edf57ba352
commit eafbf23b6e
2 changed files with 65 additions and 0 deletions

View File

@ -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

45
userlib/src/malloc.cpp Normal file
View File

@ -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;
}