main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* init/main.c
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <kernel/init.h>
  19. #include <kernel/module.h>
  20. #include <kernel/kernel.h>
  21. #include <kernel/kmlog.h>
  22. #include <kernel/mm.h>
  23. #include <arch/archinfo.h>
  24. #include <arch/asm.h>
  25. #include <arch/mm.h>
  26. #include <sys/types.h>
  27. int init_state;
  28. static int do_init_calls(void);
  29. int __init init(void) {
  30. struct page *p = NULL;
  31. int i;
  32. init_state = STATE_INIT_CALLS;
  33. do_init_calls();
  34. init_state = STATE_READY;
  35. i = 1 / (long) p;
  36. kmlog("%d\n", i);
  37. return 0;
  38. }
  39. void *__init_data init_call_levels[] = {
  40. &_init_call_arch, &_einit_call_arch,
  41. &_init_call_kernel, &_einit_call_kernel,
  42. &_init_call_modules, &_einit_call_modules
  43. };
  44. /*
  45. * call hooks in those sections those defined with init_call_levels.
  46. *
  47. * that when you use a module_init() macro, you add a new entry into
  48. * that section. when bootstrap, we call them with no argument. if one
  49. * of them returns a non-zero, kernel will halt and do nothing.
  50. * */
  51. typedef int (* __initcall_t) (void);
  52. static int do_init_calls(void) {
  53. int error;
  54. int i;
  55. __archptr_t *start, *end;
  56. __archptr_t fn, *initcalls;
  57. for (i = 0; i < ARRAYSIZE(init_call_levels); i++) {
  58. start = init_call_levels[i];
  59. end = init_call_levels[++i];
  60. int ncalls = end - start;
  61. for (initcalls = start; ncalls; initcalls++, ncalls--) {
  62. fn = *initcalls;
  63. if (!fn)
  64. break;
  65. if ((error = ((__initcall_t) fn)()))
  66. return error;
  67. }
  68. }
  69. return 0;
  70. }