main.c 2.6 KB

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