os-k/kaleid/kernel/init/info.c

118 lines
5.5 KiB
C
Raw Permalink Normal View History

//----------------------------------------------------------------------------//
2020-09-27 17:33:48 +02:00
// OS on Kaleid //
// //
// Desc: Initialization of boot info //
// //
// //
2021-02-18 19:54:35 +01:00
// Copyright © 2018-2021 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
2019-05-13 23:22:27 +02:00
#include <init/boot.h>
//
2020-02-02 13:33:57 +01:00
// BootInfo_t initialization. It is necessary because grub will potentially be
// wiped since it is below 1MB.... And we must reorganize all that stuff.
//
2019-04-22 20:15:32 +02:00
void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg)
{
2019-05-14 14:39:44 +02:00
extern ulong BtHeader;
extern ulong newKernelEnd;
2019-05-13 15:18:00 +02:00
extern ulong newStackEnd;
// We need the multiboot structure
2019-05-13 23:22:27 +02:00
assert_always(mbi);
2019-05-01 14:17:16 +02:00
// Retrieves the bootloader flags to ensure infos are valid
BtLoaderInfo.grubFlags = mbi->flags;
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
BtLoaderInfo.grubName = (char*)(ulong)(mbi->boot_loader_name);
2019-05-14 14:39:44 +02:00
BtLoaderInfo.kernelAddr = (void*)&BtHeader;
BtLoaderInfo.kernelEndAddr = (void*)newKernelEnd;
2019-05-13 15:18:00 +02:00
BtLoaderInfo.stackEndAddr = (void*)newStackEnd;
2019-04-22 20:15:32 +02:00
BtLoaderInfo.codeSegment = codeSeg;
BtLoaderInfo.valid = 1;
}
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MODS) {
BtLoaderInfo.modulesCount = mbi->mods_count;
BtLoaderInfo.modulesAddr = (void*)(ulong)mbi->mods_addr;
}
2019-05-01 14:17:16 +02:00
// Retrieves the drives informations
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
BtBootTab.drives.bufferLength = mbi->drives_length;
BtBootTab.drives.bufferAddr = (void*)(ulong)mbi->drives_addr;
BtBootTab.drives.bufferValid = 1;
}
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOTDEV) {
BtBootTab.drives.bootDrv = mbi->boot_device;
BtBootTab.drives.drvValid = 1;
}
2019-05-01 14:17:16 +02:00
// Retrieves the memory informations
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MEMORY) {
BtMemoryInfo.lowMemory = mbi->mem_lower;
BtMemoryInfo.upMemory = mbi->mem_upper;
BtMemoryInfo.memValid = 1;
}
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MEM_MAP) {
BtMemoryInfo.mapAddr = (void*)(ulong)mbi->mmap_addr;
BtMemoryInfo.mapLength = mbi->mmap_length;
BtMemoryInfo.mapValid = 1;
}
// Retrieves video mode informations
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_VBE_INFO) {
BtVideoInfo.vbeControl = (void*)(ulong)mbi->vbe_control_info;
BtVideoInfo.vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info;
BtVideoInfo.vbeMode = mbi->vbe_mode;
BtVideoInfo.vbeInterfaceSeg = mbi->vbe_interface_seg;
BtVideoInfo.vbeInterfaceOff = mbi->vbe_interface_off;
BtVideoInfo.vbeInterfaceLen = mbi->vbe_interface_len;
BtVideoInfo.vbeValid = 1;
}
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
BtVideoInfo.framebufferAddr = (void*)mbi->framebuffer_addr;
BtVideoInfo.framebufferPitch = mbi->framebuffer_pitch;
BtVideoInfo.framebufferWidth = mbi->framebuffer_width;
BtVideoInfo.framebufferHeight= mbi->framebuffer_height;
BtVideoInfo.framebufferBpp = mbi->framebuffer_bpp;
BtVideoInfo.framebufferType = mbi->framebuffer_type;
BtVideoInfo.fbuValid = 1;
}
// Retrieves the firmware infos
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
BtFirmwareInfo.romTable = mbi->config_table;
BtFirmwareInfo.romValid = 1;
}
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_APM_TABLE) {
BtFirmwareInfo.apmTable = mbi->apm_table;
BtFirmwareInfo.apmValid = 1;
}
}
void BtDoSanityChecks(uint mbMagic) {
if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC))
2019-05-18 13:39:58 +02:00
KeStartPanic("Magic number %x is incorrect\n", mbMagic);
2020-02-06 13:18:22 +01:00
DebugLog("Kernel successfully loaded at %p\n",
2019-05-14 14:39:44 +02:00
BtLoaderInfo.kernelAddr);
}