1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Implemented the new physical page allocator API.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-22 21:08:39 +02:00
parent d392045559
commit b80195dc19
3 changed files with 64 additions and 13 deletions

View file

@ -46,12 +46,15 @@ namespace Sortix
size_t ContinuousPages;
};
// Refers to private assembly functions.
addr_t GetPrivate();
void PutPrivate(addr_t page);
void Fragmentize();
UnallocPage* volatile UnallocatedPage; // Must have this name and namespace due to assembly.
size_t PagesTotal;
//size_t PagesUsed;
//size_t PagesFree;
size_t pagesTotal;
size_t pagesUsed;
size_t pagesFree;
const size_t UnallocPageMagic = 0xABBAACDC; // Must this value due to assembly
@ -59,7 +62,7 @@ namespace Sortix
void Init(multiboot_info_t* BootInfo)
{
UnallocatedPage = NULL;
PagesTotal = 0;
pagesTotal = 0;
if ( !( BootInfo->flags & MULTIBOOT_INFO_MEM_MAP ) )
{
@ -136,23 +139,70 @@ namespace Sortix
Page->Next = UnallocatedPage;
Page->ContinuousPages = Entries[I].Length - 1;
PagesTotal += Entries[I].Length;
pagesTotal += Entries[I].Length;
UnallocatedPage = Page;
}
}
if ( PagesTotal == 0 ) { Panic("memorymanagement.cpp: no RAM were available for paging"); }
if ( pagesTotal == 0 ) { Panic("memorymanagement.cpp: no RAM were available for paging"); }
// Alright, time to make our linked list into a lot of small entries.
// This speeds up the system when it's fully up and running. It only
// takes a few miliseconds to run this operation on my laptop.
Fragmentize();
pagesFree = pagesTotal;
pagesUsed = 0;
ASSERT(pagesFree + pagesUsed == pagesTotal);
#ifndef PLATFORM_SERIAL
//Log::PrintF("%zu pages are available for paging (%zu MiB RAM)\n", PagesTotal, PagesTotal >> 8 /* * 0x1000 / 1024 / 1024*/);
#endif
}
addr_t Get()
{
addr_t result = GetPrivate();
if ( result != 0 )
{
ASSERT(pagesFree > 0);
pagesUsed++;
pagesFree--;
}
else
{
ASSERT(pagesFree == 0);
}
ASSERT(pagesFree + pagesUsed == pagesTotal);
return result;
}
void Put(addr_t page)
{
pagesFree++;
pagesUsed--;
PutPrivate(page);
}
void Insert(addr_t page)
{
pagesFree++;
pagesTotal++;
PutPrivate(page);
}
void GetStats(size_t* pagesize, size_t* numfree, size_t* numused)
{
*pagesize = 4096UL;
*numfree = pagesFree;
*numused = pagesUsed;
}
}
namespace VirtualMemory

View file

@ -85,7 +85,8 @@ namespace Sortix
// (there is no RAM). You can then add memory where you desire. You can take
// a physical page and put it in several places, and you can even add
// permissions to it (read-only, read-write, kernel-only). Naturally, the
// amount of physical pages is a limit (out of memory).
// amount of physical pages is a limit (out of memory), but using swapping
// and a not-RAM storage unit, we could have potentially much more memory.
//
// There can exist several virtual address spaces, and it is possible for
// them to share physical pages. Each process in the system has its own

View file

@ -83,9 +83,9 @@ FragDone:
pop %ebx
ret
.globl _ZN6Sortix4Page3GetEv
.type _ZN6Sortix4Page3GetEv, @function # namespace Sortix { void Paging::Allocate(); }
_ZN6Sortix4Page3GetEv:
.globl _ZN6Sortix4Page10GetPrivateEv
.type _ZN6Sortix4Page10GetPrivateEv, @function # namespace Sortix { void Paging::Allocate(); }
_ZN6Sortix4Page10GetPrivateEv:
# Load the front of our linked list.
mov _ZN6Sortix4Page15UnallocatedPageE, %eax # Load UnallocPage* Sortix::Page::UnallocatedPage
@ -141,9 +141,9 @@ OutOfMem:
movl $0, %eax
ret
.globl _ZN6Sortix4Page3PutEm
.type _ZN6Sortix4Page3PutEm, @function # namespace Sortix { void Paging::Free(void* Page); }
_ZN6Sortix4Page3PutEm:
.globl _ZN6Sortix4Page10PutPrivateEm
.type _ZN6Sortix4Page10PutPrivateEm, @function # namespace Sortix { void Paging::Free(void* Page); }
_ZN6Sortix4Page10PutPrivateEm:
push %esi
mov _ZN6Sortix4Page15UnallocatedPageE, %eax # Load UnallocPage* Sortix::Page::UnallocatedPage
mov 0x8(%esp), %edx