@ -14,6 +14,9 @@ void *kheap_end;
int kmalloc_init ( uintptr_t _phys_start , uintptr_t _phys_end )
{
phys_start = _phys_start ;
phys_end = _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
@ -22,21 +25,30 @@ int kmalloc_init(uintptr_t _phys_start, uintptr_t _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 ;
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 ;
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 ;
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 = 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 ) ;
phys_start = uintptr_align ( phys_start , + HUGEPAGE_SHIFT ) ;
/*
* This is intentionally not aligned to hugepages , because __early_get_page ( )
* shrinks it in single PAGE_SIZE steps whenever it is called anyway .
* I know , this is a terrible hack , but it will be aligned to a hugepage
* from within pages_init ( ) , right after the entire physical memory has
* been mapped to the direct area ( which is the only reason we need to
* be able to allocate pages before the page frame allocator is set up
* in the first place ) .
*/
phys_end = uintptr_align ( phys_end , - PAGE_SHIFT ) ;
int err = pages_init ( ) ;
if ( err )