1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

Boot organization

This commit is contained in:
Adrien Bourmault 2019-03-21 13:30:17 +01:00
parent 965d12d2cd
commit 1aef44b1af
6 changed files with 89 additions and 37 deletions

View File

@ -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

View File

@ -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]

View File

@ -102,15 +102,18 @@ 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
@ -118,6 +121,9 @@ struct BootInfo_t
// Informations about memory
struct {
ushort memValid;
ushort mapValid;
//BIOS provided low and up memory
uint lowMemory; //mem_lower
uint upMemory; //mem_upper
@ -125,10 +131,13 @@ struct BootInfo_t
//GRUB provided memory map
uint mapLength; //mmap_length
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;

View File

@ -25,6 +25,8 @@
#include <kernel/multiboot.h>
#include <kernel/base.h>
#define MINIMUM_RAM_SIZE 16 //Mio, the minimum RAM size.
//
// Returns a pointer to the first entry of the memory map
//

View File

@ -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
//Retrieves the bootloader flags to ensure infos are valid
GetBootInfo(btldr).grubFlags = mbi->flags;
GetBootInfo(btldr).grubName = (mbi->boot_loader_name);
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;
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);
GetBootInfo(btldr).valid = 1;
}
//Retrieves the drives informations
GetBootInfo(drives).bootDrv = mbi->boot_device;
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;
DebugLog("[InitBootInfo] Root drive : %x\n",
GetBootInfo(drives).bootDrv);
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
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;
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);
GetBootInfo(memory).mapValid = 1;
}
// XXX assign video infos, but unused at this time
// Retrieves the firmware infos
GetBootInfo(firmware).apmTable = mbi->apm_table;
if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) == MULTIBOOT_INFO_CONFIG_TABLE) {
GetBootInfo(firmware).romTable = mbi->config_table;
DebugLog("[InitBootInfo] APM Table : %p, ROM Table : %p\n",
GetBootInfo(firmware).apmTable, GetBootInfo(firmware).romTable);
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 !");

View File

@ -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;
}