diff options
19 files changed, 103 insertions, 81 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 73f8888c..ed6e621e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,7 +1,7 @@ { "configurations": [ { - "name": "HCore", + "name": "HCore (Mac)", "includePath": [ "${workspaceFolder}/Private/**", "${workspaceFolder}/Private/NewBoot/**", @@ -10,8 +10,19 @@ "defines": ["__HCORE__", "__HAVE_HCORE_APIS__", "__FSKIT_NEWFS__"], "cStandard": "c17", "cppStandard": "c++20", - "compilerPath": "/opt/homebrew/bin/x86_64-elf-g++", + "compilerPath": "/opt/homebrew/bin/x86_64-w64-mingw32-gcc", "intelliSenseMode": "gcc-x64" + }, + { + "name": "HCore Tools (Mac)", + "includePath": [ + "${workspaceFolder}/Private/Tools/**" + ], + "defines": [], + "cStandard": "c17", + "cppStandard": "c++20", + "compilerPath": "/usr/bin/gcc", + "intelliSenseMode": "gcc-arm64" } ], "version": 4 diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp index 4fbe55ac..a62cc4bd 100644 --- a/Private/ArchKit/ArchKit.hpp +++ b/Private/ArchKit/ArchKit.hpp @@ -57,7 +57,7 @@ bool ke_init_hal(); #define kKernelMaxSystemCalls (256) -extern HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), +extern HCore::Array<void (*)(HCore::HAL::StackFrame *), kKernelMaxSystemCalls> kSyscalls; diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx index 23353d91..0218f666 100644 --- a/Private/FSKit/NewFS.hxx +++ b/Private/FSKit/NewFS.hxx @@ -23,9 +23,9 @@ @brief HCore File System implementation. */ -#define kInvalidFork -1 -#define kInvalidCatalog -1 -#define kNameLen 256 +#define kNewFSInvalidFork -1 +#define kNewFSInvalidCatalog -1 +#define kNewFSNodeNameLen 256 #define kNewFSIdentLen 6 #define kNewFSIdent " HCFS" @@ -34,7 +34,8 @@ //! On EPM and GPT disks. #define kNewFSUUID "DD997393-9CCE-4288-A8D5-C0FDE3908DBE" -#define kNewFSVersion 1 +#define kNewFSVersionInteger 0x11 +#define kNewFSVerionString "1.1" typedef HCore::WideChar NewCharType; @@ -48,7 +49,7 @@ enum { struct PACKED NewBootBlock final { NewCharType Ident[kNewFSIdentLen]; - NewCharType Shell[kNameLen]; + NewCharType Shell[kNewFSNodeNameLen]; HCore::Int64 NumParts; HCore::Int64 FreeSectors; @@ -74,7 +75,7 @@ struct PACKED NewBootBlock final { #define kKindPartition 4 struct PACKED NewCatalog final { - NewCharType Name[kNameLen]; + NewCharType Name[kNewFSNodeNameLen]; HCore::Int32 Flags; HCore::Int32 Kind; diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp index e568aa4d..c35d52cc 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp @@ -8,43 +8,9 @@ */ #include <ArchKit/ArchKit.hpp> -#include <KernelKit/ProcessManager.hpp> #include <NewKit/String.hpp> -static const char* kExceptionMessages[32] = { - "Division by zero", - "Debug Breakpoint", - "Non-maskable Interrupt", - "Breakpoint", - "Detected Overflow", - "Out-Of-Bounds", - "Invalid Opcode", - "No Coprocessor", - "Double Fault", - "Coprocessor Segment Overrun", - "Bad TSS", - "Segment Not Found", - "Stack Error", - "General Protection Fault", - "Page Fault", - "Invalid Interrupt", - "Coprocessor Fault", - "Alignment Check", - "Machine Check", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", -}; +/// BUGS = 1 /// @brief System call interrupt (like DOS and NT) #define kKernelSyscallInterrupt (0x21) @@ -53,10 +19,6 @@ EXTERN_C { HCore::Void rt_handle_interrupts(HCore::HAL::StackFramePtr stack) { HCore::kcout << "HCoreKrnl: Interrupting Hart...\r\n"; - if (stack->IntNum < 32) { - HCore::kcout << "HCoreKrnl: " << kExceptionMessages[stack->IntNum] << HCore::end_line(); - } - switch (stack->IntNum) { case kKernelSyscallInterrupt: { HCore::kcout << "HCoreKrnl: System call raised, checking.." diff --git a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp index 24eee910..7d0178fe 100644 --- a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp @@ -11,7 +11,7 @@ #include <HALKit/AMD64/Processor.hpp> #include <KernelKit/PermissionSelector.hxx> -typedef HCore::Void (*rt_syscall_proc)(HCore::Int32 id, HCore::HAL::StackFramePtr); +typedef HCore::Void (*rt_syscall_proc)(HCore::HAL::StackFramePtr); HCore::Array<rt_syscall_proc, kKernelMaxSystemCalls> kSyscalls; @@ -20,6 +20,6 @@ EXTERN_C void rt_syscall_handle(HCore::HAL::StackFramePtr stack) { if (!stack) return; if (stack->Rcx < kKernelMaxSystemCalls && kSyscalls[stack->Rcx] != 0) { - (kSyscalls[stack->Rcx].Leak().Leak())(stack->Rcx, stack); + (kSyscalls[stack->Rcx].Leak().Leak())(stack); } } diff --git a/Private/HALKit/AMD64/HalInstallTIB.asm b/Private/HALKit/AMD64/HalInstallTIB.asm index 260b496f..3391dc26 100644 --- a/Private/HALKit/AMD64/HalInstallTIB.asm +++ b/Private/HALKit/AMD64/HalInstallTIB.asm @@ -12,7 +12,8 @@ [global rt_install_tib] rt_install_tib: - mov rcx, gs + mov rcx, gs ;; TIB -> Thread Information Block + mov rdx, fs ;; PIB -> Process Information Block ret ;; //////////////////////////////////////////////////// ;; diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index df7ce91e..27c12509 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -13,11 +13,12 @@ #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> #include <KernelKit/PEFCodeManager.hxx> -#include <KernelKit/Rsrc/Splash.hxx> #include <KernelKit/Rsrc/Util.hxx> #include <NewKit/Json.hpp> #include <NewKit/KernelHeap.hpp> #include <NewKit/UserHeap.hpp> +#include <KernelKit/ProcessManager.hpp> +#include <KernelKit/Rsrc/Splash.rsrc> ///! @brief Disk contains HCore files. #define kInstalledMedia 0xDD @@ -94,27 +95,31 @@ EXTERN_C void RuntimeMain( KeDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH, ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2), ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2)); KeClearRsrc(); + /// START POST + Detail::_ke_power_on_self_test(); + HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); HCore::kcout << "HCoreKrnl: POST done, everything is OK...\r\n"; - if (HandoverHeader->f_Bootloader == kInstalledMedia) { - /// Mounts a NewFS block. - HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); + /// END POST + /// Mounts a NewFS block. + HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); + + /// We already have an install of HCore. + if (HandoverHeader->f_Bootloader == kInstalledMedia) { // Open file from first hard-drive. HCore::PEFLoader img("A:/System/HCoreServer.exe"); /// Run the server executive. HCore::Utils::execute_from_image(img); } else { - /** - ** This does the POST. - */ + // Open file from first hard-drive. + HCore::PEFLoader img("A:/System/HCoreInstallWizard.exe"); - /** - This mounts the NewFS drive. - */ + /// Run the server executive. + HCore::Utils::execute_from_image(img); } HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP); diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index 435847a8..93a9775a 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -82,6 +82,8 @@ typedef UIntPtr Reg; struct PACKED StackFrame { Reg IntNum, ErrCode; Reg Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax; + Reg R8, R9, R10, R11, R12, R13, R14, R15; + Reg Gs, Fs; }; typedef StackFrame *StackFramePtr; diff --git a/Private/KernelKit/Rsrc/Award.hxx b/Private/KernelKit/Rsrc/Award.rsrc index 206dc5a3..5385883a 100644 --- a/Private/KernelKit/Rsrc/Award.hxx +++ b/Private/KernelKit/Rsrc/Award.rsrc @@ -4,7 +4,7 @@ #define POWEREDBYAWARD_WIDTH 128 // array size is 13440 -static const unsigned int PoweredByAward[] = { +inline const unsigned int PoweredByAward[] = { 0xd13e38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd13d38, 0xd23f3a, 0xd13e39, 0xd13d38, 0xd13d38, diff --git a/Private/KernelKit/Rsrc/HCore.hxx b/Private/KernelKit/Rsrc/HCore.rsrc index 26a3a9e7..e53396ed 100644 --- a/Private/KernelKit/Rsrc/HCore.hxx +++ b/Private/KernelKit/Rsrc/HCore.rsrc @@ -4,7 +4,7 @@ #define HCORELOGO_WIDTH 128 // array size is 49152 -const unsigned int HCoreLogo[] = { +inline const unsigned int HCoreLogo[] = { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xffffff, 0xb6b6b6, 0xb7b7b7, 0xb8b8b8, 0xb7b7b7, 0xb7b7b7, diff --git a/Private/KernelKit/Rsrc/Splash.hxx b/Private/KernelKit/Rsrc/Splash.rsrc index 2671d6e1..9b9a3e45 100644 --- a/Private/KernelKit/Rsrc/Splash.hxx +++ b/Private/KernelKit/Rsrc/Splash.rsrc @@ -1,8 +1,10 @@ +#pragma once + #define MAHROUSSLOGIC_HEIGHT 66 #define MAHROUSSLOGIC_WIDTH 66 // array size is 13068 -static const unsigned int MahroussLogic[] = { +inline const unsigned int MahroussLogic[] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, diff --git a/Private/KernelKit/Rsrc/Util.hxx b/Private/KernelKit/Rsrc/Util.hxx index 03013888..a2f9355d 100644 --- a/Private/KernelKit/Rsrc/Util.hxx +++ b/Private/KernelKit/Rsrc/Util.hxx @@ -34,3 +34,5 @@ } #endif + +#define $rsrc import
\ No newline at end of file diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx index db04c054..95b243c9 100644 --- a/Private/KernelKit/ThreadLocalStorage.hxx +++ b/Private/KernelKit/ThreadLocalStorage.hxx @@ -27,7 +27,9 @@ bool hcore_tls_delete_ptr(T *ptr); template <typename T, typename... Args> T *hcore_tls_new_class(Args &&...args); -typedef HCore::Char rt_cookie_type[3]; +#define kTLSCookieLen 3 + +typedef HCore::Char* rt_cookie_type; #define kTIBNameLen 256 @@ -44,11 +46,14 @@ struct ThreadInformationBlock final { }; /// @brief TLS install TIB -extern void rt_install_tib(ThreadInformationBlock *pTib); +EXTERN_C void rt_install_tib(ThreadInformationBlock *pTib, HCore::VoidPtr pPib); ///! @brief Cookie Sanity check. HCore::Boolean hcore_tls_check(ThreadInformationBlock *ptr); +/// @brief TLS check system call +EXTERN_C HCore::Void hcore_tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept; + #include <KernelKit/ThreadLocalStorage.inl> // last rev 1/29/24 diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 4a51acc0..c3b07918 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -36,7 +36,7 @@ const Int32 &rt_get_exit_code() noexcept { return kExitCode; } /***********************************************************************************/ void Process::Crash() { - kcout << this->Name << ": Crashed, ExitCode: -1\n"; + kcout << "ProcessManager: Crashed, ExitCode: -1.\r\n"; MUST_PASS(!ke_bug_check()); this->Exit(-1); diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 9a9c8477..60d02efd 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -24,12 +24,13 @@ using namespace HCore; * @param ptr * @return if the cookie is enabled. */ + Boolean hcore_tls_check(VoidPtr ptr) { if (!ptr) return false; const char* _ptr = (const char*)ptr; - kcout << "Krnl\\TLS: Checking for cookie...\n"; + kcout << "HCoreKrnl\\TLS: Checking for cookie...\n"; return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && _ptr[2] == kCookieMag2; @@ -40,11 +41,13 @@ Boolean hcore_tls_check(VoidPtr ptr) { * @param ptr * @return */ -Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept { - if (!hcore_tls_check(ptr.Cookie)) { - kcout << "Krnl\\TLS: Verification failure, Crashing...\n"; +EXTERN_C Void hcore_tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept { + ThreadInformationBlock* tib = (ThreadInformationBlock*)stackPtr->Gs; + + if (!hcore_tls_check(tib->Cookie)) { + kcout << "HCoreKrnl\\TLS: Verification failed, Crashing...\n"; ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } - kcout << "Krnl\\TLS: Verification succeeded! Keeping on...\n"; + kcout << "HCoreKrnl\\TLS: Verification succeeded! Keeping on...\n"; } diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx index 01975192..ecbd56f4 100644 --- a/Private/Source/Utils.cxx +++ b/Private/Source/Utils.cxx @@ -81,7 +81,6 @@ Int rt_move_memory(const voidPtr src, voidPtr dst, Size len) { Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { if (len < 1) return -2; - if (!src || !dst) return -1; char *srcChr = reinterpret_cast<char *>(src); char *dstChar = reinterpret_cast<char *>(dst); @@ -89,10 +88,12 @@ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { while (index < len) { dstChar[index] = srcChr[index]; - index++; + ++index; } - return 0; + dstChar[index] = 0; + + return index; } const Char *alloc_string(const Char *text) { diff --git a/Private/Tools/disk_api.h b/Private/Tools/disk_api.h new file mode 100644 index 00000000..27a446c2 --- /dev/null +++ b/Private/Tools/disk_api.h @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + all rights reserved. + + File: Disk.hxx + +------------------------------------------- */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#include <stdio.h> +#include <stdint.h> + +#ifdef __cplusplus +}; +#endif // __cplusplus + +typedef struct __sDISK +{ + FILE* fFile; + int32_t fDiskFilesystem; + uintptr_t fDiskCursor; + size_t fDiskSize; +} DISK, *PDISK; diff --git a/Private/Tools/PartTool.cxx b/Private/Tools/make_hcfs.c index dd84cfb2..273cd0fc 100644 --- a/Private/Tools/PartTool.cxx +++ b/Private/Tools/make_hcfs.c @@ -16,12 +16,10 @@ /// @brief NewFS partition program. /***********************************************************************************/ -#include <ConOut.hxx> +#include <disk_api.h> -int main() { - HCore::cout - << "PartTool: build a NewFS partition image from a directory!\n" - << "Copyright Mahrouss Logic, all rights reserved. (INTERNAL TOOL)\n"; +int main(void) { + printf("%s\n", "makeHCFS, brought to you by Amlal El Mahrouss."); return 0; } diff --git a/Private/makefile b/Private/makefile index b0354e19..e053cb96 100644 --- a/Private/makefile +++ b/Private/makefile @@ -5,7 +5,7 @@ CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -c -ffreestanding -fPIC -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ +CCFLAGS = -c -ffreestanding -fPIC -fmodules-ts -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ ASM = nasm ASMFLAGS = -f win64 LDFLAGS = -e Main --subsystem=17 |
