/* init/main.c
*
* This file is part of evx.
*
* evx is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* evx is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with evx. If not, see
*/
#include
#include
#include
#include
int do_init_calls(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;
}