55 */
66
77#include " Arduino.h"
8+ #include < cstdint>
89#ifdef CONFIG_LLEXT
910#include < zephyr/llext/symbol.h>
1011#endif
@@ -45,4 +46,40 @@ int main(void) {
4546
4647#ifdef CONFIG_LLEXT
4748LL_EXTENSION_SYMBOL (main);
48- #endif
49+ #endif
50+
51+ /* These magic symbols are provided by the linker. */
52+ extern void (*__preinit_array_start []) (void ) __attribute__((weak));
53+ extern void (*__preinit_array_end []) (void ) __attribute__((weak));
54+ extern void (*__init_array_start []) (void ) __attribute__((weak));
55+ extern void (*__init_array_end []) (void ) __attribute__((weak));
56+
57+ static void __libc_init_array (void )
58+ {
59+ size_t count;
60+ size_t i;
61+
62+ count = __preinit_array_end - __preinit_array_start;
63+ for (i = 0 ; i < count; i++)
64+ __preinit_array_start[i] ();
65+
66+ count = __init_array_end - __init_array_start;
67+ for (i = 0 ; i < count; i++)
68+ __init_array_start[i] ();
69+ }
70+
71+ extern " C" __attribute__((section(" .entry_point" ), used)) void entry_point (k_thread_stack_t * stack, size_t stack_size) {
72+ // copy .data in the right place
73+ // .bss should already be in the right place
74+ // call constructors
75+ extern uintptr_t _sidata;
76+ extern uintptr_t _sdata;
77+ extern uintptr_t _edata;
78+ extern uintptr_t _sbss;
79+ extern uintptr_t _ebss;
80+ // __asm volatile ("cpsie i");
81+ memcpy (&_sdata, &_sidata, &_edata - &_sdata);
82+ memset (&_sbss, 0 , &_ebss - &_sbss);
83+ __libc_init_array ();
84+ main ();
85+ }
0 commit comments