From 1be243700efc9e36060c5fb65c951d5db6b98e94 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 30 Jan 2024 17:59:15 +0100 Subject: Add ROADMAP details, add EFI Library for bootloader. Add assignee to code in MailMap. Signed-off-by: Amlal El Mahrouss --- MailMap | 2 +- Private/ArchKit/Arch.hpp | 2 +- Private/EFIKit/EFI.hxx | 8 +-- Private/EFIKit/EFILib.hxx | 53 ++++++++++++++++ Private/EFIKit/UEFI.hxx | 10 +++ Private/HALKit/AMD64/HardwareInit.cpp | 2 +- Private/HALKit/AXP/CR.s | 11 ++++ Private/HALKit/AXP/CoreInterruptHandlerDEC.cpp | 0 Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp | 21 ++++++ Private/HALKit/AXP/HAL.s | 13 ++++ Private/HALKit/AXP/Processor.hpp | 10 +++ Private/HALKit/AXP/README | 1 + Private/HALKit/AXP/README.TXT | 1 + Private/HALKit/AXP/SYSCALL.s | 10 +++ Private/HALKit/AXP/VM.s | 5 ++ Private/HALKit/Alpha/CR.s | 11 ---- Private/HALKit/Alpha/CoreInterruptHandlerDEC.cpp | 0 Private/HALKit/Alpha/CoreSyscallHandlerDEC.cpp | 21 ------ Private/HALKit/Alpha/HAL.s | 13 ---- Private/HALKit/Alpha/Processor.hpp | 10 --- Private/HALKit/Alpha/README | 1 - Private/HALKit/Alpha/SYSCALL.s | 10 --- Private/HALKit/Alpha/VM.s | 5 -- Private/HALKit/PowerPC/Processor.cpp | 2 +- Private/NewBoot/BootKit/Boot.hxx | 81 ------------------------ Private/NewBoot/BootKit/BootKit.hxx | 81 ++++++++++++++++++++++++ Private/NewBoot/Source/HEL/AMD64/Boot.cxx | 68 -------------------- Private/NewBoot/Source/HEL/AMD64/BootKit.cxx | 68 ++++++++++++++++++++ Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 25 ++------ Private/NewKit/KernelHeap.hpp | 5 +- Private/NewKit/UserHeap.hpp | 39 ++++++------ Private/NewKit/Utils.hpp | 8 +-- Private/Source/CodeManager.cxx | 4 +- Private/Source/KernelHeap.cxx | 13 +++- Private/Source/New+Delete.cxx | 10 +-- Private/Source/PageManager.cxx | 2 +- Private/Source/ProcessManager.cxx | 10 +-- Private/Source/RuntimeMain.cxx | 7 +- Private/Source/URL.cxx | 2 +- Private/Source/UserHeap.cxx | 24 +++---- Private/Source/Utils.cxx | 8 +-- TODO_LIST.TXT | 9 +++ 42 files changed, 376 insertions(+), 310 deletions(-) create mode 100644 Private/EFIKit/EFILib.hxx create mode 100644 Private/EFIKit/UEFI.hxx create mode 100644 Private/HALKit/AXP/CR.s create mode 100644 Private/HALKit/AXP/CoreInterruptHandlerDEC.cpp create mode 100644 Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp create mode 100644 Private/HALKit/AXP/HAL.s create mode 100644 Private/HALKit/AXP/Processor.hpp create mode 100644 Private/HALKit/AXP/README create mode 100644 Private/HALKit/AXP/README.TXT create mode 100644 Private/HALKit/AXP/SYSCALL.s create mode 100644 Private/HALKit/AXP/VM.s delete mode 100644 Private/HALKit/Alpha/CR.s delete mode 100644 Private/HALKit/Alpha/CoreInterruptHandlerDEC.cpp delete mode 100644 Private/HALKit/Alpha/CoreSyscallHandlerDEC.cpp delete mode 100644 Private/HALKit/Alpha/HAL.s delete mode 100644 Private/HALKit/Alpha/Processor.hpp delete mode 100644 Private/HALKit/Alpha/README delete mode 100644 Private/HALKit/Alpha/SYSCALL.s delete mode 100644 Private/HALKit/Alpha/VM.s delete mode 100644 Private/NewBoot/BootKit/Boot.hxx create mode 100644 Private/NewBoot/BootKit/BootKit.hxx delete mode 100644 Private/NewBoot/Source/HEL/AMD64/Boot.cxx create mode 100644 Private/NewBoot/Source/HEL/AMD64/BootKit.cxx diff --git a/MailMap b/MailMap index 1a345d53..126cdd13 100644 --- a/MailMap +++ b/MailMap @@ -1 +1 @@ -amlel - amlalelmahrouss@icloud.com, amlal@mahrouss.com +33 6 58 57 30 14 +amlel - Microkernel,Bootloader - amlalelmahrouss@icloud.com, +33 6 58 57 30 14 diff --git a/Private/ArchKit/Arch.hpp b/Private/ArchKit/Arch.hpp index 4cfa5e0e..b2ae36bc 100644 --- a/Private/ArchKit/Arch.hpp +++ b/Private/ArchKit/Arch.hpp @@ -71,7 +71,7 @@ namespace HCore return hash; } - bool init_hal(); + bool ke_init_hal(); } // namespace HCore #define kMaxSyscalls 0x100 diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx index 969b42b2..febed042 100644 --- a/Private/EFIKit/EFI.hxx +++ b/Private/EFIKit/EFI.hxx @@ -11,12 +11,11 @@ #define __EFI__ /** -@brief HCore Implementation of UEFI protocols. +@brief HCore Implementation of EFI. @author Amlal El Mahrouss */ #include -#include using namespace HCore; @@ -30,11 +29,12 @@ struct EfiBootServices; struct EfiMemoryDescriptor; struct EfiSystemTable; -// Types - +/// @brief Core Handle Type +/// This is like NT's Win32 HANDLE type. typedef struct { } *EfiHandlePtr; +/* UEFI uses wide characters by default. */ typedef WideChar EfiCharType; /// What's BootBolicy? diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx new file mode 100644 index 00000000..6925d89c --- /dev/null +++ b/Private/EFIKit/EFILib.hxx @@ -0,0 +1,53 @@ +/* + * ======================================================== + * + * h-core + * Copyright 2024, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef __EFI_LIB__ +#define __EFI_LIB__ + +#include + +inline EfiSystemTable* ST = nullptr; +inline EfiBootServices* BS = nullptr; + +namespace Detail { +/** +@brief Stop Execution of Bootloader. +@param SystemTable EFI System Table. +*/ +Void Stop(EfiSystemTable* SystemTable) noexcept { + while (true) { + rt_cli(); + rt_halt(); + } +} +} // namespace Detail + +inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept { + ST = SystemTable; + BS = ST->BootServices; +} + +inline void KeRuntimeStop(const EfiCharType* File, + const EfiCharType* Reason) noexcept { + ST->ConOut->OutputString(ST->ConOut, L"*** STOP ***\r\n"); + + ST->ConOut->OutputString(ST->ConOut, L"*** File:"); + ST->ConOut->OutputString(ST->ConOut, File); + ST->ConOut->OutputString(ST->ConOut, L", Reason:"); + ST->ConOut->OutputString(ST->ConOut, Reason); + ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); + + Detail::Stop(ST); +} + +#ifdef __BOOTLOADER__ +#include +#endif // IF TARGET=BOOTLOADER + +#endif /* ifndef __EFI_LIB__ */ diff --git a/Private/EFIKit/UEFI.hxx b/Private/EFIKit/UEFI.hxx new file mode 100644 index 00000000..aeee81cb --- /dev/null +++ b/Private/EFIKit/UEFI.hxx @@ -0,0 +1,10 @@ +/* + * ======================================================== + * + * h-core + * Copyright 2024, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include diff --git a/Private/HALKit/AMD64/HardwareInit.cpp b/Private/HALKit/AMD64/HardwareInit.cpp index db84226b..1856cc2d 100644 --- a/Private/HALKit/AMD64/HardwareInit.cpp +++ b/Private/HALKit/AMD64/HardwareInit.cpp @@ -12,7 +12,7 @@ // bugs = 0 namespace HCore { -bool init_hal() { +bool ke_init_hal() { // TODO: Hardware Specific stuff. return true; diff --git a/Private/HALKit/AXP/CR.s b/Private/HALKit/AXP/CR.s new file mode 100644 index 00000000..b01dc619 --- /dev/null +++ b/Private/HALKit/AXP/CR.s @@ -0,0 +1,11 @@ +.globl read_lr1 +.globl read_lr0 + +.section .text + read_lr0: + movq %r30, %cr3 + ret + + read_cr0: + movq %r30, %cr0 + ret \ No newline at end of file diff --git a/Private/HALKit/AXP/CoreInterruptHandlerDEC.cpp b/Private/HALKit/AXP/CoreInterruptHandlerDEC.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp new file mode 100644 index 00000000..0881f9c6 --- /dev/null +++ b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -0,0 +1,21 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include +#include + +HCore::Array kSyscalls; + +extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) +{ + for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) + { + (kSyscalls[index].Leak().Leak())(stack->ID, stack); + } +} diff --git a/Private/HALKit/AXP/HAL.s b/Private/HALKit/AXP/HAL.s new file mode 100644 index 00000000..46127130 --- /dev/null +++ b/Private/HALKit/AXP/HAL.s @@ -0,0 +1,13 @@ +.globl rt_wait_for_io + +.section .text +rt_wait_for_io: + jmp .L +.L: + jmp .L2 + wtint ;; wait for interrupt +.L2: + + ret + + diff --git a/Private/HALKit/AXP/Processor.hpp b/Private/HALKit/AXP/Processor.hpp new file mode 100644 index 00000000..e6a00db3 --- /dev/null +++ b/Private/HALKit/AXP/Processor.hpp @@ -0,0 +1,10 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once \ No newline at end of file diff --git a/Private/HALKit/AXP/README b/Private/HALKit/AXP/README new file mode 100644 index 00000000..91e7b134 --- /dev/null +++ b/Private/HALKit/AXP/README @@ -0,0 +1 @@ +This is for DEC Alpha. diff --git a/Private/HALKit/AXP/README.TXT b/Private/HALKit/AXP/README.TXT new file mode 100644 index 00000000..03c2b816 --- /dev/null +++ b/Private/HALKit/AXP/README.TXT @@ -0,0 +1 @@ +A Toy HAL to test the Kernel portability. diff --git a/Private/HALKit/AXP/SYSCALL.s b/Private/HALKit/AXP/SYSCALL.s new file mode 100644 index 00000000..19cab808 --- /dev/null +++ b/Private/HALKit/AXP/SYSCALL.s @@ -0,0 +1,10 @@ +.section .text +system_handle_user_call: + .cfi_startproc + + push %r0 + jmp %r1 + mov %r30, %r2 + + .cfi_endproc + retsys \ No newline at end of file diff --git a/Private/HALKit/AXP/VM.s b/Private/HALKit/AXP/VM.s new file mode 100644 index 00000000..d8d7aa71 --- /dev/null +++ b/Private/HALKit/AXP/VM.s @@ -0,0 +1,5 @@ +.global flush_tlb + +.section .text +flush_tlb: + swppal \ No newline at end of file diff --git a/Private/HALKit/Alpha/CR.s b/Private/HALKit/Alpha/CR.s deleted file mode 100644 index b01dc619..00000000 --- a/Private/HALKit/Alpha/CR.s +++ /dev/null @@ -1,11 +0,0 @@ -.globl read_lr1 -.globl read_lr0 - -.section .text - read_lr0: - movq %r30, %cr3 - ret - - read_cr0: - movq %r30, %cr0 - ret \ No newline at end of file diff --git a/Private/HALKit/Alpha/CoreInterruptHandlerDEC.cpp b/Private/HALKit/Alpha/CoreInterruptHandlerDEC.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/HALKit/Alpha/CoreSyscallHandlerDEC.cpp b/Private/HALKit/Alpha/CoreSyscallHandlerDEC.cpp deleted file mode 100644 index 0881f9c6..00000000 --- a/Private/HALKit/Alpha/CoreSyscallHandlerDEC.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include -#include - -HCore::Array kSyscalls; - -extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) -{ - for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) - { - (kSyscalls[index].Leak().Leak())(stack->ID, stack); - } -} diff --git a/Private/HALKit/Alpha/HAL.s b/Private/HALKit/Alpha/HAL.s deleted file mode 100644 index 46127130..00000000 --- a/Private/HALKit/Alpha/HAL.s +++ /dev/null @@ -1,13 +0,0 @@ -.globl rt_wait_for_io - -.section .text -rt_wait_for_io: - jmp .L -.L: - jmp .L2 - wtint ;; wait for interrupt -.L2: - - ret - - diff --git a/Private/HALKit/Alpha/Processor.hpp b/Private/HALKit/Alpha/Processor.hpp deleted file mode 100644 index e6a00db3..00000000 --- a/Private/HALKit/Alpha/Processor.hpp +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once \ No newline at end of file diff --git a/Private/HALKit/Alpha/README b/Private/HALKit/Alpha/README deleted file mode 100644 index 91e7b134..00000000 --- a/Private/HALKit/Alpha/README +++ /dev/null @@ -1 +0,0 @@ -This is for DEC Alpha. diff --git a/Private/HALKit/Alpha/SYSCALL.s b/Private/HALKit/Alpha/SYSCALL.s deleted file mode 100644 index 19cab808..00000000 --- a/Private/HALKit/Alpha/SYSCALL.s +++ /dev/null @@ -1,10 +0,0 @@ -.section .text -system_handle_user_call: - .cfi_startproc - - push %r0 - jmp %r1 - mov %r30, %r2 - - .cfi_endproc - retsys \ No newline at end of file diff --git a/Private/HALKit/Alpha/VM.s b/Private/HALKit/Alpha/VM.s deleted file mode 100644 index d8d7aa71..00000000 --- a/Private/HALKit/Alpha/VM.s +++ /dev/null @@ -1,5 +0,0 @@ -.global flush_tlb - -.section .text -flush_tlb: - swppal \ No newline at end of file diff --git a/Private/HALKit/PowerPC/Processor.cpp b/Private/HALKit/PowerPC/Processor.cpp index 9ac0953e..04676eff 100644 --- a/Private/HALKit/PowerPC/Processor.cpp +++ b/Private/HALKit/PowerPC/Processor.cpp @@ -30,7 +30,7 @@ void rt_wakeup_thread(HAL::StackFrame* stack) {} void rt_hang_thread(HAL::StackFrame* stack) {} // @brief main HAL entrypoint -void init_hal() {} +void ke_init_hal() {} void system_io_print(const char* bytes) { if (!bytes) return; diff --git a/Private/NewBoot/BootKit/Boot.hxx b/Private/NewBoot/BootKit/Boot.hxx deleted file mode 100644 index 70607a9c..00000000 --- a/Private/NewBoot/BootKit/Boot.hxx +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -/***********************************************************************************/ -/// @file Boot.hxx -/// @brief Bootloader API. -/***********************************************************************************/ - -#pragma once - -#include - -using namespace HCore; - -typedef void *PEFImage; - -enum { - kSegmentCode = 2, - kSegmentData = 4, - kSegmentBss = 6, -}; - -/** - * @brief BootKit Text Writer class - * Writes to VGA. - */ -class BKTextWriter final { - volatile UInt16 *fWhere{nullptr}; - - public: - void WriteString(const char *c, unsigned char forecolour, - unsigned char backcolour, int x, int y); - - void WriteCharacter(char c, unsigned char forecolour, - unsigned char backcolour, int x, int y); - - public: - BKTextWriter() = default; - ~BKTextWriter() = default; - - public: - BKTextWriter &operator=(const BKTextWriter &) = default; - BKTextWriter(const BKTextWriter &) = default; -}; - -enum { - kBlack, - kBlue, - kGreen, - kCyan, - kRed, - kMagenta, - kBrown, - kLightGray, - kDarkGray, - kLightBlue, - kLightGreen, - kLightCyan, - kLightRed, - kLightMagenta, - kYellow, - kWhite, -}; - -#define BK_START_KERNEL (0x8000000) - -HCore::SizeT BStrLen(const char *ptr); -HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len); - -/***********************************************************************************/ -/// Include other APIs. -/***********************************************************************************/ - -#include -#include diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx new file mode 100644 index 00000000..70607a9c --- /dev/null +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -0,0 +1,81 @@ +/* + * ======================================================== + * + * NewBoot + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +/***********************************************************************************/ +/// @file Boot.hxx +/// @brief Bootloader API. +/***********************************************************************************/ + +#pragma once + +#include + +using namespace HCore; + +typedef void *PEFImage; + +enum { + kSegmentCode = 2, + kSegmentData = 4, + kSegmentBss = 6, +}; + +/** + * @brief BootKit Text Writer class + * Writes to VGA. + */ +class BKTextWriter final { + volatile UInt16 *fWhere{nullptr}; + + public: + void WriteString(const char *c, unsigned char forecolour, + unsigned char backcolour, int x, int y); + + void WriteCharacter(char c, unsigned char forecolour, + unsigned char backcolour, int x, int y); + + public: + BKTextWriter() = default; + ~BKTextWriter() = default; + + public: + BKTextWriter &operator=(const BKTextWriter &) = default; + BKTextWriter(const BKTextWriter &) = default; +}; + +enum { + kBlack, + kBlue, + kGreen, + kCyan, + kRed, + kMagenta, + kBrown, + kLightGray, + kDarkGray, + kLightBlue, + kLightGreen, + kLightCyan, + kLightRed, + kLightMagenta, + kYellow, + kWhite, +}; + +#define BK_START_KERNEL (0x8000000) + +HCore::SizeT BStrLen(const char *ptr); +HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len); + +/***********************************************************************************/ +/// Include other APIs. +/***********************************************************************************/ + +#include +#include diff --git a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx deleted file mode 100644 index b3ff2206..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -constexpr HCore::UInt32 kVGABaseAddress = 0xb8000; - -HCore::SizeT BStrLen(const char *ptr) { - long long int cnt = 0; - - while (*ptr != 0) { - ++ptr; - ++cnt; - } - - return cnt; -} - -HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len) { - HCore::SizeT cnt = 0UL; - - while (*src != 0) { - if (cnt > len) break; - - *src = byte; - ++src; - - ++cnt; - } - - return cnt; -} - -/** -@brief puts wrapper over VGA. -*/ -void BKTextWriter::WriteString(const char *str, unsigned char forecolour, - unsigned char backcolour, int x, int y) { - if (*str == 0 || !str) return; - - for (SizeT idx = 0; idx < BStrLen(str); ++idx) { - this->WriteCharacter(str[idx], forecolour, backcolour, x, y); - ++x; - } -} - -/** -@brief putc wrapper over VGA. -*/ -void BKTextWriter::WriteCharacter(char c, unsigned char forecolour, - unsigned char backcolour, int x, int y) { - UInt16 attrib = (backcolour << 4) | (forecolour & 0x0F); - - // Video Graphics Array - // Reads at kVGABaseAddress - // Decodes UInt16, gets attributes (back colour, fore colour) - // Gets character, send it to video display with according colour in the - // registry. - - fWhere = (volatile UInt16 *)kVGABaseAddress + (y * 80 + x); - *fWhere = c | (attrib << 8); -} diff --git a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx new file mode 100644 index 00000000..68971e0c --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx @@ -0,0 +1,68 @@ +/* + * ======================================================== + * + * NewBoot + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +constexpr HCore::UInt32 kVGABaseAddress = 0xb8000; + +HCore::SizeT BStrLen(const char *ptr) { + long long int cnt = 0; + + while (*ptr != 0) { + ++ptr; + ++cnt; + } + + return cnt; +} + +HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len) { + HCore::SizeT cnt = 0UL; + + while (*src != 0) { + if (cnt > len) break; + + *src = byte; + ++src; + + ++cnt; + } + + return cnt; +} + +/** +@brief puts wrapper over VGA. +*/ +void BKTextWriter::WriteString(const char *str, unsigned char forecolour, + unsigned char backcolour, int x, int y) { + if (*str == 0 || !str) return; + + for (SizeT idx = 0; idx < BStrLen(str); ++idx) { + this->WriteCharacter(str[idx], forecolour, backcolour, x, y); + ++x; + } +} + +/** +@brief putc wrapper over VGA. +*/ +void BKTextWriter::WriteCharacter(char c, unsigned char forecolour, + unsigned char backcolour, int x, int y) { + UInt16 attrib = (backcolour << 4) | (forecolour & 0x0F); + + // Video Graphics Array + // Reads at kVGABaseAddress + // Decodes UInt16, gets attributes (back colour, fore colour) + // Gets character, send it to video display with according colour in the + // registry. + + fWhere = (volatile UInt16 *)kVGABaseAddress + (y * 80 + x); + *fWhere = c | (attrib << 8); +} diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index f155311f..b3e63bd9 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -7,39 +7,28 @@ * ======================================================== */ -#include +#define __BOOTLOADER__ 1 -namespace Detail { -/** -@brief Stop Execution of Bootloader. -@param SystemTable EFI System Table. -*/ -Void Stop(EfiSystemTable* SystemTable) noexcept { - SystemTable->ConOut->OutputString(SystemTable->ConOut, - L"HCoreLdr: Hanging...\r\n"); - - while (true) { - rt_cli(); - rt_halt(); - } -} -} // namespace Detail +#include +#include // don't remove EfiGUID, it will call initializer_list! EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { + KeInitEFI(SystemTable); + SystemTable->ConOut->OutputString(SystemTable->ConOut, L"HCoreLdr: Initializing...\r\n"); EfiLoadImageProtocol* protocol = nullptr; EfiGUID guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; - Int32 status_code = SystemTable->BootServices->OpenProtocol( + Int32 statusCode = SystemTable->BootServices->OpenProtocol( ImageHandle, &guid, (VoidPtr*)&protocol, ImageHandle, nullptr, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (status_code != kEfiOk) { + if (statusCode != kEfiOk) { SystemTable->ConOut->OutputString( SystemTable->ConOut, L"HCoreLdr: Could not locate EfiLoadImageProtocol! Aborting...\r\n"); diff --git a/Private/NewKit/KernelHeap.hpp b/Private/NewKit/KernelHeap.hpp index 85e916d3..f45e81aa 100644 --- a/Private/NewKit/KernelHeap.hpp +++ b/Private/NewKit/KernelHeap.hpp @@ -17,6 +17,7 @@ #include namespace HCore { -Int32 kernel_delete_ptr(voidPtr allocatedPtr); -voidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user); +Void ke_init_ke_heap() noexcept; +Int32 ke_delete_ke_heap(voidPtr allocatedPtr); +voidPtr ke_new_ke_heap(const SizeT &sz, const bool rw, const bool user); } // namespace HCore diff --git a/Private/NewKit/UserHeap.hpp b/Private/NewKit/UserHeap.hpp index 63a65528..eac9d7d5 100644 --- a/Private/NewKit/UserHeap.hpp +++ b/Private/NewKit/UserHeap.hpp @@ -21,27 +21,24 @@ // description: memory pool for user programs. #define kPoolMaxSz 4096 -#define kPoolMag 0x5500A1 +#define kPoolMag 0x5500A1 -namespace HCore -{ - enum - { - kPoolHypervisor = 0x2, - kPoolShared = 0x4, - kPoolUser = 0x6, - kPoolRw = 0x8, - }; +namespace HCore { +enum { + kPoolHypervisor = 0x2, + kPoolShared = 0x4, + kPoolUser = 0x6, + kPoolRw = 0x8, +}; - struct HeapHeader final - { - UInt32 Magic; - Int32 Flags; - Boolean Free; - UIntPtr Pad; - }; +struct HeapHeader final { + UInt32 Magic; + Int32 Flags; + Boolean Free; + UIntPtr Pad; +}; - VoidPtr pool_new_ptr(Int32 flags); - Int32 pool_free_ptr(voidPtr pointer); - Boolean pool_ptr_exists(UIntPtr thePool, UIntPtr thePtr, SizeT theLimit); -} // namespace HCore +Void ke_init_heap(); +VoidPtr ke_new_heap(Int32 flags); +Int32 ke_free_heap(voidPtr pointer); +} // namespace HCore diff --git a/Private/NewKit/Utils.hpp b/Private/NewKit/Utils.hpp index 02dcd00a..42d3ca70 100644 --- a/Private/NewKit/Utils.hpp +++ b/Private/NewKit/Utils.hpp @@ -25,8 +25,8 @@ namespace HCore Boolean to_str(Char *buf, Int limit, Int base); Boolean is_newln(Char chr); Boolean is_space(Char chr); - Int to_uppercase(Int c); - Int to_lower(Int c); - voidPtr string_in_string(const char* in, const char* needle); - char* string_from_char(char* str, const char chr); + Int rt_to_uppercase(Int c); + Int rt_to_lower(Int c); + voidPtr rt_string_in_string(const char* in, const char* needle); + char* rt_string_from_char(char* str, const char chr); } // namespace HCore diff --git a/Private/Source/CodeManager.cxx b/Private/Source/CodeManager.cxx index 364a94f6..911aefd3 100644 --- a/Private/Source/CodeManager.cxx +++ b/Private/Source/CodeManager.cxx @@ -57,7 +57,7 @@ PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) { "started!\n"; fBad = true; - kernel_delete_ptr(fCachedBlob); + ke_delete_ke_heap(fCachedBlob); fCachedBlob = nullptr; }; @@ -78,7 +78,7 @@ PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) { } PEFLoader::~PEFLoader() { - if (fCachedBlob) kernel_delete_ptr(fCachedBlob); + if (fCachedBlob) ke_delete_ke_heap(fCachedBlob); } VoidPtr PEFLoader::FindSymbol(const char *name, Int32 kind) { diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 94e9156c..3e61a733 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -40,7 +40,7 @@ static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) { /// @param rw read write (true to enable it) /// @param user is it accesible by user processes? /// @return the pointer -VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user) { +VoidPtr ke_new_ke_heap(const SizeT &sz, const bool rw, const bool user) { if (kWrapperCount < sz) return nullptr; if (auto ptr = Detail::find_ptr(sz, rw, user); ptr) return ptr; @@ -62,7 +62,7 @@ VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user) { /// @brief Declare pointer as free. /// @param ptr the pointer. /// @return -Int32 kernel_delete_ptr(voidPtr ptr) { +Int32 ke_delete_ke_heap(voidPtr ptr) { if (ptr) { const UIntPtr virtualAddress = reinterpret_cast(ptr); @@ -106,4 +106,13 @@ Boolean kernel_valid_ptr(voidPtr ptr) { return false; } + +/// @brief The Kernel heap initializer function. +/// @return +Void ke_init_ke_heap() noexcept +{ + kWrapperCount = 0UL; + Ref kLastWrapper = Ref(nullptr); + Pmm kPmm = Pmm(); +} } // namespace HCore diff --git a/Private/Source/New+Delete.cxx b/Private/Source/New+Delete.cxx index e4dba396..274258a4 100644 --- a/Private/Source/New+Delete.cxx +++ b/Private/Source/New+Delete.cxx @@ -15,7 +15,7 @@ void* operator new[](size_t sz) if (sz == 0) ++sz; - return HCore::kernel_new_ptr(sz, true, false); + return HCore::ke_new_ke_heap(sz, true, false); } void* operator new(size_t sz) @@ -23,7 +23,7 @@ void* operator new(size_t sz) if (sz == 0) ++sz; - return HCore::kernel_new_ptr(sz, true, false); + return HCore::ke_new_ke_heap(sz, true, false); } void operator delete[](void* ptr) @@ -31,7 +31,7 @@ void operator delete[](void* ptr) if (ptr == nullptr) return; - HCore::kernel_delete_ptr(ptr); + HCore::ke_delete_ke_heap(ptr); } void operator delete(void* ptr) @@ -39,7 +39,7 @@ void operator delete(void* ptr) if (ptr == nullptr) return; - HCore::kernel_delete_ptr(ptr); + HCore::ke_delete_ke_heap(ptr); } void operator delete(void* ptr, size_t sz) @@ -49,6 +49,6 @@ void operator delete(void* ptr, size_t sz) (void)sz; - HCore::kernel_delete_ptr(ptr); + HCore::ke_delete_ke_heap(ptr); } diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx index 95300bd9..8ae083a3 100644 --- a/Private/Source/PageManager.cxx +++ b/Private/Source/PageManager.cxx @@ -65,7 +65,7 @@ PTEWrapper *PageManager::Request(Boolean Rw, Boolean User, HCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User)); if (PageTableEntry == nullptr) { - kcout << "PTEWrapper : Page table is nullptr!, kernel_new_ptr failed!"; + kcout << "PTEWrapper : Page table is nullptr!, ke_new_ke_heap failed!"; return nullptr; } diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 9d1792a2..404e05e6 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -132,7 +132,7 @@ void Process::Exit(Int32 exit_code) { if (this->Ring != (Int32)ProcessSelector::kRingDriver && this->Ring != (Int32)ProcessSelector::kRingKernel) { - pool_free_ptr(this->Pool); + ke_free_heap(this->Pool); this->PoolCursor = nullptr; @@ -141,9 +141,9 @@ void Process::Exit(Int32 exit_code) { } //! Delete image if not done already. - if (this->Image) kernel_delete_ptr(this->Image); + if (this->Image) ke_delete_ke_heap(this->Image); - if (this->StackFrame) kernel_delete_ptr((VoidPtr)this->StackFrame); + if (this->StackFrame) ke_delete_ke_heap((VoidPtr)this->StackFrame); ProcessManager::Shared().Leak().Remove(this->ProcessId); } @@ -153,12 +153,12 @@ bool ProcessManager::Add(Ref &process) { kcout << "ProcessManager::Add(Ref& process)\r\n"; - process.Leak().Pool = pool_new_ptr(kPoolUser | kPoolRw); + process.Leak().Pool = ke_new_heap(kPoolUser | kPoolRw); process.Leak().ProcessId = this->m_Headers.Count(); process.Leak().PoolCursor = process.Leak().Pool; process.Leak().StackFrame = reinterpret_cast( - kernel_new_ptr(sizeof(HAL::StackFrame), true, false)); + ke_new_ke_heap(sizeof(HAL::StackFrame), true, false)); MUST_PASS(process.Leak().StackFrame); diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx index 6ae257bc..94a483c5 100644 --- a/Private/Source/RuntimeMain.cxx +++ b/Private/Source/RuntimeMain.cxx @@ -11,6 +11,8 @@ #include #include #include +#include +#include /// PRIVATE SYMBOLS EXPORTED BY GCC. extern "C" void (*__SYSTEM_FINI)(); @@ -22,7 +24,10 @@ extern "C" void RuntimeMain() { __SYSTEM_INIT[index_init](); } - MUST_PASS(HCore::init_hal()); + MUST_PASS(HCore::ke_init_hal()); + + HCore::ke_init_heap(); + HCore::ke_init_ke_heap(); HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); HCore::PEFLoader img("/System/Seeker.cm"); diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx index cd676c30..f242dd32 100644 --- a/Private/Source/URL.cxx +++ b/Private/Source/URL.cxx @@ -43,7 +43,7 @@ static ErrorOr url_extract_location(const char *url) { for (; i < string_length(url); ++i) { if (!scheme_found) { for (int y = 0; kProtosCount; ++y) { - if (string_in_string(view.CData(), kProtos[y])) { + if (rt_string_in_string(view.CData(), kProtos[y])) { i += string_length(kProtos[y]) + kUrlOutSz; scheme_found = true; diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index 9df475e7..b34e123e 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -124,7 +124,7 @@ static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) { /// @brief Creates a new pool pointer. /// @param flags the flags attached to it. /// @return a pool pointer with selected permissions. -voidPtr pool_new_ptr(Int32 flags) { +voidPtr ke_new_heap(Int32 flags) { if (!HeapManager::IsEnabled()) return nullptr; if (HeapManager::GetCount() > kPoolMaxSz) return nullptr; @@ -140,7 +140,7 @@ voidPtr pool_new_ptr(Int32 flags) { auto& ref = HeapManager::GetCount(); ++ref; // increment the number of addresses we have now. - kcout << "[pool_new_ptr] New Address found!\r\n"; + kcout << "[ke_new_heap] New Address found!\r\n"; // finally make the pool address. return ke_make_heap( @@ -153,7 +153,7 @@ voidPtr pool_new_ptr(Int32 flags) { /// @brief free a pool pointer. /// @param ptr The pool pointer to free. /// @return status code -Int32 pool_free_ptr(voidPtr ptr) { +Int32 ke_free_heap(voidPtr ptr) { if (!HeapManager::IsEnabled()) return -1; if (ptr) { @@ -171,18 +171,10 @@ Int32 pool_free_ptr(voidPtr ptr) { return -1; } -/// @brief Checks if pointer is valid. -/// @param thePool the pool pointer. -/// @param thePtr the pointer. -/// @param theLimit the last address of the pool. -/// @return if it is valid. -Boolean pool_ptr_exists(UIntPtr thePool, UIntPtr thePtr, SizeT theLimit) { - if (HeapManager::GetCount() < 1) return false; - - if (thePool == 0 || thePtr == 0 || theLimit == 0) { - return false; - } - - return ((thePool) < (thePtr) < (theLimit)); +/// @brief Init HeapManager, set GetCount to zero and IsEnabled to true. +/// @return +Void ke_init_heap() { + HeapManager::GetCount() = 0UL; + HeapManager::IsEnabled() = true; } } // namespace HCore diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx index 3a3ba2a0..7c61ec96 100644 --- a/Private/Source/Utils.cxx +++ b/Private/Source/Utils.cxx @@ -107,13 +107,13 @@ const Char *alloc_string(const Char *text) { return string; } -Int to_uppercase(Int character) { +Int rt_to_uppercase(Int character) { if (character >= 'a' && character <= 'z') return character - 0x20; return character; } -Int to_lower(Int character) { +Int rt_to_lower(Int character) { if (character >= 'A' && character <= 'Z') return character + 0x20; return character; @@ -143,7 +143,7 @@ Boolean is_space(Char chr) { return chr == ' '; } Boolean is_newln(Char chr) { return chr == '\n'; } -voidPtr string_in_string(const char *in, const char *needle) { +voidPtr rt_string_in_string(const char *in, const char *needle) { for (size_t i = 0; i < string_length(in); ++i) { if (string_compare(in + i, needle, string_length(needle)) == 0) return reinterpret_cast(const_cast(in + i)); @@ -154,7 +154,7 @@ voidPtr string_in_string(const char *in, const char *needle) { // @brief Checks for a string start at the character. -char *string_from_char(char *str, const char chr) { +char *rt_string_from_char(char *str, const char chr) { while (*str != chr) { ++str; diff --git a/TODO_LIST.TXT b/TODO_LIST.TXT index 7479344e..b89c0659 100644 --- a/TODO_LIST.TXT +++ b/TODO_LIST.TXT @@ -9,3 +9,12 @@ - Context switch x87/SSE/AVX registers [ ] - Framebuffer and ATA support [ ] - Native Subsystem and GUI [ ] + +Status: + +HCoreLdr: Working. +HCoreKrnl: Not run yet. + +Prioritize: +HCoreLdr: Protocol and API. +HCoreKrnl: Complying to specs. -- cgit v1.2.3