2018-12-20 18:03:39 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
2019-03-08 09:00:55 +01:00
|
|
|
// Desc: Kernel entry point //
|
2018-12-20 18:03:39 +01:00
|
|
|
// //
|
2019-02-16 23:36:33 +01:00
|
|
|
// //
|
|
|
|
// 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 <https://www.gnu.org/licenses/>. //
|
2018-12-20 18:03:39 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-03-18 17:25:44 +01:00
|
|
|
|
2019-03-19 13:38:09 +01:00
|
|
|
#include <kernel/multiboot.h>
|
2019-02-16 23:36:33 +01:00
|
|
|
#include <kernel/term.h>
|
|
|
|
#include <kernel/panic.h>
|
2019-03-18 17:43:41 +01:00
|
|
|
#include <kernel/mm.h>
|
2019-03-11 19:22:37 +01:00
|
|
|
|
2019-03-19 00:25:22 +01:00
|
|
|
//
|
|
|
|
// BootInfo_t initialization. It is necessary because grub will potentially be
|
2019-03-21 13:30:17 +01:00
|
|
|
// wiped since it is below 1MB.... And we must reorganize all that stuff.
|
2019-03-19 00:25:22 +01:00
|
|
|
//
|
|
|
|
void InitBootInfo(multiboot_info_t *mbi)
|
|
|
|
{
|
2019-03-19 13:59:54 +01:00
|
|
|
// We need the multiboot structure
|
|
|
|
KalAlwaysAssert(mbi);
|
2019-03-19 12:24:27 +01:00
|
|
|
extern uint MB_header;
|
|
|
|
|
2019-03-21 13:30:17 +01:00
|
|
|
//Retrieves the bootloader flags to ensure infos are valid
|
|
|
|
GetBootInfo(btldr).grubFlags = mbi->flags;
|
2019-03-19 00:25:22 +01:00
|
|
|
|
2019-03-21 13:30:17 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-03-19 00:25:22 +01:00
|
|
|
//Retrieves the drives informations
|
2019-03-21 13:30:17 +01:00
|
|
|
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;
|
|
|
|
GetBootInfo(drives).bufferValid = 1;
|
|
|
|
}
|
|
|
|
if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) == MULTIBOOT_INFO_BOOTDEV) {
|
|
|
|
GetBootInfo(drives).bootDrv = mbi->boot_device;
|
|
|
|
GetBootInfo(drives).drvValid = 1;
|
|
|
|
}
|
2019-03-19 12:24:27 +01:00
|
|
|
|
|
|
|
//Retrieves the memory informations
|
2019-03-21 13:30:17 +01:00
|
|
|
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;
|
|
|
|
GetBootInfo(memory).mapValid = 1;
|
|
|
|
}
|
2019-03-19 12:24:27 +01:00
|
|
|
|
|
|
|
// XXX assign video infos, but unused at this time
|
|
|
|
|
|
|
|
// Retrieves the firmware infos
|
2019-03-21 13:30:17 +01:00
|
|
|
if ((GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) == MULTIBOOT_INFO_CONFIG_TABLE) {
|
|
|
|
GetBootInfo(firmware).romTable = mbi->config_table;
|
|
|
|
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");
|
2019-03-19 00:25:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-25 19:09:58 +01:00
|
|
|
//
|
2019-02-16 23:36:33 +01:00
|
|
|
// Entry point of the Kaleid kernel
|
2018-12-25 19:09:58 +01:00
|
|
|
//
|
2019-03-12 23:25:30 +01:00
|
|
|
noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic)
|
2018-12-29 23:51:00 +01:00
|
|
|
{
|
2019-02-16 23:36:33 +01:00
|
|
|
// We're not ready to deal with interrupts
|
2019-01-14 14:31:49 +01:00
|
|
|
DisableIRQs();
|
|
|
|
|
2019-02-16 23:36:33 +01:00
|
|
|
// Kernel terminals
|
2019-01-01 13:09:57 +01:00
|
|
|
InitTerms();
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-18 21:14:09 +01:00
|
|
|
//Hello world because why not
|
|
|
|
KernLog("%c%c%c OS/K\n\n", 219, 219, 219);
|
2019-03-19 13:38:09 +01:00
|
|
|
|
|
|
|
KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC);
|
2019-03-18 21:14:09 +01:00
|
|
|
KernLog("[Init] We have magic : %x\n", mbMagic);
|
|
|
|
|
2019-03-19 00:25:22 +01:00
|
|
|
//Initialize the BootInfo_t structure
|
|
|
|
InitBootInfo(mbInfo);
|
|
|
|
|
2019-03-18 17:43:41 +01:00
|
|
|
//Memory mapping
|
2019-03-21 13:30:17 +01:00
|
|
|
error_t mapBad = InitMemoryMap();
|
|
|
|
if (mapBad)
|
|
|
|
StartPanic("[Init] The memory map failed to initialize. Error : %d", mapBad);
|
2019-03-13 09:19:43 +01:00
|
|
|
|
2019-03-18 17:43:41 +01:00
|
|
|
// We're out
|
2019-03-19 12:24:27 +01:00
|
|
|
KernLog("\n[Init] Evil never dies !");
|
2019-03-18 17:43:41 +01:00
|
|
|
CrashSystem(); //yay
|
|
|
|
}
|