|
@@ -22,12 +22,67 @@
|
|
|
#include <kernel/init.h>
|
|
#include <kernel/init.h>
|
|
|
#include <kernel/module.h>
|
|
#include <kernel/module.h>
|
|
|
|
|
|
|
|
|
|
+#include <arch/archinfo.h>
|
|
|
|
|
+
|
|
|
#include <sys/types.h>
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+int do_init_calls(void);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
int __init init(void) {
|
|
int __init init(void) {
|
|
|
|
|
+ return do_init_calls();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+static void *init_call_levels[] = {
|
|
|
|
|
+ &_init_call_arch, &_einit_call_arch,
|
|
|
|
|
+ &_init_call_kernel, &_einit_call_kernel,
|
|
|
|
|
+ &_init_call_modules, &_einit_call_modules
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ * call hooks in those sections those defined with init_call_levels.
|
|
|
|
|
+ *
|
|
|
|
|
+ * that when you use a module_init() macro, you add a new entry into
|
|
|
|
|
+ * that section. when bootstrap, we call them with no argument. if one
|
|
|
|
|
+ * of them returns a non-zero, kernel will halt and do nothing.
|
|
|
|
|
+ * */
|
|
|
|
|
+
|
|
|
|
|
+typedef int (* __initcall_t) (void);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+int do_init_calls(void) {
|
|
|
|
|
+ int error;
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ __archptr_t *start, *end;
|
|
|
|
|
+ __archptr_t fn, *initcalls;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < ARRAYSIZE(init_call_levels); i++) {
|
|
|
|
|
+ start = init_call_levels[++i];
|
|
|
|
|
+ end = init_call_levels[++i];
|
|
|
|
|
+
|
|
|
|
|
+ int ncalls = (end - start) >> PTRSHIFT;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ for (initcalls = start; ncalls; initcalls++, ncalls--) {
|
|
|
|
|
+ fn = *initcalls;
|
|
|
|
|
+
|
|
|
|
|
+ if (!fn)
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ if ((error = ((__initcall_t) fn)()))
|
|
|
|
|
+ return error;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|