summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-01-25 01:19:57 -0800
committerPixel <pixel@nobis-crew.org>2011-01-25 07:08:07 -0800
commitd6205d3578e89b5e20757b152d3d7ad46b5c236b (patch)
tree6d0608f7d765ecab39654266a7ee71bca372e187
parent7dd67a49d58d01cb777615aa10f642280b93e0e5 (diff)
Tweaking the init / exit sequence to make it slightly more robust.
-rw-r--r--os/src/init.c33
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));
}