From d6205d3578e89b5e20757b152d3d7ad46b5c236b Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 25 Jan 2011 01:19:57 -0800 Subject: Tweaking the init / exit sequence to make it slightly more robust. --- os/src/init.c | 33 +++++++++++++++++++++++++-------- 1 file 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 +#include -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)); } -- cgit v1.2.3