diff options
-rw-r--r-- | os/src/init.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/os/src/init.c b/os/src/init.c index d161355..4febb10 100644 --- a/os/src/init.c +++ b/os/src/init.c @@ -1,23 +1,40 @@ #include <stdlib.h> +#include <BoardConsole.h> -extern void __libc_init_array(void) __attribute__ ((weak)); -extern void __libc_fini_array(void) __attribute__ ((weak)); -extern void exit(int) __attribute__ ((noreturn, weak)); +extern void __libc_init_array() __attribute__((weak)); +extern void __libc_fini_array() __attribute__((weak)); extern void __main() __attribute__ ((weak)); extern int main(int, char **, char **); +extern void BoardEarlyInit() __attribute__((weak)); +extern void BoardLateInit() __attribute__((weak)); +extern void BoardExceptionHandler(int) __attribute__((weak)); +extern void BoardShutdown() __attribute__((weak)); + +void _exit(int return_code) __attribute__((noreturn)); +void _exit(int return_code) { + if (return_code && BoardExceptionHandler) + BoardExceptionHandler(return_code); + if (BoardShutdown) + BoardShutdown(); + while(1); +} void _start() { + if (BoardEarlyInit) + BoardEarlyInit(); + BoardConsoleInit(); + BoardConsolePuts("uC-sdk - booting."); if (__libc_init_array) __libc_init_array(); if (__main) __main(); - int return_code = main(0, NULL, NULL); - + if (BoardLateInit) + BoardLateInit(); + if (__libc_fini_array) - __libc_fini_array(); + atexit(__libc_fini_array); - if (exit) - exit(return_code); + exit(main(0, NULL, NULL)); } |