Merged i386 PTE class into mmap.cpp
This commit is contained in:
@@ -5,8 +5,7 @@ quark_kernel_CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-except
|
|||||||
quark_kernel_LDFLAGS = -nostdlib
|
quark_kernel_LDFLAGS = -nostdlib
|
||||||
|
|
||||||
if x86
|
if x86
|
||||||
quark_kernel_SOURCES += x86/pagetableentry.cpp \
|
quark_kernel_SOURCES += x86/mmap.cpp \
|
||||||
x86/mmap.cpp \
|
|
||||||
x86/interrupts.cpp \
|
x86/interrupts.cpp \
|
||||||
x86/entry.S
|
x86/entry.S
|
||||||
quark_kernel_LDFLAGS += -T x86/linker.ld
|
quark_kernel_LDFLAGS += -T x86/linker.ld
|
||||||
|
|||||||
150
src/x86/mmap.cpp
150
src/x86/mmap.cpp
@@ -1,5 +1,153 @@
|
|||||||
#include "../mmap.hpp"
|
#include "../mmap.hpp"
|
||||||
#include "pagetableentry.hpp"
|
|
||||||
|
class PageTableEntry {
|
||||||
|
public:
|
||||||
|
|
||||||
|
PageTableEntry()
|
||||||
|
{
|
||||||
|
this->present = 0;
|
||||||
|
this->rw = 0;
|
||||||
|
this->usermode = 0;
|
||||||
|
this->writeThrough = 0;
|
||||||
|
this->cacheDisable = 0;
|
||||||
|
this->accessed = 0;
|
||||||
|
this->dirty = 0;
|
||||||
|
this->pat = 0;
|
||||||
|
this->global = 0;
|
||||||
|
this->shared = 0;
|
||||||
|
this->ignored = 0;
|
||||||
|
this->physicalAddress = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getAccessed() const
|
||||||
|
{
|
||||||
|
return accessed == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getCacheDisable() const
|
||||||
|
{
|
||||||
|
return cacheDisable == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCacheDisable(bool cacheDisable)
|
||||||
|
{
|
||||||
|
this->cacheDisable = cacheDisable ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getDirty() const
|
||||||
|
{
|
||||||
|
return dirty == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getGlobal() const
|
||||||
|
{
|
||||||
|
return global == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setGlobal(bool global)
|
||||||
|
{
|
||||||
|
this->global = global ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getPat() const
|
||||||
|
{
|
||||||
|
return pat == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPat(bool pat)
|
||||||
|
{
|
||||||
|
this->pat = pat ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
physaddr_t getPhysicalAddress() const
|
||||||
|
{
|
||||||
|
physaddr_t physicalAddress = this->physicalAddress;
|
||||||
|
return physicalAddress << 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
physaddr_t setPhysicalAddress(physaddr_t physicalAddress)
|
||||||
|
{
|
||||||
|
this->physicalAddress = physicalAddress >> 12;
|
||||||
|
return this->physicalAddress << 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getPresent() const
|
||||||
|
{
|
||||||
|
return present == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPresent(bool present)
|
||||||
|
{
|
||||||
|
this->present = present ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getRw() const
|
||||||
|
{
|
||||||
|
return rw == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRw(bool rw)
|
||||||
|
{
|
||||||
|
this->rw = rw ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getShared() const
|
||||||
|
{
|
||||||
|
return shared == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setShared(bool shared)
|
||||||
|
{
|
||||||
|
this->shared = shared ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getUsermode() const
|
||||||
|
{
|
||||||
|
return usermode == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUsermode(bool usermode)
|
||||||
|
{
|
||||||
|
this->usermode = usermode ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getWriteThrough() const
|
||||||
|
{
|
||||||
|
return writeThrough == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWriteThrough(bool writeThrough)
|
||||||
|
{
|
||||||
|
this->writeThrough = writeThrough ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
physaddr_t operator=(physaddr_t rhs)
|
||||||
|
{
|
||||||
|
return setPhysicalAddress(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
PageTableEntry operator=(PageTableEntry rhs)
|
||||||
|
{
|
||||||
|
uint32_t* iThis = (uint32_t*) this;
|
||||||
|
uint32_t* iThat = (uint32_t*) &rhs;
|
||||||
|
*iThis = *iThat;
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t present : 1;
|
||||||
|
uint32_t rw : 1;
|
||||||
|
uint32_t usermode : 1;
|
||||||
|
uint32_t writeThrough : 1;
|
||||||
|
uint32_t cacheDisable : 1;
|
||||||
|
uint32_t accessed : 1;
|
||||||
|
uint32_t dirty : 1;
|
||||||
|
uint32_t pat : 1;
|
||||||
|
uint32_t global : 1;
|
||||||
|
uint32_t shared : 1;
|
||||||
|
uint32_t ignored : 2;
|
||||||
|
uint32_t physicalAddress : 20;
|
||||||
|
};
|
||||||
|
|
||||||
int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags)
|
int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* PageTableEntry.cpp
|
|
||||||
*
|
|
||||||
* Created on: May 22, 2019
|
|
||||||
* Author: nathan
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "pagetableentry.hpp"
|
|
||||||
|
|
||||||
namespace kernel {
|
|
||||||
|
|
||||||
static_assert(sizeof(PageTableEntry) == 4, "PTE structure is the wrong size!");
|
|
||||||
|
|
||||||
PageTableEntry::PageTableEntry() {
|
|
||||||
this->present = 0;
|
|
||||||
this->rw = 0;
|
|
||||||
this->usermode = 0;
|
|
||||||
this->writeThrough = 0;
|
|
||||||
this->cacheDisable = 0;
|
|
||||||
this->accessed = 0;
|
|
||||||
this->dirty = 0;
|
|
||||||
this->pat = 0;
|
|
||||||
this->global = 0;
|
|
||||||
this->shared = 0;
|
|
||||||
this->ignored = 0;
|
|
||||||
this->physicalAddress = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getAccessed() const {
|
|
||||||
return accessed == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getCacheDisable() const
|
|
||||||
{
|
|
||||||
return cacheDisable == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setCacheDisable(bool cacheDisable)
|
|
||||||
{
|
|
||||||
this->cacheDisable = cacheDisable ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getDirty() const
|
|
||||||
{
|
|
||||||
return dirty == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getGlobal() const
|
|
||||||
{
|
|
||||||
return global == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setGlobal(bool global)
|
|
||||||
{
|
|
||||||
this->global = global ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getPat() const
|
|
||||||
{
|
|
||||||
return pat == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setPat(bool pat)
|
|
||||||
{
|
|
||||||
this->pat = pat ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
physaddr_t PageTableEntry::getPhysicalAddress() const {
|
|
||||||
physaddr_t physicalAddress = this->physicalAddress;
|
|
||||||
return physicalAddress << 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
physaddr_t PageTableEntry::setPhysicalAddress(physaddr_t physicalAddress)
|
|
||||||
{
|
|
||||||
this->physicalAddress = physicalAddress >> 12;
|
|
||||||
return this->physicalAddress << 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getPresent() const
|
|
||||||
{
|
|
||||||
return present == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setPresent(bool present)
|
|
||||||
{
|
|
||||||
this->present = present ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getRw() const
|
|
||||||
{
|
|
||||||
return rw == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setRw(bool rw)
|
|
||||||
{
|
|
||||||
this->rw = rw ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getUsermode() const
|
|
||||||
{
|
|
||||||
return usermode == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setUsermode(bool usermode)
|
|
||||||
{
|
|
||||||
this->usermode = usermode ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getWriteThrough() const {
|
|
||||||
return writeThrough == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageTableEntry::getShared() const
|
|
||||||
{
|
|
||||||
return shared == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setShared(bool shared)
|
|
||||||
{
|
|
||||||
this->shared = shared ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTableEntry::setWriteThrough(bool writeThrough)
|
|
||||||
{
|
|
||||||
this->writeThrough = writeThrough ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
physaddr_t PageTableEntry::operator=(physaddr_t rhs)
|
|
||||||
{
|
|
||||||
return setPhysicalAddress(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
PageTableEntry PageTableEntry::operator=(PageTableEntry rhs)
|
|
||||||
{
|
|
||||||
uint32_t* iThis = (uint32_t*) this;
|
|
||||||
uint32_t* iThat = (uint32_t*) &rhs;
|
|
||||||
*iThis = *iThat;
|
|
||||||
return rhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef SRC_PAGETABLEENTRY_H_
|
|
||||||
#define SRC_PAGETABLEENTRY_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "../systypes.hpp"
|
|
||||||
|
|
||||||
namespace kernel {
|
|
||||||
|
|
||||||
class PageTableEntry {
|
|
||||||
public:
|
|
||||||
PageTableEntry();
|
|
||||||
bool getAccessed() const;
|
|
||||||
bool getCacheDisable() const;
|
|
||||||
void setCacheDisable(bool cacheDisable);
|
|
||||||
bool getDirty() const;
|
|
||||||
bool getGlobal() const;
|
|
||||||
void setGlobal(bool global);
|
|
||||||
bool getPat() const;
|
|
||||||
void setPat(bool pat);
|
|
||||||
physaddr_t getPhysicalAddress() const;
|
|
||||||
physaddr_t setPhysicalAddress(physaddr_t physicalAddress);
|
|
||||||
bool getPresent() const;
|
|
||||||
void setPresent(bool present);
|
|
||||||
bool getRw() const;
|
|
||||||
void setRw(bool rw);
|
|
||||||
bool getShared() const;
|
|
||||||
void setShared(bool shared);
|
|
||||||
bool getUsermode() const;
|
|
||||||
void setUsermode(bool usermode);
|
|
||||||
bool getWriteThrough() const;
|
|
||||||
void setWriteThrough(bool writeThrough);
|
|
||||||
physaddr_t operator=(physaddr_t rhs);
|
|
||||||
PageTableEntry operator=(PageTableEntry rhs);
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t present : 1;
|
|
||||||
uint32_t rw : 1;
|
|
||||||
uint32_t usermode : 1;
|
|
||||||
uint32_t writeThrough : 1;
|
|
||||||
uint32_t cacheDisable : 1;
|
|
||||||
uint32_t accessed : 1;
|
|
||||||
uint32_t dirty : 1;
|
|
||||||
uint32_t pat : 1;
|
|
||||||
uint32_t global : 1;
|
|
||||||
uint32_t shared : 1;
|
|
||||||
uint32_t ignored : 2;
|
|
||||||
uint32_t physicalAddress : 20;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user