main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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(1024, 768, FR_address, 1024 * 768 * 4, 8, 16);
  57. printk("11111\n");
  58. load_TR(10); // 加载TR寄存器
  59. while(1);
  60. // 初始化任务状态段表
  61. ul tss_item_addr = 0xffff800000007c00;
  62. set_TSS64(_stack_start, _stack_start, _stack_start, tss_item_addr, tss_item_addr,
  63. tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr);
  64. // 初始化中断描述符表
  65. init_sys_vector();
  66. // 初始化内存管理单元
  67. mm_init();
  68. // 初始化中断模块
  69. init_irq();
  70. // 先初始化系统调用模块
  71. syscall_init();
  72. // 再初始化进程模块。顺序不能调转
  73. process_init();
  74. }
  75. //操作系统内核从这里开始执行
  76. void Start_Kernel(void)
  77. {
  78. system_initialize();
  79. // show_welcome();
  80. // test_mm();
  81. while (1)
  82. ;
  83. }
  84. void ignore_int()
  85. {
  86. printk("[");
  87. printk_color(YELLOW, BLACK, "WARN");
  88. printk("] Unknown interrupt or fault at RIP.\n");
  89. return;
  90. }