Added key systems to kernel state
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#ifndef KERNELSTATE_H
|
||||
#define KERNELSTATE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "process.hpp"
|
||||
#include "pageallocator.hpp"
|
||||
#include "allocator.hpp"
|
||||
#include "interrupts.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
namespace kernel
|
||||
{
|
||||
@@ -12,7 +13,15 @@ class State
|
||||
{
|
||||
public:
|
||||
|
||||
static const size_t MAX_PROCESSES = 2048;
|
||||
static const unsigned int MAX_PROCESSES = 2048;
|
||||
|
||||
static BuddyAllocator pageAllocator;
|
||||
|
||||
static Allocator allocator;
|
||||
|
||||
static Interrupts interrupts;
|
||||
|
||||
static ProcessQueue processQueue;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
int mmap(PageAllocator& allocator, void* start, size_t length, int flags);
|
||||
int mmap(void* start, size_t length, int flags);
|
||||
|
||||
int munmap(PageAllocator& allocator, void* start, size_t length);
|
||||
int munmap(void* start, size_t length);
|
||||
|
||||
bool isMapped(void* addr);
|
||||
|
||||
|
||||
@@ -6,28 +6,41 @@
|
||||
#include "mmgr.hpp"
|
||||
#include "tty.hpp"
|
||||
#include "util.hpp"
|
||||
#include "kernelstate.hpp"
|
||||
#include "config.h"
|
||||
|
||||
using namespace kernel;
|
||||
|
||||
BuddyAllocator State::pageAllocator;
|
||||
Allocator State::allocator;
|
||||
Interrupts State::interrupts;
|
||||
ProcessQueue State::processQueue;
|
||||
|
||||
extern int _pageMapLocation;
|
||||
extern int _heapLocation;
|
||||
extern int _heapSize;
|
||||
|
||||
extern SystemInfo system_info;
|
||||
extern MemoryMap::Region memory_map;
|
||||
|
||||
void main(char* cmdline)
|
||||
{
|
||||
MemoryMap memmap(&memory_map, 16);
|
||||
State::pageAllocator = BuddyAllocator(memmap, (char*) &_pageMapLocation, system_info.getHighMemory() / 4 + 256, 6);
|
||||
mmap((void*) &_heapLocation, 0x100000, MMAP_RW);
|
||||
State::allocator = Allocator((void*) 0xFFB00000, 0x100000, 256);
|
||||
|
||||
TTY tty((char*) 0xFF8B8000);
|
||||
tty << PACKAGE_STRING << "\n\n";
|
||||
tty << "Low memory: \t" << (int) system_info.getLowMemory() << " KiB\n";
|
||||
tty << "High memory:\t" << (int) system_info.getHighMemory() << " KiB\n";
|
||||
tty << "Type\t\tLocation\t\tSize\n";
|
||||
MemoryMap memmap(&memory_map, 16);
|
||||
for(size_t i = 0; i < memmap.size() && memmap[i].getSize() > 0; i++)
|
||||
{
|
||||
tty << (int) memmap[i].getType() << "\t\t\t";
|
||||
tty << (void*) memmap[i].getLocation() << "\t\t";
|
||||
tty << (int) memmap[i].getSize() << "\n";
|
||||
}
|
||||
BuddyAllocator alloc(memmap, (char*) 0xFF800000, system_info.getHighMemory() / 4 + 256, 6);
|
||||
mmap(alloc, (void*) 0, 4096, MMAP_RW);
|
||||
mmap((void*) 0, 4096, MMAP_RW);
|
||||
tty << "Nothing left to do. Hanging.\n";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
ENTRY(_start)
|
||||
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
. = 0xFF900000;
|
||||
VIRTUAL_BASE = .;
|
||||
PHYSICAL_BASE = 0x100000;
|
||||
@@ -33,4 +34,10 @@ SECTIONS
|
||||
LOAD_END = ADDR(.data) + SIZEOF(.data) - (VIRTUAL_BASE - PHYSICAL_BASE);
|
||||
BSS_END = ADDR(.bss) + SIZEOF(.bss) - (VIRTUAL_BASE - PHYSICAL_BASE);
|
||||
IMAGE_SIZE = ((BSS_END - LOAD_START) + (4096 - ((BSS_END - LOAD_START) % 4096))) / 4096;
|
||||
|
||||
_pageMapLocation = 0xFF800000;
|
||||
_heapLocation = 0xFFB00000;
|
||||
_heapSize = 0x100000;
|
||||
_kernelStart = VIRTUAL_BASE;
|
||||
_kernelEnd = VIRTUAL_BASE + (4096 * IMAGE_SIZE);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../mmap.hpp"
|
||||
#include "../kernelstate.hpp"
|
||||
|
||||
class PageTableEntry {
|
||||
public:
|
||||
@@ -149,7 +150,7 @@ private:
|
||||
uint32_t physicalAddress : 20;
|
||||
};
|
||||
|
||||
int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags)
|
||||
int kernel::mmap(void* start, size_t length, int flags)
|
||||
{
|
||||
if((size_t) start % 4096 != 0)
|
||||
return -1;
|
||||
@@ -161,7 +162,7 @@ int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags
|
||||
size_t directoryIndex = tableIndex / 1024;
|
||||
if(!pageDirectory[directoryIndex].getPresent())
|
||||
{
|
||||
physaddr_t newPT = allocator.allocate(4096);
|
||||
physaddr_t newPT = State::pageAllocator.allocate(4096);
|
||||
if(newPT == 0)
|
||||
return -1;
|
||||
pageDirectory[directoryIndex] = newPT;
|
||||
@@ -171,7 +172,7 @@ int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags
|
||||
}
|
||||
if(!pageTables[tableIndex].getPresent())
|
||||
{
|
||||
physaddr_t page = allocator.allocate(4096);
|
||||
physaddr_t page = State::pageAllocator.allocate(4096);
|
||||
pageTables[tableIndex] = page;
|
||||
pageTables[tableIndex].setPresent(true);
|
||||
pageTables[tableIndex].setUsermode(false);
|
||||
@@ -184,7 +185,7 @@ int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kernel::munmap(PageAllocator& allocator, void* start, size_t length)
|
||||
int kernel::munmap(void* start, size_t length)
|
||||
{
|
||||
if((size_t) start % 4096 != 0)
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user