From 0c4a3e29f60d696c07a27ec21580ef4047f4720a Mon Sep 17 00:00:00 2001 From: d0p1 Date: Sat, 28 Dec 2024 12:38:21 +0100 Subject: [PATCH] feat(mm): bootstrap don't map extra memory after kernel end --- kernel/mm/bootstrap.inc | 7 +++--- kernel/mm/mm.new.inc | 49 +++++++++++++++++++++++++++++++++++++++++ kernel/mm/pmm.new.inc | 16 ++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 kernel/mm/mm.new.inc diff --git a/kernel/mm/bootstrap.inc b/kernel/mm/bootstrap.inc index d942df0..db4d560 100644 --- a/kernel/mm/bootstrap.inc +++ b/kernel/mm/bootstrap.inc @@ -8,23 +8,22 @@ mm_bootstrap: mov esi, szMsgMmBootstrap call klog ; 0x400000 - ; PDE entry: 0x7ffc00 phys addr 0xC0 and curr virt addr: 0xc07ffc00 + ; PDE entry: 0x7ffc00 phys addr and curr virt addr: 0xc07ffc00 ; map first 4MB at KERNEL_VIRT_BASE xor esi, esi mov edi, KERNEL_VIRT_BASE + 0x400000 + (768 * PAGE_SIZE) - xor ecx, ecx @@: mov edx, esi or edx, (PTE_P or PTE_W) mov [edi], edx add edi, 4 add esi, PAGE_SIZE - inc ecx - cmp ecx, 1024 + cmp esi, kend - KERNEL_VIRT_BASE jb @b ; recusive page dir + mov esi, 0x400000 mov edi, KERNEL_VIRT_BASE + 0x400000 + (1023 * PAGE_SIZE) xor ecx, ecx @@: diff --git a/kernel/mm/mm.new.inc b/kernel/mm/mm.new.inc new file mode 100644 index 0000000..1472027 --- /dev/null +++ b/kernel/mm/mm.new.inc @@ -0,0 +1,49 @@ + ;; Based on +VM_BESTFIT = (1 shl 0) +VM_INSTANTFIT = (1 shl 1) +VM_NEXTFIT = (1 shl 2) +VM_SLEEP = (1 shl 3) +VM_NOSLEEP = (1 shl 4) +VM_BOOTSTRAP = (1 shl 5) + +FREELISTS_N = 4 * 8 +HASHTABLE_N = 16 + +SEGMENT_ALLOCATED = 0 +SEGMENT_FREE = 1 +SEGMENT_SPAN = 2 + +struc VmSegment { + .type db ? + .imported db ? + .base dd ? + .size dd ? +} + +struc VmObject { + .tmp dd ? +} + +struc VmPager { + .tmp dd ? +} + +struc Vmem { + .name db 32 dup(0) + .base dd ? + .size dd ? + .quantum dd ? + .alloc dd ? + .free dd ? + .source dd ? + .qcache_max dd ? + .vmflag dd ? ;; db ? + + .segqueue dd ? + .freelist dd FREELISTS_N dup(0) + .hashtable dd HASHTABLE_N dup(0) + .spanlist dd ? +} + +vmem_init: + ret diff --git a/kernel/mm/pmm.new.inc b/kernel/mm/pmm.new.inc index deb771a..9a4d8d6 100644 --- a/kernel/mm/pmm.new.inc +++ b/kernel/mm/pmm.new.inc @@ -4,4 +4,20 @@ struc PMMFreeRange { .next dd ? } + ;; pPMMFreeListHead dd 0 + +pmm_alloc: + ret + +pmm_alloc_page: + ret + +pmm_free_page: + ret + + ;; + ;; kend - 4Mb + ;; 8Mb - max ram +pmm_init: + ret