From 97d28519f1ddffb495b158b0fbe68c9bd81322af Mon Sep 17 00:00:00 2001 From: acevest Date: Sun, 22 Jun 2025 19:38:51 +0800 Subject: [PATCH] imac backup --- boot/boot.c | 3 +-- gdbscript | 4 ++++ include/mm.h | 2 +- include/task.h | 3 +++ kernel/sched.c | 1 + kernel/task_init.c | 7 +++--- mm/mm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ scripts/iso.grub.cfg | 4 ++-- 8 files changed, 69 insertions(+), 8 deletions(-) diff --git a/boot/boot.c b/boot/boot.c index 78b4774..b006e98 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -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; diff --git a/gdbscript b/gdbscript index 252fc3b..c509829 100644 --- 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 diff --git a/include/mm.h b/include/mm.h index d16d93a..442f1d0 100644 --- a/include/mm.h +++ b/include/mm.h @@ -34,5 +34,5 @@ typedef struct vm_area { uint32_t vm_flags; - struct vma *vm_next; + struct vm_area *vm_next; } vm_area_t; diff --git a/include/task.h b/include/task.h index a68102a..7f9fc2f 100644 --- a/include/task.h +++ b/include/task.h @@ -18,6 +18,7 @@ #ifndef ASM #include #include +#include #include #include #include @@ -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; // 某些条件串成一个链表 diff --git a/kernel/sched.c b/kernel/sched.c index 08a98e6..f1751de 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -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; diff --git a/kernel/task_init.c b/kernel/task_init.c index ba87691..1a30bf0 100644 --- a/kernel/task_init.c +++ b/kernel/task_init.c @@ -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 8fa0dce..7aa09e8 100644 --- a/mm/mm.c +++ b/mm/mm.c @@ -21,6 +21,7 @@ #include #include #include +#include #include 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; } diff --git a/scripts/iso.grub.cfg b/scripts/iso.grub.cfg index 13c0b97..c245630 100644 --- a/scripts/iso.grub.cfg +++ b/scripts/iso.grub.cfg @@ -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 } -- 2.47.0