#include <liballoc.h>
#include <stdint.h>
#include <system.h>

extern volatile uint8_t __bss_start[];
extern volatile uint8_t __bss_end[];

extern void app_main (void);

static void clear_bss (void) {
  uint8_t* p = (uint8_t*)__bss_start;
  while (p < __bss_end) {
    *p++ = 0;
  }
}

void __premain (void) {
  clear_bss ();

  liballoc_init ();

  app_main ();

  liballoc_deinit ();

  quit ();
}
