kernel.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2011-2017 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <kern/init.h>
  18. #include <kern/kernel.h>
  19. #include <kern/log.h>
  20. #include <kern/thread.h>
  21. #include <machine/cpu.h>
  22. #include <test/test.h>
  23. #include <vm/vm_page.h>
  24. static int
  25. vm_page_info_helper(const char *format, ...)
  26. {
  27. va_list ap;
  28. int ret;
  29. va_start(ap, format);
  30. ret = log_vmsg(LOG_INFO, format, ap);
  31. va_end(ap);
  32. return ret;
  33. }
  34. void __init
  35. kernel_main(void)
  36. {
  37. assert(!cpu_intr_enabled());
  38. init_setup();
  39. vm_page_info(vm_page_info_helper);
  40. #ifdef CONFIG_TEST_MODULE
  41. test_setup();
  42. #endif /* CONFIG_TEST_MODULE */
  43. /*
  44. * Enabling application processors is done late in the boot process for
  45. * two reasons :
  46. * - It's much simpler to bootstrap with interrupts disabled on all
  47. * processors, enabling them only when necessary on the BSP.
  48. * - Depending on the architecture, the pmap module could create per
  49. * processor page tables. Once done, keeping the kernel page tables
  50. * synchronized requires interrupts (and potentially scheduling)
  51. * enabled on all processors.
  52. *
  53. * It is highly recommended not to do anything else than starting the
  54. * scheduler right after this call.
  55. */
  56. cpu_mp_setup();
  57. thread_run_scheduler();
  58. /* Never reached */
  59. }
  60. void __init
  61. kernel_ap_main(void)
  62. {
  63. assert(!cpu_intr_enabled());
  64. thread_run_scheduler();
  65. /* Never reached */
  66. }