From 0f0fc9f252ca030f3b28878c9f81f38b9d931c1d Mon Sep 17 00:00:00 2001 From: Nigel Date: Sun, 21 Aug 2022 21:18:53 +0200 Subject: [PATCH] Adding a skeleton for the memory management code Moved the PMM away from being object orientated as it is just plain annoying renamed src folder to source Set timeout to 5 seconds in the grub config --- Makefile | 6 +- {src => source}/grub.cfg | 0 {src => source}/kernel/Drivers/PCI/pci.cpp | 0 {src => source}/kernel/Drivers/PCI/pci.h | 0 {src => source}/kernel/Drivers/PIC/pic.cpp | 0 {src => source}/kernel/Drivers/PIC/pic.h | 0 {src => source}/kernel/Drivers/PIT/pit.cpp | 0 {src => source}/kernel/Drivers/PIT/pit.h | 0 .../kernel/Drivers/PS-2/keyboard.cpp | 0 .../kernel/Drivers/PS-2/keyboard.h | 0 .../kernel/Drivers/Serial/serial.cpp | 0 .../kernel/Drivers/Serial/serial.h | 0 {src => source}/kernel/Drivers/VGA/VBE.h | 0 {src => source}/kernel/Drivers/VGA/colors.h | 0 {src => source}/kernel/Drivers/cmos/cmos.cpp | 0 .../kernel/FileSystem/FAT/FAT16.cpp | 0 {src => source}/kernel/FileSystem/FAT/FAT16.h | 0 {src => source}/kernel/Interrupts/idt/idt.cpp | 0 {src => source}/kernel/Interrupts/idt/idt.h | 0 {src => source}/kernel/Interrupts/idt/idt.s | 0 .../kernel/Interrupts/idt/scancodes/set1.h | 0 {src => source}/kernel/KernelLauncher/boot.s | 0 .../kernel/KernelLauncher/bootcheck.h | 2 +- {src => source}/kernel/KernelLauncher/crti.s | 0 {src => source}/kernel/KernelLauncher/crtn.s | 0 .../kernel/KernelLauncher/launcher.cpp | 0 {src => source}/kernel/Lib/mem.h | 0 {src => source}/kernel/Lib/string.c | 0 {src => source}/kernel/Lib/string.h | 0 {src => source}/kernel/Memory/GDT/gdt.s | 0 {src => source}/kernel/Memory/GDT/gdtc.cpp | 0 {src => source}/kernel/Memory/GDT/gdtc.h | 0 source/kernel/Memory/KernelHeap.cpp | 51 ++++++ source/kernel/Memory/KernelHeap.h | 9 + source/kernel/Memory/MBIMMap/MBI_MMap.cpp | 43 +++++ source/kernel/Memory/MBIMMap/MBI_MMap.h | 16 ++ .../kernel/Memory/PhysicalMemoryManager.cpp | 102 +++++++++++ source/kernel/Memory/PhysicalMemoryManager.h | 30 +++ source/kernel/Memory/VirtualMemoryManager.cpp | 24 +++ source/kernel/Memory/VirtualMemoryManager.h | 12 ++ {src => source}/kernel/Memory/memoryinfo.h | 0 .../kernel/Memory/paging.definitions.h | 0 {src => source}/kernel/Memory/paging.s | 0 .../SuperVisorTerminal/superVisorTerminal.cpp | 2 +- .../SuperVisorTerminal/superVisorTerminal.h | 2 +- {src => source}/kernel/Terminal/kterm.cpp | 0 {src => source}/kernel/Terminal/kterm.h | 0 {src => source}/kernel/bitmap.h | 0 {src => source}/kernel/bootinfo.h | 0 {src => source}/kernel/cpu.h | 0 {src => source}/kernel/cpu.s | 0 {src => source}/kernel/definitions.h | 0 {src => source}/kernel/io.cpp | 0 {src => source}/kernel/io.h | 0 {src => source}/kernel/irq_table.s | 0 {src => source}/kernel/irs_table.s | 0 {src => source}/kernel/kernel.cpp | 8 +- {src => source}/kernel/kernel.h | 16 +- {src => source}/kernel/linker.ld | 0 {src => source}/kernel/multiboot.h | 0 {src => source}/kernel/serial.h | 0 {src => source}/kernel/time.cpp | 0 {src => source}/kernel/time.h | 0 {src => source}/kernel/timer.cpp | 0 {src => source}/kernel/timer.h | 0 src/kernel/Memory/KernelHeap.h | 2 - src/kernel/Memory/PhysicalMemoryManager.cpp | 144 --------------- src/kernel/Memory/PhysicalMemoryManager.h | 50 ----- src/kernel/Memory/VirtualMemoryManager.cpp | 171 ------------------ src/kernel/Memory/VirtualMemoryManager.h | 22 --- 70 files changed, 308 insertions(+), 404 deletions(-) rename {src => source}/grub.cfg (100%) rename {src => source}/kernel/Drivers/PCI/pci.cpp (100%) rename {src => source}/kernel/Drivers/PCI/pci.h (100%) rename {src => source}/kernel/Drivers/PIC/pic.cpp (100%) rename {src => source}/kernel/Drivers/PIC/pic.h (100%) rename {src => source}/kernel/Drivers/PIT/pit.cpp (100%) rename {src => source}/kernel/Drivers/PIT/pit.h (100%) rename {src => source}/kernel/Drivers/PS-2/keyboard.cpp (100%) rename {src => source}/kernel/Drivers/PS-2/keyboard.h (100%) rename {src => source}/kernel/Drivers/Serial/serial.cpp (100%) rename {src => source}/kernel/Drivers/Serial/serial.h (100%) rename {src => source}/kernel/Drivers/VGA/VBE.h (100%) rename {src => source}/kernel/Drivers/VGA/colors.h (100%) rename {src => source}/kernel/Drivers/cmos/cmos.cpp (100%) rename {src => source}/kernel/FileSystem/FAT/FAT16.cpp (100%) rename {src => source}/kernel/FileSystem/FAT/FAT16.h (100%) rename {src => source}/kernel/Interrupts/idt/idt.cpp (100%) rename {src => source}/kernel/Interrupts/idt/idt.h (100%) rename {src => source}/kernel/Interrupts/idt/idt.s (100%) rename {src => source}/kernel/Interrupts/idt/scancodes/set1.h (100%) rename {src => source}/kernel/KernelLauncher/boot.s (100%) rename {src => source}/kernel/KernelLauncher/bootcheck.h (97%) rename {src => source}/kernel/KernelLauncher/crti.s (100%) rename {src => source}/kernel/KernelLauncher/crtn.s (100%) rename {src => source}/kernel/KernelLauncher/launcher.cpp (100%) rename {src => source}/kernel/Lib/mem.h (100%) rename {src => source}/kernel/Lib/string.c (100%) rename {src => source}/kernel/Lib/string.h (100%) rename {src => source}/kernel/Memory/GDT/gdt.s (100%) rename {src => source}/kernel/Memory/GDT/gdtc.cpp (100%) rename {src => source}/kernel/Memory/GDT/gdtc.h (100%) create mode 100644 source/kernel/Memory/KernelHeap.cpp create mode 100644 source/kernel/Memory/KernelHeap.h create mode 100644 source/kernel/Memory/MBIMMap/MBI_MMap.cpp create mode 100644 source/kernel/Memory/MBIMMap/MBI_MMap.h create mode 100644 source/kernel/Memory/PhysicalMemoryManager.cpp create mode 100644 source/kernel/Memory/PhysicalMemoryManager.h create mode 100644 source/kernel/Memory/VirtualMemoryManager.cpp create mode 100644 source/kernel/Memory/VirtualMemoryManager.h rename {src => source}/kernel/Memory/memoryinfo.h (100%) rename {src => source}/kernel/Memory/paging.definitions.h (100%) rename {src => source}/kernel/Memory/paging.s (100%) rename {src => source}/kernel/SuperVisorTerminal/superVisorTerminal.cpp (96%) rename {src => source}/kernel/SuperVisorTerminal/superVisorTerminal.h (65%) rename {src => source}/kernel/Terminal/kterm.cpp (100%) rename {src => source}/kernel/Terminal/kterm.h (100%) rename {src => source}/kernel/bitmap.h (100%) rename {src => source}/kernel/bootinfo.h (100%) rename {src => source}/kernel/cpu.h (100%) rename {src => source}/kernel/cpu.s (100%) rename {src => source}/kernel/definitions.h (100%) rename {src => source}/kernel/io.cpp (100%) rename {src => source}/kernel/io.h (100%) rename {src => source}/kernel/irq_table.s (100%) rename {src => source}/kernel/irs_table.s (100%) rename {src => source}/kernel/kernel.cpp (93%) rename {src => source}/kernel/kernel.h (58%) rename {src => source}/kernel/linker.ld (100%) rename {src => source}/kernel/multiboot.h (100%) rename {src => source}/kernel/serial.h (100%) rename {src => source}/kernel/time.cpp (100%) rename {src => source}/kernel/time.h (100%) rename {src => source}/kernel/timer.cpp (100%) rename {src => source}/kernel/timer.h (100%) delete mode 100644 src/kernel/Memory/KernelHeap.h delete mode 100644 src/kernel/Memory/PhysicalMemoryManager.cpp delete mode 100644 src/kernel/Memory/PhysicalMemoryManager.h delete mode 100644 src/kernel/Memory/VirtualMemoryManager.cpp delete mode 100644 src/kernel/Memory/VirtualMemoryManager.h diff --git a/Makefile b/Makefile index 95f137b..038150f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CFLAGS = -ffreestanding -Og -ggdb -Wall -Wextra 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 $(BUILD_DIR)/launcher.o -SRC_DIR = src +SRC_DIR = source BUILD_DIR = build CRTBEGIN_OBJ = $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o) @@ -99,10 +99,10 @@ $(BUILD_DIR)/sv-terminal.o: $(CPP) -c $(SRC_DIR)/kernel/SuperVisorTerminal/superVisorTerminal.cpp -o $(BUILD_DIR)/sv-terminal.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/memory.o: - $(CPP) -c $(SRC_DIR)/kernel/Memory/memory.cpp -o $(BUILD_DIR)/memory.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/Memory/PhysicalMemoryManager.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 + $(CPP) -c $(SRC_DIR)/kernel/Memory/VirtualMemoryManager.cpp -o $(BUILD_DIR)/paging.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/launcher.o: $(CPP) -c $(SRC_DIR)/kernel/KernelLauncher/launcher.cpp -o $(BUILD_DIR)/launcher.o $(CFLAGS) -fno-exceptions -fno-rtti \ No newline at end of file diff --git a/src/grub.cfg b/source/grub.cfg similarity index 100% rename from src/grub.cfg rename to source/grub.cfg diff --git a/src/kernel/Drivers/PCI/pci.cpp b/source/kernel/Drivers/PCI/pci.cpp similarity index 100% rename from src/kernel/Drivers/PCI/pci.cpp rename to source/kernel/Drivers/PCI/pci.cpp diff --git a/src/kernel/Drivers/PCI/pci.h b/source/kernel/Drivers/PCI/pci.h similarity index 100% rename from src/kernel/Drivers/PCI/pci.h rename to source/kernel/Drivers/PCI/pci.h diff --git a/src/kernel/Drivers/PIC/pic.cpp b/source/kernel/Drivers/PIC/pic.cpp similarity index 100% rename from src/kernel/Drivers/PIC/pic.cpp rename to source/kernel/Drivers/PIC/pic.cpp diff --git a/src/kernel/Drivers/PIC/pic.h b/source/kernel/Drivers/PIC/pic.h similarity index 100% rename from src/kernel/Drivers/PIC/pic.h rename to source/kernel/Drivers/PIC/pic.h diff --git a/src/kernel/Drivers/PIT/pit.cpp b/source/kernel/Drivers/PIT/pit.cpp similarity index 100% rename from src/kernel/Drivers/PIT/pit.cpp rename to source/kernel/Drivers/PIT/pit.cpp diff --git a/src/kernel/Drivers/PIT/pit.h b/source/kernel/Drivers/PIT/pit.h similarity index 100% rename from src/kernel/Drivers/PIT/pit.h rename to source/kernel/Drivers/PIT/pit.h diff --git a/src/kernel/Drivers/PS-2/keyboard.cpp b/source/kernel/Drivers/PS-2/keyboard.cpp similarity index 100% rename from src/kernel/Drivers/PS-2/keyboard.cpp rename to source/kernel/Drivers/PS-2/keyboard.cpp diff --git a/src/kernel/Drivers/PS-2/keyboard.h b/source/kernel/Drivers/PS-2/keyboard.h similarity index 100% rename from src/kernel/Drivers/PS-2/keyboard.h rename to source/kernel/Drivers/PS-2/keyboard.h diff --git a/src/kernel/Drivers/Serial/serial.cpp b/source/kernel/Drivers/Serial/serial.cpp similarity index 100% rename from src/kernel/Drivers/Serial/serial.cpp rename to source/kernel/Drivers/Serial/serial.cpp diff --git a/src/kernel/Drivers/Serial/serial.h b/source/kernel/Drivers/Serial/serial.h similarity index 100% rename from src/kernel/Drivers/Serial/serial.h rename to source/kernel/Drivers/Serial/serial.h diff --git a/src/kernel/Drivers/VGA/VBE.h b/source/kernel/Drivers/VGA/VBE.h similarity index 100% rename from src/kernel/Drivers/VGA/VBE.h rename to source/kernel/Drivers/VGA/VBE.h diff --git a/src/kernel/Drivers/VGA/colors.h b/source/kernel/Drivers/VGA/colors.h similarity index 100% rename from src/kernel/Drivers/VGA/colors.h rename to source/kernel/Drivers/VGA/colors.h diff --git a/src/kernel/Drivers/cmos/cmos.cpp b/source/kernel/Drivers/cmos/cmos.cpp similarity index 100% rename from src/kernel/Drivers/cmos/cmos.cpp rename to source/kernel/Drivers/cmos/cmos.cpp diff --git a/src/kernel/FileSystem/FAT/FAT16.cpp b/source/kernel/FileSystem/FAT/FAT16.cpp similarity index 100% rename from src/kernel/FileSystem/FAT/FAT16.cpp rename to source/kernel/FileSystem/FAT/FAT16.cpp diff --git a/src/kernel/FileSystem/FAT/FAT16.h b/source/kernel/FileSystem/FAT/FAT16.h similarity index 100% rename from src/kernel/FileSystem/FAT/FAT16.h rename to source/kernel/FileSystem/FAT/FAT16.h diff --git a/src/kernel/Interrupts/idt/idt.cpp b/source/kernel/Interrupts/idt/idt.cpp similarity index 100% rename from src/kernel/Interrupts/idt/idt.cpp rename to source/kernel/Interrupts/idt/idt.cpp diff --git a/src/kernel/Interrupts/idt/idt.h b/source/kernel/Interrupts/idt/idt.h similarity index 100% rename from src/kernel/Interrupts/idt/idt.h rename to source/kernel/Interrupts/idt/idt.h diff --git a/src/kernel/Interrupts/idt/idt.s b/source/kernel/Interrupts/idt/idt.s similarity index 100% rename from src/kernel/Interrupts/idt/idt.s rename to source/kernel/Interrupts/idt/idt.s diff --git a/src/kernel/Interrupts/idt/scancodes/set1.h b/source/kernel/Interrupts/idt/scancodes/set1.h similarity index 100% rename from src/kernel/Interrupts/idt/scancodes/set1.h rename to source/kernel/Interrupts/idt/scancodes/set1.h diff --git a/src/kernel/KernelLauncher/boot.s b/source/kernel/KernelLauncher/boot.s similarity index 100% rename from src/kernel/KernelLauncher/boot.s rename to source/kernel/KernelLauncher/boot.s diff --git a/src/kernel/KernelLauncher/bootcheck.h b/source/kernel/KernelLauncher/bootcheck.h similarity index 97% rename from src/kernel/KernelLauncher/bootcheck.h rename to source/kernel/KernelLauncher/bootcheck.h index 50335d2..cb7e30c 100644 --- a/src/kernel/KernelLauncher/bootcheck.h +++ b/source/kernel/KernelLauncher/bootcheck.h @@ -31,7 +31,7 @@ void CheckMBT ( multiboot_info_t* mbt ){ if (CHECK_FLAG ( mbi->flags,2)) { #ifdef __VERBOSE__ - printf("cmdline = %s\n", (char *) mbi->cmdline); + printf("cmdline = %s\n", (char *) (mbi->cmdline + 0xC0000000)); #endif } diff --git a/src/kernel/KernelLauncher/crti.s b/source/kernel/KernelLauncher/crti.s similarity index 100% rename from src/kernel/KernelLauncher/crti.s rename to source/kernel/KernelLauncher/crti.s diff --git a/src/kernel/KernelLauncher/crtn.s b/source/kernel/KernelLauncher/crtn.s similarity index 100% rename from src/kernel/KernelLauncher/crtn.s rename to source/kernel/KernelLauncher/crtn.s diff --git a/src/kernel/KernelLauncher/launcher.cpp b/source/kernel/KernelLauncher/launcher.cpp similarity index 100% rename from src/kernel/KernelLauncher/launcher.cpp rename to source/kernel/KernelLauncher/launcher.cpp diff --git a/src/kernel/Lib/mem.h b/source/kernel/Lib/mem.h similarity index 100% rename from src/kernel/Lib/mem.h rename to source/kernel/Lib/mem.h diff --git a/src/kernel/Lib/string.c b/source/kernel/Lib/string.c similarity index 100% rename from src/kernel/Lib/string.c rename to source/kernel/Lib/string.c diff --git a/src/kernel/Lib/string.h b/source/kernel/Lib/string.h similarity index 100% rename from src/kernel/Lib/string.h rename to source/kernel/Lib/string.h diff --git a/src/kernel/Memory/GDT/gdt.s b/source/kernel/Memory/GDT/gdt.s similarity index 100% rename from src/kernel/Memory/GDT/gdt.s rename to source/kernel/Memory/GDT/gdt.s diff --git a/src/kernel/Memory/GDT/gdtc.cpp b/source/kernel/Memory/GDT/gdtc.cpp similarity index 100% rename from src/kernel/Memory/GDT/gdtc.cpp rename to source/kernel/Memory/GDT/gdtc.cpp diff --git a/src/kernel/Memory/GDT/gdtc.h b/source/kernel/Memory/GDT/gdtc.h similarity index 100% rename from src/kernel/Memory/GDT/gdtc.h rename to source/kernel/Memory/GDT/gdtc.h diff --git a/source/kernel/Memory/KernelHeap.cpp b/source/kernel/Memory/KernelHeap.cpp new file mode 100644 index 0000000..bc5abce --- /dev/null +++ b/source/kernel/Memory/KernelHeap.cpp @@ -0,0 +1,51 @@ +#include "KernelHeap.h" + +// Size of heap meta data is 5 bytes +struct heap_block{ + uint8_t Used; + uint32_t Size; +} + +uint32_t heap_size; +heap_block* start ; + +void* malloc(size_t size) +{ + printf("Received request for %d bytes of memory", size); + heap_block* current = start; + + while(current < start + heap_size) + { + if(current->size >= size && current->Used == false ) + { + // We found a spot + // Set the spot to in-use + current->Used = false; + // return the free address + // NOTE: added an offset from the initial address to accomodate for + // meta-data. + return current + sizeof(heap_block); + + } + + current += current->Size + sizeof(heap_block); + } + + // If we are here we need more memory so we should + // probably ask the VMM for more + // TODO: ask for more memory + +} + +void free(void* addr) +{ + // clear the free boolean that corresponds to this adddress + // This should be fairly simple + heap_block* allocatedBlock = addr - sizeof(heap_block); + allocate_block->Used = false; +} + +void initHeap() +{ + +} \ No newline at end of file diff --git a/source/kernel/Memory/KernelHeap.h b/source/kernel/Memory/KernelHeap.h new file mode 100644 index 0000000..e38110b --- /dev/null +++ b/source/kernel/Memory/KernelHeap.h @@ -0,0 +1,9 @@ +#pragma once +#include + + +void initHeap(); + +void* malloc (size_t size ); +void free(void* addr); + diff --git a/source/kernel/Memory/MBIMMap/MBI_MMap.cpp b/source/kernel/Memory/MBIMMap/MBI_MMap.cpp new file mode 100644 index 0000000..dc5da2f --- /dev/null +++ b/source/kernel/Memory/MBIMMap/MBI_MMap.cpp @@ -0,0 +1,43 @@ +#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 + ); +} diff --git a/source/kernel/Memory/MBIMMap/MBI_MMap.h b/source/kernel/Memory/MBIMMap/MBI_MMap.h new file mode 100644 index 0000000..bd24198 --- /dev/null +++ b/source/kernel/Memory/MBIMMap/MBI_MMap.h @@ -0,0 +1,16 @@ +#pragma once +#include +#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); diff --git a/source/kernel/Memory/PhysicalMemoryManager.cpp b/source/kernel/Memory/PhysicalMemoryManager.cpp new file mode 100644 index 0000000..dd8bd5c --- /dev/null +++ b/source/kernel/Memory/PhysicalMemoryManager.cpp @@ -0,0 +1,102 @@ +#include "./PhysicalMemoryManager.h" + +PhysicalMemoryManagerInfoBlock* PMMInfoBlock; + + +void initPMM( MemoryInfo* memory) { + + // NOTE: Lets for now puts the Physical memoryManagerBlock at a random address + // We'll think of a more proper solution a bit later + PMMInfoBlock = (PhysicalMemoryManagerInfoBlock*) 0xCC900000; + + + // calculate the maximum number of blocks + PMMInfoBlock->max_blocks = KB_TO_BLOCKS(memory->TotalMemory); + PMMInfoBlock->used_blocks = 0; + PMMInfoBlock->memoryBitMap = (uint32_t*) 0xCCA00000; + + printf("Maximum Number of blocks: 0x%x, Number of bytes for memMap: 0x%x\n", PMMInfoBlock->max_blocks , (PMMInfoBlock->max_blocks/8)); + + //Size of memory map + uint32_t memMap_size = (PMMInfoBlock->max_blocks / 8 ) ; + + printf("Memory Map size: 0x%x\n", memMap_size ); + printf("size of int in bytes: 0x%x \n" , sizeof(int)); + + // Set all places in memory as free + memset(PMMInfoBlock->memoryBitMap, 0xFF, memMap_size ); +} + +// NOTE: this can only give blocks of 4kb at a time! +void* allocate_block() { + uint8_t blocks_available = PMMInfoBlock->max_blocks - PMMInfoBlock->used_blocks; + // Are there any blocks available? + if( blocks_available <= 0) + { + printf("No blocks available. Blocks Delta: 0x%x\n", blocks_available); + return 0; + } + + // Find 1 free block somewhere + int free_block_index = bitmap_first_unset(PMMInfoBlock->memoryBitMap, (PMMInfoBlock->max_blocks /8) /*memMap Size*/ ); + + + + if(free_block_index == -1) + { + printf("Could not find a good block!\n"); + // Could not find a block + return (void*)0xFFFF; + } + + if(free_block_index == 0) + printf("Somethings wrong!!!\n"); + + // Set the block to be used! + bitmap_unset(PMMInfoBlock->memoryBitMap, free_block_index); + // Increase the used_block count! + PMMInfoBlock->used_blocks++; + printf("used blocks: 0x%x\n", PMMInfoBlock->used_blocks); + // return the pointer to the physical address + return (void*) (BLOCK_SIZE * free_block_index); +} + +void free_block(void* p) { + // If it is a null pointer we don't need to do anything. + if(p==0) { + return; + } + // calculate the index into the bitmap + int index = ((uint32_t) p) / BLOCK_SIZE; + + // set the block to be free + bitmap_set(PMMInfoBlock->memoryBitMap, index); + PMMInfoBlock->used_blocks--; + printf("used blocks: 0x%x, after free\n", PMMInfoBlock->used_blocks); + +} + +void allocate_region(uint32_t startAddress, uint32_t size) { + // every bit should be 4KiB + // every byte is 8*4KiB = 32KiB + + int NumberOfBlocksToAllocate = ( size / 1024) / 4 / 8 + 1; + int startBlock = (startAddress / 1024) / 4 / 8 ; + + // printf("NumberOfBlocksToAllocate: 0x%x\n", NumberOfBlocksToAllocate); + //printf( "start block: 0x%x\n" , startBlock); + for( int i = 0; i < NumberOfBlocksToAllocate; i++) + { + + //printf("ALLOCATE BLOCK: 0x%x\n" , startBlock + i ); + bitmap_unset(PMMInfoBlock->memoryBitMap, startBlock+ i); + PMMInfoBlock->used_blocks++; + } + + +} +void deallocate_region(uint32_t StartAddress , uint32_t size ) { + // NOT IMPLEMENTED YET +} + + diff --git a/source/kernel/Memory/PhysicalMemoryManager.h b/source/kernel/Memory/PhysicalMemoryManager.h new file mode 100644 index 0000000..649c922 --- /dev/null +++ b/source/kernel/Memory/PhysicalMemoryManager.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include "memoryinfo.h" + +#include "../Terminal/kterm.h" +#include "../Lib/mem.h" +#include "../bitmap.h" + +// Asumming 32 bit x86 for now! +#define BLOCK_SIZE 4092 +#define WORD_SIZE 2 +#define BLOCKS_PER_WORD 32 + +#define KB_TO_BLOCKS(x) (x / BLOCK_SIZE) +#define IS_ALIGNED(addr, align) !((addr) & ~((align) - 1)) +#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align)) + +struct PhysicalMemoryManagerInfoBlock +{ + uint32_t* memoryBitMap; + size_t pmmap_size; + size_t max_blocks; + int used_blocks; +}; + +void initPMM(MemoryInfo* memory); +void free_block(void* ptr); +void* allocate_block(); +void allocate_region(uint32_t, uint32_t); +void deallocate_region(uint32_t , uint32_t ); diff --git a/source/kernel/Memory/VirtualMemoryManager.cpp b/source/kernel/Memory/VirtualMemoryManager.cpp new file mode 100644 index 0000000..2af5da6 --- /dev/null +++ b/source/kernel/Memory/VirtualMemoryManager.cpp @@ -0,0 +1,24 @@ +#include "VirtualMemoryManager.h" + +extern "C" void loadPageDirectory (uint32_t* addr ); +extern "C" void enablePaging(); + +void AllocatePage(uint32_t vaddr) +{ + +} + +void FreePage(uint32_t vaddr ) +{ + +} + +void Map ( uint32_t vaddr, uint32_t paddr) +{ + +} + +void Unmap(uint32_t vaddr) +{ + // NOTE: I will implement lazy unmapping for now +} diff --git a/source/kernel/Memory/VirtualMemoryManager.h b/source/kernel/Memory/VirtualMemoryManager.h new file mode 100644 index 0000000..32abf0c --- /dev/null +++ b/source/kernel/Memory/VirtualMemoryManager.h @@ -0,0 +1,12 @@ +#pragma once +#include "PhysicalMemoryManager.h" +#include "../Terminal/kterm.h" +#include "../cpu.h" + +void AllocatePage(uint32_t v_addr ); +void FreePage(uint32_t v_addr); + +void Map(uint32_t p_addr, uint32_t v_addr); +void Unmap (uint32_t v_addr); + + diff --git a/src/kernel/Memory/memoryinfo.h b/source/kernel/Memory/memoryinfo.h similarity index 100% rename from src/kernel/Memory/memoryinfo.h rename to source/kernel/Memory/memoryinfo.h diff --git a/src/kernel/Memory/paging.definitions.h b/source/kernel/Memory/paging.definitions.h similarity index 100% rename from src/kernel/Memory/paging.definitions.h rename to source/kernel/Memory/paging.definitions.h diff --git a/src/kernel/Memory/paging.s b/source/kernel/Memory/paging.s similarity index 100% rename from src/kernel/Memory/paging.s rename to source/kernel/Memory/paging.s diff --git a/src/kernel/SuperVisorTerminal/superVisorTerminal.cpp b/source/kernel/SuperVisorTerminal/superVisorTerminal.cpp similarity index 96% rename from src/kernel/SuperVisorTerminal/superVisorTerminal.cpp rename to source/kernel/SuperVisorTerminal/superVisorTerminal.cpp index b568208..79dd349 100644 --- a/src/kernel/SuperVisorTerminal/superVisorTerminal.cpp +++ b/source/kernel/SuperVisorTerminal/superVisorTerminal.cpp @@ -39,7 +39,7 @@ void startSuperVisorTerminal(BootInfo* bootinfo){ // Show memory layout printf("========= Memory ==========\n"); printf("Kernel MemoryMap:\n"); - printf("kernel: 0x%x - 0x%x\n", &kernel_begin , &kernel_end); + //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; diff --git a/src/kernel/SuperVisorTerminal/superVisorTerminal.h b/source/kernel/SuperVisorTerminal/superVisorTerminal.h similarity index 65% rename from src/kernel/SuperVisorTerminal/superVisorTerminal.h rename to source/kernel/SuperVisorTerminal/superVisorTerminal.h index 99d083d..eeed1df 100644 --- a/src/kernel/SuperVisorTerminal/superVisorTerminal.h +++ b/source/kernel/SuperVisorTerminal/superVisorTerminal.h @@ -3,7 +3,7 @@ #include "../time.h" #include "../Drivers/PIT/pit.h" #include "../Drivers/PS-2/keyboard.h" -#include "../Memory/memory.h" +#include "../Memory/PhysicalMemoryManager.h" #include "../bootinfo.h" void startSuperVisorTerminal(BootInfo * ); \ No newline at end of file diff --git a/src/kernel/Terminal/kterm.cpp b/source/kernel/Terminal/kterm.cpp similarity index 100% rename from src/kernel/Terminal/kterm.cpp rename to source/kernel/Terminal/kterm.cpp diff --git a/src/kernel/Terminal/kterm.h b/source/kernel/Terminal/kterm.h similarity index 100% rename from src/kernel/Terminal/kterm.h rename to source/kernel/Terminal/kterm.h diff --git a/src/kernel/bitmap.h b/source/kernel/bitmap.h similarity index 100% rename from src/kernel/bitmap.h rename to source/kernel/bitmap.h diff --git a/src/kernel/bootinfo.h b/source/kernel/bootinfo.h similarity index 100% rename from src/kernel/bootinfo.h rename to source/kernel/bootinfo.h diff --git a/src/kernel/cpu.h b/source/kernel/cpu.h similarity index 100% rename from src/kernel/cpu.h rename to source/kernel/cpu.h diff --git a/src/kernel/cpu.s b/source/kernel/cpu.s similarity index 100% rename from src/kernel/cpu.s rename to source/kernel/cpu.s diff --git a/src/kernel/definitions.h b/source/kernel/definitions.h similarity index 100% rename from src/kernel/definitions.h rename to source/kernel/definitions.h diff --git a/src/kernel/io.cpp b/source/kernel/io.cpp similarity index 100% rename from src/kernel/io.cpp rename to source/kernel/io.cpp diff --git a/src/kernel/io.h b/source/kernel/io.h similarity index 100% rename from src/kernel/io.h rename to source/kernel/io.h diff --git a/src/kernel/irq_table.s b/source/kernel/irq_table.s similarity index 100% rename from src/kernel/irq_table.s rename to source/kernel/irq_table.s diff --git a/src/kernel/irs_table.s b/source/kernel/irs_table.s similarity index 100% rename from src/kernel/irs_table.s rename to source/kernel/irs_table.s diff --git a/src/kernel/kernel.cpp b/source/kernel/kernel.cpp similarity index 93% rename from src/kernel/kernel.cpp rename to source/kernel/kernel.cpp index e120dab..0387146 100644 --- a/src/kernel/kernel.cpp +++ b/source/kernel/kernel.cpp @@ -1,11 +1,5 @@ #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; - -const uint32_t KERNEL_BASE_ADDR = 0xC0000000; extern "C" void early_main(unsigned long magic, unsigned long addr){ // Convert MBI address to higher quarter kernel space @@ -63,7 +57,7 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){ MemoryInfo meminfo = {}; bootinfo.memory = &meminfo; - mapMultibootMemoryMap(bootinfo.memory , mbt); + ///mapMultibootMemoryMap(bootinfo.memory , mbt); printf("Memory size: 0x%x bytes\n", bootinfo.memory->TotalMemory ); /* diff --git a/src/kernel/kernel.h b/source/kernel/kernel.h similarity index 58% rename from src/kernel/kernel.h rename to source/kernel/kernel.h index d9c6a9c..529fb5e 100644 --- a/src/kernel/kernel.h +++ b/source/kernel/kernel.h @@ -12,9 +12,9 @@ extern "C" #include "multiboot.h" #include "bootinfo.h" -#include "Memory/memory.h" +#include "Memory/PhysicalMemoryManager.h" #include "Memory/memoryinfo.h" -#include "Memory/paging.h" +#include "Memory/VirtualMemoryManager.h" #include "KernelLauncher/bootcheck.h" #include "Memory/GDT/gdtc.h" @@ -32,3 +32,15 @@ extern "C" #define PANIC(message) {return;} +void map_multiboot_info_structure(unsigned long addr); + +extern "C" void kernel_main (BootInfo* bootinfo); + +extern "C" const void* kernel_begin; +extern "C" const void* kernel_end; + +extern "C" uint32_t boot_page_directory; +extern "C" uint32_t multiboot_page_table; + + +const uint32_t KERNEL_BASE_ADDR = 0xC0000000; \ No newline at end of file diff --git a/src/kernel/linker.ld b/source/kernel/linker.ld similarity index 100% rename from src/kernel/linker.ld rename to source/kernel/linker.ld diff --git a/src/kernel/multiboot.h b/source/kernel/multiboot.h similarity index 100% rename from src/kernel/multiboot.h rename to source/kernel/multiboot.h diff --git a/src/kernel/serial.h b/source/kernel/serial.h similarity index 100% rename from src/kernel/serial.h rename to source/kernel/serial.h diff --git a/src/kernel/time.cpp b/source/kernel/time.cpp similarity index 100% rename from src/kernel/time.cpp rename to source/kernel/time.cpp diff --git a/src/kernel/time.h b/source/kernel/time.h similarity index 100% rename from src/kernel/time.h rename to source/kernel/time.h diff --git a/src/kernel/timer.cpp b/source/kernel/timer.cpp similarity index 100% rename from src/kernel/timer.cpp rename to source/kernel/timer.cpp diff --git a/src/kernel/timer.h b/source/kernel/timer.h similarity index 100% rename from src/kernel/timer.h rename to source/kernel/timer.h diff --git a/src/kernel/Memory/KernelHeap.h b/src/kernel/Memory/KernelHeap.h deleted file mode 100644 index 84a1624..0000000 --- a/src/kernel/Memory/KernelHeap.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once - diff --git a/src/kernel/Memory/PhysicalMemoryManager.cpp b/src/kernel/Memory/PhysicalMemoryManager.cpp deleted file mode 100644 index a24ff3d..0000000 --- a/src/kernel/Memory/PhysicalMemoryManager.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include "./memory.h" -uint32_t* memoryBitMap; -/* - -*/ -void PhysicalMemory::setup( MemoryInfo* memory) { - - // calculate the maximum number of blocks - max_blocks = KB_TO_BLOCKS(memory->TotalMemory); - - used_blocks = 0; - - memoryBitMap = (uint32_t*) 0xCCA00000; - - - printf("Maximum Number of blocks: 0x%x, Number of bytes for memMap: 0x%x\n", max_blocks , (max_blocks/8)); - - //Size of memory map - uint32_t memMap_size = (max_blocks / 8 ) ; - - printf("Memory Map size: 0x%x\n", memMap_size ); - printf("size of int in bytes: 0x%x \n" , sizeof(int)); - - // Set all places in memory as free - memset(memoryBitMap, 0xFF, memMap_size ); -} - -// NOTE: this can only give blocks of 4kb at a time! -void* PhysicalMemory::allocate_block() { - uint8_t blocks_available = max_blocks - used_blocks; - // Are there any blocks available? - if( blocks_available <= 0) - { - printf("No blocks available. Blocks Delta: 0x%x\n", blocks_available); - return 0; - } - - // Find 1 free block somewhere - int free_block_index = bitmap_first_unset(memoryBitMap, (max_blocks /8) /*memMap Size*/ ); - - - - if(free_block_index == -1) - { - printf("Could not find a good block!\n"); - // Could not find a block - return (void*)0xFFFF; - } - - if(free_block_index == 0) - printf("Somethings wrong!!!\n"); - - // Set the block to be used! - bitmap_unset(memoryBitMap, free_block_index); - // Increase the used_block count! - used_blocks++; - printf("used blocks: 0x%x\n", used_blocks); - // return the pointer to the physical address - return (void*) (BLOCK_SIZE * free_block_index); -} - - -void PhysicalMemory::free_block(void* p) { - // If it is a null pointer we don't need to do anything. - if(p==0) { - return; - } - // calculate the index into the bitmap - int index = ((uint32_t) p) / BLOCK_SIZE; - - // set the block to be free - bitmap_set(memoryBitMap, index); - used_blocks--; - printf("used blocks: 0x%x, after free\n", used_blocks); - -} - - - -void PhysicalMemory::allocate_region(uint32_t startAddress, uint32_t size) { - // every bit should be 4KiB - // every byte is 8*4KiB = 32KiB - - int NumberOfBlocksToAllocate = ( size / 1024) / 4 / 8 + 1; - int startBlock = (startAddress / 1024) / 4 / 8 ; - - // printf("NumberOfBlocksToAllocate: 0x%x\n", NumberOfBlocksToAllocate); - //printf( "start block: 0x%x\n" , startBlock); - for( int i = 0; i < NumberOfBlocksToAllocate; i++) - { - - //printf("ALLOCATE BLOCK: 0x%x\n" , startBlock + i ); - bitmap_unset(memoryBitMap, startBlock+ i); - used_blocks++; - } - - -} -void PhysicalMemory::deallocate_region(uint32_t StartAddress , uint32_t size ) { - // NOT IMPLEMENTED YET -} - - -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 - ); -} - diff --git a/src/kernel/Memory/PhysicalMemoryManager.h b/src/kernel/Memory/PhysicalMemoryManager.h deleted file mode 100644 index cef690c..0000000 --- a/src/kernel/Memory/PhysicalMemoryManager.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once -#include -#include - -#include "memoryinfo.h" -#include "../multiboot.h" -#include "../Terminal/kterm.h" -#include "../Lib/mem.h" -#include "../bitmap.h" - -// Asumming 32 bit x86 for now! -#define BLOCK_SIZE 4092 -#define WORD_SIZE 2 -#define BLOCKS_PER_WORD 32 - -#define KB_TO_BLOCKS(x) (x / BLOCK_SIZE) -#define IS_ALIGNED(addr, align) !((addr) & ~((align) - 1)) -#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align)) - -extern uint32_t kernel_begin; -extern uint32_t kernel_end; - -void initialise_available_regions(uint32_t memoryMapAddr, uint32_t memoryMapLastAddr, uint32_t* memoryBitMap, int* used_blocks); - -extern uint32_t* memoryBitMap; - -class PhysicalMemory -{ - public: - void setup(MemoryInfo* memory); - void destroy(); - void free_block(void* ptr); - void* allocate_block(); - void allocate_region(uint32_t, uint32_t); - void deallocate_region(uint32_t , uint32_t ); - - private: - size_t pmmap_size; - size_t max_blocks; - 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); diff --git a/src/kernel/Memory/VirtualMemoryManager.cpp b/src/kernel/Memory/VirtualMemoryManager.cpp deleted file mode 100644 index 45f0344..0000000 --- a/src/kernel/Memory/VirtualMemoryManager.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "paging.h" -// PageDirectoryEntry kernel_directory[MAX_DIRECTORY_ENTRIES]__attribute__((aligned(4096))); -// PageTableEntry first_page_table[MAX_PAGE_TABLE_ENTRIES]__attribute__((aligned(4096))); - -void IdentityMap (){ - 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] = 0x2; - 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"); -} - -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; - } - - // BIOS Address Identity mapping - // Identity map the first 8MiB ... Physical addresses 0x00000000 to 0x007A1200 - PHYSICAL_ADDRESS BIOSAddr = 0x00000000; - PHYSICAL_ADDRESS BIOSAddr_Max = 0x800000; - - // How many PDE's do we need - 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++) - { - // setup a page table - // PageTableEntry pagetable[MAX_PAGE_TABLE_ENTRIES] = PhysicalMemory::allocate_block(); // TODO :: Physical memory manager functions should be available here. - - for(int j = 0; j < MAX_PAGE_TABLE_ENTRIES; j++) - { - // pagetable[j] = ( j * 4096 ) | 3; - } - - // 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; - PHYSICAL_ADDRESS KernelEndAddr = kernel_end; - - uint32_t KernelSizeInBytes = (KernelEndAddr - KernelAddr); - printf("Kernel is 0x%x bytes\n", KernelSizeInBytes); - 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(); - - for(int j = 0; j < MAX_PAGE_TABLE_ENTRIES; j++) - { - // pageTable[j] = ( j * 4096) | 3; // NOTE: Check if page is actually supposed to be present - } - - // TODO: Calculate Page Directory index - - - - } - - - - - - // Identity map VGA memory - // Calc which PDE adn - -} - - -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 vaddr, PageDirectoryEntry& page_directory) -{ - // NOTE: I will implement lazy unmapping for now - -} - -void Enable() -{ - - //TODO: Write protect will not be turned on - // for the moment altough according to the intel - // developer manual this should happen. - - uint32_t CR0; - - CR0 = GetCR0(); - printf("PG bit = %d \n" , GET_PG_BIT(CR0)); - - // printf("Load into CR3 address: 0x%x\n", (uint32_t)(&kernel_directory[0])); - // loadPageDirectory(&kernel_directory[0]); - // enablePaging(); - - printf("Paging enabled!\n"); - - - CR0 = GetCR0(); - uint32_t CR4 = GetCR4(); - printf("PG bit = %d\n" , GET_PG_BIT(CR0) ); - printf("PAE bit = %d\n", GET_PAE_BIT(CR4)); - - if(GET_PAE_BIT(CR4) == 0){ - printf("Using 32bit paging\n"); - - if(GET_PSE_BIT(CR4) == 0 ){ - printf("Page size is 4KiB\n"); - } else { - printf("Page size is 4MiB\n"); - } - } else { - printf("Using some extended version for paging\n"); - } - -} diff --git a/src/kernel/Memory/VirtualMemoryManager.h b/src/kernel/Memory/VirtualMemoryManager.h deleted file mode 100644 index 8e1e155..0000000 --- a/src/kernel/Memory/VirtualMemoryManager.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "memory.h" -#include "paging.definitions.h" -#include "../Terminal/kterm.h" -#include "../cpu.h" - -extern "C" void loadPageDirectory (uint32_t* addr ); -extern "C" void enablePaging(); - - -void IdentityMap(); -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&); - -