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.

50 lines
1.7 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>
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)
{
kprintf("kmalloc_init(%p, %p)\n", (void *)_phys_start, (void *)_phys_end);
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);
return pages_init();
}
/*
* 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.
*/