More unfinished work on kernel API
This commit is contained in:
@@ -1,30 +1,14 @@
|
||||
#include <stdint.h>
|
||||
#include "multiboot2.hpp"
|
||||
#include "tty.hpp"
|
||||
#include "../kernelstate.hpp"
|
||||
#include "../systeminfo.hpp"
|
||||
#include "../mmap.hpp"
|
||||
#include "../util.hpp"
|
||||
#include "../memorytype.hpp"
|
||||
|
||||
using namespace kernelns;
|
||||
|
||||
extern int _kernelEnd;
|
||||
|
||||
enum BootInfoType
|
||||
{
|
||||
Terminate = 0,
|
||||
CommandLine = 1,
|
||||
BootLoader = 2,
|
||||
Module = 3,
|
||||
MemoryInfo = 4,
|
||||
BootDevice = 5,
|
||||
MMap = 6,
|
||||
VBEInfo = 7,
|
||||
FramebufferInfo = 8,
|
||||
ELFSymbols = 9,
|
||||
APMTable = 10
|
||||
};
|
||||
|
||||
extern "C"
|
||||
int startPaging(uint32_t* directory, uint32_t* table, uint32_t* identityTable)
|
||||
{
|
||||
@@ -57,12 +41,12 @@ int initialize(void* multibootInfo)
|
||||
for(; heapSize > 1; log++)
|
||||
heapSize >>= 1;
|
||||
heapSize <<= log;
|
||||
new(&State::allocator) Allocator((void*) (0xFFC00000 - heapSize), heapSize, 64);
|
||||
//new(&State::allocator) Allocator((void*) (0xFFC00000 - heapSize), heapSize, 64);
|
||||
Multiboot2Info bootInfo(multibootInfo);
|
||||
if(!bootInfo.isValid())
|
||||
return 1;
|
||||
bootInfo.getMemoryMap().insertEntry(0, 4 * 1024 * 1024, MemoryMap::UNAVAILABLE);
|
||||
new(&State::config) SystemInfo(bootInfo.getMemoryMap(), bootInfo.getCommandLine());
|
||||
bootInfo.getMemoryMap().insertEntry(0, 4 * 1024 * 1024, (unsigned int) MemoryType::Unavailable);
|
||||
//new(&State::config) SystemInfo(bootInfo.getMemoryMap(), bootInfo.getCommandLine());
|
||||
TTY tty((char*) 0xFF8B8000);
|
||||
tty << "Type\t\tLocation\t\tSize\n";
|
||||
for(size_t i = 0; i < bootInfo.getMemoryMap().size() && bootInfo.getMemoryMap()[i].getSize() > 0; i++)
|
||||
|
||||
31
src/x86/memorymanagerx86.cpp
Normal file
31
src/x86/memorymanagerx86.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "memorymanagerx86.hpp"
|
||||
|
||||
unsigned int MemoryManagerx86::getPageSize() const
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
physaddr_t MemoryManagerx86::createAddressSpace()
|
||||
{
|
||||
if(((size_t) table & 0xFFF) != 0)
|
||||
return -1;
|
||||
PageTableEntry* newDirectory = (PageTableEntry*) table;
|
||||
newDirectory[1022] = m_pageDirectory[1022];
|
||||
newDirectory[1023] = m_pageDirectory[1023];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MemoryManagerx86::loadAddressSpace(physaddr_t table)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int MemoryManagerx86::mapPage(void *page, physaddr_t frame, int flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
physaddr_t MemoryManagerx86::unmapPage(void *page)
|
||||
{
|
||||
|
||||
}
|
||||
29
src/x86/memorymanagerx86.hpp
Normal file
29
src/x86/memorymanagerx86.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef MEMORYMANAGERX86_H
|
||||
#define MEMORYMANAGERX86_H
|
||||
|
||||
#include "../memorymanager.hpp"
|
||||
#include "pagetableentry.hpp"
|
||||
|
||||
class MemoryManagerx86 : public MemoryManager
|
||||
{
|
||||
public:
|
||||
|
||||
virtual unsigned int getPageSize() const;
|
||||
|
||||
virtual physaddr_t createAddressSpace();
|
||||
|
||||
virtual void loadAddressSpace(physaddr_t table);
|
||||
|
||||
virtual int mapPage(void* page, physaddr_t frame, int flags);
|
||||
|
||||
virtual physaddr_t unmapPage(void* page);
|
||||
|
||||
private:
|
||||
|
||||
static const unsigned int pageSize = 4096;
|
||||
|
||||
PageTableEntry *m_pageTables, *m_pageDirectory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "multiboot2.hpp"
|
||||
#include "../memorytype.hpp"
|
||||
|
||||
using namespace kernelns;
|
||||
|
||||
@@ -11,31 +12,35 @@ Multiboot2Info::Multiboot2Info(void* tableLocation)
|
||||
ptr += 2;
|
||||
while(*ptr != 0)
|
||||
{
|
||||
if(*ptr == T_BootCommand)
|
||||
if(*ptr == (uint32_t) Tag::BootCommand)
|
||||
{
|
||||
m_commandLine = &reinterpret_cast<TagString*>(ptr)->str;
|
||||
}
|
||||
else if(*ptr == T_Bootloader)
|
||||
else if(*ptr == (uint32_t) Tag::Bootloader)
|
||||
{
|
||||
m_bootloader = &reinterpret_cast<TagString*>(ptr)->str;
|
||||
}
|
||||
else if(*ptr == T_MemoryMap)
|
||||
else if(*ptr == (uint32_t) Tag::MemoryMap)
|
||||
{
|
||||
unsigned int tagSize = reinterpret_cast<TagMemoryMap*>(ptr)->size - 16;
|
||||
unsigned int entrySize = reinterpret_cast<TagMemoryMap*>(ptr)->entrySize;
|
||||
MemoryMapEntry* entry = &reinterpret_cast<TagMemoryMap*>(ptr)->entries;
|
||||
while(tagSize > 0)
|
||||
{
|
||||
m_memmap.insertEntry(entry->base, entry->length, (MemoryMap::Type) entry->type);
|
||||
unsigned int regionType =
|
||||
(entry->type == (unsigned int) Multiboot2MemoryType::Available) ? (unsigned int) MemoryType::Available
|
||||
: ((entry->type == (unsigned int) Multiboot2MemoryType::Defective) ? (unsigned int) MemoryType::Defective
|
||||
: (unsigned int) MemoryType::Unavailable);
|
||||
m_memmap.insertEntry(entry->base, entry->length, entry->type);
|
||||
entry = (MemoryMapEntry*) (reinterpret_cast<char*>(entry) + entrySize);
|
||||
tagSize -= entrySize;
|
||||
}
|
||||
}
|
||||
else if(*ptr == T_Module)
|
||||
else if(*ptr == (uint32_t) Tag::Module)
|
||||
{
|
||||
TagModule* moduleTag = reinterpret_cast<TagModule*>(ptr);
|
||||
m_modules[m_moduleCount] = Module(moduleTag->start, moduleTag->end, &moduleTag->str);
|
||||
m_memmap.insertEntry(moduleTag->start, moduleTag->end - moduleTag->start, MemoryMap::UNAVAILABLE);
|
||||
m_memmap.insertEntry(moduleTag->start, moduleTag->end - moduleTag->start, (unsigned int) MemoryType::Unavailable);
|
||||
}
|
||||
unsigned int size = (ptr[1] + 7) - ((ptr[1] + 7) % 8);
|
||||
ptr += size / sizeof(uint32_t);
|
||||
|
||||
@@ -11,29 +11,36 @@ class Multiboot2Info
|
||||
{
|
||||
public:
|
||||
|
||||
enum TagType
|
||||
enum class Tag
|
||||
{
|
||||
T_BootCommand = 1,
|
||||
T_Bootloader = 2,
|
||||
T_Module = 3,
|
||||
T_MemoryInfo = 4,
|
||||
T_BIOSBootDevice = 5,
|
||||
T_MemoryMap = 6,
|
||||
T_VBE = 7,
|
||||
T_Framebuffer = 8,
|
||||
T_ELFSymbols = 9,
|
||||
T_APM = 10,
|
||||
T_EFI32SystemTable = 11,
|
||||
T_EFI64SystemTable = 12,
|
||||
T_SMBIOS = 13,
|
||||
T_ACPI10RSDP = 14,
|
||||
T_ACPT20RSDP = 15,
|
||||
T_Network = 16,
|
||||
T_EFIMemoryMap = 17,
|
||||
T_EFIBootServices = 18,
|
||||
T_EFI32Image = 19,
|
||||
T_EFI64Image = 20,
|
||||
T_LoadAddress = 21
|
||||
BootCommand = 1,
|
||||
Bootloader = 2,
|
||||
Module = 3,
|
||||
MemoryInfo = 4,
|
||||
BIOSBootDevice = 5,
|
||||
MemoryMap = 6,
|
||||
VBE = 7,
|
||||
Framebuffer = 8,
|
||||
ELFSymbols = 9,
|
||||
APM = 10,
|
||||
EFI32SystemTable = 11,
|
||||
EFI64SystemTable = 12,
|
||||
SMBIOS = 13,
|
||||
ACPI10RSDP = 14,
|
||||
ACPT20RSDP = 15,
|
||||
Network = 16,
|
||||
EFIMemoryMap = 17,
|
||||
EFIBootServices = 18,
|
||||
EFI32Image = 19,
|
||||
EFI64Image = 20,
|
||||
LoadAddress = 21
|
||||
};
|
||||
|
||||
enum class Multiboot2MemoryType
|
||||
{
|
||||
Available = 1,
|
||||
ACPI = 3,
|
||||
Defective = 5
|
||||
};
|
||||
|
||||
struct TagString
|
||||
|
||||
132
src/x86/pagetableentry.cpp
Normal file
132
src/x86/pagetableentry.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include "pagetableentry.hpp"
|
||||
|
||||
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::getShared() const
|
||||
{
|
||||
return shared == 1;
|
||||
}
|
||||
|
||||
void PageTableEntry::setShared(bool shared)
|
||||
{
|
||||
this->shared = shared ? 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
83
src/x86/pagetableentry.hpp
Normal file
83
src/x86/pagetableentry.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef PAGETABLEENTRY_H
|
||||
#define PAGETABLEENTRY_H
|
||||
|
||||
#include "../systypes.hpp"
|
||||
|
||||
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