summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-22 11:18:10 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-22 11:20:06 +0100
commitda9920a33d12a2ebd04f4572a6d134dfb6e6cab6 (patch)
treec61a3f26f529b3bd97030614e253b6bb05c216ce /Private
parent223aad0fd3f8af6f69eb6429e5514bc888afe0d9 (diff)
Kernel: Got HCoreLite up and running.
- Working on standard edition of HCoreLdr (Kernel and Bootloader separated) Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private')
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.cpp7
-rw-r--r--Private/HALKit/PowerPC/HalHardware.cxx2
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx4
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx42
-rw-r--r--Private/NewBoot/Source/bundle.mk35
-rw-r--r--Private/NewBoot/Source/standard.mk (renamed from Private/NewBoot/Source/makefile)0
-rw-r--r--Private/Source/KernelHeap.cxx2
-rw-r--r--Private/Source/PageManager.cxx6
8 files changed, 80 insertions, 18 deletions
diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp
index 8920f295..64752520 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.cpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.cpp
@@ -22,14 +22,15 @@ namespace HCore {
namespace HAL {
static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user)
-> PageTable64 * {
- PageTable64 *pte = reinterpret_cast<PageTable64 *>(
- (UIntPtr)kKernelVirtualStart + kPageCnt + kPagePad);
+ PageTable64 *pte =
+ reinterpret_cast<PageTable64 *>((UIntPtr)kKernelVirtualStart);
pte->Rw = rw;
pte->User = user;
pte->Present = true;
- kKernelVirtualStart = (VoidPtr)((UIntPtr)kKernelVirtualStart + kPageCnt + sz);
+ kKernelVirtualStart =
+ (VoidPtr)((UIntPtr)kKernelVirtualStart + kPageCnt + sz + kPagePad);
return pte;
}
diff --git a/Private/HALKit/PowerPC/HalHardware.cxx b/Private/HALKit/PowerPC/HalHardware.cxx
index a5f11449..c066051c 100644
--- a/Private/HALKit/PowerPC/HalHardware.cxx
+++ b/Private/HALKit/PowerPC/HalHardware.cxx
@@ -44,6 +44,4 @@ void ke_com_print(const Char* bytes) {
++index;
}
}
-
-TerminalDevice kcout(HCore::ke_com_print, nullptr);
} // namespace HCore
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index dcb8daf4..093b20dc 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -14,6 +14,10 @@
#pragma once
+class BTextWriter;
+class BFileReader;
+class BFileRunner;
+
#include <BootKit/Arch/ATA.hxx>
#include <EFIKit/EFI.hxx>
#include <NewKit/Defines.hpp>
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index 65cd1e44..0db90e6f 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -24,6 +24,10 @@
#define kHeadersSz \
(sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader))
+#ifdef __BUNDLE_KERNEL__
+EXTERN_C EFI_API void RuntimeMain(HEL::HandoverInformationHeader* HIH);
+#endif
+
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
InitEFI(SystemTable);
@@ -31,25 +35,41 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
BTextWriter writer;
+#ifdef __BUNDLE_KERNEL__
+ writer.WriteString(L"HCoreLite: ");
+#else
+ writer.WriteString(L"HCoreLdr:");
+#endif
+
#ifndef __DEBUG__
- writer.WriteString(L"HCoreLdr: Version 1.00 (Release Channel)\r\n");
+ writer.WriteString(L"Version 1.00 (Release Channel)\r\n");
#else
- writer.WriteString(L"HCoreLdr: Version 1.00 (Insiders Channel)\r\n");
+ writer.WriteString(L"Version 1.00 (Insiders Channel)\r\n");
#endif
const char strDate[] = __DATE__;
+#ifdef __BUNDLE_KERNEL__
+ writer.WriteString(L"HCoreLite: Build: ");
+#else
writer.WriteString(L"HCoreLdr: Build: ");
+#endif
for (auto& ch : strDate) writer.WriteCharacter(ch);
+#ifdef __BUNDLE_KERNEL__
+ writer.WriteString(L"\r\nHCoreLite: Firmware Vendor: ")
+ .WriteString(SystemTable->FirmwareVendor)
+ .WriteString(L"\r\n");
+#else
writer.WriteString(L"\r\nHCoreLdr: Firmware Vendor: ")
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
+#endif
BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
@@ -75,7 +95,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
UInt32 SzDesc = 0;
UInt32 RevDesc = 0;
- if (BS->AllocatePool(EfiLoaderData, sizeof(UInt64), (VoidPtr*)&Size) !=
+ if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&Size) !=
kEfiOk) {
EFI::RaiseHardError(
L"HCoreLdr-BadAlloc",
@@ -108,7 +128,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_PhysicalStart =
reinterpret_cast<voidPtr>(Descriptor->PhysicalStart);
- handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages * kPTESize;
+ handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages;
handoverHdrPtr->f_VirtualStart =
reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
@@ -123,10 +143,22 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
SystemTable->FirmwareVendor,
handoverHdrPtr->f_FirmwareVendorLen);
- writer.WriteString(L"HCoreLdr: Booting HCore...\r\n");
+#ifdef __BUNDLE_KERNEL__
+ writer.WriteString(L"HCoreLite: Exit Boot...").WriteString(L"\r\n");
+#else
+ writer.WriteString(L"HCoreLdr: Load File succeeded, running it...")
+ .WriteString(L"\r\n");
+#endif
EFI::ExitBootServices(MapKey, ImageHandle);
+#ifdef __BUNDLE_KERNEL__
+ RuntimeMain(handoverHdrPtr);
+#else
+ // Load HCoreKrnl.exe (TODO)
+
+#endif // ifdef __BUNDLE_KERNEL__
+
EFI::Stop();
return kEfiOk;
diff --git a/Private/NewBoot/Source/bundle.mk b/Private/NewBoot/Source/bundle.mk
new file mode 100644
index 00000000..c5a83ffb
--- /dev/null
+++ b/Private/NewBoot/Source/bundle.mk
@@ -0,0 +1,35 @@
+##################################################
+# ; (C) Mahrouss Logic, 2024, all rights reserved.
+# This is the bootloader makefile.
+##################################################
+
+CC_GNU=x86_64-w64-mingw32-g++
+LD_GNU=x86_64-w64-mingw32-ld
+LD_FLAGS=-e efi_main -shared --subsystem=10 -ffreestanding
+ASM=nasm
+OBJ=$(wildcard *.obj) $(wildcard *.o) $(wildcard ../../Obj/*.obj) $(wildcard HEL/AMD64/*.obj) $(wildcard HEL/AMD64/*.o)
+
+FLAG_ASM=-f win64
+FLAG_GNU=-fshort-wchar -O0 -D__BUNDLE_KERNEL__ -D__DEBUG__ -fPIC -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/
+
+.PHONY: invalid-recipe
+invalid-recipe:
+ @echo "invalid-recipe: Use make bootloader-<arch> all instead."
+
+.PHONY: bootloader-amd64
+bootloader-amd64:
+ $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx
+ $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm
+ $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreKrnl.exe
+ cp HCoreKrnl.exe CDROM/EFI/BOOT/BOOTX64.EFI
+ cp HCoreKrnl.exe CDROM/HCOREKRNL.EXE
+ cp ../../Root/System/LookAndFeel.css CDROM/LOOK.CSS
+
+.PHONY: run-efi-amd64
+run-efi-amd64:
+ wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
+ qemu-system-x86_64 -net none -smp 2 -m 8G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
+
+.PHONY: clean
+clean:
+ rm -f $(OBJ) HCoreLdr.exe OVMF.fd
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/standard.mk
index fab7453d..fab7453d 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/standard.mk
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 358330f0..10d3fdd2 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -9,8 +9,6 @@
#include <NewKit/KernelHeap.hpp>
-#include "KernelKit/DebugOutput.hpp"
-
//! @file KernelHeap.cpp
//! @brief Kernel allocator.
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index c520da78..c801fe07 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -41,7 +41,6 @@ PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable,
PTEWrapper::~PTEWrapper() {
PTE *raw = reinterpret_cast<PTE *>(m_VirtAddr);
- MUST_PASS(raw);
raw->Present = false;
raw->Rw = false;
@@ -78,11 +77,6 @@ PTEWrapper *PageManager::Request(Boolean Rw, Boolean User,
PTEWrapper *PageTableEntry = reinterpret_cast<PTEWrapper *>(
HCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User));
- if (PageTableEntry == nullptr) {
- kcout << "PTEWrapper : Page table is nullptr!, ke_new_ke_heap failed!\n";
- return nullptr;
- }
-
PageTableEntry->NoExecute(ExecDisable);
*PageTableEntry = PTEWrapper{Rw, User, ExecDisable,