Merge into main the new state of the operating system/kernel #1
@ -4,7 +4,7 @@ extern "C" void kernel_main (BootInfo* bootinfo) {
|
|||||||
init_serial();
|
init_serial();
|
||||||
pit_initialise();
|
pit_initialise();
|
||||||
|
|
||||||
InitializePaging();
|
//InitializePaging();
|
||||||
//Enable();
|
//Enable();
|
||||||
|
|
||||||
startSuperVisorTerminal(bootinfo);
|
startSuperVisorTerminal(bootinfo);
|
||||||
@ -90,8 +90,7 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
|
|||||||
memAlloc.allocate_region(kernel_end, kernel_end - kernel_begin);
|
memAlloc.allocate_region(kernel_end, kernel_end - kernel_begin);
|
||||||
|
|
||||||
// test alloc_block
|
// test alloc_block
|
||||||
|
/*
|
||||||
|
|
||||||
uint8_t* memory = (uint8_t*) memAlloc.allocate_block();
|
uint8_t* memory = (uint8_t*) memAlloc.allocate_block();
|
||||||
printf("Got a new pointer: 0x%x\n", memory);
|
printf("Got a new pointer: 0x%x\n", memory);
|
||||||
|
|
||||||
@ -102,13 +101,13 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
|
|||||||
memAlloc.free_block((void*) memory);
|
memAlloc.free_block((void*) memory);
|
||||||
|
|
||||||
uint8_t* newBlockPlse = (uint8_t*) memAlloc.allocate_block();
|
uint8_t* newBlockPlse = (uint8_t*) memAlloc.allocate_block();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// memAlloc.free_block((void*) memory);
|
// memAlloc.free_block((void*) memory);
|
||||||
|
InitializePaging();
|
||||||
|
Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
initGDT();
|
initGDT();
|
||||||
|
@ -1,16 +1,79 @@
|
|||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
PageDirectoryEntry kernel_directory[MAX_DIRECTORY_ENTRIES];
|
PageDirectoryEntry kernel_directory[MAX_DIRECTORY_ENTRIES]__attribute__((aligned(4096)));
|
||||||
|
PageTableEntry first_page_table[1024]__attribute__((aligned(4096)));
|
||||||
|
|
||||||
|
#define KERNEL_VRT_MEMORY_BEGIN 0xC0000000
|
||||||
|
#define KERNEL_VRT_MEMORY_END 0xCFFFFFFF
|
||||||
|
#define PAGE_SIZE 0xFA0;
|
||||||
|
|
||||||
|
|
||||||
void InitializePaging()
|
void InitializePaging()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nInit paging\n");
|
||||||
|
// The basics as explained by wiki.osdev.org
|
||||||
|
|
||||||
|
// Set all page_directories to not present
|
||||||
|
int i = 0;
|
||||||
|
while ( i < 1024)
|
||||||
|
{
|
||||||
|
kernel_directory[i] = 0x00000002;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// map 4 megabytes
|
||||||
|
unsigned int j ;
|
||||||
|
for( j = 0; j < 1024; j++ )
|
||||||
|
{
|
||||||
|
first_page_table[j] = (j * 0x1000) | 3 ;
|
||||||
|
/*
|
||||||
|
Attributes:
|
||||||
|
Supervisor Level ,
|
||||||
|
read/write,
|
||||||
|
present,
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the page table in the page directory
|
||||||
|
// attributes: supervisor level, read/write, present;
|
||||||
|
kernel_directory[0] = ((unsigned int)first_page_table) | 3;
|
||||||
|
|
||||||
|
printf("Init paging DONE\n");
|
||||||
|
// NOTE: Adjust this as needed
|
||||||
|
|
||||||
|
// BIOS Address Identity mapping
|
||||||
// Identity map the first 8MB ... Physical addresses 0x00000000 to 0x007A1200
|
// Identity map the first 8MB ... Physical addresses 0x00000000 to 0x007A1200
|
||||||
|
/*
|
||||||
|
|
||||||
|
PHYSICAL_ADDRESS BIOSAddr = 0x00000000;
|
||||||
|
PHYSICAL_ADDRESS BIOSAddr_Max = 0x007A1200;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Map( BIOSAddr, BIOSAddr, *kernel_directory);
|
||||||
|
BIOSAddr += PAGE_SIZE
|
||||||
|
} while(BIOSAddr <= BIOSAddr_Max);
|
||||||
|
|
||||||
|
// Identity map the kernel space
|
||||||
|
VIRTUAL_ADDRESS Vaddr = KERNEL_VRT_MEMORY_BEGIN;
|
||||||
|
PHYSICAL_ADDRESS KernelAddr = kernel_begin;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Map(KernelAddr, Vaddr , *kernel_directory);
|
||||||
|
|
||||||
|
Vaddr += PAGE_SIZE;
|
||||||
|
KernelAddr += PAGE_SIZE
|
||||||
|
|
||||||
|
}
|
||||||
|
while(KernelAddr < kernel_end);
|
||||||
|
|
||||||
|
|
||||||
// Identity map the kernel space || our map to 3GB space
|
//TODO: Identity map VGA memory
|
||||||
|
*/
|
||||||
|
|
||||||
// Identity map VGA memory
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,9 +93,11 @@ void FreePage(VIRTUAL_ADDRESS vaddr , PageDirectoryEntry& page_directory)
|
|||||||
void Map ( PHYSICAL_ADDRESS paddr, VIRTUAL_ADDRESS vaddr, PageDirectoryEntry& page_directory)
|
void Map ( PHYSICAL_ADDRESS paddr, VIRTUAL_ADDRESS vaddr, PageDirectoryEntry& page_directory)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unmap(VIRTUAL_ADDRESS, PageDirectoryEntry& page_directory)
|
void Unmap(VIRTUAL_ADDRESS vaddr, PageDirectoryEntry& page_directory)
|
||||||
{
|
{
|
||||||
// NOTE: I will implement lazy unmapping for now
|
// NOTE: I will implement lazy unmapping for now
|
||||||
|
|
||||||
|
@ -12,10 +12,7 @@ void InitializePaging();
|
|||||||
void Enable();
|
void Enable();
|
||||||
|
|
||||||
void AllocatePage(VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
void AllocatePage(VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
||||||
|
|
||||||
|
|
||||||
void FreePage(VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
void FreePage(VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
||||||
|
|
||||||
|
|
||||||
void Map(PHYSICAL_ADDRESS, VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
void Map(PHYSICAL_ADDRESS, VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
||||||
void Unmap (VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
void Unmap (VIRTUAL_ADDRESS, PageDirectoryEntry&);
|
||||||
|
Loading…
Reference in New Issue
Block a user