-
- // Check compiled base
- base = pBinary->Base;
- // - Sanity Check
- if(base < KLIB_LOWEST || base > KLIB_HIGHEST || base + (pBinary->NumPages<<12) > KLIB_HIGHEST) {
- base = 0;
- }
- // - Check if it is a valid base address
- if(base != 0)
- {
- for(i=0;i<pBinary->NumPages;i++)
- {
- if( MM_GetPhysAddr( pBinary->Pages[i].Virtual & ~0xFFF ) ) {
- base = 0;
- LOG("Address 0x%x is taken\n", pBinary->Pages[i].Virtual & ~0xFFF);
- break;
- }
- }
- }
-
- // Check if the executable has no base or it is not free
- if(base == 0)
- {
- // If so, give it a base
- base = KLIB_LOWEST;
- while(base < KLIB_HIGHEST)
- {
- for(i = 0; i < pBinary->NumPages; i++)
- {
- addr = pBinary->Pages[i].Virtual & ~0xFFF;
- addr -= pBinary->Base;
- addr += base;
- if( MM_GetPhysAddr( addr ) ) break;
- }
- // If space was found, break
- if(i == pBinary->NumPages) break;
- // Else decrement pointer and try again
- base += KLIB_GRANUALITY;
- }
- }
-
- // - Error Check
- if(base >= KLIB_HIGHEST) {
- Warning("[BIN ] Executable '%s' cannot be loaded into kernel, no space", pBinary->TruePath);
- Binary_Dereference( pBinary );
- LEAVE('n');
- return 0;
- }
-
- LOG("base = 0x%x", base);
-
- // - Map binary in
- LOG("pBinary = {NumPages:%i, Pages=%p}", pBinary->NumPages, pBinary->Pages);
- for(i = 0; i < pBinary->NumPages; i++)
- {
- addr = pBinary->Pages[i].Virtual & ~0xFFF;
- addr -= pBinary->Base;
- addr += base;
- LOG("%i - 0x%x to 0x%x", i, addr, pBinary->Pages[i].Physical);
- MM_Map( addr, (Uint) (pBinary->Pages[i].Physical) );
- MM_SetFlags( addr, MM_PFLAG_KERNEL, MM_PFLAG_KERNEL );
-
- if( pBinary->Pages[i].Flags & BIN_PAGEFLAG_RO) // Read-Only?
- MM_SetFlags( addr, MM_PFLAG_RO, MM_PFLAG_KERNEL );
- }