More work on Kernel class, syscalls

This commit is contained in:
Nathan Giddings
2020-12-11 09:19:29 -06:00
parent e8c3de4a63
commit 69c3c8a847
34 changed files with 390 additions and 121 deletions

View File

@@ -21,12 +21,12 @@ uint32_t ilog2(uint32_t n, bool roundUp)
return count - (isPowerOfTwo ? 1 : (roundUp ? 0 : 1));
}
kernel::BuddyAllocator::BuddyAllocator()
kernelns::BuddyAllocator::BuddyAllocator()
{
}
kernel::BuddyAllocator::BuddyAllocator(const kernel::MemoryMap& memmap,
kernelns::BuddyAllocator::BuddyAllocator(const kernelns::MemoryMap& memmap,
char* bitmap, size_t blockCount,
size_t treeHeight)
{
@@ -44,7 +44,7 @@ kernel::BuddyAllocator::BuddyAllocator(const kernel::MemoryMap& memmap,
physaddr_t location = 0x100000;
for(size_t i = 0; i < memmap.size() && memmap[i].getSize() > 0; i++)
{
if(memmap[i].getType() != kernel::MemoryMap::AVAILABLE)
if(memmap[i].getType() != kernelns::MemoryMap::AVAILABLE)
continue;
if(memmap[i].getLocation() > location)
location = roundUp(memmap[i].getLocation(), 4096);
@@ -58,7 +58,7 @@ kernel::BuddyAllocator::BuddyAllocator(const kernel::MemoryMap& memmap,
}
}
kernel::BuddyAllocator::BuddyAllocator(char* bitmap, size_t blockSize,
kernelns::BuddyAllocator::BuddyAllocator(char* bitmap, size_t blockSize,
size_t blockCount, size_t treeHeight)
{
this->bitmap = bitmap;
@@ -77,7 +77,7 @@ kernel::BuddyAllocator::BuddyAllocator(char* bitmap, size_t blockSize,
}
}
physaddr_t kernel::BuddyAllocator::allocate(size_t size)
physaddr_t kernelns::BuddyAllocator::allocate(size_t size)
{
size_t height = ilog2(roundUp(size, blockSize) / blockSize, true);
if(height > treeHeight) // Requested block size is greater than maximum
@@ -99,7 +99,7 @@ physaddr_t kernel::BuddyAllocator::allocate(size_t size)
}
}
void kernel::BuddyAllocator::free(physaddr_t location, size_t size)
void kernelns::BuddyAllocator::free(physaddr_t location, size_t size)
{
size_t height = ilog2(roundUp(size, blockSize) / blockSize, true);
if(height <= treeHeight)
@@ -113,7 +113,7 @@ void kernel::BuddyAllocator::free(physaddr_t location, size_t size)
}
}
size_t kernel::BuddyAllocator::freeBlocks() const
size_t kernelns::BuddyAllocator::freeBlocks() const
{
size_t count = 0;
for(size_t j = 0; j < blockCount; j++)
@@ -126,7 +126,7 @@ size_t kernel::BuddyAllocator::freeBlocks() const
return count;
}
size_t kernel::BuddyAllocator::maxAllocationSize() const
size_t kernelns::BuddyAllocator::maxAllocationSize() const
{
for(size_t i = treeHeight; i >= 0; i--)
{
@@ -141,17 +141,17 @@ size_t kernel::BuddyAllocator::maxAllocationSize() const
return 0;
}
size_t kernel::BuddyAllocator::getBlockSize() const
size_t kernelns::BuddyAllocator::getBlockSize() const
{
return blockSize;
}
size_t kernel::BuddyAllocator::getMemorySize() const
size_t kernelns::BuddyAllocator::getMemorySize() const
{
return blockCount;
}
size_t kernel::BuddyAllocator::findFreeBlock(size_t height)
size_t kernelns::BuddyAllocator::findFreeBlock(size_t height)
{
for(size_t i = 0; i < (blockCount >> height); i++)
{
@@ -171,7 +171,7 @@ size_t kernel::BuddyAllocator::findFreeBlock(size_t height)
return INVALID;
}
size_t kernel::BuddyAllocator::split(size_t height, size_t index)
size_t kernelns::BuddyAllocator::split(size_t height, size_t index)
{
if(height > 0 && isFree(height, index))
{
@@ -186,7 +186,7 @@ size_t kernel::BuddyAllocator::split(size_t height, size_t index)
}
}
size_t kernel::BuddyAllocator::merge(size_t height, size_t index)
size_t kernelns::BuddyAllocator::merge(size_t height, size_t index)
{
if(isFree(height, index) && isFree(height, getBuddy(index)) && height < treeHeight)
{
@@ -209,34 +209,34 @@ size_t kernel::BuddyAllocator::merge(size_t height, size_t index)
}
}
size_t kernel::BuddyAllocator::getBuddy(size_t index)
size_t kernelns::BuddyAllocator::getBuddy(size_t index)
{
return index ^ 1;
}
size_t kernel::BuddyAllocator::getParent(size_t index)
size_t kernelns::BuddyAllocator::getParent(size_t index)
{
return index / 2;
}
size_t kernel::BuddyAllocator::getChild(size_t index)
size_t kernelns::BuddyAllocator::getChild(size_t index)
{
return index * 2;
}
physaddr_t kernel::BuddyAllocator::nodeToAddress(size_t height, size_t index)
physaddr_t kernelns::BuddyAllocator::nodeToAddress(size_t height, size_t index)
const
{
return index * (blockSize << height);
}
size_t kernel::BuddyAllocator::addressToNode(size_t height,
size_t kernelns::BuddyAllocator::addressToNode(size_t height,
physaddr_t location) const
{
return location / (blockSize << height);
}
void kernel::BuddyAllocator::reserveNode(size_t height, size_t index)
void kernelns::BuddyAllocator::reserveNode(size_t height, size_t index)
{
size_t bit = (height == 0) ? 0
: ((blockCount * 2) - (blockCount >> (height - 1)));
@@ -244,7 +244,7 @@ void kernel::BuddyAllocator::reserveNode(size_t height, size_t index)
bitmap[bit / 8] |= 1 << (bit % 8);
}
void kernel::BuddyAllocator::freeNode(size_t height, size_t index)
void kernelns::BuddyAllocator::freeNode(size_t height, size_t index)
{
size_t bit = (height == 0) ? 0
: ((blockCount * 2) - (blockCount >> (height - 1)));
@@ -252,7 +252,7 @@ void kernel::BuddyAllocator::freeNode(size_t height, size_t index)
bitmap[bit / 8] &= ~(1 << (bit % 8));
}
bool kernel::BuddyAllocator::isFree(size_t height, size_t index) const
bool kernelns::BuddyAllocator::isFree(size_t height, size_t index) const
{
size_t bit = (height == 0) ? 0
: ((blockCount * 2) - (blockCount >> (height - 1)));