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:
parent
965d12d2cd
commit
1aef44b1af
6
Makefile
6
Makefile
@ -165,13 +165,13 @@ $(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c
|
|||||||
./ProjectTree: ./.stylehlp_sh
|
./ProjectTree: ./.stylehlp_sh
|
||||||
@cat ./.stylehlp_sh > ./ProjectTree
|
@cat ./.stylehlp_sh > ./ProjectTree
|
||||||
@echo "\n" >> ./ProjectTree
|
@echo "\n" >> ./ProjectTree
|
||||||
@tree >> ./ProjectTree
|
@tree --dirsfirst >> ./ProjectTree
|
||||||
@echo ${CL2}[$@] ${CL}Generated.${CL3}
|
@echo ${CL2}[$@] ${CL}Generated.${CL3}
|
||||||
## MAIN MAKEFILE ------------------------------------------------------------- #
|
## MAIN MAKEFILE ------------------------------------------------------------- #
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: all
|
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 64 > loader_disasm64.asm
|
||||||
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
|
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
|
||||||
.PHONY: test32
|
.PHONY: test32
|
||||||
@ -182,7 +182,7 @@ test32: all
|
|||||||
|
|
||||||
.PHONY: debug
|
.PHONY: debug
|
||||||
debug: all
|
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 64 > loader_disasm64.asm
|
||||||
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
|
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
|
||||||
|
|
||||||
|
@ -154,6 +154,7 @@ _loader64:
|
|||||||
call write
|
call write
|
||||||
|
|
||||||
;; Launch the kernel !
|
;; Launch the kernel !
|
||||||
|
;; XXX CHECK THE RAM BEFORE CALLING KERNEL !
|
||||||
call tritemporize ; Let time to see
|
call tritemporize ; Let time to see
|
||||||
|
|
||||||
mov rdi, [mbInfo]
|
mov rdi, [mbInfo]
|
||||||
|
@ -102,33 +102,42 @@ struct BootInfo_t
|
|||||||
{
|
{
|
||||||
// The Bootloader infos (GRUB in our case)
|
// The Bootloader infos (GRUB in our case)
|
||||||
struct {
|
struct {
|
||||||
|
ushort valid;
|
||||||
uint grubFlags; //flags
|
uint grubFlags; //flags
|
||||||
uint modulesCount; //mods_count
|
uint modulesCount; //mods_count
|
||||||
void *modulesAddr; //mods_addr
|
void *modulesAddr; //mods_addr
|
||||||
uint grubName; //boot_loader_name
|
char *grubName; //boot_loader_name
|
||||||
void *mbHeaderAddr;
|
void *mbHeaderAddr;
|
||||||
} btldr;
|
} btldr;
|
||||||
|
|
||||||
// Informations about drives
|
// Informations about drives
|
||||||
struct {
|
struct {
|
||||||
|
ushort drvValid;
|
||||||
|
ushort bufferValid;
|
||||||
uint bootDrv; //boot_device
|
uint bootDrv; //boot_device
|
||||||
uint bufferLength; //drives_length
|
uint bufferLength; //drives_length
|
||||||
void *bufferAddr; //drives_addr
|
void *bufferAddr; //drives_addr
|
||||||
} drives;
|
} drives;
|
||||||
|
|
||||||
// Informations about memory
|
// Informations about memory
|
||||||
struct {
|
struct {
|
||||||
|
ushort memValid;
|
||||||
|
ushort mapValid;
|
||||||
|
|
||||||
//BIOS provided low and up memory
|
//BIOS provided low and up memory
|
||||||
uint lowMemory; //mem_lower
|
uint lowMemory; //mem_lower
|
||||||
uint upMemory; //mem_upper
|
uint upMemory; //mem_upper
|
||||||
|
|
||||||
//GRUB provided memory map
|
//GRUB provided memory map
|
||||||
uint mapLength; //mmap_length
|
uint mapLength; //mmap_length
|
||||||
void *mapAddr; //mmap_addr
|
void *mapAddr; //mmap_addr
|
||||||
|
|
||||||
|
uint ramSize; //The ram (init by map.c)
|
||||||
} memory;
|
} memory;
|
||||||
|
|
||||||
// Informations about the video drive
|
// Informations about the video drive
|
||||||
struct {
|
struct {
|
||||||
|
ushort valid;
|
||||||
uint vbeControl; //vbe_control_info
|
uint vbeControl; //vbe_control_info
|
||||||
uint vbeModeInfo; //vbe_mode_info
|
uint vbeModeInfo; //vbe_mode_info
|
||||||
ushort vbeMode; //vbe_mode
|
ushort vbeMode; //vbe_mode
|
||||||
@ -145,6 +154,8 @@ struct BootInfo_t
|
|||||||
|
|
||||||
// Informations about the microcode firmware (BIOS/EFI)
|
// Informations about the microcode firmware (BIOS/EFI)
|
||||||
struct {
|
struct {
|
||||||
|
ushort apmValid;
|
||||||
|
ushort romValid;
|
||||||
uint apmTable; //apm_table
|
uint apmTable; //apm_table
|
||||||
uint romTable; //config_table
|
uint romTable; //config_table
|
||||||
} firmware;
|
} firmware;
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include <kernel/multiboot.h>
|
#include <kernel/multiboot.h>
|
||||||
#include <kernel/base.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
|
// Returns a pointer to the first entry of the memory map
|
||||||
//
|
//
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// BootInfo_t initialization. It is necessary because grub will potentially be
|
// 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)
|
void InitBootInfo(multiboot_info_t *mbi)
|
||||||
{
|
{
|
||||||
@ -37,41 +37,69 @@ void InitBootInfo(multiboot_info_t *mbi)
|
|||||||
KalAlwaysAssert(mbi);
|
KalAlwaysAssert(mbi);
|
||||||
extern uint MB_header;
|
extern uint MB_header;
|
||||||
|
|
||||||
//Retrieves the bootloader informations
|
//Retrieves the bootloader flags to ensure infos are valid
|
||||||
GetBootInfo(btldr).grubFlags = mbi->flags;
|
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);
|
|
||||||
|
|
||||||
|
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
|
//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).bufferLength = mbi->drives_length;
|
||||||
GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr;
|
GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr;
|
||||||
DebugLog("[InitBootInfo] Root drive : %x\n",
|
GetBootInfo(drives).bufferValid = 1;
|
||||||
GetBootInfo(drives).bootDrv);
|
}
|
||||||
|
if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) == MULTIBOOT_INFO_BOOTDEV) {
|
||||||
|
GetBootInfo(drives).bootDrv = mbi->boot_device;
|
||||||
|
GetBootInfo(drives).drvValid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
//Retrieves the memory informations
|
//Retrieves the memory informations
|
||||||
GetBootInfo(memory).lowMemory = mbi->mem_lower;
|
if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) == MULTIBOOT_INFO_MEMORY) {
|
||||||
GetBootInfo(memory).upMemory = mbi->mem_upper;
|
GetBootInfo(memory).lowMemory = mbi->mem_lower;
|
||||||
GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr;
|
GetBootInfo(memory).upMemory = mbi->mem_upper;
|
||||||
GetBootInfo(memory).mapLength = mbi->mmap_length;
|
GetBootInfo(memory).memValid = 1;
|
||||||
DebugLog("[InitBootInfo] Low memory : %d Kio, Up memory : %d Mio\n",
|
}
|
||||||
GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB));
|
if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) == MULTIBOOT_INFO_MEM_MAP) {
|
||||||
DebugLog("[InitBootInfo] Memory map address : %p, length : %d\n",
|
GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr;
|
||||||
GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength);
|
GetBootInfo(memory).mapLength = mbi->mmap_length;
|
||||||
|
GetBootInfo(memory).mapValid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// XXX assign video infos, but unused at this time
|
// XXX assign video infos, but unused at this time
|
||||||
|
|
||||||
// Retrieves the firmware infos
|
// 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;
|
GetBootInfo(firmware).romTable = mbi->config_table;
|
||||||
DebugLog("[InitBootInfo] APM Table : %p, ROM Table : %p\n",
|
GetBootInfo(firmware).romValid = 1;
|
||||||
GetBootInfo(firmware).apmTable, GetBootInfo(firmware).romTable);
|
}
|
||||||
|
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);
|
InitBootInfo(mbInfo);
|
||||||
|
|
||||||
//Memory mapping
|
//Memory mapping
|
||||||
InitMemoryMap();
|
error_t mapBad = InitMemoryMap();
|
||||||
|
if (mapBad)
|
||||||
|
StartPanic("[Init] The memory map failed to initialize. Error : %d", mapBad);
|
||||||
|
|
||||||
// We're out
|
// We're out
|
||||||
KernLog("\n[Init] Evil never dies !");
|
KernLog("\n[Init] Evil never dies !");
|
||||||
|
@ -27,8 +27,16 @@
|
|||||||
|
|
||||||
error_t InitMemoryMap(void)
|
error_t InitMemoryMap(void)
|
||||||
{
|
{
|
||||||
uint mapIsValid = (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) == MULTIBOOT_INFO_MEM_MAP;
|
if (!GetBootInfo(memory).memValid && GetBootInfo(memory).mapValid)
|
||||||
KalAlwaysAssert(mapIsValid);
|
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;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user