diff --git a/CMakeLists.txt b/CMakeLists.txt index f8b2837..4e51804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.16) project(Nova64 VERSION 1.0.0 LANGUAGES C) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + option(BUILD_CORE "Build the Nova64 native core library" ON) option(BUILD_ESP32 "Build the ESP32 firmware project" OFF) option(BUILD_SIMULATOR "Build the C# simulator project" OFF) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 00dc88d..65a82ee 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -6,10 +6,9 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) + endif() - - if(ESP_PLATFORM) # -------------------------------------------------------------------------- # 1. ESP-IDF BUILD MODE (Target: ESP32-P4) @@ -48,10 +47,11 @@ else() projCOVERAGE_TEST=0 ) + include(FetchContent) + # -------------------------------------------------------------------------- # FreeRTOS Kernel via FetchContent # -------------------------------------------------------------------------- - include(FetchContent) # Download FreeRTOS-Kernel Repository FetchContent_Declare( @@ -70,8 +70,36 @@ else() # Disable FreeRTOS Demos/Tests set(BUILD_TESTING OFF CACHE BOOL "" FORCE) + # -------------------------------------------------------------------------- + # WAMR (WebAssembly Micro Runtime) via FetchContent + # -------------------------------------------------------------------------- + + FetchContent_Declare( + wamr_runtime + GIT_REPOSITORY https://github.com/bytecodealliance/wasm-micro-runtime.git + GIT_TAG WAMR-2.4.5 + ) + + # WAMR Desktop-Konfiguration + set(WAMR_BUILD_INTERP 1 CACHE BOOL "" FORCE) + set(WAMR_BUILD_FAST_INTERP 1 CACHE BOOL "" FORCE) + set(WAMR_BUILD_JIT 0 CACHE BOOL "" FORCE) + set(WAMR_BUILD_AOT 0 CACHE BOOL "" FORCE) + set(WAMR_BUILD_LIBC_BUILTIN 1 CACHE BOOL "" FORCE) + + # Disable WASI + set(WAMR_BUILD_LIBC_WASI 0 CACHE BOOL "" FORCE) + + if(WIN32) + set(WAMR_BUILD_PLATFORM "windows" CACHE STRING "" FORCE) + elseif(APPLE) + set(WAMR_BUILD_PLATFORM "darwin" CACHE STRING "" FORCE) + else() + set(WAMR_BUILD_PLATFORM "linux" CACHE STRING "" FORCE) + endif() + # define Target 'freertos_kernel' - FetchContent_MakeAvailable(FreeRTOS_Kernel) + FetchContent_MakeAvailable(FreeRTOS_Kernel wamr_runtime) # -------------------------------------------------------------------------- # Nova64 Core Target @@ -85,10 +113,18 @@ else() ) # Link FreeRTOS Kernel to the nova64_core library - target_link_libraries(nova64_core PRIVATE freertos_kernel freertos_config) + target_link_libraries(nova64_core PRIVATE freertos_kernel freertos_config vmlib) target_compile_definitions(nova64_core PRIVATE NOVA64_EXPORTS) + if(MSVC) + add_compile_definitions( + COMPILING_WASM_RUNTIME_API + alignof=__alignof + _Alignof=__alignof + ) + endif() + if (WIN32) set_target_properties(nova64_core PROPERTIES C_VISIBILITY_PRESET hidden diff --git a/core/include/nova64_core.h b/core/include/nova64_core.h index 582bd11..771a053 100644 --- a/core/include/nova64_core.h +++ b/core/include/nova64_core.h @@ -3,6 +3,7 @@ #include #include +#include // Cross-platform DLL export/import visibility macros #if defined(_WIN32) || defined(__CYGWIN__) diff --git a/core/include/nova64_internal.h b/core/include/nova64_internal.h new file mode 100644 index 0000000..a04d1db --- /dev/null +++ b/core/include/nova64_internal.h @@ -0,0 +1,6 @@ +#ifndef NOVA64_INTERNAL_H +#define NOVA64_INTERNAL_H + +void nova64_log(const char *format, ...); + +#endif // NOVA64_INTERNAL_H \ No newline at end of file diff --git a/core/include/wasm_runner.h b/core/include/wasm_runner.h new file mode 100644 index 0000000..fc2e983 --- /dev/null +++ b/core/include/wasm_runner.h @@ -0,0 +1,40 @@ +#ifndef WASM_RUNNER_H +#define WASM_RUNNER_H + +#include +#include + +typedef enum { + wasm_runner_role_main = 0, + wasm_runner_role_status, + wasm_runner_role_background, +} wasm_runner_role_t; + +typedef struct wasm_runner_instance wasm_runner_instance_t; + +typedef struct { + bool enabled; + uint16_t x; + uint16_t y; + uint16_t width; + uint16_t height; +} wasm_runner_framebuffer_config_t; + +bool wasm_runner_initialize(void); + +/** + * @brief Starts a WASM program with optional framebuffer access. + * + * @param module_path Path to the WASM module to start. + * @param framebuffer_config Optional framebuffer configuration. If NULL, + * framebuffer access is disabled. + * @param out_instance Optional output pointer that receives a handle to the + * running WAMR instance. + * @return True on success, false on failure. + */ +bool wasm_runner_start_program( + const char *module_path, + const wasm_runner_framebuffer_config_t *framebuffer_config, + wasm_runner_instance_t **out_instance); + +#endif // WASM_RUNNER_H diff --git a/core/src/nova64_core.c b/core/src/nova64_core.c index b7747bf..4d7ae65 100644 --- a/core/src/nova64_core.c +++ b/core/src/nova64_core.c @@ -1,17 +1,18 @@ #include "nova64_core.h" +#include "nova64_internal.h" #include "FreeRTOS.h" #include "queue.h" #include "task.h" +#include "wasm_runner.h" #include #include + #if defined(ESP_PLATFORM) -/* ESP32-spezifische Header für Low-Power & Watchdog */ #include "esp_pm.h" #include "esp_rom_sys.h" #include "esp_task_wdt.h" #elif defined(_WIN32) -/* Windows API für Schlafen im Desktop-Thread */ #include #else /* POSIX / Linux / macOS Sleep */ @@ -30,7 +31,7 @@ static volatile bool shutdown_requested = false; static const char *const kInternalLauncherPath = "SYS:/launcher.wasm"; -static void nova64_log(const char *format, ...) { +void nova64_log(const char *format, ...) { char buffer[512]; va_list args; va_start(args, format); @@ -46,6 +47,7 @@ static void nova64_log(const char *format, ...) { static bool initialize_wasm_runtime(void) { nova64_log("Initializing WASM runtime...\n"); + wasm_runner_initialize(); // TODO: Replace this stub with real WAMR initialization. return true; } @@ -174,8 +176,7 @@ NOVA64_API int32_t nova64_main() { return -1; } - nova64_log( - "Entering main runtime and starting FreeRTOS scheduler...\n"); + nova64_log("Entering main runtime and starting FreeRTOS scheduler...\n"); vTaskStartScheduler(); // vTaskStartScheduler only returns if the scheduler fails to start or if diff --git a/core/src/wasm_runner.c b/core/src/wasm_runner.c index e69de29..730ed07 100644 --- a/core/src/wasm_runner.c +++ b/core/src/wasm_runner.c @@ -0,0 +1,16 @@ +#include "wasm_runner.h" +#include "nova64_internal.h" +#include "wasm_export.h" + +struct wasm_runner_instance { + void *native_instance; + char *module_path; + wasm_runner_framebuffer_config_t framebuffer_config; + wasm_runner_instance_t *next; +}; + +bool wasm_runner_initialize(void) { + wasm_runtime_init(); + nova64_log("WASM runtime initialized successfully.\n"); + return true; +}