main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/mm.h>
  22. #include <arch/archinfo.h>
  23. #include <arch/mm.h>
  24. #include <sys/types.h>
  25. static int do_init_calls(void);
  26. int __init init(void) {
  27. do_init_calls();
  28. mapto((void *) 1048576, (void *) 0xffffffff);
  29. printk("%x\n", *(unsigned long *) 0xfffff000);
  30. return 0;
  31. }
  32. void *__init_data init_call_levels[] = {
  33. &_init_call_arch, &_einit_call_arch,
  34. &_init_call_kernel, &_einit_call_kernel,
  35. &_init_call_modules, &_einit_call_modules
  36. };
  37. /*
  38. * call hooks in those sections those defined with init_call_levels.
  39. *
  40. * that when you use a module_init() macro, you add a new entry into
  41. * that section. when bootstrap, we call them with no argument. if one
  42. * of them returns a non-zero, kernel will halt and do nothing.
  43. * */
  44. typedef int (* __initcall_t) (void);
  45. static int do_init_calls(void) {
  46. int error;
  47. int i;
  48. __archptr_t *start, *end;
  49. __archptr_t fn, *initcalls;
  50. for (i = 0; i < ARRAYSIZE(init_call_levels); i++) {
  51. start = init_call_levels[i];
  52. end = init_call_levels[++i];
  53. int ncalls = end - start;
  54. for (initcalls = start; ncalls; initcalls++, ncalls--) {
  55. fn = *initcalls;
  56. if (!fn)
  57. break;
  58. if ((error = ((__initcall_t) fn)()))
  59. return error;
  60. }
  61. }
  62. return 0;
  63. }