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-28 23:03:26 +01:00
|
|
|
#include <kernel/mboot.h>
|
2019-02-16 23:36:33 +01:00
|
|
|
#include <kernel/panic.h>
|
2019-03-25 17:33:51 +01:00
|
|
|
#include <kernel/sched.h>
|
|
|
|
#include <kernel/heap.h>
|
|
|
|
#include <kernel/buf.h>
|
2019-03-29 14:19:29 +01:00
|
|
|
#include <kernel/log.h>
|
2019-03-18 17:43:41 +01:00
|
|
|
#include <kernel/mm.h>
|
2019-03-11 19:22:37 +01:00
|
|
|
|
2019-03-29 10:29:05 +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
|
|
|
//
|
2019-03-24 14:44:59 +01:00
|
|
|
void BtInitBootInfo(multiboot_info_t *mbi)
|
2019-03-19 00:25:22 +01:00
|
|
|
{
|
2019-03-25 17:33:51 +01:00
|
|
|
extern ulong MB_header;
|
2019-03-25 23:10:06 +01:00
|
|
|
extern ulong newKernelEnd;
|
2019-03-22 15:16:37 +01:00
|
|
|
|
2019-03-19 13:59:54 +01:00
|
|
|
// We need the multiboot structure
|
|
|
|
KalAlwaysAssert(mbi);
|
2019-03-19 12:24:27 +01:00
|
|
|
|
2019-03-21 13:30:17 +01:00
|
|
|
//Retrieves the bootloader flags to ensure infos are valid
|
2019-03-24 14:44:59 +01:00
|
|
|
BtGetBootInfo(btldr).grubFlags = mbi->flags;
|
2019-03-19 00:25:22 +01:00
|
|
|
|
2019-03-24 21:24:21 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
|
2019-03-25 17:33:51 +01:00
|
|
|
BtGetBootInfo(btldr).grubName = (char*)(ulong)(mbi->boot_loader_name);
|
2019-03-24 21:24:21 +01:00
|
|
|
BtGetBootInfo(btldr).kernelAddr = (void*)&MB_header;
|
2019-03-25 23:10:06 +01:00
|
|
|
BtGetBootInfo(btldr).kernelEndAddr = (void*)newKernelEnd;
|
2019-03-24 21:24:21 +01:00
|
|
|
BtGetBootInfo(btldr).valid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) {
|
|
|
|
BtGetBootInfo(btldr).modulesCount = mbi->mods_count;
|
2019-03-25 17:33:51 +01:00
|
|
|
BtGetBootInfo(btldr).modulesAddr = (void*)(ulong)mbi->mods_addr;
|
2019-03-22 15:03:41 +01:00
|
|
|
}
|
2019-03-19 00:25:22 +01:00
|
|
|
//Retrieves the drives informations
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
|
|
|
|
BtGetBootInfo(drives).bufferLength = mbi->drives_length;
|
2019-03-25 17:33:51 +01:00
|
|
|
BtGetBootInfo(drives).bufferAddr = (void*)(ulong)mbi->drives_addr;
|
2019-03-24 14:44:59 +01:00
|
|
|
BtGetBootInfo(drives).bufferValid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) {
|
|
|
|
BtGetBootInfo(drives).bootDrv = mbi->boot_device;
|
|
|
|
BtGetBootInfo(drives).drvValid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-19 12:24:27 +01:00
|
|
|
|
|
|
|
//Retrieves the memory informations
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) {
|
|
|
|
BtGetBootInfo(memory).lowMemory = mbi->mem_lower;
|
|
|
|
BtGetBootInfo(memory).upMemory = mbi->mem_upper;
|
|
|
|
BtGetBootInfo(memory).memValid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) {
|
2019-03-25 17:33:51 +01:00
|
|
|
BtGetBootInfo(memory).mapAddr = (void*)(ulong)mbi->mmap_addr;
|
2019-03-24 14:44:59 +01:00
|
|
|
BtGetBootInfo(memory).mapLength = mbi->mmap_length;
|
|
|
|
BtGetBootInfo(memory).mapValid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-19 12:24:27 +01:00
|
|
|
|
2019-03-23 20:34:32 +01:00
|
|
|
// Retrieves video mode informations
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_VBE_INFO) {
|
2019-03-25 17:33:51 +01:00
|
|
|
BtGetBootInfo(video).vbeControl = (void*)(ulong)mbi->vbe_control_info;
|
|
|
|
BtGetBootInfo(video).vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info;
|
2019-03-24 14:44:59 +01:00
|
|
|
BtGetBootInfo(video).vbeMode = mbi->vbe_mode;
|
|
|
|
BtGetBootInfo(video).vbeInterfaceSeg = mbi->vbe_interface_seg;
|
|
|
|
BtGetBootInfo(video).vbeInterfaceOff = mbi->vbe_interface_off;
|
|
|
|
BtGetBootInfo(video).vbeInterfaceLen = mbi->vbe_interface_len;
|
|
|
|
BtGetBootInfo(video).vbeValid = 1;
|
2019-03-23 20:34:32 +01:00
|
|
|
}
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
2019-03-25 17:33:51 +01:00
|
|
|
BtGetBootInfo(video).framebufferAddr = (void*)mbi->framebuffer_addr;
|
2019-03-24 14:44:59 +01:00
|
|
|
BtGetBootInfo(video).framebufferPitch = mbi->framebuffer_pitch;
|
|
|
|
BtGetBootInfo(video).framebufferWidth = mbi->framebuffer_width;
|
|
|
|
BtGetBootInfo(video).framebufferHeight= mbi->framebuffer_height;
|
|
|
|
BtGetBootInfo(video).framebufferBpp = mbi->framebuffer_bpp;
|
|
|
|
BtGetBootInfo(video).framebufferType = mbi->framebuffer_type;
|
|
|
|
BtGetBootInfo(video).fbuValid = 1;
|
2019-03-23 20:34:32 +01:00
|
|
|
}
|
2019-03-19 12:24:27 +01:00
|
|
|
|
|
|
|
// Retrieves the firmware infos
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
|
|
|
|
BtGetBootInfo(firmware).romTable = mbi->config_table;
|
|
|
|
BtGetBootInfo(firmware).romValid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-24 14:44:59 +01:00
|
|
|
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) {
|
|
|
|
BtGetBootInfo(firmware).apmTable = mbi->apm_table;
|
|
|
|
BtGetBootInfo(firmware).apmValid = 1;
|
2019-03-21 13:30:17 +01:00
|
|
|
}
|
2019-03-19 00:25:22 +01:00
|
|
|
}
|
|
|
|
|
2019-03-25 17:33:51 +01:00
|
|
|
extern void pstest(void);
|
2019-03-29 14:19:29 +01:00
|
|
|
extern error_t IoInitVGABuffer(void);
|
|
|
|
|
|
|
|
#define BARRIER() do{\
|
|
|
|
asm volatile("": : :"memory");__sync_synchronize();}while(0)
|
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-24 14:44:59 +01:00
|
|
|
noreturn void BtStartKern(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-03-24 14:44:59 +01:00
|
|
|
KeDisableIRQs();
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
// Initialize the BootInfo_t structure
|
2019-03-24 14:44:59 +01:00
|
|
|
BtInitBootInfo(mbInfo);
|
2019-03-23 23:52:18 +01:00
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
// Get ready to print things
|
|
|
|
IoInitVGABuffer();
|
|
|
|
|
|
|
|
BARRIER();
|
|
|
|
|
|
|
|
// Hello world
|
2019-03-18 21:14:09 +01:00
|
|
|
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-29 10:29:05 +01:00
|
|
|
|
|
|
|
KernLog("[Init] Kernel successfully loaded at %p with %x magic\n"
|
|
|
|
" and it uses %d Kio\n\n",
|
2019-03-24 14:44:59 +01:00
|
|
|
BtGetBootInfo(btldr).kernelAddr,
|
2019-03-29 10:29:05 +01:00
|
|
|
mbMagic,
|
|
|
|
(BtGetBootInfo(btldr).kernelEndAddr - BtGetBootInfo(btldr).kernelAddr)
|
|
|
|
/ KB
|
2019-03-23 23:52:18 +01:00
|
|
|
);
|
2019-03-19 00:25:22 +01:00
|
|
|
|
2019-03-18 17:43:41 +01:00
|
|
|
//Memory mapping
|
2019-03-29 10:29:05 +01:00
|
|
|
MmInitMemoryMap();
|
2019-03-13 09:19:43 +01:00
|
|
|
|
2019-03-30 12:09:14 +01:00
|
|
|
int i = 0;
|
|
|
|
while(i < 3900) { KernLog("%d\n", i++);}
|
|
|
|
|
2019-03-25 17:33:51 +01:00
|
|
|
MmInitHeap();
|
|
|
|
PsInitSched();
|
2019-03-24 20:25:11 +01:00
|
|
|
|
2019-03-18 17:43:41 +01:00
|
|
|
// We're out
|
2019-03-25 17:33:51 +01:00
|
|
|
PsFiniSched();
|
2019-03-24 14:44:59 +01:00
|
|
|
KeCrashSystem(); //yay
|
2019-03-18 17:43:41 +01:00
|
|
|
}
|