#include <cstdint>

extern "C" uint32_t _bss_begin, _bss_end, _initial_stack_pointer;
extern "C" int main();
extern "C" void __libc_init_array();

__attribute__((section(".start"), used, naked)) void _start() {
    // clear .bss
    for (uint32_t* ptr = &_bss_begin; ptr < &_bss_end; ptr++) {
        *ptr = 0;
    }

    asm volatile("la sp, _initial_stack_pointer");

    __libc_init_array();

    main();

    while (true) {
    }
}
