From 2529c8722d6d3491a3e19aa728f4bfce099bcc91 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 29 Jan 2024 09:55:05 +0100 Subject: Kernel: Improve BootKit and EFIKit. TODO: Add File Protocol support and Pool support for EFIKit. Signed-off-by: Amlal El Mahrouss --- .clang-format | 2 +- .gitignore | 2 + Private/EFIKit/EFI.hxx | 18 ++--- Private/HALKit/AMD64/Processor.cpp | 85 +++++++++++++---------- Private/KernelKit/ThreadLocalStorage.hxx | 28 ++++---- Private/NewBoot/BootKit/Boot.hpp | 69 ------------------ Private/NewBoot/BootKit/Boot.hxx | 69 ++++++++++++++++++ Private/NewBoot/BootKit/EPM.hxx | 12 ++++ Private/NewBoot/BootKit/Processor.hxx | 24 +++++++ Private/NewBoot/BootKit/Protocol.hxx | 30 ++++++++ Private/NewBoot/CxxKit/__cxxkit_unwind.cxx | 11 --- Private/NewBoot/CxxKit/manifest.json | 3 - Private/NewBoot/CxxRuntime/manifest.json | 3 + Private/NewBoot/CxxRuntime/unwind.cxx | 11 +++ Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep | 0 Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc | 40 ----------- Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc | 36 ---------- Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx | 10 --- Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm | 50 ------------- Private/NewBoot/Source/HEL/AMD64/Boot.cxx | 56 +++++++++++++++ Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx | 55 --------------- Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx | 12 +++- Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx | 10 --- Private/NewBoot/Source/HEL/AMD64/Processor.cxx | 36 +++++++--- Private/NewBoot/Source/HEL/AMD64/Protocol.hxx | 30 -------- Private/NewBoot/Source/makefile | 2 + Public/SDK/SystemKit/ThreadAPI.hxx | 10 +-- TODO_LIST.TXT | 4 +- 28 files changed, 323 insertions(+), 395 deletions(-) delete mode 100644 Private/NewBoot/BootKit/Boot.hpp create mode 100644 Private/NewBoot/BootKit/Boot.hxx create mode 100644 Private/NewBoot/BootKit/EPM.hxx create mode 100644 Private/NewBoot/BootKit/Processor.hxx create mode 100644 Private/NewBoot/BootKit/Protocol.hxx delete mode 100644 Private/NewBoot/CxxKit/__cxxkit_unwind.cxx delete mode 100644 Private/NewBoot/CxxKit/manifest.json create mode 100644 Private/NewBoot/CxxRuntime/manifest.json create mode 100644 Private/NewBoot/CxxRuntime/unwind.cxx delete mode 100644 Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep delete mode 100644 Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc delete mode 100644 Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc delete mode 100644 Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx delete mode 100644 Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm create mode 100644 Private/NewBoot/Source/HEL/AMD64/Boot.cxx delete mode 100644 Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx delete mode 100644 Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx delete mode 100644 Private/NewBoot/Source/HEL/AMD64/Protocol.hxx diff --git a/.clang-format b/.clang-format index e7f0de7b..a17d1800 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,3 @@ --- Language: Cpp -BasedOnStyle: Microsoft \ No newline at end of file +BasedOnStyle: Microsoft diff --git a/.gitignore b/.gitignore index 3102b158..ba873061 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ build.ninja cmake_install.cmake qtcsettings.cmake +MAHROUSS/ + x86_64/ *.epm diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx index 2e7f4443..17f2da48 100644 --- a/Private/EFIKit/EFI.hxx +++ b/Private/EFIKit/EFI.hxx @@ -29,21 +29,21 @@ typedef UInt64 (*EfiTextString)(struct EfiSimpleTextOutputProtocol *self, const typedef struct EfiSimpleTextOutputProtocol { UInt64 reset; - EfiTextString output_string; - UInt64 test_string; - UInt64 query_mode; - UInt64 set_mode; - UInt64 set_attribute; - UInt64 clear_screen; - UInt64 set_cursor_position; - UInt64 enable_cursor; + EfiTextString outputString; + UInt64 testString; + UInt64 queryMode; + UInt64 setMode; + UInt64 setAttribute; + UInt64 clearScreen; + UInt64 setCursorPosition; + UInt64 enableCursor; UInt64 mode; } EfiSimpleTextOutputProtocol; typedef struct EfiSystemTable { EfiTableHeader hdr; - Int16 *firmwareVendor; + wchar_t *firmwareVendor; UInt32 firmwareRevision; VoidPtr consoleInHandle; UInt64 conIn; diff --git a/Private/HALKit/AMD64/Processor.cpp b/Private/HALKit/AMD64/Processor.cpp index 13732381..c70c7959 100644 --- a/Private/HALKit/AMD64/Processor.cpp +++ b/Private/HALKit/AMD64/Processor.cpp @@ -9,53 +9,64 @@ #include -namespace hCore::HAL { - void out8(UInt16 port, UInt8 value) { - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); - } +namespace hCore::HAL +{ +void out8(UInt16 port, UInt8 value) +{ + asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); +} - void out16(UInt16 port, UInt16 value) { - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); - } +void out16(UInt16 port, UInt16 value) +{ + asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); +} - void out32(UInt16 port, UInt32 value) { - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); - } +void out32(UInt16 port, UInt32 value) +{ + asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); +} - UInt8 in8(UInt16 port) { - UInt8 value = 0UL; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); +UInt8 in8(UInt16 port) +{ + UInt8 value = 0UL; + asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - return value; - } + return value; +} - UInt16 in16(UInt16 port) { - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); +UInt16 in16(UInt16 port) +{ + UInt16 value = 0UL; + asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); - return value; - } + return value; +} - UInt32 in32(UInt16 port) { - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); +UInt32 in32(UInt16 port) +{ + UInt32 value = 0UL; + asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - return value; - } + return value; +} - void rt_halt() { - asm volatile("hlt"); - } +void rt_halt() +{ + asm volatile("hlt"); +} - void rt_cli() { - asm volatile("cli"); - } +void rt_cli() +{ + asm volatile("cli"); +} - void rt_sti() { - asm volatile("sti"); - } +void rt_sti() +{ + asm volatile("sti"); +} - void rt_cld() { - asm volatile("cld"); - } +void rt_cld() +{ + asm volatile("cld"); +} } // namespace hCore::HAL diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx index afd0afb3..8fc8b9dd 100644 --- a/Private/KernelKit/ThreadLocalStorage.hxx +++ b/Private/KernelKit/ThreadLocalStorage.hxx @@ -18,14 +18,11 @@ #define kCookieMag1 'C' #define kCookieMag2 'o' -template -T* hcore_tls_new_ptr(void); +template T *hcore_tls_new_ptr(void); -template -bool hcore_tls_delete_ptr(T* ptr); +template bool hcore_tls_delete_ptr(T *ptr); -template -T* hcore_tls_new_class(Args&&... args); +template T *hcore_tls_new_class(Args &&...args); typedef char rt_cookie_type[3]; @@ -33,19 +30,22 @@ typedef char rt_cookie_type[3]; /// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) struct ThreadInformationBlock final { - hCore::Char Name[255]; // Module Name - hCore::UIntPtr StartCode; // Start Address - hCore::UIntPtr StartData; // Allocation Heap + hCore::Char Name[255]; // Module Name + hCore::UIntPtr StartCode; // Start Address + hCore::UIntPtr StartData; // Allocation Heap hCore::UIntPtr StartStack; // Stack Pointer. - hCore::Int32 Arch; // Architecture and/or platform. - rt_cookie_type Cookie; // Not shown in public header, this is the way we tell something went wrong. + hCore::Int32 Arch; // Architecture and/or platform. + rt_cookie_type Cookie; // Not shown in public header, this is the way we tell something went wrong. }; -//! @brief Cookie Sanity check. -hCore::Boolean hcore_tls_check(ThreadInformationBlock* ptr); +/// @brief TLS install TIB +extern void rt_install_tib(ThreadInformationBlock *pTib); + +///! @brief Cookie Sanity check. +hCore::Boolean hcore_tls_check(ThreadInformationBlock *ptr); #include "ThreadLocalStorage.inl" -// last rev 1/27/24 +// last rev 1/29/24 #endif /* ifndef _KERNELKIT_TLS_HPP */ diff --git a/Private/NewBoot/BootKit/Boot.hpp b/Private/NewBoot/BootKit/Boot.hpp deleted file mode 100644 index 6df2e08f..00000000 --- a/Private/NewBoot/BootKit/Boot.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#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 (0x10000000) - -long long int BStrLen(const char *ptr); diff --git a/Private/NewBoot/BootKit/Boot.hxx b/Private/NewBoot/BootKit/Boot.hxx new file mode 100644 index 00000000..07148702 --- /dev/null +++ b/Private/NewBoot/BootKit/Boot.hxx @@ -0,0 +1,69 @@ +/* + * ======================================================== + * + * NewBoot + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#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 (0x10000000) + +hCore::SizeT BStrLen(const char *ptr); diff --git a/Private/NewBoot/BootKit/EPM.hxx b/Private/NewBoot/BootKit/EPM.hxx new file mode 100644 index 00000000..803d500c --- /dev/null +++ b/Private/NewBoot/BootKit/EPM.hxx @@ -0,0 +1,12 @@ +/* + * ======================================================== + * + * h-core + * Copyright 2024, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include diff --git a/Private/NewBoot/BootKit/Processor.hxx b/Private/NewBoot/BootKit/Processor.hxx new file mode 100644 index 00000000..d4143094 --- /dev/null +++ b/Private/NewBoot/BootKit/Processor.hxx @@ -0,0 +1,24 @@ +/* + * ======================================================== + * + * h-core + * Copyright 2024, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +/** + @file Processor.hxx + @brief Processor specific code. +*/ + +#ifdef __x86_64__ + +extern "C" void rt_halt(); +extern "C" void rt_cli(); +extern "C" void rt_sti(); +extern "C" void rt_cld(); + +#endif /* ifdef __x86_64__ */ diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx new file mode 100644 index 00000000..7e292c7d --- /dev/null +++ b/Private/NewBoot/BootKit/Protocol.hxx @@ -0,0 +1,30 @@ +/* + * ======================================================== + * + * NewBoot + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include + +namespace HEL +{ +using namespace hCore; + +struct HandoverHeader final +{ + Int32 magic; + Int32 type; + Int32 arch; + // WIP +}; +} // namespace HEL + +#define kHandoverMagic 0xBAD55 + +#define kBaseHandoverStruct 0x10000000 +#define kHandoverStructSz sizeof(HEL::HandoverHeader) diff --git a/Private/NewBoot/CxxKit/__cxxkit_unwind.cxx b/Private/NewBoot/CxxKit/__cxxkit_unwind.cxx deleted file mode 100644 index 477b6302..00000000 --- a/Private/NewBoot/CxxKit/__cxxkit_unwind.cxx +++ /dev/null @@ -1,11 +0,0 @@ -namespace cxxkit -{ - ///! @brief C++ ABI unwinding - ///! finis array (r1) - ///! n of finis (r2) - void __unwind(void(**finis)(void), int cnt) - { - for (int i = 0; i < cnt; ++i) - (finis[i])(); - } -} diff --git a/Private/NewBoot/CxxKit/manifest.json b/Private/NewBoot/CxxKit/manifest.json deleted file mode 100644 index 42b5d166..00000000 --- a/Private/NewBoot/CxxKit/manifest.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "pluginName": "C++Kit" -} \ No newline at end of file diff --git a/Private/NewBoot/CxxRuntime/manifest.json b/Private/NewBoot/CxxRuntime/manifest.json new file mode 100644 index 00000000..42b5d166 --- /dev/null +++ b/Private/NewBoot/CxxRuntime/manifest.json @@ -0,0 +1,3 @@ +{ + "pluginName": "C++Kit" +} \ No newline at end of file diff --git a/Private/NewBoot/CxxRuntime/unwind.cxx b/Private/NewBoot/CxxRuntime/unwind.cxx new file mode 100644 index 00000000..acfc0b6b --- /dev/null +++ b/Private/NewBoot/CxxRuntime/unwind.cxx @@ -0,0 +1,11 @@ +namespace cxxkit +{ +///! @brief C++ ABI unwinding +///! finis array (r1) +///! n of finis (r2) +extern "C" void __unwind(void (**finis)(void), int cnt) +{ + for (int i = 0; i < cnt; ++i) + (finis[i])(); +} +} // namespace cxxkit diff --git a/Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep b/Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc b/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc deleted file mode 100644 index a43881fa..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc +++ /dev/null @@ -1,40 +0,0 @@ -;; COPYRIGHT Mahrouss Logic, all rights reserved - -bits 32 - -[global __BIOSLoadRegister] -[global __BIOSAlloc] - -__BIOSLoadRegister: - cmp [ebp - 4], 0 - jmp __BIOSLoadGDT - ret -__BIOSLoadGDT: - lgdt [ebp - 8] - ret - -;; This memory resides in the BIOS Memory Region BMR (0x9000-(0x9000 + 0x1000)) -;; It contains bootloader data. - -__BIOSAlloc: - push ebp - mov ebp, esp - mov eax, __bios_lookup_table -__BIOSAllocLoop: - cmp eax, __end_bios_lookup_table - jne __BIOSAllocDone - add eax, 4 - jmp $ -__BIOSAllocDone: - cmp eax, 0 - je __BIOSAllocLoop - add esp, 12 - mov esp, ebp - pop ebp - ret - -;; Allocation table. - -__bios_lookup_table: - resb 8096 * 4 -__end_bios_lookup_table: diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc b/Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc deleted file mode 100644 index be7a97e3..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc +++ /dev/null @@ -1,36 +0,0 @@ -[BITS 32] - -NewBootGdtRegister: - dw NewBootGdtEnd - NewBootGdt - 1 - dq NewBootGdt - -[BITS 32] - -NewBootGdt: - ;; Entry 0x0: Null descriptor - dd 0x0 - dd 0x0 - ;; Entry 0x8: Code segment -NewBootGdtCode: - dw 0xffff ; Limit - dw 0x0000 ; Base 15:00 - db 0x00 ; Base 23:16 - dw 0xcf9a ; Flags / Limit / Type [F,L,F,Type] - db 0x00 ; Base 32:24 - ;; Entry 0x10: Data segment -NewBootGdtData: - dw 0xffff ; Limit - dw 0x0000 ; Base 15:00 - db 0x00 ; Base 23:16 - dw 0xcf92 ; Flags / Limit / Type [F,L,F,Type] - db 0x00 ;Base 32:24 - ;; Entry 0x18: GS Data segment - dw 0x0100 ; Limit - dw 0x1000 ; Base 15:00 - db 0x00 ; Base 23:16 - dw 0x4092 ; Flags / Limit / Type [F,L,F,Type] - db 0x00 ; Base 32:24 -NewBootGdtEnd: - -NB_CODE: db 0x8 -NB_DATA: db 0x10 \ No newline at end of file diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx b/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx deleted file mode 100644 index 1cc249ee..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2024 Mahrouss Logic, all rights reserved - */ - -#include - -// unused now, used to be in dev; -#ifdef __BIOS__ -extern "C" char __runtime_stack[4096] = {0}; -#endif // ifdef __BIOS__ diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm b/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm deleted file mode 100644 index f5ba44ec..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm +++ /dev/null @@ -1,50 +0,0 @@ -;; Copyright 2024 Mahrouss Logic, all rights reserved - -extern __runtime_stack -global NBRuntimeZero - -bits 16 - -NBRuntimeZero: - cli - - lgdt [NewBootGdtRegister] - - mov ebx, cr0 - or ebx, 1 - mov cr0, ebx - - jmp 0x8:NBProtectedMode - -%include "BIOSApiGdt.inc" - -[bits 32] - -NBMasterPartitionTable: - resb 32 - resw 1 - resw 1 - resw 1 - resb 211 -NBMasterPartitionTableEnd: - -NBProtectedMode: - mov ax, 0x10 ; 0x10 is a stand-in for your data segment - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax - - mov esp, __runtime_stack - jmp 0x8000000 - -NBLoopOne: - cli - hlt - jmp $ - -NBMasterBootRecord: - times 510 - ($-$$) db 0 - dw 0xAA55 -NBEndMasterBootRecord: \ No newline at end of file diff --git a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx new file mode 100644 index 00000000..96c30c12 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx @@ -0,0 +1,56 @@ +/* + * ======================================================== + * + * 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; +} + +/** +@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/BootAMD64.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx deleted file mode 100644 index 39f8761e..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -constexpr hCore::UInt32 kVGABaseAddress = 0xb8000; - -long long int BStrLen(const char *ptr) -{ - long long int cnt = 0; - while (*ptr != 0) - { - ++ptr; - ++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/EfiMain.cxx b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx index d8a26acd..9b00a6a9 100644 --- a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx @@ -7,11 +7,19 @@ * ======================================================== */ -#include "Protocol.hxx" +#include +#include +#include extern "C" int EfiMain(void *ImageHandle, EfiSystemTable *SystemTable) { - SystemTable->conOut->output_string(SystemTable->conOut, L"HCORELDR: Preparing Handover structure...\r\n"); + SystemTable->conOut->outputString(SystemTable->conOut, L"HCoreLdr: Starting HCore...\r\n"); + + while (true) + { + rt_cli(); + rt_halt(); + } return 0; } diff --git a/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx b/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx deleted file mode 100644 index 490cc41a..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ======================================================== - * - * h-core - * Copyright 2024, Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include diff --git a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx b/Private/NewBoot/Source/HEL/AMD64/Processor.cxx index d2a0c15f..f1f9b617 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Processor.cxx @@ -1,11 +1,11 @@ /* -* ======================================================== -* -* NewBoot -* Copyright 2024 Mahrouss Logic, all rights reserved. -* -* ======================================================== -*/ + * ======================================================== + * + * NewBoot + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ /* * @@ -14,10 +14,24 @@ * */ -extern "C" void rt_halt(void) { asm volatile("hlt"); } +#include + +extern "C" void rt_halt(void) +{ + asm volatile("hlt"); +} -extern "C" void rt_cli(void) { asm volatile("cli"); } +extern "C" void rt_cli(void) +{ + asm volatile("cli"); +} -extern "C" void rt_sti(void) { asm volatile("sti"); } +extern "C" void rt_sti(void) +{ + asm volatile("sti"); +} -extern "C" void rt_cld(void) { asm volatile("cld"); } +extern "C" void rt_cld(void) +{ + asm volatile("cld"); +} diff --git a/Private/NewBoot/Source/HEL/AMD64/Protocol.hxx b/Private/NewBoot/Source/HEL/AMD64/Protocol.hxx deleted file mode 100644 index 7e292c7d..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/Protocol.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include - -namespace HEL -{ -using namespace hCore; - -struct HandoverHeader final -{ - Int32 magic; - Int32 type; - Int32 arch; - // WIP -}; -} // namespace HEL - -#define kHandoverMagic 0xBAD55 - -#define kBaseHandoverStruct 0x10000000 -#define kHandoverStructSz sizeof(HEL::HandoverHeader) diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index c5c382ac..b84f4425 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -12,9 +12,11 @@ arch-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx $(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCORELDR.EXE cp HCORELDR.EXE CDROM/EFI/BOOT/BOOTX64.EFI + cp -r ../../Root ./CDROM/MAHROUSS .PHONY: efi-debug efi-debug: + wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd qemu-system-x86_64 -bios OVMF.fd -net none -drive file=fat:rw:CDROM,format=raw -d int .PHONY: clean diff --git a/Public/SDK/SystemKit/ThreadAPI.hxx b/Public/SDK/SystemKit/ThreadAPI.hxx index f99da698..8d948a35 100644 --- a/Public/SDK/SystemKit/ThreadAPI.hxx +++ b/Public/SDK/SystemKit/ThreadAPI.hxx @@ -22,11 +22,11 @@ namespace hCore /// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) struct ThreadInformationBlock final { - const Char TIB_NAME[255]; // Module Name - const UIntPtr TIB_START; // Start Address - const UIntPtr TIB_ALLOC; // Allocation Heap - const UIntPtr TIB_STACK; // Stack Pointer. - const Int32 TIB_ARCH; // Architecture and/or platform. + const Char TIB_NAME[255]; // Module Name + const UIntPtr TIB_START_CODE; // Start Address + const UIntPtr TIB_START_ALLOC; // Allocation Heap + const UIntPtr TIB_START_STACK; // Stack Pointer. + const Int32 TIB_ARCH; // Architecture and/or platform. }; enum diff --git a/TODO_LIST.TXT b/TODO_LIST.TXT index c8f7c123..f6085f65 100644 --- a/TODO_LIST.TXT +++ b/TODO_LIST.TXT @@ -1,6 +1,6 @@ - We need preemptive multi-threading. [ X ] - We then need sync primitives. [ X ] - We also need a system library for the OS. [ X ] -- We need a bootloader for AMD64 [ ] - - Load MPT into memory [ ] +- We need a bootloader for AMD64 [ X ] + - Load Handover and kernel into memory [ ] - Jump to kernel [ ] -- cgit v1.2.3