//----------------------------------------------------------------------------// // 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 // // 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 InitBootInfo(multiboot_info_t *mbi) { extern uint MB_header; char *okStr = "available"; char *noStr = "unavailable"; // We need the multiboot structure KalAlwaysAssert(mbi); //Retrieves the bootloader flags to ensure infos are valid GetBootInfo(btldr).grubFlags = mbi->flags; if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) { GetBootInfo(btldr).grubName = (char*)(ullong)(mbi->boot_loader_name); GetBootInfo(btldr).mbHeaderAddr = (void*)(ullong)&MB_header; GetBootInfo(btldr).valid = 1; } if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) { GetBootInfo(btldr).modulesCount = mbi->mods_count; GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr; } //Retrieves the drives informations if (GetBootInfo(btldr).grubFlags & 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) { GetBootInfo(drives).bootDrv = mbi->boot_device; GetBootInfo(drives).drvValid = 1; } //Retrieves the memory informations if (GetBootInfo(btldr).grubFlags & 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) { GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr; GetBootInfo(memory).mapLength = mbi->mmap_length; GetBootInfo(memory).mapValid = 1; } // Retrieves video mode informations if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_VBE_INFO) { GetBootInfo(video).vbeControl = (void*)(ullong)mbi->vbe_control_info; GetBootInfo(video).vbeModeInfo = (void*)(ullong)mbi->vbe_mode_info; GetBootInfo(video).vbeMode = mbi->vbe_mode; GetBootInfo(video).vbeInterfaceSeg = mbi->vbe_interface_seg; GetBootInfo(video).vbeInterfaceOff = mbi->vbe_interface_off; GetBootInfo(video).vbeInterfaceLen = mbi->vbe_interface_len; GetBootInfo(video).vbeValid = 1; } if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) { GetBootInfo(video).framebufferAddr = (void*)(ullong)mbi->framebuffer_addr; GetBootInfo(video).framebufferPitch = mbi->framebuffer_pitch; GetBootInfo(video).framebufferWidth = mbi->framebuffer_width; GetBootInfo(video).framebufferHeight= mbi->framebuffer_height; GetBootInfo(video).framebufferBpp = mbi->framebuffer_bpp; GetBootInfo(video).framebufferType = mbi->framebuffer_type; GetBootInfo(video).fbuValid = 1; } // Retrieves the firmware infos if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) { GetBootInfo(firmware).romTable = mbi->config_table; GetBootInfo(firmware).romValid = 1; } if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) { GetBootInfo(firmware).apmTable = mbi->apm_table; GetBootInfo(firmware).apmValid = 1; } //Now we check (debug) /*DebugLog("[InitBootInfo] Flags : %b\n\n", GetBootInfo(btldr).grubFlags);*/ DebugLog("[InitBootInfo] Boot loader %s\n", GetBootInfo(btldr).valid ? okStr : noStr); DebugLog("[InitBootInfo] Boot drive %s\n", GetBootInfo(drives).drvValid ? okStr : noStr); DebugLog("[InitBootInfo] Disk buffer %s\n", GetBootInfo(drives).bufferValid ? okStr : noStr); DebugLog("[InitBootInfo] Basic mem %s\n", GetBootInfo(memory).memValid ? okStr : noStr); DebugLog("[InitBootInfo] Memory map %s\n", GetBootInfo(memory).mapValid ? okStr : noStr); DebugLog("[InitBootInfo] Video infos %s\n", GetBootInfo(video).vbeValid ? okStr : noStr); DebugLog("[InitBootInfo] Framebuffer %s\n", GetBootInfo(video).fbuValid ? okStr : noStr); DebugLog("[InitBootInfo] ROM table %s\n", GetBootInfo(firmware).romValid ? okStr : noStr); DebugLog("[InitBootInfo] APM table %s\n\n", GetBootInfo(firmware).apmValid ? okStr : noStr); } // // Entry point of the Kaleid kernel // noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) { // We're not ready to deal with interrupts DisableIRQs(); // Kernel terminals InitTerms(); //Hello world because why not KernLog("%c%c%c OS/K\n\n", 219, 219, 219); KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC); KernLog("[Init] We have magic : %x\n\n", mbMagic); //Initialize the BootInfo_t structure InitBootInfo(mbInfo); //Memory mapping 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 !"); CrashSystem(); //yay }