KERNEL: Cleanup

Removing quite a few unnecessary parts.
dev
Nigel Barink 2022-09-01 17:02:04 +02:00
parent a70ae5ca31
commit 9893a0bd17
15 changed files with 26 additions and 274 deletions

View File

@ -58,7 +58,7 @@ $(BUILD_DIR)/kterm.o:
$(CPP) -c $(SRC_DIR)/kernel/Terminal/kterm.cpp -o $(BUILD_DIR)/kterm.o $(CFLAGS) -fno-exceptions -fno-rtti
$(BUILD_DIR)/boot.o:
$(AS) $(SRC_DIR)/kernel/Boot/boot.s -o $(BUILD_DIR)/boot.o
$(AS) $(SRC_DIR)/kernel/boot/boot.s -o $(BUILD_DIR)/boot.o
$(BUILD_DIR)/crti.o:
$(AS) $(SRC_DIR)/kernel/crti.s -o $(BUILD_DIR)/crti.o

View File

@ -1,7 +1,7 @@
#pragma once
#include "stdint.h"
#include "stddef.h"
#include <stdint.h>
#include <stddef.h>
#include "../../Drivers/VGA/colors.h"
#include "../../Drivers/PIC/pic.h"

View File

@ -1,44 +0,0 @@
#include "MBI_MMap.h"
/*
void mapMultibootMemoryMap( MemoryInfo* memInfo , multiboot_info_t *mbt) {
printf("mmap_addr = 0x%x, mmap_length = 0x%x\n", (unsigned) mbt->mmap_addr , (unsigned) mbt->mmap_length );
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) mbt->mmap_addr;
for (; (unsigned long) mmap < mbt->mmap_addr + mbt->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
if ( mmap->type == MULTIBOOT_MEMORY_AVAILABLE){
memInfo->TotalMemory += mmap->len;
} else {
memInfo->ReservedMemory += mmap->len;
}
print_Multiboot_memory_Map(mmap);
}
}
*/
/**
* @brief Debug Verbose functions
*
* @param mmap
*/
/*
void print_Multiboot_memory_Map(multiboot_memory_map_t* mmap) {
printf(
"size = 0x%x, base_addr = 0x%x%08x, length = 0x%x%08x, type = 0x%x\n",
(unsigned) mmap->size,
(unsigned) (mmap->addr >> 32),
(unsigned) (mmap->addr & 0xffffffff),
(unsigned) (mmap->len >> 32),
(unsigned) (mmap->len & 0xffffffff),
(unsigned) mmap->type
);
}
*/

View File

@ -1,18 +0,0 @@
#pragma once
#include <stddef.h>
//#include "../../multiboot.h"
#include "../memoryinfo.h"
void initialise_available_regions(uint32_t memoryMapAddr, uint32_t memoryMapLastAddr, uint32_t* memoryBitMap, int* used_blocks);
/*
void mapMultibootMemoryMap( MemoryInfo* memInfo , multiboot_info_t *mbt);
*/
/**
* @brief Debug Verbose Functions
*
* @param mmap
*/
/*
void print_Multiboot_memory_Map(multiboot_memory_map_t* mmap);
*/

View File

@ -1,20 +0,0 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
struct MemoryArea{
void* StartAddress;
size_t Size;
unsigned int type;
MemoryArea* Next;
}__attribute__((packed));
struct MemoryInfo {
uint32_t TotalMemory;
uint32_t ReservedMemory;
MemoryArea* MemoryRegionList;
}__attribute__((packed));

View File

@ -1,56 +0,0 @@
#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
#define KERNEL_VRT_MEMORY_BEGIN 0xC0000000
#define KERNEL_VRT_MEMORY_END 0xCFFFFFFF
#define PAGE_SIZE 4096;
// 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

@ -1,44 +0,0 @@
# NOTE: I wish this wasn't AT&T Syntax its horrible
# REMINDER: INSTRUCTION FROM_REGISTER, TO_REGISTER
.globl enablePaging
enablePaging:
# Create a new call frame
push %ebp
mov %esp, %ebp
# Set the PG bit of CR0
mov %cr0, %eax
or $0x80000000, %eax
mov %eax, %cr0
# Restore to the previous call frame
mov %ebp, %esp
pop %ebp
ret
.globl loadPageDirectory
loadPageDirectory:
push %ebp
mov %esp, %ebp
/* NOTE: We should probably check if paging is already enabled.
Changing the CR3 register whilst paging is enabled might
result in unwanted behaviour (in the worst case) or cause a
fault (in the best case).
*/
mov 8(%esp), %eax # Move the first argument in the eax register
mov %eax, %cr3 # Move the value of eax into the CR3 register
/*
Moving the value of the argument passed to this function
into the CR3 register will allow the MMU to access the paging
structure we setup in memory once we enable paging
*/
mov %ebp, %esp
pop %ebp
ret

View File

@ -1,6 +1,6 @@
#include "superVisorTerminal.h"
void startSuperVisorTerminal(BootInfo* bootinfo){
void startSuperVisorTerminal(){
while (true){
printf("SUPERVISOR:>$ " );
@ -38,22 +38,11 @@ void startSuperVisorTerminal(BootInfo* bootinfo){
{
// Show memory layout
printf("========= Memory ==========\n");
printf("Not Available!\n");
printf("Kernel MemoryMap:\n");
//printf("kernel: 0x%x - 0x%x\n", &kernel_begin , &kernel_end);
printf("Frames used: 0x%x blocks of 4 KiB\n", 0);
const int bytesInGiB = 1073741824;
int64_t bytesLeft = (bootinfo->memory->TotalMemory % bytesInGiB) / bytesInGiB;
int64_t effectiveNumberOfGib = bootinfo->memory->TotalMemory / bytesInGiB;
int64_t GiBs = effectiveNumberOfGib + bytesLeft;
printf("Available Memory: %d bytes, %d GiB\n", bootinfo->memory->TotalMemory, GiBs );
printf("Reserved Memory: %d bytes\n", bootinfo->memory->ReservedMemory);
//printf("\n\n");
//PrintPhysicalMemoryAllocation( );
printf("Frames used: -- \n");
printf("Available Memory:-- \n");
printf("Reserved Memory: -- bytes\n");
}
else if(strncmp("TEST", command, characterCount) == 0)
{

View File

@ -4,6 +4,5 @@
#include "../Drivers/PIT/pit.h"
#include "../Drivers/PS-2/keyboard.h"
#include "../Memory/PhysicalMemoryManager.h"
#include "../bootinfo.h"
void startSuperVisorTerminal(BootInfo * );
void startSuperVisorTerminal();

View File

@ -1,4 +1,4 @@
.include "./source/kernel/Boot/Multiboot.S"
.include "./source/kernel/boot/multiboot.s"
/*
* Allocate initial stack
*/
@ -116,7 +116,6 @@ isPaging:
.include "./source/kernel/irs_table.s"
.include "./source/kernel/irq_table.s"
.include "./source/kernel/Interrupts/idt/idt.s"
.include "./source/kernel/Memory/paging.s"
.include "./source/kernel/cpu.s"

View File

@ -1,8 +0,0 @@
#pragma once
#include "Memory/memoryinfo.h"
struct BootInfo{
const char* BootStructureID = "BarinkOS";
MemoryInfo* memory;
};

View File

@ -1,4 +1,5 @@
#pragma once
#pragma once
#include <stdint.h>
/*
Based on Intel specifications.

View File

@ -21,7 +21,7 @@ extern "C" void early_main()
* Show a little banner for cuteness
*/
printf("|=== BarinkOS ===|\n");
printf("Kernel End Addr: 0x%x\n" , &kernel_end + KERNEL_BASE_ADDR);
printf("Kernel End Addr: 0x%x\n" , &kernel_end );
uint32_t PageDirectoryEntryIndex = ((uint32_t)&kernel_end + KERNEL_BASE_ADDR ) >> 22 ;
@ -93,16 +93,7 @@ extern "C" void early_main()
// Setup PhysicalMemoryManagement
SetupPhysicalMemoryManager(BootInfo);
// Small test!
void* block = allocate_block();
void* block2 = allocate_block();
printf("Allocated addresss 1: 0x%x 2: 0x%x\n", (uint32_t)block ,(uint32_t)block2);
free_block(block);
free_block(block2);
void* block3 = allocate_block();
printf("Allocated addresss 3: 0x%x\n", (uint32_t)block3);
free_block(block3);
}
asm volatile("mov %cr0, %eax ");
@ -112,57 +103,23 @@ extern "C" void early_main()
}
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" );
}
void PhysicalMemoryAllocatorTest(){
#ifdef UNIT_TESTS
// test alloc_block
uint8_t* memory = (uint8_t*) memAlloc.allocate_block();
printf("Got a new pointer: 0x%x\n", memory);
uint8_t* memory2 = (uint8_t*) memAlloc.allocate_block();
printf("Got a new pointer: 0x%x\n", memory2);
memAlloc.free_block((void*) memory);
uint8_t* newBlockPlse = (uint8_t*) memAlloc.allocate_block();
#endif
#ifdef UNIT_TESTS
// Small test!
void* block = allocate_block();
void* block2 = allocate_block();
printf("Allocated addresss 1: 0x%x 2: 0x%x\n", (uint32_t)block ,(uint32_t)block2);
free_block(block);
free_block(block2);
void* block3 = allocate_block();
printf("Allocated addresss 3: 0x%x\n", (uint32_t)block3);
free_block(block3);
#endif
}
extern "C" void kernel_main () {
pit_initialise();
// Create a dummy BootInfo object
// TODO: This should be done properly or the dependency should
// be removed from the SuperVisorTerminal.
BootInfo* bootinfo = {};
startSuperVisorTerminal(bootinfo);
startSuperVisorTerminal();
}

View File

@ -8,10 +8,7 @@ extern "C"
#include "Drivers/VGA/VBE.h"
#include "Terminal/kterm.h"
#include "bootinfo.h"
#include "Memory/PhysicalMemoryManager.h"
#include "Memory/memoryinfo.h"
#include "Memory/VirtualMemoryManager.h"
#include "Memory/GDT/gdtc.h"