Setup paging function signatures... Ready to be implemented.

dev
Nigel Barink 2022-03-18 22:09:04 +01:00
parent b4cff3e667
commit 23c68d9863
10 changed files with 141 additions and 75 deletions

View File

@ -5,7 +5,7 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc
CPP = ${HOME}/opt/cross/bin/i686-elf-g++
CFLAGS = -ffreestanding -O2 -Wall -Wextra
OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/pit.o $(BUILD_DIR)/time.o $(BUILD_DIR)/keyboard.o $(BUILD_DIR)/io.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o
OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/paging.o $(BUILD_DIR)/pit.o $(BUILD_DIR)/time.o $(BUILD_DIR)/keyboard.o $(BUILD_DIR)/io.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o
SRC_DIR = src
BUILD_DIR = build
@ -96,3 +96,6 @@ $(BUILD_DIR)/sv-terminal.o:
$(BUILD_DIR)/memory.o:
$(CPP) -c $(SRC_DIR)/kernel/memory/memory.cpp -o $(BUILD_DIR)/memory.o $(CFLAGS) -fno-exceptions -fno-rtti
$(BUILD_DIR)/paging.o:
$(CPP) -c $(SRC_DIR)/kernel/memory/paging.cpp -o $(BUILD_DIR)/paging.o $(CFLAGS) -fno-exceptions -fno-rtti

View File

View File

@ -0,0 +1,8 @@
#pragma once
#include "../../vfs/File.h"
class FAT16 : File {
public:
};

View File

@ -4,6 +4,9 @@ extern "C" void kernel_main (BootInfo* bootinfo) {
init_serial();
pit_initialise();
InitializePaging();
//Enable();
startSuperVisorTerminal(bootinfo);
}

View File

@ -14,6 +14,7 @@ extern "C"
#include "memory/memory.h"
#include "memory/memoryinfo.h"
#include "memory/paging.h"
#include "bootcheck.h"
#include "gdt/gdtc.h"

View File

@ -1,43 +0,0 @@
#include "PageDirectory.h"
void PageDirectory::enable()
{
// https://wiki.osdev.org/Setting_Up_Paging
//set each entry to not present
// int i;
// for(i = 0; i < 1024; i++)
// {
// // This sets the following flags to the pages:
// // Supervisor: Only kernel-mode can access them
// // Write Enabled: It can be both read from and written to
// // Not Present: The page table is not present
// this->page_directory[i] = 0x00000002;
// }
// // holds the physical address where we want to start mapping these pages to.
// // in this case, we want to map these pages to the very beginning of memory.
// //we will fill all 1024 entries in the table, mapping 4 megabytes
// for(unsigned int i = 0; i < 1024; i++)
// {
// // As the address is page aligned, it will always leave 12 bits zeroed.
// // Those bits are used by the attributes ;)
// first_page_table[i] = (i * 0x1000) | 3; // attributes: supervisor level, read/write, present.
// }
// // attributes: supervisor level, read/write, present
// this->page_directory[0] = ((unsigned int)first_page_table) | 3;
printf("Enable Paging!\n");
loadPageDirectory(this->page_directory);
enablePaging();
}
void PageDirectory::MapPhysicalToVirtualAddress ( address_t PAddress , address_t VAddress, uint32_t size )
{
}

View File

@ -1,31 +0,0 @@
#pragma once
#include <stdint.h>
#include "./memory.h"
#include "./../tty/kterm.h"
#define KB 1024
typedef uintptr_t address_t;
static const int MAX_PAGES = 1024 * KB; // 4GB , 4kB/page
static volatile address_t pmem_stack[MAX_PAGES];
static volatile address_t pmem_stack_top = MAX_PAGES; // top down allocation
extern "C" void loadPageDirectory (uint32_t* addr );
extern "C" void enablePaging();
struct page_directory_entry {};
struct page_table_entry{};
class PageDirectory {
public:
void enable ();
void MapPhysicalToVirtualAddress ( address_t PAddress , address_t VAddress, uint32_t size );
private:
uint32_t page_directory[1024] __attribute__((aligned(4096))); // align on 4 kiloByte pages
uint32_t first_page_table[1024] __attribute__((aligned(4096))); // align on 4 kiloByte pages
};

View File

@ -0,0 +1,49 @@
#include "paging.h"
PageDirectoryEntry kernel_directory[MAX_DIRECTORY_ENTRIES];
void InitializePaging()
{
// Identity map the first 8MB ... Physical addresses 0x00000000 to 0x007A1200
// Identity map the kernel space || our map to 3GB space
// Identity map VGA memory
}
void AllocatePage(VIRTUAL_ADDRESS vaddr, PageDirectoryEntry& page_directory)
{
}
void FreePage(VIRTUAL_ADDRESS vaddr , PageDirectoryEntry& page_directory)
{
}
void Map ( PHYSICAL_ADDRESS paddr, VIRTUAL_ADDRESS vaddr, PageDirectoryEntry& page_directory)
{
}
void Unmap(VIRTUAL_ADDRESS, PageDirectoryEntry& page_directory)
{
// NOTE: I will implement lazy unmapping for now
}
void Enable()
{
printf("Load into CR3 address: 0x%x\n", (uint32_t)(&kernel_directory[0]));
loadPageDirectory(&kernel_directory[0]);
enablePaging();
printf("Paging enabled!\n");
}

View File

@ -0,0 +1,55 @@
#pragma once
#include <stdint.h>
/*
This file contains some handy definitions for different types
that have to do with paging in atleast 32 bit and maybe sometime in the future
also 64 bit mode.
*/
#define MAX_DIRECTORY_ENTRIES 1024
#define MAX_PAGE_TABLE_ENTRIES 1024
#define MAX_PAGES 1024
#define PHYSICAL_ADDRESS uint32_t
#define VIRTUAL_ADDRESS uint32_t
#define PageDirectoryEntry uint32_t
#define PageTableEntry uint32_t
// NOTE: FIXME: I am fairly certain these masks are off by one!
#define PD32_PRESENT_MASK (0x1 << 0)
#define PD32_READ_WRITE_MASK (0x1 << 1)
#define PD32_SUPERVISOR_MASK (0x1 << 2)
#define PD32_WRITE_THROUGH_MASK (0x1 << 3)
#define PD32_CACHE_DISABLE_MASK (0x1 << 4)
#define PD32_ACCESSED_MASK (0x1 << 5)
#define PD32_AVAILABLE_1_4KB_MASK (0x1 << 6)
#define PD32_DISABLE_4MB_MASK (0x1 << 6)
#define PD32_PAGE_SIZE_MASK (0x1 << 7)
#define PD32_GLOBAL_4MB_MASK (0x1 << 8)
#define PD32_AVAILABLE_2_4MB_MASK ( 14 << 9)
#define PD32_AVAILABLE_2_4KB_MASK ( 15 << 8)
#define PD32_ADDRESS_4KB_MASK (0x8FFFF << 12)
#define PD32_PAGE_ATTRIBUTE_TABLE_4MB_MASK (0x1 << 12)
#define PD32_HIGH_HALF_ADDRESS_4MB_MASK (0x7F<< 13)
#define PD32_RESERVED_4MB_MASK (0x1 << 21)
#define PD32_LOWER_HALF_ADDRESS_4MB_MASK (0x1FF << 22)
#define PT32_PRESENT_MASK (0x1 << 0)
#define PT32_READ_WRITE_MASK (0x1 << 1)
#define PT32_SUPERVISOR_MASK (0x1 << 2)
#define PT32_WRITE_THROUGH_MASK (0x1 << 3)
#define PT32_CACHE_DISABLE_MASK (0x1 << 4)
#define PT32_ACCESSED_MASK (0x1 << 5)
#define PT32_DIRTY_MASK (0x1 << 6)
#define PT32_PAGE_ATTRIBUTE_TABLE_MASK (0x1 << 7)
#define PT32_GLOBAL_MASK (0x1 << 8)
#define PT32_AVAILABLE_MASK (0x7 << 9)
#define PT32_CACHE_DISABLE_MASK (0x7FFFF << 12)

View File

@ -0,0 +1,21 @@
#pragma once
#include "./memory.h"
#include "./../tty/kterm.h"
#include "paging.definitions.h"
extern "C" void loadPageDirectory (uint32_t* addr );
extern "C" void enablePaging();
void InitializePaging();
void Enable();
void AllocatePage(VIRTUAL_ADDRESS, PageDirectoryEntry&);
void FreePage(VIRTUAL_ADDRESS, PageDirectoryEntry&);
void Map(PHYSICAL_ADDRESS, VIRTUAL_ADDRESS, PageDirectoryEntry&);
void Unmap (VIRTUAL_ADDRESS, PageDirectoryEntry&);