#include <cstdint>

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

namespace {

enum VectorTableEntry {
    StackPointer = 0,
    Reset = 1,
};

void ResetHandler() {
    // clear .bss
    for (uint32_t* ptr = &_bss_begin; ptr < &_bss_end; ptr++) {
        *ptr = 0;
    }

    main();

    while (true) {
    }
}

}  // namespace

__attribute__((section(".vector_table"), used)) uint32_t vector_table[16] = {
    [StackPointer] = reinterpret_cast<uint32_t>(&_initial_stack_pointer),
    [Reset] = reinterpret_cast<uint32_t>(ResetHandler),
};
