starting work on page tables
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
kernel/lib/paging/PageFrameAllocator.o
Normal file
BIN
kernel/lib/paging/PageFrameAllocator.o
Normal file
Binary file not shown.
BIN
kernel/lib/paging/PageMapIndexer.o
Normal file
BIN
kernel/lib/paging/PageMapIndexer.o
Normal file
Binary file not shown.
@@ -3,17 +3,18 @@
|
|||||||
BasicRenderer::BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
BasicRenderer::BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
||||||
targetFramebuffer = framebuffer;
|
targetFramebuffer = framebuffer;
|
||||||
PSF1_Font = psf1_Font;
|
PSF1_Font = psf1_Font;
|
||||||
|
Colour = 0xFFFFFFFF;
|
||||||
cursorPosition = {0,0};
|
cursorPosition = {0,0};
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicRenderer::PutChar(unsigned int colour, char chr, unsigned int xOff, unsigned int yOff) {
|
void BasicRenderer::PutChar(char chr, unsigned int xOff, unsigned int yOff) {
|
||||||
unsigned int* pixPtr = (unsigned int*)targetFramebuffer->BaseAddress;
|
unsigned int* pixPtr = (unsigned int*)targetFramebuffer->BaseAddress;
|
||||||
char* fontPtr = (char*)PSF1_Font->glyphBuffer + (chr * PSF1_Font->psf1_Header->charsize);
|
char* fontPtr = (char*)PSF1_Font->glyphBuffer + (chr * PSF1_Font->psf1_Header->charsize);
|
||||||
for (unsigned long y = yOff; y < yOff + 18; y++) {
|
for (unsigned long y = yOff; y < yOff + 18; y++) {
|
||||||
for (unsigned long x = xOff; x < xOff+8; x++) {
|
for (unsigned long x = xOff; x < xOff+8; x++) {
|
||||||
|
|
||||||
if ((*fontPtr & (0b10000000 >> (x - xOff))) > 0) {
|
if ((*fontPtr & (0b10000000 >> (x - xOff))) > 0) {
|
||||||
*(unsigned int*)(pixPtr + x + (y * targetFramebuffer->PixelsPerScanline)) = colour;
|
*(unsigned int*)(pixPtr + x + (y * targetFramebuffer->PixelsPerScanline)) = Colour;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,12 +23,12 @@ void BasicRenderer::PutChar(unsigned int colour, char chr, unsigned int xOff, un
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicRenderer::Print(unsigned int colour, const char* str) {
|
void BasicRenderer::Print(const char* str) {
|
||||||
unsigned int x = 0;
|
unsigned int x = 0;
|
||||||
char* chr = (char*)str;
|
char* chr = (char*)str;
|
||||||
|
|
||||||
while (*chr != 0) {
|
while (*chr != 0) {
|
||||||
PutChar(colour, *chr, cursorPosition.x, cursorPosition.y);
|
PutChar(*chr, cursorPosition.x, cursorPosition.y);
|
||||||
cursorPosition.x+=8;
|
cursorPosition.x+=8;
|
||||||
|
|
||||||
if (cursorPosition.x + 8 > targetFramebuffer->Width) {
|
if (cursorPosition.x + 8 > targetFramebuffer->Width) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class BasicRenderer {
|
|||||||
Point cursorPosition;
|
Point cursorPosition;
|
||||||
Framebuffer* targetFramebuffer;
|
Framebuffer* targetFramebuffer;
|
||||||
PSF1_FONT* PSF1_Font;
|
PSF1_FONT* PSF1_Font;
|
||||||
void Print(unsigned int colour, const char* str);
|
unsigned int Colour;
|
||||||
void PutChar(unsigned int colour, char chr, unsigned int xOff, unsigned int yOff);
|
void Print(const char* str);
|
||||||
|
void PutChar(char chr, unsigned int xOff, unsigned int yOff);
|
||||||
};
|
};
|
||||||
@@ -5,7 +5,8 @@
|
|||||||
#include "efiMemory.h"
|
#include "efiMemory.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
#include "PageFrameAllocator.h"
|
#include "paging/PageFrameAllocator.h"
|
||||||
|
#include "paging/PageMapIndexer.h"
|
||||||
|
|
||||||
struct BootInfo {
|
struct BootInfo {
|
||||||
Framebuffer* framebuffer;
|
Framebuffer* framebuffer;
|
||||||
@@ -40,19 +41,15 @@ extern "C" void _start(BootInfo* bootInfo) {
|
|||||||
|
|
||||||
newAllocator.LockPages(&_KernelStart, kernelPages);
|
newAllocator.LockPages(&_KernelStart, kernelPages);
|
||||||
|
|
||||||
// print out ram info
|
PageMapIndexer pageIndexer = PageMapIndexer(0x1000);
|
||||||
newRenderer.Print(0xFFFFFFFF, "Free RAM: ");
|
|
||||||
newRenderer.Print(0xFF00FFFF, to_string(newAllocator.GetFreeRAM() / 1024));
|
newRenderer.Print(to_string(pageIndexer.P_i));
|
||||||
newRenderer.Print(0xFF00FFFF, " KB");
|
newRenderer.Print(" - ");
|
||||||
newRenderer.cursorPosition = {0, newRenderer.cursorPosition.y + 18};
|
newRenderer.Print(to_string(pageIndexer.PT_i));
|
||||||
newRenderer.Print(0xFFFFFFFF, "Used RAM: ");
|
newRenderer.Print(" - ");
|
||||||
newRenderer.Print(0xFF00FFFF, to_string(newAllocator.GetUsedRAM() / 1024));
|
newRenderer.Print(to_string(pageIndexer.PD_i));
|
||||||
newRenderer.Print(0xFF00FFFF, " KB");
|
newRenderer.Print(" - ");
|
||||||
newRenderer.cursorPosition = {0, newRenderer.cursorPosition.y + 18};
|
newRenderer.Print(to_string(pageIndexer.PDP_i));
|
||||||
newRenderer.Print(0xFFFFFFFF, "Reserved RAM: ");
|
|
||||||
newRenderer.Print(0xFF00FFFF, to_string(newAllocator.GetReservedRAM() / 1024));
|
|
||||||
newRenderer.Print(0xFF00FFFF, " KB");
|
|
||||||
newRenderer.cursorPosition = {0, newRenderer.cursorPosition.y + 18};
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "efiMemory.h"
|
#include "../efiMemory.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "Bitmap.h"
|
#include "../Bitmap.h"
|
||||||
#include "memory.h"
|
#include "../memory.h"
|
||||||
|
|
||||||
class PageFrameAllocator {
|
class PageFrameAllocator {
|
||||||
public:
|
public:
|
||||||
12
kernel/src/paging/PageMapIndexer.cpp
Normal file
12
kernel/src/paging/PageMapIndexer.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "PageMapIndexer.h"
|
||||||
|
|
||||||
|
PageMapIndexer::PageMapIndexer(uint64_t virtualAddress) {
|
||||||
|
virtualAddress >>= 12; // 4096 aligned
|
||||||
|
P_i = virtualAddress & 0x1FF;
|
||||||
|
virtualAddress >>= 9;
|
||||||
|
PT_i = virtualAddress & 0x1FF;
|
||||||
|
virtualAddress >>= 9;
|
||||||
|
PD_i = virtualAddress & 0x1FF;
|
||||||
|
virtualAddress >>= 9;
|
||||||
|
PDP_i = virtualAddress & 0x1FF;
|
||||||
|
}
|
||||||
11
kernel/src/paging/PageMapIndexer.h
Normal file
11
kernel/src/paging/PageMapIndexer.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
class PageMapIndexer {
|
||||||
|
public:
|
||||||
|
PageMapIndexer(uint64_t virtualAddress);
|
||||||
|
uint64_t PDP_i;
|
||||||
|
uint64_t PD_i;
|
||||||
|
uint64_t PT_i;
|
||||||
|
uint64_t P_i;
|
||||||
|
};
|
||||||
21
kernel/src/paging/paging.h
Normal file
21
kernel/src/paging/paging.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct PageDirectoryEntry {
|
||||||
|
bool Present : 1; // memory exists and can be accessed
|
||||||
|
bool ReadWrite : 1; //
|
||||||
|
bool UserSuper : 1; // memory can only be accessed by supervisor or both user and supervisor
|
||||||
|
bool WriteThrough : 1; //
|
||||||
|
bool CacheDisabled : 1; //
|
||||||
|
bool Accessed : 1; // set when cpu accesses page
|
||||||
|
bool ignore0 : 1; //
|
||||||
|
bool LargerPages : 1; //
|
||||||
|
bool ignore1 : 1; //
|
||||||
|
uint8_t Available : 3; //
|
||||||
|
uint64_t Address : 52; // physical address
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PageTable {
|
||||||
|
PageDirectoryEntry entries[512];
|
||||||
|
}__attribute__((aligned(0x1000)));
|
||||||
Reference in New Issue
Block a user