You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0 KiB
C

/* See the end of this file for copyright and license terms. */
#include <gay/kprintf.h>
#include <gay/mm.h>
#include <gay/types.h>
#include <gay/util.h>
extern void _image_start_phys;
extern void _image_end_phys;
/* these are initialized by pages_init() */
void *kheap_start;
void *kheap_end;
int kmalloc_init(uintptr_t _phys_start, uintptr_t _phys_end)
{
/*
* The kernel image is very likely gonna be within the physical memory
* range, so we're gonna need to do some cropping in order to not hand
* out pages that actually contain kernel code.
* Furthermore, somebody should probably clean up this mess somehow.
*/
uintptr_t image_start_phys = (uintptr_t)&_image_start_phys;
uintptr_t image_end_phys = (uintptr_t)&_image_end_phys;
if (_phys_start < image_start_phys && _phys_end > image_start_phys) {
if (image_start_phys - _phys_start > _phys_end - image_start_phys)
_phys_end = image_start_phys;
else
_phys_start = image_end_phys;
}
if (_phys_start < image_end_phys && _phys_end > image_end_phys) {
if (image_end_phys - _phys_start > _phys_end - image_end_phys)
_phys_end = image_start_phys;
else
_phys_start = image_end_phys;
}
phys_start = uintptr_align(_phys_start, +HUGEPAGE_SHIFT);
phys_end = uintptr_align(_phys_end, -HUGEPAGE_SHIFT);
kprintf("Aligning physical memory to 0x%08x-0x%08x\n", phys_start, phys_end);
int err = pages_init();
if (err)
return err;
slab_init();
return 0;
}
/*
* 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.
*/