main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX 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) and later version.
  8. */
  9. /*
  10. XNIX 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. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <kernel/init.h>
  20. #include <kernel/errno.h>
  21. #include <kernel/types.h>
  22. #include <modules/tty.h>
  23. #include <modules/ide.h>
  24. #include <kernel/vsprintf.h>
  25. #include <kernel/schk.h>
  26. #include <kernel/mm.h>
  27. #include <kernel/pci.h>
  28. #include <kernel/int.h>
  29. #include <kernel/sched.h>
  30. #include <kernel/keyboard.h>
  31. #include <lib/string.h>
  32. #include <sys/syscall.h>
  33. #include <arch/io.h>
  34. #include <arch/sys.h>
  35. #include <arch/x86/int.h>
  36. #include <arch/x86/paging.h>
  37. /* we save boot-time arguments at that address where boot was. */
  38. struct bootarg *bootarg = (struct bootarg *) 0x7c00;
  39. /*
  40. * init(void): initial all modules and devices.
  41. *
  42. * return value: error number. main will return after initial done.
  43. * if return value isn't 0, head.S will panic. else, it will halt.
  44. * */
  45. int init(void) {
  46. tty_init();
  47. print(red, "XNIX kernel starting...\n");
  48. int_init();
  49. mm_init();
  50. sti();
  51. task_init();
  52. kbd_init();
  53. ide_init();
  54. printk(white, "total %d devices. \n", pci_lspci());
  55. printk(white, "System boots from the device %b: ", bootarg->bootdev);
  56. if (bootarg->bootdev & 0x80)
  57. printk(white, "hard disk %b. \n", bootarg->bootdev & 7);
  58. else
  59. printk(white, "floppy / flash memory / cd-rom %b. \n", bootarg->bootdev);
  60. pci_infodev(0, 0x1f, 2);
  61. for (;;)
  62. put_keycode();
  63. return 0;
  64. }