From 788da9d1caab3d6617a6b96052bfcf6dd43348ef Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 23 Feb 2026 17:59:16 +0100 Subject: [PATCH] baremetal: second try (with i386-elf-gcc) --- core/shared/platform/baremetal/platform_init.c | 18 +++++++++++++----- .../platform/baremetal/platform_internal.h | 6 ++++-- .../platform/baremetal/shared_platform.cmake | 6 +++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/shared/platform/baremetal/platform_init.c b/core/shared/platform/baremetal/platform_init.c index d9b647af..2b6d91b8 100644 --- a/core/shared/platform/baremetal/platform_init.c +++ b/core/shared/platform/baremetal/platform_init.c @@ -2,6 +2,7 @@ // Many implementations taken from musl: https://git.musl-libc.org +#ifdef NODEF typedef int (*cmpfun)(const void *, const void *); void @@ -183,11 +184,13 @@ os_cond_destroy(korp_cond *cond) { return 0; } +#endif /**************************************************** * string ****************************************************/ +#ifdef NODEF static char * twobyte_strstr(const unsigned char *h, const unsigned char *n) { @@ -381,6 +384,7 @@ strstr(const char *h, const char *n) return twoway_strstr((void *)h, (void *)n); } +#endif __attribute__((weak)) void * memcpy(void *restrict dest, const void *restrict src, size_t n) @@ -459,6 +463,7 @@ memset(void *dest, int c, size_t n) return dest; } +#ifdef NODEF __attribute__((weak)) int memcmp(const void *vl, const void *vr, size_t n) { @@ -611,11 +616,13 @@ strncasecmp(const char *_l, const char *_r, size_t n) ; return my_tolower(*l) - my_tolower(*r); } +#endif /**************************************************** * stdio ****************************************************/ +#ifdef NODEF __attribute__((weak)) int snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) { @@ -644,6 +651,7 @@ __vsnprintf_chk(char *s, size_t n, int m, size_t o, const char *fmt, { return 0; } +#endif /**************************************************** * mman @@ -676,6 +684,7 @@ os_mprotect(void *addr, size_t size, int prot) * lgcc/math ****************************************************/ +#ifdef NODEF double sqrt(double x) { @@ -688,7 +697,6 @@ sqrtf(float x) return 0.0; } -/* #define arith64_u64 unsigned long long int #define arith64_s64 signed long long int #define arith64_u32 unsigned int @@ -1002,17 +1010,17 @@ __attribute__((weak)) arith64_u64 __udivmoddi4(arith64_u64 a, arith64_u64 b, arith64_u64 *c) { // -https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#index-_005f_005fudivmoddi4 +https: // gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#index-_005f_005fudivmoddi4 *c = __umoddi3(a, b); return __udivdi3(a, b); } -*/ +#endif /**************************************************** * rwlock ****************************************************/ -/* +#ifdef NODEF int os_rwlock_init(korp_rwlock *rwlock) { @@ -1076,7 +1084,7 @@ os_rwlock_unlock(korp_rwlock *rwlock) } return 0; } -*/ +#endif /**************************************************** * Section 1 * diff --git a/core/shared/platform/baremetal/platform_internal.h b/core/shared/platform/baremetal/platform_internal.h index 8a4ae791..60f149d3 100644 --- a/core/shared/platform/baremetal/platform_internal.h +++ b/core/shared/platform/baremetal/platform_internal.h @@ -13,7 +13,7 @@ #include #include // #include -#include +// #include // #include #include // #include @@ -46,7 +46,9 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; -typedef sem_t korp_sem; +typedef struct { + int dummy; +} korp_sem; // typedef pthread_rwlock_t korp_rwlock; typedef struct { diff --git a/core/shared/platform/baremetal/shared_platform.cmake b/core/shared/platform/baremetal/shared_platform.cmake index a123d693..6c0d3db3 100644 --- a/core/shared/platform/baremetal/shared_platform.cmake +++ b/core/shared/platform/baremetal/shared_platform.cmake @@ -3,10 +3,10 @@ set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR}) add_definitions(-DBH_PLATFORM_BAREMETAL) include_directories(${PLATFORM_SHARED_DIR}) + include_directories(${PLATFORM_SHARED_DIR}/../include) +# file (GLOB header ${PLATFORM_SHARED_DIR}/../include/baremetal/*.h) +# list (APPEND RUNTIME_LIB_HEADER_LIST ${header}) file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c) set (PLATFORM_SHARED_SOURCE ${source_all}) - -file (GLOB header ${PLATFORM_SHARED_DIR}/../include/baremetal/*.h) -LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})