From 370218b35fc2db978cc0b8cc0a9eb25bbdbc7f91 Mon Sep 17 00:00:00 2001 From: Miraculous Ladybugreport <3642643+PeyTy@users.noreply.github.com> Date: Thu, 23 May 2024 20:49:48 +0300 Subject: [PATCH] [DLL] Proper initializers --- dlls/advapi32.dll/advapiMain.hexa | 48 ++++++++++++++++++--- dlls/advapi32.dll/hexa.json | 56 ++++++++++++------------ dlls/comctl32.dll/hexa.json | 59 ++++++++++++------------- dlls/gdi32.dll/hexa.json | 1 + dlls/kernel32.dll/kernel32.header.hexa | 2 +- dlls/kernel32.dll/kernelMain.hexa | 21 +++++++-- dlls/msvcrt.dll/hexa.json | 60 +++++++++++++------------- dlls/msvcrt.dll/msvcrt.hexa | 11 ++--- 8 files changed, 157 insertions(+), 101 deletions(-) diff --git a/dlls/advapi32.dll/advapiMain.hexa b/dlls/advapi32.dll/advapiMain.hexa index 04ad14c2..84eb4542 100644 --- a/dlls/advapi32.dll/advapiMain.hexa +++ b/dlls/advapi32.dll/advapiMain.hexa @@ -16,15 +16,54 @@ // Entry point of the project @customHeader(' - #if 0 + #define HEXA_NEW(z) HeapAlloc(0,0,z) + void *tmemcpy(void *dest, const void *src, uint64_t count) { + uint8_t *dst8 = (uint8_t *)dest; + const uint8_t *src8 = (const uint8_t *)src; + + while (count--) { + *dst8++ = *src8++; + } + + return dest; + } + // TODO + #define memcpy(z,u,x) tmemcpy(z,u,x) + + // TODO just import kernel32 + #define wprintf(z,...) {} + #define HEAP_ZERO_MEMORY 0 + #define fflush(z) {} + #define stdout ((void*)0) + #define GetProcessHeap() 0 + + int64_t _fltused = 0; + #ifdef bit64 - #define ADVAPI32_DLL __declspec(dllexport) #else - #define ADVAPI32_DLL __declspec(dllexport) __stdcall + int64_t __alldiv() asm("__alldiv"); + int64_t __alldiv() { return 0; } // TODO + + int64_t __allrem() asm("__allrem"); + int64_t __allrem() { return 0; } // TODO + + uint64_t __aulldiv() asm("__aulldiv"); + uint64_t __aulldiv() { return 0; } // TODO + + uint64_t __aullrem() asm("__aullrem"); + uint64_t __aullrem() { return 0; } // TODO + + void _memset() asm("_memset"); + void _memset() { + } // TODO TODO TODO + + void _memcpy() asm("_memcpy"); + void _memcpy() { + } // TODO TODO TODO #endif void startup() { - // TODO hexa + HEXA_MAIN(0, nullptr); } #ifdef bit64 @@ -39,6 +78,5 @@ // TODO must return something? } #endif - #endif ') declare fun entryTODO() Void diff --git a/dlls/advapi32.dll/hexa.json b/dlls/advapi32.dll/hexa.json index 86664c62..2a71d443 100644 --- a/dlls/advapi32.dll/hexa.json +++ b/dlls/advapi32.dll/hexa.json @@ -1,30 +1,30 @@ { - "name": "Advapeh", - "version": "1.0.0", - "description": "Greentea OS", - "author": "PeyTy", - "license": "LGPL-3.0-only", - "global": [ - "../types", - "../../kernel/syscalls/syscalls", - "../kernel32.dll/kernel32.header", - "../ntdll.dll/ntdll.header", - "../gdi32.dll/gdiMain", - "advapiMain" - ], - "targets": [ - { - "name": "default", - "generator": "c", - "output": "advapi32.64.c", - "options": [] - }, - { - "name": "i386", - "generator": "c", - "output": "advapi32.32.c", - "options": [] - } - ], - "entry": "advapi32" + "name": "Advapeh", + "version": "1.0.0", + "description": "Greentea OS", + "author": "PeyTy", + "license": "LGPL-3.0-only", + "global": [ + "../types", + "../../kernel/syscalls/syscalls", + "../tofita32.dll/tofita32.header", + "../kernel32.dll/kernel32.header", + "../ntdll.dll/ntdll.header", + "advapiMain" + ], + "targets": [ + { + "name": "default", + "generator": "c", + "output": "advapi32.64.c", + "options": [] + }, + { + "name": "i386", + "generator": "c", + "output": "advapi32.32.c", + "options": [] + } + ], + "entry": "advapi32" } diff --git a/dlls/comctl32.dll/hexa.json b/dlls/comctl32.dll/hexa.json index 096066b8..31c29c14 100644 --- a/dlls/comctl32.dll/hexa.json +++ b/dlls/comctl32.dll/hexa.json @@ -1,31 +1,32 @@ { - "name": "CommonControls", - "version": "1.0.0", - "description": "Greentea OS", - "author": "PeyTy", - "license": "LGPL-3.0-only", - "global": [ - "../types", - "../../kernel/syscalls/syscalls", - "../kernel32.dll/kernel32.header", - "../ntdll.dll/ntdll.header", - "comctl32.header", - "comctlMain", - "comctl32Vars" - ], - "targets": [ - { - "name": "default", - "generator": "c", - "output": "comctl32.64.c", - "options": [] - }, - { - "name": "i386", - "generator": "c", - "output": "comctl32.32.c", - "options": [] - } - ], - "entry": "comctl32" + "name": "CommonControls", + "version": "1.0.0", + "description": "Greentea OS", + "author": "PeyTy", + "license": "LGPL-3.0-only", + "global": [ + "../types", + "../../kernel/syscalls/syscalls", + "../tofita32.dll/tofita32.header", + "../kernel32.dll/kernel32.header", + "../ntdll.dll/ntdll.header", + "comctl32.header", + "comctlMain", + "comctl32Vars" + ], + "targets": [ + { + "name": "default", + "generator": "c", + "output": "comctl32.64.c", + "options": [] + }, + { + "name": "i386", + "generator": "c", + "output": "comctl32.32.c", + "options": [] + } + ], + "entry": "comctl32" } diff --git a/dlls/gdi32.dll/hexa.json b/dlls/gdi32.dll/hexa.json index 1abfcddd..b11e46dd 100644 --- a/dlls/gdi32.dll/hexa.json +++ b/dlls/gdi32.dll/hexa.json @@ -7,6 +7,7 @@ "global": [ "../types", "../../kernel/syscalls/syscalls", + "../tofita32.dll/tofita32.header", "../kernel32.dll/kernel32.header", "../ntdll.dll/ntdll.header", "gdi32.header", diff --git a/dlls/kernel32.dll/kernel32.header.hexa b/dlls/kernel32.dll/kernel32.header.hexa index 6964b2f9..5b2b2a74 100644 --- a/dlls/kernel32.dll/kernel32.header.hexa +++ b/dlls/kernel32.dll/kernel32.header.hexa @@ -21,7 +21,7 @@ fun localAlloc(flags UInt32, bytes SizeOfPointer) HLocal @dllImport @rename('HeapAlloc') declare -fun heapAlloc(heap UInt32, flags UInt32, bytes SizeOfPointer) ArrayPointer +fun heapAlloc(heap SizeOfPointer, flags UInt32, bytes SizeOfPointer) ArrayPointer // TODO // let kernel32 = "kernel32.dll" (uppercase?) // @dllImport(kernel32) (fpc) diff --git a/dlls/kernel32.dll/kernelMain.hexa b/dlls/kernel32.dll/kernelMain.hexa index 57339d1f..020fdfd8 100644 --- a/dlls/kernel32.dll/kernelMain.hexa +++ b/dlls/kernel32.dll/kernelMain.hexa @@ -16,12 +16,25 @@ // Entry point of the project @customHeader(' +void *tmemcpy(void *dest, const void *src, uint64_t count) { + tofitaDebugLog_(L"tmemcpy", (uint64_t)((int32_t)0), (uint64_t)((int32_t)0)); + uint8_t *dst8 = (uint8_t *)dest; + const uint8_t *src8 = (const uint8_t *)src; + + while (count--) { + *dst8++ = *src8++; + } + + return dest; +} +// TODO +#define memcpy(z,u,x) tmemcpy(z,u,x) + #define HEXA_NO_DEFAULT_INCLUDES #define HEXA_MAIN mainHexa -#define HEXA_NEW(z) ((void*)0) -#define HeapAlloc(z,...) ((void*)0) +#define HeapAlloc heapAlloc_ +#define GetProcessHeap() 0 // TODO ^ -#define memcpy(z,...) {} #define wprintf(z,...) {} #define HEAP_ZERO_MEMORY ((void*)0) #define fflush(z) {} @@ -50,6 +63,7 @@ void _memset() { } // TODO TODO TODO void startup() { // TODO hexa + HEXA_MAIN(0, nullptr); } #ifdef bit64 @@ -62,6 +76,5 @@ __attribute__((stdcall)) void _DllMainCRTStartup(void *, void *, void *) { startup(); } #endif - ') declare fun entry() Void diff --git a/dlls/msvcrt.dll/hexa.json b/dlls/msvcrt.dll/hexa.json index 8ff3dd47..0f02e08e 100644 --- a/dlls/msvcrt.dll/hexa.json +++ b/dlls/msvcrt.dll/hexa.json @@ -1,31 +1,33 @@ { - "name": "ClangRuntime", - "version": "1.0.0", - "description": "Greentea OS", - "author": "PeyTy", - "license": "LGPL-3.0-only", - "global": [ - "../types", - "../../kernel/syscalls/syscalls", - "../kernel32.dll/kernel32.header", - "../ntdll.dll/ntdll.header", - "msvcrt.header", - "msvcrtMain", - "msvcrtVars" - ], - "targets": [ - { - "name": "default", - "generator": "c", - "output": "msvcrt.64.c", - "options": [] - }, - { - "name": "i386", - "generator": "c", - "output": "msvcrt.32.c", - "options": [] - } - ], - "entry": "msvcrt" + "name": "ClangRuntime", + "version": "1.0.0", + "description": "Greentea OS", + "author": "PeyTy", + "license": "LGPL-3.0-only", + "global": [ + "../types", + "../../kernel/syscalls/syscalls", + "../tofita32.dll/tofita32.header", + "../kernel32.dll/kernel32.header", + "../ntdll.dll/ntdll.header", + "msvcrt.header", + "msvcrtMain", + "msvcrtVars" + ], + "targets": [ + { + "name": "default", + "generator": "c", + "output": "msvcrt.64.c", + "options": [] + }, + { + "name": "i386", + "generator": "c", + "output": "msvcrt.32.c", + "options": [ + ] + } + ], + "entry": "msvcrt" } diff --git a/dlls/msvcrt.dll/msvcrt.hexa b/dlls/msvcrt.dll/msvcrt.hexa index 51194b16..4491d8eb 100644 --- a/dlls/msvcrt.dll/msvcrt.hexa +++ b/dlls/msvcrt.dll/msvcrt.hexa @@ -19,13 +19,14 @@ fun stub() {} @linkName('_DllMainCRTStartup_TODO') #if bit32 @stdcall + @stdcall #else - @fastcall + @fastcall #end fun _DllMainCRTStartup( - unusedX Any, - unusedY Any, - unusedZ Any + unusedX Any, + unusedY Any, + unusedZ Any ) Void { - // TODO + // TODO }