Merge into main the new state of the operating system/kernel #1

Open
Nigel wants to merge 120 commits from dev into main
3 changed files with 66 additions and 50 deletions
Showing only changes of commit 560dd64e64 - Show all commits

View File

@ -28,10 +28,14 @@ stack_top:
*/
.section .bss, "aw", @nobits
.align 4096
.globl boot_page_directory
boot_page_directory:
.skip 4096
boot_page_table:
.skip 4096
.globl multiboot_page_table
multiboot_page_table:
.skip 4096
# More page tables may be required
# Entry point

View File

@ -1,7 +1,7 @@
#include "paging.h"
PageDirectoryEntry kernel_directory[MAX_DIRECTORY_ENTRIES]__attribute__((aligned(4096)));
/*PageDirectoryEntry kernel_directory[MAX_DIRECTORY_ENTRIES]__attribute__((aligned(4096)));
PageTableEntry first_page_table[MAX_PAGE_TABLE_ENTRIES]__attribute__((aligned(4096)));
//PageTableEntry first_page_table[MAX_PAGE_TABLE_ENTRIES]__attribute__((aligned(4096)));
void IdentityMap (){
printf("\nInit paging\n");
@ -43,6 +43,7 @@ void InitializePaging()
Initial kernel page directory
set all page tables to not present
*/
/*
for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++)
{
kernel_directory[i] = 0x2;
@ -57,6 +58,7 @@ void InitializePaging()
uint8_t NUM_PDE = BIOSAddr_Max / (4 * 1024 * 1024);
printf("The first 8MiB require %d Page Directory Entries\n", NUM_PDE);
*/
/*
for( int i = 0; i < NUM_PDE; i++)
{
@ -71,7 +73,7 @@ void InitializePaging()
// add page table as page directory entry
kernel_directory[i] = ( (unsigned int) pagetable ) | 3;
}
*/
// map the kernel space
VIRTUAL_ADDRESS Vaddr = KERNEL_VRT_MEMORY_BEGIN;
PHYSICAL_ADDRESS KernelAddr = kernel_begin;
@ -82,7 +84,7 @@ void InitializePaging()
NUM_PDE = KernelSizeInBytes / (4 * 1024* 1024);
printf("Kernel requires %d Page Directory Entries\n", NUM_PDE);
/*
for(int i = 0; i < NUM_PDE; i++)
{
PageTableEntry pageTable [MAX_PAGE_TABLE_ENTRIES] = PhysicalMemory::allocate_block();
@ -97,7 +99,7 @@ void InitializePaging()
}
*/
@ -168,3 +170,4 @@ void Enable()
}
}
*/

View File

@ -1,13 +1,11 @@
#include "kernel.h"
void map_multiboot_info_structure(unsigned long addr);
extern "C" void kernel_main (BootInfo* bootinfo);
extern "C" uint32_t boot_page_directory;
extern "C" uint32_t multiboot_page_table;
extern "C" void kernel_main (BootInfo* bootinfo) {
pit_initialise();
startSuperVisorTerminal(bootinfo);
}
const uint32_t KERNEL_BASE_ADDR = 0xC0000000;
extern "C" void early_main(unsigned long magic, unsigned long addr){
/**
* Initialize terminal interface
@ -22,32 +20,7 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
// Enable interrupts
asm volatile("STI");
// map the multiboot structure into virtual memory
// so we can gather the necessary data from it.
/* const uint32_t KERNEL_BASE_ADDR = 0xC0000000;
uint32_t pageDirectoryIndex = (addr + KERNEL_BASE_ADDR) >> 22;
printf("pageDirectoryIndex: %d\n", pageDirectoryIndex);
uint32_t pageTableIndex = (addr + KERNEL_BASE_ADDR >> 12) & 0x1FFF;
printf("PagTableIndex: %d\n", pageTableIndex);
printf("boot_page_directory addr: 0x%x\n", &boot_page_directory);
printf("boot_page_table addr: 0x%x\n", &boot_page_table);
uint32_t* pageDirectoryEntry = (uint32_t*) ((uint32_t) &boot_page_directory) + (pageDirectoryIndex * 4);
printf("page_directory_entry addr: 0x%x\n", pageDirectoryEntry);
*pageDirectoryEntry = ( addr & 0xFFFFF000 ) | 0x003;
uint32_t* page_table_entry = (uint32_t*) ((uint32_t) &boot_page_table) + ( pageTableIndex * 4);
printf("page_table_entry addr: 0x%x\n" , page_table_entry);
*page_table_entry = addr | 0x003;
// Reload CR3 to force a flush
asm("movl %cr3, %ecx;" "movl %ecx, %cr3" );
*/
map_multiboot_info_structure(addr);
printf("DEBUG:\n Magic: 0x%x\n MBT_addr: 0x%x\n", magic, addr);
/**
@ -63,12 +36,11 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
* Show a little banner for cuteness
*/
printf("|=== BarinkOS ===|\n");
const uint32_t KERNEL_BASE_ADDR = 0xC0000000;
/**
* Use the address given as an argument as the pointer
* to a Multiboot information structure.
*/
multiboot_info_t* mbt = (multiboot_info_t*) (addr + KERNEL_BASE_ADDR);
multiboot_info_t* mbt = (multiboot_info_t*) (addr );
/**
* Construct our own bootInfo structure
@ -92,15 +64,19 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
mapMultibootMemoryMap(bootinfo.memory , mbt);
printf("Memory size: 0x%x bytes\n", bootinfo.memory->TotalMemory );
/*
PhysicalMemory memAlloc = PhysicalMemory{};
memAlloc.setup(bootinfo.memory );
*/
// TODO: FIX physical allocator
/*
Mark already in use sections
*/
// Mark kernel memory as used
printf("Kernel Begin Pointer: 0x%x, Kernel end pointer: 0x%x\n", kernel_begin , kernel_end );
printf("Kernel Begin Pointer: 0x%x, Kernel end pointer: 0x%x\n", &kernel_begin , &kernel_end );
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) mbt->mmap_addr;
@ -110,15 +86,15 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
} else{
printf("allocate region: 0x%x, size : 0x%x bytes\n", (unsigned) mmap->addr,(unsigned) mmap->len );
memAlloc.allocate_region((unsigned)mmap->addr , (unsigned)mmap->len);
// memAlloc.allocate_region((unsigned)mmap->addr , (unsigned)mmap->len);
}
}
printf("allocate region: 0x%x, size : 0x%x bytes\n", kernel_begin, kernel_end - kernel_begin );
memAlloc.allocate_region(kernel_end, kernel_end - kernel_begin);
printf("allocate region: 0x%x, size : 0x%x bytes\n", &kernel_begin, &kernel_end - &kernel_begin );
//memAlloc.allocate_region(kernel_end, kernel_end - kernel_begin);
// test alloc_block
/*
@ -150,3 +126,36 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
}
void map_multiboot_info_structure(unsigned long addr){
// map the multiboot structure into virtual memory
// so we can gather the necessary data from it.
uint32_t pageDirectoryIndex = (addr ) >> 22;
printf("pageDirectoryIndex: %d\n", pageDirectoryIndex);
uint32_t pageTableIndex = (addr >> 12) & 0x1FFF;
printf("PagTableIndex: %d\n", pageTableIndex);
printf("boot_page_directory addr: 0x%x\n", &boot_page_directory);
printf("boot_page_table addr: 0x%x\n", &multiboot_page_table);
uint32_t* current_page_directory = &boot_page_directory;
uint32_t* needed_page_table = &multiboot_page_table - KERNEL_BASE_ADDR;
// set the page tabel reference;
current_page_directory[pageDirectoryIndex] = (uint32_t)&multiboot_page_table - KERNEL_BASE_ADDR + 0x003;
// set the page reference;
needed_page_table[ pageTableIndex ] = addr | 0x003;
// Reload CR3 to force a flush
asm("movl %cr3, %ecx;" "movl %ecx, %cr3" );
}
extern "C" void kernel_main (BootInfo* bootinfo) {
pit_initialise();
startSuperVisorTerminal(bootinfo);
}