//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Kernel entry point //
// //
// //
// Copyright © 2018-2019 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 . //
//----------------------------------------------------------------------------//
#include
#include
#include
#include
#include
#include
#include
//
// BootInfo_t initialization. It is necessary because grub will potentially be
// wiped since it is below 1MB.... And we must reorganize all that stuff.
//
void BtInitBootInfo(multiboot_info_t *mbi)
{
extern ulong MB_header;
extern ulong newKernelEnd;
// We need the multiboot structure
KalAlwaysAssert(mbi);
//Retrieves the bootloader flags to ensure infos are valid
BtBootTab.btldr.grubFlags = mbi->flags;
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
BtBootTab.btldr.grubName = (char*)(ulong)(mbi->boot_loader_name);
BtBootTab.btldr.kernelAddr = (void*)&MB_header;
BtBootTab.btldr.kernelEndAddr = (void*)newKernelEnd;
BtBootTab.btldr.valid = 1;
}
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_MODS) {
BtBootTab.btldr.modulesCount = mbi->mods_count;
BtBootTab.btldr.modulesAddr = (void*)(ulong)mbi->mods_addr;
}
//Retrieves the drives informations
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
BtBootTab.drives.bufferLength = mbi->drives_length;
BtBootTab.drives.bufferAddr = (void*)(ulong)mbi->drives_addr;
BtBootTab.drives.bufferValid = 1;
}
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_BOOTDEV) {
BtBootTab.drives.bootDrv = mbi->boot_device;
BtBootTab.drives.drvValid = 1;
}
//Retrieves the memory informations
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_MEMORY) {
BtBootTab.memory.lowMemory = mbi->mem_lower;
BtBootTab.memory.upMemory = mbi->mem_upper;
BtBootTab.memory.memValid = 1;
}
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_MEM_MAP) {
BtBootTab.memory.mapAddr = (void*)(ulong)mbi->mmap_addr;
BtBootTab.memory.mapLength = mbi->mmap_length;
BtBootTab.memory.mapValid = 1;
}
// Retrieves video mode informations
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_VBE_INFO) {
BtBootTab.video.vbeControl = (void*)(ulong)mbi->vbe_control_info;
BtBootTab.video.vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info;
BtBootTab.video.vbeMode = mbi->vbe_mode;
BtBootTab.video.vbeInterfaceSeg = mbi->vbe_interface_seg;
BtBootTab.video.vbeInterfaceOff = mbi->vbe_interface_off;
BtBootTab.video.vbeInterfaceLen = mbi->vbe_interface_len;
BtBootTab.video.vbeValid = 1;
}
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
BtBootTab.video.framebufferAddr = (void*)mbi->framebuffer_addr;
BtBootTab.video.framebufferPitch = mbi->framebuffer_pitch;
BtBootTab.video.framebufferWidth = mbi->framebuffer_width;
BtBootTab.video.framebufferHeight= mbi->framebuffer_height;
BtBootTab.video.framebufferBpp = mbi->framebuffer_bpp;
BtBootTab.video.framebufferType = mbi->framebuffer_type;
BtBootTab.video.fbuValid = 1;
}
// Retrieves the firmware infos
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
BtBootTab.firmware.romTable = mbi->config_table;
BtBootTab.firmware.romValid = 1;
}
if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_APM_TABLE) {
BtBootTab.firmware.apmTable = mbi->apm_table;
BtBootTab.firmware.apmValid = 1;
}
}
void BtInitSanity(uint mbMagic){
uint tmp;
KernLog("%c%c%c OS/K\n \n", 219, 219, 219);
if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC))
KeStartPanic("[Init] Magic number %x is incorrect\n", mbMagic);
tmp = (BtBootTab.btldr.kernelEndAddr
- BtBootTab.btldr.kernelAddr) / KB;
DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n"
" and it uses %d Kio\n\n",
BtBootTab.btldr.kernelAddr,
mbMagic,tmp);
}
extern void pstest(void);
extern error_t IoInitVGABuffer(void);
//
// Entry point of the Kaleid kernel
//
noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
{
// We're not ready to deal with interrupts
KeDisableIRQs();
// Initialize the BootInfo_t structure
BtInitBootInfo(mbInfo);
// Screen I/O available from this point on
IoInitVGABuffer();
// Sanity checks and hello world
BtInitSanity(mbMagic);
// Memory & scheduler
MmInitMemoryMap();
MmInitHeap();
PsInitSched();
KeStartPanic("Test Panic %d", 4);
// End this machine's suffering
KeCrashSystem();
}