From bf8ba3e100d420488c2120b4a35afd9a7e16f341 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 18:50:35 +0100 Subject: [PATCH 1/9] Win32: Insert a portable entry point before WinMain It's ugly but since CLI args aren't relevant, this will do. --- Core/Platforms/Win32.cpp | 6 ++---- Core/RagLite2.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Core/Platforms/Win32.cpp b/Core/Platforms/Win32.cpp index 8b310f7e..0c206a59 100644 --- a/Core/Platforms/Win32.cpp +++ b/Core/Platforms/Win32.cpp @@ -280,8 +280,8 @@ LRESULT CALLBACK MainWindowProcessIncomingMessage(HWND window, UINT message, WPA return result; } -int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, - int) { +INTERNAL void PlatformRuntimeMain() { + HINSTANCE instance = GetModuleHandle(NULL); hardware_tick_t applicationStartTime = PerformanceMetricsNow(); IntrinsicsReadCPUID(); @@ -385,6 +385,4 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, } timeEndPeriod(requestedSchedulerGranularityInMilliseconds); - - return 0; } diff --git a/Core/RagLite2.cpp b/Core/RagLite2.cpp index 23b04bab..99ecd8e8 100644 --- a/Core/RagLite2.cpp +++ b/Core/RagLite2.cpp @@ -11,4 +11,11 @@ GLOBAL memory_arena_t TRANSIENT_MEMORY = {}; #ifdef RAGLITE_PLATFORM_WINDOWS #include "Platforms/Win32.cpp" -#endif \ No newline at end of file +int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int) +#else +int main() +#endif +{ + PlatformRuntimeMain(); + return 0; +} \ No newline at end of file From 11b44898693a1a58da2ce669eb1c9ec56567231d Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 18:58:59 +0100 Subject: [PATCH 2/9] Core: Add placeholder entry points for OSX and Linux --- Core/Platforms/Linux.cpp | 3 +++ Core/Platforms/MacOS.cpp | 3 +++ Core/RagLite2.cpp | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 Core/Platforms/Linux.cpp create mode 100644 Core/Platforms/MacOS.cpp diff --git a/Core/Platforms/Linux.cpp b/Core/Platforms/Linux.cpp new file mode 100644 index 00000000..6fc59cbb --- /dev/null +++ b/Core/Platforms/Linux.cpp @@ -0,0 +1,3 @@ +INTERNAL void PlatformRuntimeMain() { + // NYI +} \ No newline at end of file diff --git a/Core/Platforms/MacOS.cpp b/Core/Platforms/MacOS.cpp new file mode 100644 index 00000000..6fc59cbb --- /dev/null +++ b/Core/Platforms/MacOS.cpp @@ -0,0 +1,3 @@ +INTERNAL void PlatformRuntimeMain() { + // NYI +} \ No newline at end of file diff --git a/Core/RagLite2.cpp b/Core/RagLite2.cpp index 99ecd8e8..b2ac9184 100644 --- a/Core/RagLite2.cpp +++ b/Core/RagLite2.cpp @@ -11,6 +11,13 @@ GLOBAL memory_arena_t TRANSIENT_MEMORY = {}; #ifdef RAGLITE_PLATFORM_WINDOWS #include "Platforms/Win32.cpp" +#elifdef RAGLITE_PLATFORM_MACOS +#include "Platforms/MacOS.cpp" +#elifdef RAGLITE_PLATFORM_LINUX +#include "Platforms/Linux.cpp" +#endif + +#ifdef RAGLITE_PLATFORM_WINDOWS int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int) #else int main() From 522f7a4ebd2acea4bb67dfceb32daadd87a1fcd0 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 19:11:02 +0100 Subject: [PATCH 3/9] Core: Add toolchain defines for GCC and CLANG There's some overlap here because clang may define the GNU and MSVC ones. Once it's clear which toolchain features are actually required, replace with a more specific (and hopefully robust) approach to builtin/feature detection? --- Core/RagLite2.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Core/RagLite2.hpp b/Core/RagLite2.hpp index 9a09bcfa..01cd2ee3 100644 --- a/Core/RagLite2.hpp +++ b/Core/RagLite2.hpp @@ -18,13 +18,13 @@ #error "Unsupported Platform: OS-specific code paths have yet to be ported" #endif -#define RAGLITE_COMPILER_GCC 0 -#define RAGLITE_COMPILER_LLVM 0 -#define RAGLITE_COMPILER_MSVC 0 - -#ifdef _MSC_VER -#undef RAGLITE_COMPILER_MSVC -#define RAGLITE_COMPILER_MSVC 1 +// NOTE: Should probably use feature detection macros, but for now assume the latest (tested) version will work +#if defined(__clang__) +#define RAGLITE_COMPILER_CLANG +#elif defined(_MSC_VER) +#define RAGLITE_COMPILER_MSVC +#elif defined(__GNUC__) +#define RAGLITE_COMPILER_GCC 1 #else #define RAGLITE_UNSUPPORTED_COMPILER #endif From 58b0306885f87ec5d4dafbcca6fe2fd68e0c4d0c Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 19:27:16 +0100 Subject: [PATCH 4/9] Win32: Fix MSYS2/GCC compilation errors It does not figure out what a size_t is without specific headers, but it did know you're supposed to include cstddef (which I'd rather avoid). --- Core/Platforms/Win32.cpp | 2 +- Core/RagLite2.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Platforms/Win32.cpp b/Core/Platforms/Win32.cpp index 0c206a59..9caecbec 100644 --- a/Core/Platforms/Win32.cpp +++ b/Core/Platforms/Win32.cpp @@ -326,7 +326,7 @@ INTERNAL void PlatformRuntimeMain() { GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); ATOM classGUID = RegisterClassEx(&windowClass); - ASSUME(classGUID != NULL, "Failed to register window class (...really?)"); + ASSUME(classGUID, "Failed to register window class (...really?)"); // TODO: On modern Windows systems, MAX_PATH is insufficient and Unicode paths should ideally be supported (later?) TCHAR executableFileSystemPath[MAX_PATH]; diff --git a/Core/RagLite2.hpp b/Core/RagLite2.hpp index 01cd2ee3..8524dd1a 100644 --- a/Core/RagLite2.hpp +++ b/Core/RagLite2.hpp @@ -44,10 +44,10 @@ #define EXPAND_AS_STRING(x) #x #define TOSTRING(x) EXPAND_AS_STRING(x) -constexpr size_t BITS_PER_BYTE = 8ULL; +constexpr int BITS_PER_BYTE = 8; #define Bits(bits) ((bits) / BITS_PER_BYTE) -constexpr size_t PLATFORM_POINTER_SIZE = sizeof(void*); +constexpr int PLATFORM_POINTER_SIZE = sizeof(void*); static_assert(PLATFORM_POINTER_SIZE == Bits(64), "Only 64-bit platforms are currently supported"); #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ From 3ce1083524dd0b98c5c5b093072dd52410619764 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 19:27:53 +0100 Subject: [PATCH 5/9] Core: Port some of the intrinsics to GCC and CLANG Skipping the CPU ID utility for now as the requirements may change. --- Core/Intrinsics.hpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Core/Intrinsics.hpp b/Core/Intrinsics.hpp index 74b606ae..ca7eb5ca 100644 --- a/Core/Intrinsics.hpp +++ b/Core/Intrinsics.hpp @@ -1,5 +1,3 @@ -#include - // TODO Eliminate this #include @@ -8,6 +6,9 @@ GLOBAL char CPU_BRAND_STRING[0x40] = { "N/A (__cpuid intrinsic not yet supported #ifdef RAGLITE_COMPILER_MSVC +#include + +// TODO: Should look into whether (and how much) dllimport improves performance? #define EXPORT extern "C" __declspec(dllexport) INTERNAL void IntrinsicsReadCPUID() { @@ -25,14 +26,25 @@ INTERNAL void IntrinsicsReadCPUID() { __cpuid((int*)CPU_INFO_MASK, 0x80000004); memcpy(CPU_BRAND_STRING + 32, CPU_INFO_MASK, sizeof(CPU_INFO_MASK)); } +} #define DebugTrap() __debugbreak(); #else -// TODO Support for the other toolchains -#endif + +#include + +// TODO: Only relevant if the build script (that doesn't currently exist) uses -fvisibility=hidden +#define EXPORT extern "C" __attribute__((visibility("default"))) + +INTERNAL void IntrinsicsReadCPUID() { + // NYI: Probably need to rewrite this anyway, so for now just leave it as a placeholder } +#define DebugTrap() __builtin_trap(); + +#endif + // TODO: typeof(x) could simplify this - look into toolchain support/extensions? #define Swap(first, second, type) \ do { \ From 89611151fccaf1aaddbfb107e01b747c4d329200 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 20:58:36 +0100 Subject: [PATCH 6/9] Linux: Create a runtime stub that dumps CPUID info Throwaway code that can be replaced with an intrinsic utility later. --- Core/Platforms/Linux.cpp | 52 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/Core/Platforms/Linux.cpp b/Core/Platforms/Linux.cpp index 6fc59cbb..15a3a40b 100644 --- a/Core/Platforms/Linux.cpp +++ b/Core/Platforms/Linux.cpp @@ -1,3 +1,51 @@ +// ABOUT: This is a placeholder program that has nothing in common with the Win32 platform runtime (delete when porting) + +#include +#include +#include +#include +#include + +void DebugPrintASCII(unsigned int value) { + for(int i = 0; i < 4; i++) { + char byte = (value >> (i * 8)) & 0xFF; + printf("%c", byte); + } +} + +// See https://en.wikipedia.org/wiki/CPUID and https://github.com/gcc-mirror/gcc/blob/master/gcc/config/i386/cpuid.h +INTERNAL void DebugDumpCPUID() { + unsigned int eax, ebx, ecx, edx; + // EAX=0: Highest Function Parameter and Manufacturer ID + uint EAX_input = 0; + unsigned int ret = __get_cpuid(EAX_input, &eax, &ebx, &ecx, &edx); + if(ret != 1) { + errx(EXIT_FAILURE, "Failed to call CPUID with EAX=%d", EAX_input); + } + + printf("CPU Manufacturer ID: "); + DebugPrintASCII(ebx); + DebugPrintASCII(edx); + DebugPrintASCII(ecx); + printf("\n"); +} + INTERNAL void PlatformRuntimeMain() { - // NYI -} \ No newline at end of file + printf("There is no platform runtime for Linux yet. Instead, behold this placeholder program :3\n"); + + DebugDumpCPUID(); + // TODO: Maybe dump some of the other CPU details also? Not really useful right now... + + unsigned eax = 0; + unsigned ebx = 0; + unsigned ecx = 0; + unsigned edx = 0; + + int r = __get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx); + if(!r) { + fprintf(stderr, "cpuid leaf 7 unsupported ...\n"); + return; + } + printf("cpuid.07h.0: eax=0x%x ebx=0x%x ecx=0x%x edx=0x%x\n", + eax, ebx, ecx, edx); +} From 5268c76c444dfda97bdb6069b5f4f6d24fcf00af Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 21:12:18 +0100 Subject: [PATCH 7/9] Build: Create a basic build script for Linux and OSX --- unixbuild.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 unixbuild.sh diff --git a/unixbuild.sh b/unixbuild.sh new file mode 100755 index 00000000..bdaddbec --- /dev/null +++ b/unixbuild.sh @@ -0,0 +1,6 @@ +# NOTE: This is not a full port of the MSVC build script, but rather a placeholder for local testing. +# NOTE: Eventually, a proper (more portable) solution will be required. But not today... so this is all there is + +mkdir -p BuildArtifacts +RUNTIME_LIBS="" +gcc Core/RagLite2.cpp -o BuildArtifacts/RagLite2 $RUNTIME_LIBS -lm -fvisibility=hidden From e73088f530d1f66c697edbd12458caed8a1b1305 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 21:10:12 +0100 Subject: [PATCH 8/9] Repo: Create a placeholder build script for MSYS2 Not at all comprehensive, no CI testing either. Will be replaced with something else. --- msys2build.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 msys2build.sh diff --git a/msys2build.sh b/msys2build.sh new file mode 100644 index 00000000..43ce135f --- /dev/null +++ b/msys2build.sh @@ -0,0 +1,6 @@ +# NOTE: This is not a full port of the MSVC build script, but rather a placeholder for local testing. +# NOTE: Eventually, a proper (more portable) solution will be required. But not today... so this is all there is + +mkdir -p BuildArtifacts +RUNTIME_LIBS="-l gdi32 -l shlwapi -l user32 -l xinput -l winmm -l imagehlp -l ws2_32" +gcc Core/RagLite2.cpp -o BuildArtifacts/RagLiteMSYS2.exe $RUNTIME_LIBS \ No newline at end of file From 1a4f06f812a34810c74c7a4e831ac044f2369cbe Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 20 Mar 2026 21:41:34 +0100 Subject: [PATCH 9/9] MacOS: Create a placeholder program for the OSX platform runtime --- Core/Platforms/MacOS.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/Platforms/MacOS.cpp b/Core/Platforms/MacOS.cpp index 6fc59cbb..26e4b96c 100644 --- a/Core/Platforms/MacOS.cpp +++ b/Core/Platforms/MacOS.cpp @@ -1,3 +1,6 @@ +// ABOUT: This is a placeholder program that has nothing in common with the Win32 platform runtime (delete when porting) + +#include INTERNAL void PlatformRuntimeMain() { - // NYI + printf("This is a placeholder program; there's no OSX platform runtime yet...\n"); } \ No newline at end of file