123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #include "common/glib.h"
- #include "common/printk.h"
- #include "common/kprint.h"
- #include "exception/gate.h"
- #include "exception/trap.h"
- #include "exception/irq.h"
- #include <exception/softirq.h>
- #include "mm/mm.h"
- #include "mm/slab.h"
- #include "process/process.h"
- #include "syscall/syscall.h"
- #include "smp/smp.h"
- #include <smp/ipi.h>
- #include "driver/multiboot2/multiboot2.h"
- #include "driver/acpi/acpi.h"
- #include "driver/keyboard/ps2_keyboard.h"
- #include "driver/mouse/ps2_mouse.h"
- #include "driver/disk/ata.h"
- #include "driver/pci/pci.h"
- #include "driver/disk/ahci/ahci.h"
- #include <driver/timers/rtc/rtc.h>
- #include <driver/timers/HPET/HPET.h>
- #include <driver/timers/timer.h>
- unsigned int *FR_address = (unsigned int *)0xb8000;
- struct memory_desc memory_management_struct = {{0}, 0};
- void test_slab();
- void show_welcome()
- {
-
- printk("\n\n");
- for (int i = 0; i < 74; ++i)
- printk(" ");
- printk_color(0x00e0ebeb, 0x00e0ebeb, " \n");
- for (int i = 0; i < 74; ++i)
- printk(" ");
- printk_color(BLACK, 0x00e0ebeb, " Welcome to DragonOS ! \n");
- for (int i = 0; i < 74; ++i)
- printk(" ");
- printk_color(0x00e0ebeb, 0x00e0ebeb, " \n\n");
- }
- void test_mm()
- {
- kinfo("Testing memory management unit...");
- struct Page *page = NULL;
- page = alloc_pages(ZONE_NORMAL, 63, 0);
- page = alloc_pages(ZONE_NORMAL, 63, 0);
- printk_color(ORANGE, BLACK, "4.memory_management_struct.bmp:%#018lx\tmemory_management_struct.bmp+1:%#018lx\tmemory_management_struct.bmp+2:%#018lx\tzone_struct->count_pages_using:%d\tzone_struct->count_pages_free:%d\n", *memory_management_struct.bmp, *(memory_management_struct.bmp + 1), *(memory_management_struct.bmp + 2), memory_management_struct.zones_struct->count_pages_using, memory_management_struct.zones_struct->count_pages_free);
- for (int i = 80; i <= 85; ++i)
- {
- printk_color(INDIGO, BLACK, "page%03d attr:%#018lx address:%#018lx\t", i, (memory_management_struct.pages_struct + i)->attr, (memory_management_struct.pages_struct + i)->addr_phys);
- i++;
- printk_color(INDIGO, BLACK, "page%03d attr:%#018lx address:%#018lx\n", i, (memory_management_struct.pages_struct + i)->attr, (memory_management_struct.pages_struct + i)->addr_phys);
- }
- for (int i = 140; i <= 145; i++)
- {
- printk_color(INDIGO, BLACK, "page%03d attr:%#018lx address:%#018lx\t", i, (memory_management_struct.pages_struct + i)->attr, (memory_management_struct.pages_struct + i)->addr_phys);
- i++;
- printk_color(INDIGO, BLACK, "page%03d attr:%#018lx address:%#018lx\n", i, (memory_management_struct.pages_struct + i)->attr, (memory_management_struct.pages_struct + i)->addr_phys);
- }
- free_pages(page, 1);
- printk_color(ORANGE, BLACK, "5.memory_management_struct.bmp:%#018lx\tmemory_management_struct.bmp+1:%#018lx\tmemory_management_struct.bmp+2:%#018lx\tzone_struct->count_pages_using:%d\tzone_struct->count_pages_free:%d\n", *memory_management_struct.bmp, *(memory_management_struct.bmp + 1), *(memory_management_struct.bmp + 2), memory_management_struct.zones_struct->count_pages_using, memory_management_struct.zones_struct->count_pages_free);
- for (int i = 75; i <= 85; i++)
- {
- printk_color(INDIGO, BLACK, "page%03d attr:%#018lx address:%#018lx\t", i, (memory_management_struct.pages_struct + i)->attr, (memory_management_struct.pages_struct + i)->addr_phys);
- i++;
- printk_color(INDIGO, BLACK, "page%03d attr:%#018lx address:%#018lx\n", i, (memory_management_struct.pages_struct + i)->attr, (memory_management_struct.pages_struct + i)->addr_phys);
- }
- page = alloc_pages(ZONE_UNMAPPED_IN_PGT, 63, 0);
- printk_color(ORANGE, BLACK, "6.memory_management_struct.bmp:%#018lx\tmemory_management_struct.bmp+1:%#018lx\tzone_struct->count_pages_using:%d\tzone_struct->count_pages_free:%d\n", *(memory_management_struct.bmp + (page->addr_phys >> PAGE_2M_SHIFT >> 6)), *(memory_management_struct.bmp + 1 + (page->addr_phys >> PAGE_2M_SHIFT >> 6)), (memory_management_struct.zones_struct + ZONE_UNMAPPED_INDEX)->count_pages_using, (memory_management_struct.zones_struct + ZONE_UNMAPPED_INDEX)->count_pages_free);
- free_pages(page, 1);
- printk_color(ORANGE, BLACK, "7.memory_management_struct.bmp:%#018lx\tmemory_management_struct.bmp+1:%#018lx\tzone_struct->count_pages_using:%d\tzone_struct->count_pages_free:%d\n", *(memory_management_struct.bmp + (page->addr_phys >> PAGE_2M_SHIFT >> 6)), *(memory_management_struct.bmp + 1 + (page->addr_phys >> PAGE_2M_SHIFT >> 6)), (memory_management_struct.zones_struct + ZONE_UNMAPPED_INDEX)->count_pages_using, (memory_management_struct.zones_struct + ZONE_UNMAPPED_INDEX)->count_pages_free);
- test_slab();
- kinfo("Memory management module test completed!");
- }
- void test_slab()
- {
- kinfo("Testing SLAB...");
- kinfo("Testing kmalloc()...");
- for (int i = 1; i < 16; ++i)
- {
- printk_color(ORANGE, BLACK, "mem_obj_size: %ldbytes\t", kmalloc_cache_group[i].size);
- printk_color(ORANGE, BLACK, "bmp(before): %#018lx\t", *kmalloc_cache_group[i].cache_pool_entry->bmp);
- ul *tmp = kmalloc(kmalloc_cache_group[i].size, 0);
- if (tmp == NULL)
- {
- kBUG("Cannot kmalloc such a memory: %ld bytes", kmalloc_cache_group[i].size);
- }
- printk_color(ORANGE, BLACK, "bmp(middle): %#018lx\t", *kmalloc_cache_group[i].cache_pool_entry->bmp);
- kfree(tmp);
- printk_color(ORANGE, BLACK, "bmp(after): %#018lx\n", *kmalloc_cache_group[i].cache_pool_entry->bmp);
- }
-
- void *ptrs[7];
- for (int i = 0; i < 7; ++i)
- ptrs[i] = kmalloc(kmalloc_cache_group[15].size, 0);
- struct slab_obj *slab_obj_ptr = kmalloc_cache_group[15].cache_pool_entry;
- int count = 0;
- do
- {
- kdebug("bmp(%d): addr=%#018lx\t value=%#018lx", count, slab_obj_ptr->bmp, *slab_obj_ptr->bmp);
- slab_obj_ptr = container_of(list_next(&slab_obj_ptr->list), struct slab_obj, list);
- ++count;
- } while (slab_obj_ptr != kmalloc_cache_group[15].cache_pool_entry);
- for (int i = 0; i < 7; ++i)
- kfree(ptrs[i]);
- kinfo("SLAB test completed!");
- }
- void system_initialize()
- {
-
- printk_init(8, 16);
- kinfo("Kernel Starting...");
- load_TR(10);
- ul tss_item_addr = 0x7c00;
- set_tss64(TSS64_Table, _stack_start, _stack_start, _stack_start, tss_item_addr,
- tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr);
- cpu_core_info[0].stack_start = _stack_start;
- cpu_core_info[0].tss_vaddr = &TSS64_Table;
-
- sys_vector_init();
-
- mm_init();
- acpi_init();
-
- irq_init();
- softirq_init();
- timer_init();
- HPET_init();
- smp_init();
-
- syscall_init();
- cpu_init();
-
-
-
- pci_init();
- ahci_init();
-
-
-
-
- }
- void Start_Kernel(void)
- {
- system_initialize();
-
-
-
-
-
-
- int last_sec = rtc_now.second;
-
- while (1)
- hlt();
- }
- void ignore_int()
- {
- kwarn("Unknown interrupt or fault at RIP.\n");
- return;
- }
|