From 398d889c7409570fa3b7b7305427be0408e2c475 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 13 Oct 2022 09:32:26 +0300 Subject: [PATCH] Multiboot2Initializator stub --- Architecture/i686/MultibootInit.cpp | 43 +++++++++++++++++++++++++++++ Architecture/i686/boot.asm | 2 ++ Kernel.cpp | 5 ++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Architecture/i686/MultibootInit.cpp diff --git a/Architecture/i686/MultibootInit.cpp b/Architecture/i686/MultibootInit.cpp new file mode 100644 index 0000000..4712b33 --- /dev/null +++ b/Architecture/i686/MultibootInit.cpp @@ -0,0 +1,43 @@ +#include + +EXTERNC __attribute__((no_stack_protector, section(".multiboot.text"))) void Multiboot2Initializator() +{ + for (int i = 0; i < 2000; i++) + { + ((unsigned int *)0xb8000)[i * 2] = ' '; + ((unsigned int *)0xb8000)[i * 2 + 1] = 0; + } + ((uint8_t *)0xb8000)[2 * (80) * (25) - 2] = 'W'; + ((uint8_t *)0xb8000)[2 * (80) * (25) - 1] = 6; + unsigned char *SMBIOSAddress = (unsigned char *)0xF0000; + while ((unsigned int)(unsigned long)SMBIOSAddress < 0x100000) + { + if (SMBIOSAddress[0] == '_' && + SMBIOSAddress[1] == 'S' && + SMBIOSAddress[2] == 'M' && + SMBIOSAddress[3] == '_') + { + unsigned char Checksum = 0; + int Length = SMBIOSAddress[5]; + for (int i = 0; i < Length; i++) + Checksum += SMBIOSAddress[i]; + + if (Checksum == 0) + break; + } + SMBIOSAddress += 16; + } + + if ((unsigned int)(unsigned long)SMBIOSAddress == 0x100000) + { + // No SMBIOS found + ((uint8_t *)0xb8000)[2 * (80) * (25) - 4] = 'S'; + ((uint8_t *)0xb8000)[2 * (80) * (25) - 3] = 4; + while (1) + asmv("hlt"); + } + + ((uint8_t *)0xb8000)[2 * (80) * (25) - 10] = 'Y'; + ((uint8_t *)0xb8000)[2 * (80) * (25) - 9] = 2; + return; +} diff --git a/Architecture/i686/boot.asm b/Architecture/i686/boot.asm index 277066d..78c1d33 100644 --- a/Architecture/i686/boot.asm +++ b/Architecture/i686/boot.asm @@ -26,6 +26,7 @@ BOOT_PAGE_TBL1: resb 4096 section .multiboot2.text extern x32Entry +extern Multiboot2Initializator extern _kernel_start extern _kernel_end global _start @@ -58,6 +59,7 @@ _start: add edi, 4 loop .PagingLoop .LoopEnd: + call Multiboot2Initializator push ebx mov dword [BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE + (000 * 4)], (BOOT_PAGE_TBL0 - KERNEL_VIRTUAL_BASE + 3) mov dword [BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE + (001 * 4)], (BOOT_PAGE_TBL1 - KERNEL_VIRTUAL_BASE + 3) diff --git a/Kernel.cpp b/Kernel.cpp index 7b2883e..ca38fd8 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -8,6 +8,7 @@ #include #include #include +#include NEWLOCK(KernelLock); @@ -42,9 +43,9 @@ EXTERNC void KPrint(const char *format, ...) EXTERNC void Entry(BootInfo *Info) { - BootClock = ReadClock(); - trace("Hello, World!"); InitializeMemoryManagement(Info); + trace("Hello, World!"); + BootClock = ReadClock(); bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo))); memcpy(bInfo, Info, sizeof(BootInfo)); debug("BootInfo structure is at %p", bInfo);