diff --git a/Makefile b/Makefile index 0c75b9e..4d47d3b 100644 --- a/Makefile +++ b/Makefile @@ -165,13 +165,13 @@ $(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c ./ProjectTree: ./.stylehlp_sh @cat ./.stylehlp_sh > ./ProjectTree @echo "\n" >> ./ProjectTree - @tree >> ./ProjectTree + @tree --dirsfirst >> ./ProjectTree @echo ${CL2}[$@] ${CL}Generated.${CL3} ## MAIN MAKEFILE ------------------------------------------------------------- # .PHONY: test test: all - @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & + @qemu-system-x86_64 -m 5G -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm .PHONY: test32 @@ -182,7 +182,7 @@ test32: all .PHONY: debug debug: all - @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & + @qemu-system-x86_64 -m 5G -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 8e39fa7..8441366 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -154,6 +154,7 @@ _loader64: call write ;; Launch the kernel ! + ;; XXX CHECK THE RAM BEFORE CALLING KERNEL ! call tritemporize ; Let time to see mov rdi, [mbInfo] diff --git a/kaleid/include/kernel/base.h b/kaleid/include/kernel/base.h index 476c647..9b9ed11 100644 --- a/kaleid/include/kernel/base.h +++ b/kaleid/include/kernel/base.h @@ -102,33 +102,42 @@ struct BootInfo_t { // The Bootloader infos (GRUB in our case) struct { + ushort valid; uint grubFlags; //flags uint modulesCount; //mods_count void *modulesAddr; //mods_addr - uint grubName; //boot_loader_name + char *grubName; //boot_loader_name void *mbHeaderAddr; } btldr; // Informations about drives struct { + ushort drvValid; + ushort bufferValid; uint bootDrv; //boot_device uint bufferLength; //drives_length - void *bufferAddr; //drives_addr + void *bufferAddr; //drives_addr } drives; // Informations about memory struct { + ushort memValid; + ushort mapValid; + //BIOS provided low and up memory uint lowMemory; //mem_lower uint upMemory; //mem_upper //GRUB provided memory map uint mapLength; //mmap_length - void *mapAddr; //mmap_addr + void *mapAddr; //mmap_addr + + uint ramSize; //The ram (init by map.c) } memory; // Informations about the video drive struct { + ushort valid; uint vbeControl; //vbe_control_info uint vbeModeInfo; //vbe_mode_info ushort vbeMode; //vbe_mode @@ -145,6 +154,8 @@ struct BootInfo_t // Informations about the microcode firmware (BIOS/EFI) struct { + ushort apmValid; + ushort romValid; uint apmTable; //apm_table uint romTable; //config_table } firmware; diff --git a/kaleid/include/kernel/mm.h b/kaleid/include/kernel/mm.h index 3ef8494..49072e0 100644 --- a/kaleid/include/kernel/mm.h +++ b/kaleid/include/kernel/mm.h @@ -25,6 +25,8 @@ #include #include +#define MINIMUM_RAM_SIZE 16 //Mio, the minimum RAM size. + // // Returns a pointer to the first entry of the memory map // diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 4c0b168..998ae3b 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -29,7 +29,7 @@ // // BootInfo_t initialization. It is necessary because grub will potentially be -// wiped since it is below 1MB.... +// wiped since it is below 1MB.... And we must reorganize all that stuff. // void InitBootInfo(multiboot_info_t *mbi) { @@ -37,41 +37,69 @@ void InitBootInfo(multiboot_info_t *mbi) KalAlwaysAssert(mbi); extern uint MB_header; - //Retrieves the bootloader informations - GetBootInfo(btldr).grubFlags = mbi->flags; - GetBootInfo(btldr).grubName = (mbi->boot_loader_name); - GetBootInfo(btldr).modulesCount = mbi->mods_count; - GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr; - GetBootInfo(btldr).mbHeaderAddr = (void*)(ullong)&MB_header; - DebugLog("\n[InitBootInfo] %s\n", GetBootInfo(btldr).grubName); - DebugLog("[InitBootInfo] Header address : %p, modules address : %p\n", - GetBootInfo(btldr).mbHeaderAddr, GetBootInfo(btldr).modulesAddr); - DebugLog("[InitBootInfo] GRUB flags : %x\n", GetBootInfo(btldr).grubFlags); + //Retrieves the bootloader flags to ensure infos are valid + GetBootInfo(btldr).grubFlags = mbi->flags; + if ( + (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) == MULTIBOOT_INFO_BOOT_LOADER_NAME && + (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) == MULTIBOOT_INFO_MODS + ) { + GetBootInfo(btldr).grubName = (char*)(ullong)(mbi->boot_loader_name); + GetBootInfo(btldr).modulesCount = mbi->mods_count; + GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr; + GetBootInfo(btldr).mbHeaderAddr = (void*)(ullong)&MB_header; + GetBootInfo(btldr).valid = 1; + } //Retrieves the drives informations - GetBootInfo(drives).bootDrv = mbi->boot_device; - GetBootInfo(drives).bufferLength = mbi->drives_length; - GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr; - DebugLog("[InitBootInfo] Root drive : %x\n", - GetBootInfo(drives).bootDrv); + if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) == MULTIBOOT_INFO_DRIVE_INFO) { + GetBootInfo(drives).bufferLength = mbi->drives_length; + GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr; + GetBootInfo(drives).bufferValid = 1; + } + if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) == MULTIBOOT_INFO_BOOTDEV) { + GetBootInfo(drives).bootDrv = mbi->boot_device; + GetBootInfo(drives).drvValid = 1; + } //Retrieves the memory informations - GetBootInfo(memory).lowMemory = mbi->mem_lower; - GetBootInfo(memory).upMemory = mbi->mem_upper; - GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr; - GetBootInfo(memory).mapLength = mbi->mmap_length; - DebugLog("[InitBootInfo] Low memory : %d Kio, Up memory : %d Mio\n", - GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB)); - DebugLog("[InitBootInfo] Memory map address : %p, length : %d\n", - GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength); + if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) == MULTIBOOT_INFO_MEMORY) { + GetBootInfo(memory).lowMemory = mbi->mem_lower; + GetBootInfo(memory).upMemory = mbi->mem_upper; + GetBootInfo(memory).memValid = 1; + } + if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) == MULTIBOOT_INFO_MEM_MAP) { + GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr; + GetBootInfo(memory).mapLength = mbi->mmap_length; + GetBootInfo(memory).mapValid = 1; + } // XXX assign video infos, but unused at this time // Retrieves the firmware infos - GetBootInfo(firmware).apmTable = mbi->apm_table; - GetBootInfo(firmware).romTable = mbi->config_table; - DebugLog("[InitBootInfo] APM Table : %p, ROM Table : %p\n", - GetBootInfo(firmware).apmTable, GetBootInfo(firmware).romTable); + if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) == MULTIBOOT_INFO_CONFIG_TABLE) { + GetBootInfo(firmware).romTable = mbi->config_table; + GetBootInfo(firmware).romValid = 1; + } + if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE ) == MULTIBOOT_INFO_APM_TABLE ) { + GetBootInfo(firmware).apmTable = mbi->apm_table; + GetBootInfo(firmware).apmValid = 1; + } + + //Now we check (debug) + DebugLog("\n[InitBootInfo] Boot loader %s", + GetBootInfo(btldr).valid ? "OK" : ""); + DebugLog("\n[InitBootInfo] Boot drive %s", + GetBootInfo(drives).drvValid ? "OK" : ""); + DebugLog("\n[InitBootInfo] Disk buffer %s", + GetBootInfo(drives).bufferValid ? "OK" : ""); + DebugLog("\n[InitBootInfo] Basic mem %s", + GetBootInfo(memory).memValid ? "OK" : ""); + DebugLog("\n[InitBootInfo] Memory map %s", + GetBootInfo(memory).mapValid ? "OK" : ""); + DebugLog("\n[InitBootInfo] ROM table %s", + GetBootInfo(firmware).romValid ? "OK" : ""); + DebugLog("\n[InitBootInfo] APM table %s", + GetBootInfo(firmware).apmValid ? "OK\n" : "\n"); } @@ -96,7 +124,9 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) InitBootInfo(mbInfo); //Memory mapping - InitMemoryMap(); + error_t mapBad = InitMemoryMap(); + if (mapBad) + StartPanic("[Init] The memory map failed to initialize. Error : %d", mapBad); // We're out KernLog("\n[Init] Evil never dies !"); diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index ed39670..5ea56c6 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -27,8 +27,16 @@ error_t InitMemoryMap(void) { - uint mapIsValid = (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) == MULTIBOOT_INFO_MEM_MAP; - KalAlwaysAssert(mapIsValid); + if (!GetBootInfo(memory).memValid && GetBootInfo(memory).mapValid) + return ENXIO; + DebugLog("[InitMemoryMap] Memory map address : %p, length : %d\n", + GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength); + + if ((GetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE) //XXX before loading kernel... + return ENOMEM; + DebugLog("[InitMemoryMap] Low memory : %d Kio, Up memory : %d Mio\n", + GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB)); + return EOK; }