]> Zhao Yanbai Git Server - kernel.git/commitdiff
imac backup dev/2410/vfs
authoracevest <zhaoyanbai@126.com>
Sun, 22 Jun 2025 11:38:51 +0000 (19:38 +0800)
committeracevest <zhaoyanbai@126.com>
Sun, 22 Jun 2025 11:38:51 +0000 (19:38 +0800)
boot/boot.c
gdbscript
include/mm.h
include/task.h
kernel/sched.c
kernel/task_init.c
mm/mm.c
scripts/iso.grub.cfg

index 78b4774c8e43696ee21198ea7391a861911b8c86..b006e98c587e5f4e231d151f2581b4a3c69f9be0 100644 (file)
@@ -116,7 +116,7 @@ void check_kernel(unsigned long addr, unsigned long magic) {
             printk("module 0x%08x - 0x%08x size %u cmdline %s\n", m->mod_start, m->mod_end, m->size, m->cmdline);
             boot_params.boot_module_begin = (void *)m->mod_start;
             boot_params.boot_module_end = (void *)m->mod_end;
-#if 0
+#if 1
             const uint32_t mod_magic = *(uint32_t *)(mod_start + 0);
             const uint32_t mod_head_size = *(uint32_t *)(mod_start + 4);
             const uint32_t mod_timestamp = *(uint32_t *)(mod_start + 8);
@@ -148,7 +148,6 @@ void check_kernel(unsigned long addr, unsigned long magic) {
                     printk("%02X ", c);
                 }
                 printk("\n");
-
             }
 #endif
             break;
index 252fc3b73790f42e4c0fb2e937908f8e8218ba6d..c5098296f9b6aad71368f9034fb7de1d0809cd66 100644 (file)
--- a/gdbscript
+++ b/gdbscript
@@ -20,6 +20,10 @@ target remote localhost:1234
 
 set pagination off
 
+display/z $ss
+
+set disassemble-next-line on
+
 #b init_serial
 
 #b init_system_info
index d16d93a1ef73253f274c596e3ca32134f93d2dfa..442f1d044703e08d5fd522ee22af898f493a01b5 100644 (file)
@@ -34,5 +34,5 @@ typedef struct vm_area {
 
     uint32_t vm_flags;
 
-    struct vma *vm_next;
+    struct vm_area *vm_next;
 } vm_area_t;
index a68102a4164ecbb19ee749198af7786395ec8140..7f9fc2f37e4084c75f84be78dd24af922a4d554a 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef ASM
 #include <fs.h>
 #include <list.h>
+#include <mm.h>
 #include <page.h>
 #include <processor.h>
 #include <system.h>
@@ -80,6 +81,8 @@ typedef union task_union {
         path_t root;
         path_t pwd;
 
+        vm_area_t *vma_list;
+
         list_head_t list;  // 所有进程串成一个链表
 
         list_head_t pend;  // 某些条件串成一个链表
index 08a98e6626efa0f0f07e9880c9b550b14f55c22b..f1751dee1ea4752e85ba14fce0f4374bf397d89f 100644 (file)
@@ -59,6 +59,7 @@ void init_root_task() {
     root_task.reason = "root";
     root_task.priority = 7;
     root_task.ticks = root_task.priority;
+    root_task.vma_list = NULL;
     root_task.turn = 0;
     root_task.need_resched = 0;
     root_task.sched_cnt = 0;
index ba87691a955fe259e545fdb75cf3d308f789ae64..1a30bf070af867e3e89bdba85b3363a7d9c67a0c 100644 (file)
@@ -200,7 +200,7 @@ void init_task_entry() {
     kernel_task("tskC", taskC_entry, NULL);
 #endif
 
-#if 1
+#if 0
     void *mod_start = pa2va(boot_params.boot_module_begin);
 
     mod_start = (void *)va2pa(mod_start);
@@ -225,7 +225,8 @@ void init_task_entry() {
     LoadCR3(current->cr3);
 
     asm("sysexit;" ::"d"(mod_start), "c"(mod_start + PAGE_SIZE - 4));
-#else
+#endif
+#if 0
     void *mod_start = pa2va(boot_params.boot_module_begin);
     printk("RING3 ENTRY %x\n", mod_start);
 
@@ -254,7 +255,7 @@ void init_task_entry() {
 }
 
 void init_rootfs() {
-#if 0
+#if 1
     void *mod_start = pa2va(boot_params.boot_module_begin);
 
     const uint32_t mod_magic = *(uint32_t *)(mod_start + 0);
diff --git a/mm/mm.c b/mm/mm.c
index 8fa0dcec13dfec4dde04a13d61043914edcc9228..7aa09e8c365ec960db8c62ea990e1df207a4fe5f 100644 (file)
--- a/mm/mm.c
+++ b/mm/mm.c
@@ -21,6 +21,7 @@
 #include <printk.h>
 #include <string.h>
 #include <system.h>
+#include <task.h>
 #include <types.h>
 
 extern char etext, edata, end;
@@ -121,6 +122,8 @@ void init_paging() {
 
 extern void init_ttys();
 
+kmem_cache_t *g_vma_kmem_cache = NULL;
+
 void init_mm() {
     printk("init bootmem alloc...\n");
     extern void init_bootmem();
@@ -140,4 +143,54 @@ void init_mm() {
     init_kmem_caches();
     printk("memory init finished...\n");
     boot_delay(DEFAULT_BOOT_DELAY_TICKS);
+
+    g_vma_kmem_cache = kmem_cache_create("vma", sizeof(vm_area_t), 4);
+    assert(g_vma_kmem_cache != NULL);
+}
+
+vm_area_t *vma_alloc() {
+    vm_area_t *vma = kmem_cache_alloc(g_vma_kmem_cache, 0);
+    vma->vm_bgn = 0;
+    vma->vm_end = 0;
+    vma->vm_flags = 0;
+    vma->vm_next = NULL;
+    return vma;
+}
+
+void vma_insert(task_t *tsk, vm_area_t *vma_new) {
+    //
+    vm_area_t **p = &tsk->vma_list;
+
+    while (*p != NULL) {
+        vm_area_t *v = *p;
+
+        assert(v->vm_bgn < v->vm_end);
+        assert(vma_new->vm_bgn < vma_new->vm_end);
+        assert(vma_new->vm_bgn < v->vm_bgn || vma_new->vm_bgn > v->vm_end);
+        assert(vma_new->vm_end < v->vm_bgn || vma_new->vm_end > v->vm_end);
+
+        if (vma_new->vm_end < v->vm_bgn) {
+            break;
+        }
+
+        p = &v->vm_next;
+    }
+
+    vma_new->vm_next = *p;
+    *p = vma_new;
+}
+
+vm_area_t *vma_find(task_t *tsk, vm_area_t *vma, uint32_t addr) {
+    vm_area_t **p = &tsk->vma_list;
+    while (*p != NULL) {
+        vm_area_t *v = *p;
+
+        if (addr <= v->vm_end) {
+            break;
+        }
+
+        p = &v->vm_next;
+    }
+
+    return *p;
 }
index 13c0b97bfa7ea8816f30e3783f5d47ac3f9ce740..c245630173de5e47aa647e6ab4d7db76ce2be2ad 100644 (file)
@@ -11,7 +11,7 @@ menuentry 'Kernel' --class os {
     #set gfxpayload=1024x768x32
     #insmod all_video
     multiboot2 /boot/Kernel root=hda7 delay=2
-    #module2 /boot/rootfs rootfs
-    module2 /boot/init init
+    module2 /boot/rootfs rootfs
+    #module2 /boot/init init
     boot
 }