Changed name of kernel namespace
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
#include "addressspace.hpp"
|
||||
|
||||
qkernel::AddressSpace::AddressSpace(MemoryAllocator& malloc)
|
||||
kernel::AddressSpace::AddressSpace(MemoryAllocator& malloc)
|
||||
: malloc(malloc)
|
||||
{
|
||||
this->pageTables = (PageTableEntry*) 0xFFC00000;
|
||||
this->pageDirectory = (PageTableEntry*) 0xFFFFF000;
|
||||
}
|
||||
|
||||
void* qkernel::AddressSpace::mmap(void* start, size_t length)
|
||||
void* kernel::AddressSpace::mmap(void* start, size_t length)
|
||||
{
|
||||
size_t tableIndex = (size_t) start / 4096;
|
||||
for(int i = (int) length; i > 0; i -= 4096)
|
||||
@@ -34,12 +34,12 @@ void* qkernel::AddressSpace::mmap(void* start, size_t length)
|
||||
return start;
|
||||
}
|
||||
|
||||
void qkernel::AddressSpace::munmap(void* start, size_t length)
|
||||
void kernel::AddressSpace::munmap(void* start, size_t length)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
physaddr_t qkernel::AddressSpace::getPhysicalAddress(void* virtualAddress)
|
||||
physaddr_t kernel::AddressSpace::getPhysicalAddress(void* virtualAddress)
|
||||
const
|
||||
{
|
||||
size_t index = (size_t) virtualAddress / 4096;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "pagetableentry.hpp"
|
||||
#include "systypes.hpp"
|
||||
|
||||
namespace qkernel {
|
||||
namespace kernel {
|
||||
|
||||
class AddressSpace {
|
||||
public:
|
||||
@@ -37,6 +37,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
} /* namespace qkernel */
|
||||
} /* namespace kernel */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
#define roundUp(n, m) ((n % m == 0) ? n : (n + m - (n % m)))
|
||||
|
||||
qkernel::BuddyAllocator::BuddyAllocator()
|
||||
kernel::BuddyAllocator::BuddyAllocator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
qkernel::BuddyAllocator::BuddyAllocator(qkernel::MemoryMap& memmap,
|
||||
kernel::BuddyAllocator::BuddyAllocator(kernel::MemoryMap& memmap,
|
||||
char* bitmap, size_t blockCount,
|
||||
size_t treeHeight)
|
||||
{
|
||||
@@ -28,7 +28,7 @@ qkernel::BuddyAllocator::BuddyAllocator(qkernel::MemoryMap& memmap,
|
||||
physaddr_t location = 0x100000;
|
||||
for(size_t i = 0; i < memmap.size() && memmap[i].getSize() > 0; i++)
|
||||
{
|
||||
if(memmap[i].getType() != qkernel::MemoryMap::AVAILABLE)
|
||||
if(memmap[i].getType() != kernel::MemoryMap::AVAILABLE)
|
||||
continue;
|
||||
if(memmap[i].getLocation() > location)
|
||||
location = roundUp(memmap[i].getLocation(), 4096);
|
||||
@@ -42,7 +42,7 @@ qkernel::BuddyAllocator::BuddyAllocator(qkernel::MemoryMap& memmap,
|
||||
}
|
||||
}
|
||||
|
||||
qkernel::BuddyAllocator::BuddyAllocator(char* bitmap, size_t blockSize,
|
||||
kernel::BuddyAllocator::BuddyAllocator(char* bitmap, size_t blockSize,
|
||||
size_t blockCount, size_t treeHeight)
|
||||
{
|
||||
this->bitmap = bitmap;
|
||||
@@ -61,7 +61,7 @@ qkernel::BuddyAllocator::BuddyAllocator(char* bitmap, size_t blockSize,
|
||||
}
|
||||
}
|
||||
|
||||
physaddr_t qkernel::BuddyAllocator::allocate(size_t size)
|
||||
physaddr_t kernel::BuddyAllocator::allocate(size_t size)
|
||||
{
|
||||
size_t height = ilog2(roundUp(size, blockSize) / blockSize, true);
|
||||
if(height > treeHeight) // Requested block size is greater than maximum
|
||||
@@ -83,7 +83,7 @@ physaddr_t qkernel::BuddyAllocator::allocate(size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
void qkernel::BuddyAllocator::free(physaddr_t location, size_t size)
|
||||
void kernel::BuddyAllocator::free(physaddr_t location, size_t size)
|
||||
{
|
||||
size_t height = ilog2(roundUp(size, blockSize) / blockSize, true);
|
||||
if(height <= treeHeight)
|
||||
@@ -97,7 +97,7 @@ void qkernel::BuddyAllocator::free(physaddr_t location, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::freeBlocks() const
|
||||
size_t kernel::BuddyAllocator::freeBlocks() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for(size_t j = 0; j < blockCount; j++)
|
||||
@@ -110,7 +110,7 @@ size_t qkernel::BuddyAllocator::freeBlocks() const
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::maxAllocationSize() const
|
||||
size_t kernel::BuddyAllocator::maxAllocationSize() const
|
||||
{
|
||||
for(size_t i = treeHeight; i >= 0; i--)
|
||||
{
|
||||
@@ -125,17 +125,17 @@ size_t qkernel::BuddyAllocator::maxAllocationSize() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::getBlockSize() const
|
||||
size_t kernel::BuddyAllocator::getBlockSize() const
|
||||
{
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::getMemorySize() const
|
||||
size_t kernel::BuddyAllocator::getMemorySize() const
|
||||
{
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::findFreeBlock(size_t height)
|
||||
size_t kernel::BuddyAllocator::findFreeBlock(size_t height)
|
||||
{
|
||||
for(size_t i = 0; i < (blockCount >> height); i++)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ size_t qkernel::BuddyAllocator::findFreeBlock(size_t height)
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::split(size_t height, size_t index)
|
||||
size_t kernel::BuddyAllocator::split(size_t height, size_t index)
|
||||
{
|
||||
if(height > 0 && isFree(height, index))
|
||||
{
|
||||
@@ -170,7 +170,7 @@ size_t qkernel::BuddyAllocator::split(size_t height, size_t index)
|
||||
}
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::merge(size_t height, size_t index)
|
||||
size_t kernel::BuddyAllocator::merge(size_t height, size_t index)
|
||||
{
|
||||
if(isFree(height, index) && isFree(height, getBuddy(index)) && height < treeHeight)
|
||||
{
|
||||
@@ -193,34 +193,34 @@ size_t qkernel::BuddyAllocator::merge(size_t height, size_t index)
|
||||
}
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::getBuddy(size_t index)
|
||||
size_t kernel::BuddyAllocator::getBuddy(size_t index)
|
||||
{
|
||||
return index ^ 1;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::getParent(size_t index)
|
||||
size_t kernel::BuddyAllocator::getParent(size_t index)
|
||||
{
|
||||
return index / 2;
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::getChild(size_t index)
|
||||
size_t kernel::BuddyAllocator::getChild(size_t index)
|
||||
{
|
||||
return index * 2;
|
||||
}
|
||||
|
||||
physaddr_t qkernel::BuddyAllocator::nodeToAddress(size_t height, size_t index)
|
||||
physaddr_t kernel::BuddyAllocator::nodeToAddress(size_t height, size_t index)
|
||||
const
|
||||
{
|
||||
return index * (blockSize << height);
|
||||
}
|
||||
|
||||
size_t qkernel::BuddyAllocator::addressToNode(size_t height,
|
||||
size_t kernel::BuddyAllocator::addressToNode(size_t height,
|
||||
physaddr_t location) const
|
||||
{
|
||||
return location / (blockSize << height);
|
||||
}
|
||||
|
||||
void qkernel::BuddyAllocator::reserveNode(size_t height, size_t index)
|
||||
void kernel::BuddyAllocator::reserveNode(size_t height, size_t index)
|
||||
{
|
||||
size_t bit = (height == 0) ? 0
|
||||
: ((blockCount * 2) - (blockCount >> (height - 1)));
|
||||
@@ -228,7 +228,7 @@ void qkernel::BuddyAllocator::reserveNode(size_t height, size_t index)
|
||||
bitmap[bit / 8] |= 1 << (bit % 8);
|
||||
}
|
||||
|
||||
void qkernel::BuddyAllocator::freeNode(size_t height, size_t index)
|
||||
void kernel::BuddyAllocator::freeNode(size_t height, size_t index)
|
||||
{
|
||||
size_t bit = (height == 0) ? 0
|
||||
: ((blockCount * 2) - (blockCount >> (height - 1)));
|
||||
@@ -236,7 +236,7 @@ void qkernel::BuddyAllocator::freeNode(size_t height, size_t index)
|
||||
bitmap[bit / 8] &= ~(1 << (bit % 8));
|
||||
}
|
||||
|
||||
bool qkernel::BuddyAllocator::isFree(size_t height, size_t index) const
|
||||
bool kernel::BuddyAllocator::isFree(size_t height, size_t index) const
|
||||
{
|
||||
size_t bit = (height == 0) ? 0
|
||||
: ((blockCount * 2) - (blockCount >> (height - 1)));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "memoryallocator.hpp"
|
||||
#include "memorymap.hpp"
|
||||
|
||||
namespace qkernel
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
class BuddyAllocator : public MemoryAllocator
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "interruptdescriptor.hpp"
|
||||
|
||||
qkernel::InterruptDescriptor::InterruptDescriptor()
|
||||
kernel::InterruptDescriptor::InterruptDescriptor()
|
||||
{
|
||||
this->m_offset1 = 0;
|
||||
this->m_selector = 0;
|
||||
@@ -12,8 +12,7 @@ qkernel::InterruptDescriptor::InterruptDescriptor()
|
||||
this->m_offset2 = 0;
|
||||
}
|
||||
|
||||
qkernel::InterruptDescriptor::InterruptDescriptor(void* handler,
|
||||
Type type, unsigned int dpl)
|
||||
kernel::InterruptDescriptor::InterruptDescriptor(void* handler, Type type, unsigned int dpl)
|
||||
{
|
||||
uint32_t offset = (uint32_t) handler;
|
||||
this->m_offset1 = (uint16_t) offset;
|
||||
@@ -23,19 +22,41 @@ qkernel::InterruptDescriptor::InterruptDescriptor(void* handler,
|
||||
this->m_storage = 0;
|
||||
this->m_dpl = dpl;
|
||||
this->m_present = 0;
|
||||
this->m_offset = (uint16_t) (offset >> 16);
|
||||
this->m_offset2 = (uint16_t) (offset >> 16);
|
||||
}
|
||||
|
||||
bool qkernel::InterruptDescriptor::present()
|
||||
bool kernel::InterruptDescriptor::present()
|
||||
{
|
||||
return m_present == 1;
|
||||
}
|
||||
void qkernel::InterruptDescriptor::present(bool present)
|
||||
void kernel::InterruptDescriptor::present(bool present)
|
||||
{
|
||||
m_present = present ? 1 : 0;
|
||||
}
|
||||
|
||||
Type qkernel::InterruptDescriptor::type()
|
||||
kernel::InterruptDescriptor::Type kernel::InterruptDescriptor::type()
|
||||
{
|
||||
|
||||
return (Type) m_type;
|
||||
}
|
||||
|
||||
void kernel::InterruptDescriptor::type(kernel::InterruptDescriptor::Type type)
|
||||
{
|
||||
m_type = (unsigned int) type;
|
||||
}
|
||||
|
||||
unsigned int kernel::InterruptDescriptor::dpl()
|
||||
{
|
||||
return m_dpl;
|
||||
}
|
||||
|
||||
void kernel::InterruptDescriptor::dpl(unsigned int dpl)
|
||||
{
|
||||
m_dpl = dpl;
|
||||
}
|
||||
|
||||
void* kernel::InterruptDescriptor::operator=(void* rhs)
|
||||
{
|
||||
uint32_t offset = (uint32_t) rhs;
|
||||
m_offset1 = (uint16_t) offset;
|
||||
m_offset2 = (uint16_t) (offset >> 16);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace qkernel
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
class InterruptDescriptor
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
InterruptDescriptor();
|
||||
|
||||
InterruptDescriptor(void* handler, unsigned int type, unsigned int dpl);
|
||||
InterruptDescriptor(void* handler, Type type, unsigned int dpl);
|
||||
|
||||
bool present();
|
||||
|
||||
@@ -30,7 +30,10 @@ public:
|
||||
Type type();
|
||||
|
||||
void type(Type type);
|
||||
|
||||
|
||||
unsigned int dpl();
|
||||
|
||||
void dpl(unsigned int dpl);
|
||||
|
||||
void* operator=(void* rhs);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include "systypes.hpp"
|
||||
|
||||
namespace qkernel
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#include "memorymap.hpp"
|
||||
|
||||
qkernel::MemoryMap::MemoryMap(qkernel::MemoryMap::Region* map, size_t entries)
|
||||
kernel::MemoryMap::MemoryMap(kernel::MemoryMap::Region* map, size_t entries)
|
||||
{
|
||||
this->map = map;
|
||||
this->entries = entries;
|
||||
}
|
||||
|
||||
qkernel::MemoryMap::Region& qkernel::MemoryMap::operator[](size_t index)
|
||||
kernel::MemoryMap::Region& kernel::MemoryMap::operator[](size_t index)
|
||||
{
|
||||
return map[index];
|
||||
}
|
||||
|
||||
size_t qkernel::MemoryMap::size()
|
||||
size_t kernel::MemoryMap::size()
|
||||
{
|
||||
return entries;
|
||||
}
|
||||
|
||||
physaddr_t qkernel::MemoryMap::Region::getLocation()
|
||||
physaddr_t kernel::MemoryMap::Region::getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
size_t qkernel::MemoryMap::Region::getSize()
|
||||
size_t kernel::MemoryMap::Region::getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
qkernel::MemoryMap::Type qkernel::MemoryMap::Region::getType()
|
||||
kernel::MemoryMap::Type kernel::MemoryMap::Region::getType()
|
||||
{
|
||||
return (Type) type;
|
||||
}
|
||||
|
||||
bool qkernel::MemoryMap::Region::contains(physaddr_t location, size_t size)
|
||||
bool kernel::MemoryMap::Region::contains(physaddr_t location, size_t size)
|
||||
{
|
||||
return (location >= this->location) &&
|
||||
(location + size <= this->location + this->size);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "systypes.hpp"
|
||||
|
||||
namespace qkernel
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
class MemoryMap
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "pagetableentry.hpp"
|
||||
|
||||
namespace qkernel {
|
||||
namespace kernel {
|
||||
|
||||
static_assert(sizeof(PageTableEntry) == 4, "PTE structure is the wrong size!");
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <stdint.h>
|
||||
#include "systypes.hpp"
|
||||
|
||||
namespace qkernel {
|
||||
namespace kernel {
|
||||
|
||||
class PageTableEntry {
|
||||
public:
|
||||
|
||||
@@ -8,11 +8,7 @@
|
||||
#include "addressspace.hpp"
|
||||
#include "tty.h"
|
||||
|
||||
#if __STDC_HOSTED__ == 1 || __i686__ != 1
|
||||
#error "ERROR: This program must be compiled for a freestanding environment, and currently only supports the i686 target."
|
||||
#endif
|
||||
|
||||
using namespace qkernel;
|
||||
using namespace kernel;
|
||||
|
||||
extern SystemInfo system_info;
|
||||
extern MemoryMap::Region memory_map;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "systeminfo.hpp"
|
||||
|
||||
size_t qkernel::SystemInfo::getLowMemory()
|
||||
size_t kernel::SystemInfo::getLowMemory()
|
||||
{
|
||||
return lowMemory;
|
||||
}
|
||||
|
||||
size_t qkernel::SystemInfo::getHighMemory()
|
||||
size_t kernel::SystemInfo::getHighMemory()
|
||||
{
|
||||
return highMemory;
|
||||
}
|
||||
|
||||
physaddr_t qkernel::SystemInfo::getKernelBase()
|
||||
physaddr_t kernel::SystemInfo::getKernelBase()
|
||||
{
|
||||
return kernelBase;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "systypes.hpp"
|
||||
|
||||
namespace qkernel
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
class SystemInfo
|
||||
|
||||
26
src/tty.cpp
26
src/tty.cpp
@@ -1,7 +1,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "tty.h"
|
||||
|
||||
qkernel::TTY::TTY(char* vga)
|
||||
kernel::TTY::TTY(char* vga)
|
||||
{
|
||||
this->vga = vga;
|
||||
this->cursor = 0;
|
||||
@@ -9,7 +9,7 @@ qkernel::TTY::TTY(char* vga)
|
||||
this->base = 10;
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::operator<<(qkernel::TTY::Format fmt)
|
||||
kernel::TTY& kernel::TTY::operator<<(kernel::TTY::Format fmt)
|
||||
{
|
||||
switch(fmt)
|
||||
{
|
||||
@@ -25,42 +25,42 @@ qkernel::TTY& qkernel::TTY::operator<<(qkernel::TTY::Format fmt)
|
||||
}
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::operator<<(const char* str)
|
||||
kernel::TTY& kernel::TTY::operator<<(const char* str)
|
||||
{
|
||||
return printString(str);
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::operator<<(unsigned int n)
|
||||
kernel::TTY& kernel::TTY::operator<<(unsigned int n)
|
||||
{
|
||||
return printNumber(n, base, width);
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::operator<<(int n)
|
||||
kernel::TTY& kernel::TTY::operator<<(int n)
|
||||
{
|
||||
return printNumber((unsigned int) n, base, width);
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::operator<<(void* n)
|
||||
kernel::TTY& kernel::TTY::operator<<(void* n)
|
||||
{
|
||||
return printNumber((unsigned int) n, 16, 8);
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::operator<<(char c)
|
||||
kernel::TTY& kernel::TTY::operator<<(char c)
|
||||
{
|
||||
return putChar(c);
|
||||
}
|
||||
|
||||
void qkernel::TTY::setWidth(size_t width)
|
||||
void kernel::TTY::setWidth(size_t width)
|
||||
{
|
||||
this->width = width;
|
||||
}
|
||||
|
||||
size_t qkernel::TTY::getWidth()
|
||||
size_t kernel::TTY::getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
void qkernel::TTY::clear()
|
||||
void kernel::TTY::clear()
|
||||
{
|
||||
for(int i = 0; i < 80*25; i++)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ void qkernel::TTY::clear()
|
||||
cursor = 0;
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::printNumber(unsigned int n, size_t base,
|
||||
kernel::TTY& kernel::TTY::printNumber(unsigned int n, size_t base,
|
||||
size_t width)
|
||||
{
|
||||
const char* digits = "0123456789ABCDEF";
|
||||
@@ -94,7 +94,7 @@ qkernel::TTY& qkernel::TTY::printNumber(unsigned int n, size_t base,
|
||||
return *this;
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::printString(const char* str)
|
||||
kernel::TTY& kernel::TTY::printString(const char* str)
|
||||
{
|
||||
while(*str)
|
||||
{
|
||||
@@ -104,7 +104,7 @@ qkernel::TTY& qkernel::TTY::printString(const char* str)
|
||||
return *this;
|
||||
}
|
||||
|
||||
qkernel::TTY& qkernel::TTY::putChar(char c)
|
||||
kernel::TTY& kernel::TTY::putChar(char c)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user