main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // Created by longjin on 2022/1/20.
  3. //
  4. #include "common/glib.h"
  5. #include "common/printk.h"
  6. #include "common/kprint.h"
  7. #include "exception/gate.h"
  8. #include "exception/trap.h"
  9. #include "exception/irq.h"
  10. #include "mm/mm.h"
  11. #include "process/process.h"
  12. #include "syscall/syscall.h"
  13. unsigned int *FR_address = (unsigned int *)0xffff800000a00000; //帧缓存区的地址
  14. // char fxsave_region[512] __attribute__((aligned(16)));
  15. struct memory_desc memory_management_struct = {{0}, 0};
  16. //struct Global_Memory_Descriptor memory_management_struct = {{0}, 0};
  17. void show_welcome()
  18. {
  19. /**
  20. * @brief 打印欢迎页面
  21. *
  22. */
  23. printk("\n\n");
  24. for (int i = 0; i < 74; ++i)
  25. printk(" ");
  26. printk_color(0x00e0ebeb, 0x00e0ebeb, " \n");
  27. for (int i = 0; i < 74; ++i)
  28. printk(" ");
  29. printk_color(BLACK, 0x00e0ebeb, " Welcome to DragonOS ! \n");
  30. for (int i = 0; i < 74; ++i)
  31. printk(" ");
  32. printk_color(0x00e0ebeb, 0x00e0ebeb, " \n\n");
  33. }
  34. // 测试内存管理单元
  35. /*
  36. void test_mm()
  37. {
  38. kinfo("Testing memory management unit...");
  39. //printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *memory_management_struct.bmp, *(memory_management_struct.bmp + 1));
  40. kinfo("Try to allocate 64 memory pages.");
  41. struct Page *page = alloc_pages(ZONE_NORMAL, 64, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
  42. for (int i = 0; i <= 65; ++i)
  43. {
  44. printk("page%d\tattr:%#018lx\tphys_addr:%#018lx\t", i, page->attr, page->addr_phys);
  45. ++page;
  46. if (((i + 1) % 2) == 0)
  47. printk("\n");
  48. }
  49. printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *(memory_management_struct.bmp), *(memory_management_struct.bmp + 1));
  50. }
  51. */
  52. // 初始化系统各模块
  53. void system_initialize()
  54. {
  55. // 初始化printk
  56. init_printk(1440, 900, FR_address, 1440 * 900 * 4, 8, 16);
  57. load_TR(10); // 加载TR寄存器
  58. // 初始化任务状态段表
  59. ul tss_item_addr = 0xffff800000007c00;
  60. set_TSS64(_stack_start, _stack_start, _stack_start, tss_item_addr, tss_item_addr,
  61. tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr);
  62. // 初始化中断描述符表
  63. init_sys_vector();
  64. // 初始化内存管理单元
  65. mm_init();
  66. // 初始化中断模块
  67. init_irq();
  68. // 先初始化系统调用模块
  69. syscall_init();
  70. // 再初始化进程模块。顺序不能调转
  71. process_init();
  72. }
  73. //操作系统内核从这里开始执行
  74. void Start_Kernel(void)
  75. {
  76. system_initialize();
  77. // show_welcome();
  78. // test_mm();
  79. while (1)
  80. ;
  81. }
  82. void ignore_int()
  83. {
  84. printk("[");
  85. printk_color(YELLOW, BLACK, "WARN");
  86. printk("] Unknown interrupt or fault at RIP.\n");
  87. return;
  88. }