mm: add page frame allocator

This commit is contained in:
anna 2021-09-21 18:25:54 +02:00
parent 2a0ed8121a
commit d436d9b203
Signed by: fef
GPG key ID: EC22E476DC2D3D84
11 changed files with 442 additions and 7 deletions

17
kernel/mm/CMakeLists.txt Normal file
View file

@ -0,0 +1,17 @@
# See the end of this file for copyright and license terms.
target_sources(gay_kernel PRIVATE
kmalloc.c
)
# This file is part of GayBSD.
# Copyright (c) 2021 fef <owo@fef.moe>.
#
# GayBSD is nonviolent software: you may only use, redistribute, and/or
# modify it under the terms of the Cooperative Nonviolent Public License
# (CNPL) as found in the LICENSE file in the source code root directory
# or at <https://git.pixie.town/thufie/npl-builder>; either version 7
# of the license, or (at your option) any later version.
#
# GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
# permitted by applicable law. See the CNPL for details.

44
kernel/mm/kmalloc.c Normal file
View file

@ -0,0 +1,44 @@
/* See the end of this file for copyright and license terms. */
#include <arch/page.h>
#include <gay/config.h>
#include <gay/kprintf.h>
#include <gay/mm.h>
#include <gay/types.h>
/* yeah this is probably the most stupid memory allocator there is */
void *kmalloc(size_t size, enum mm_flags flags)
{
if (flags != MM_KERNEL) {
kprintf("invalild flags passed to kmalloc()\n");
return NULL;
}
if (size > PAGE_SIZE) {
kprintf("Requested alloc size of %u > PAGE_SIZE, i can't do that yet qwq\n", size);
return NULL;
}
return get_page();
}
void kfree(void *ptr)
{
put_page(ptr);
}
/*
* This file is part of GayBSD.
* Copyright (c) 2021 fef <owo@fef.moe>.
*
* GayBSD is nonviolent software: you may only use, redistribute, and/or
* modify it under the terms of the Cooperative Nonviolent Public License
* (CNPL) as found in the LICENSE file in the source code root directory
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
* of the license, or (at your option) any later version.
*
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPL for details.
*/