main.c 2.0 KB

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