chore: fix shellcheck errors, and some wip stuff
This commit is contained in:
parent
0c4a3e29f6
commit
3093e6bc82
8 changed files with 245 additions and 72 deletions
|
@ -1,49 +1,34 @@
|
|||
;; Based on <https://github.com/rdmsr/tinyvmem at tinyvm>
|
||||
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)
|
||||
MM_PTE_BASE = 0xFFC00000
|
||||
MM_VIRT_TEMP = 0xD0000000
|
||||
|
||||
FREELISTS_N = 4 * 8
|
||||
HASHTABLE_N = 16
|
||||
;; EAX - Physical address to map
|
||||
mm_map_temp:
|
||||
mov ecx, MM_PTE_BASE + (MM_VIRT_TEMP shr 12)
|
||||
or eax, 0x3
|
||||
mov [ecx], eax
|
||||
|
||||
SEGMENT_ALLOCATED = 0
|
||||
SEGMENT_FREE = 1
|
||||
SEGMENT_SPAN = 2
|
||||
if COMPAT_I386
|
||||
mov eax, 0x40000 + (1023 * PAGE_SIZE)
|
||||
mov cr3, eax
|
||||
else
|
||||
mov eax, MM_VIRT_TEMP
|
||||
invlpg [eax]
|
||||
end if
|
||||
|
||||
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
|
||||
|
||||
mm_unmap_temp:
|
||||
mov ecx, MM_PTE_BASE + (MM_VIRT_TEMP shr 12)
|
||||
mov dword [ecx], 0
|
||||
|
||||
if COMPAT_I386
|
||||
mov eax, 0x40000 + (1023 * PAGE_SIZE)
|
||||
mov cr3, eax
|
||||
else
|
||||
mov eax, MM_VIRT_TEMP
|
||||
invlpg [eax]
|
||||
end if
|
||||
ret
|
||||
|
||||
mm_init:
|
||||
ret
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;; File: mm.inc
|
||||
;; File: mm.old.inc
|
||||
;; StupidOS Memory Manager
|
||||
;;
|
||||
;; About: Memory Layout
|
||||
|
|
131
kernel/mm/pmm.inc
Normal file
131
kernel/mm/pmm.inc
Normal file
|
@ -0,0 +1,131 @@
|
|||
;; File: pmm.inc
|
||||
;;
|
||||
;; Our PMM is just a linked list of page-aligned size blocks.
|
||||
;;
|
||||
;; > ┌─────┐ ┌─────┐
|
||||
;; > │size │ ┌──►│size │
|
||||
;; > │next ├──┘ │next ├────► 0
|
||||
;; > └─────┘ └─────┘
|
||||
;;
|
||||
|
||||
;; Macro: PAGE_ALIGN_UP reg
|
||||
macro PAGE_ALIGN_UP reg {
|
||||
add reg, PAGE_SIZE - 1
|
||||
and reg, -PAGE_SIZE
|
||||
}
|
||||
|
||||
;; Macro: PAGE_ALIGN_DOWN reg
|
||||
macro PAGE_ALIGN_DOWN reg {
|
||||
and reg, -PAGE_SIZE
|
||||
}
|
||||
|
||||
;; Struc: PMMFreeRange
|
||||
struc PMMFreeRange {
|
||||
.size dd ?
|
||||
.next dd ?
|
||||
}
|
||||
DEFN PMMFreeRange
|
||||
|
||||
;; Function: _pmm_map_temp_page
|
||||
;;
|
||||
_pmm_map_temp_page:
|
||||
ret
|
||||
|
||||
_pmm_unmap_temp_page:
|
||||
ret
|
||||
|
||||
_pmm_init_region:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
push eax
|
||||
call _pmm_map_temp_page
|
||||
pop eax
|
||||
|
||||
xor ecx, ecx
|
||||
mov [MM_VIRT_TEMP], edx
|
||||
mov [MM_VIRT_TEMP + PMMFreeRange.next], ecx
|
||||
mov ecx, [pPMMFreeListHead]
|
||||
or ecx, ecx
|
||||
jz @f
|
||||
mov [MM_VIRT_TEMP + PMMFreeRange.next], ecx
|
||||
@@:
|
||||
mov [pPMMFreeListHead], eax
|
||||
|
||||
call _pmm_unmap_temp_page
|
||||
|
||||
leave
|
||||
ret
|
||||
|
||||
;; Function: pmm_alloc
|
||||
;;
|
||||
;; In:
|
||||
;; EAX - size in page
|
||||
;;
|
||||
;; Out:
|
||||
;; EAX - first page physical address, 0 on error
|
||||
pmm_alloc:
|
||||
ret
|
||||
|
||||
;; Function: pmm_alloc_page
|
||||
;;
|
||||
;; Out:
|
||||
;; EAX - page physical address, 0 on error
|
||||
pmm_alloc_page:
|
||||
mov eax, 1
|
||||
call pmm_alloc
|
||||
ret
|
||||
|
||||
;; Function: pmm_free
|
||||
;;
|
||||
;; In:
|
||||
;; EAX - Start
|
||||
;; EDX - End
|
||||
pmm_free:
|
||||
ret
|
||||
|
||||
;; Function: _pmm_init_region
|
||||
;;
|
||||
;; Add new memory region to the linked list.
|
||||
;;
|
||||
;; In:
|
||||
;; EAX - Start
|
||||
;; EDX - End
|
||||
;;
|
||||
|
||||
;; Function: pmm_init
|
||||
;;
|
||||
;; Out:
|
||||
;; EAX - return -1 on error
|
||||
pmm_init:
|
||||
mov esi, szMsgMmInit
|
||||
call klog
|
||||
|
||||
mov eax, kend
|
||||
PAGE_ALIGN_UP eax
|
||||
|
||||
mov edx, 0x400000
|
||||
sub edx, eax
|
||||
jle @f
|
||||
cmp edx, PAGE_SIZE
|
||||
jle @f
|
||||
|
||||
mov edx, 0x400000
|
||||
call _pmm_init_region
|
||||
|
||||
@@:
|
||||
mov eax, 0x800000
|
||||
mov edx, [stBootInfo.high_mem]
|
||||
PAGE_ALIGN_DOWN edx
|
||||
call _pmm_init_region
|
||||
|
||||
xor eax, eax ; TODO: check if enough memory and so on
|
||||
ret
|
||||
|
||||
;; Variable: pPMMFreeListHead
|
||||
;; Hold first free list entry physical address
|
||||
pPMMFreeListHead dd 0
|
||||
|
||||
szMsgPmmInit db "PMM: initialize", 0
|
||||
szMsgPmmFreeRange db "PMM: add free memory region %x - %x", 0
|
||||
szErrorNoMemLeft db "Error(PMM): no free memory left", 0
|
|
@ -1,23 +0,0 @@
|
|||
;; Struc: PMMFreeRange
|
||||
struc PMMFreeRange {
|
||||
.size dd ?
|
||||
.next dd ?
|
||||
}
|
||||
|
||||
;;
|
||||
pPMMFreeListHead dd 0
|
||||
|
||||
pmm_alloc:
|
||||
ret
|
||||
|
||||
pmm_alloc_page:
|
||||
ret
|
||||
|
||||
pmm_free_page:
|
||||
ret
|
||||
|
||||
;;
|
||||
;; kend - 4Mb
|
||||
;; 8Mb - max ram
|
||||
pmm_init:
|
||||
ret
|
|
@ -1,4 +1,4 @@
|
|||
;; File: pmm.inc
|
||||
;; File: pmm.old.inc
|
||||
|
||||
macro ALIGN reg {
|
||||
local ..end
|
||||
|
|
80
kernel/mm/vm.inc
Normal file
80
kernel/mm/vm.inc
Normal file
|
@ -0,0 +1,80 @@
|
|||
;; File: vm.inc
|
||||
;; Based on <https://github.com/rdmsr/tinyvmem at tinyvm>
|
||||
|
||||
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 ?
|
||||
}
|
||||
|
||||
;; Subroutine: _murmur32
|
||||
;;
|
||||
;; In:
|
||||
;; EAX - Address
|
||||
;;
|
||||
;; Out:
|
||||
;; EAX - Hash
|
||||
;;
|
||||
_murmur32:
|
||||
; hash ← hash XOR (hash >> 16)
|
||||
mov ecx, eax
|
||||
shr ecx, 16
|
||||
xor eax, ecx
|
||||
; hash ← hash × 0x85ebca6b
|
||||
mov ecx, 0x85ebca6b
|
||||
mul ecx
|
||||
; hash ← hash XOR (hash >> 13)
|
||||
mov ecx, eax
|
||||
shr ecx, 13
|
||||
xor eax, ecx
|
||||
; hash ← hash × 0xc2b2ae35
|
||||
mov ecx, 0xc2b2ae35
|
||||
mul ecx
|
||||
; hash ← hash XOR (hash >> 16)
|
||||
mov ecx, eax
|
||||
shr ecx, 16
|
||||
xor eax, ecx
|
||||
ret
|
||||
|
||||
vmem_init:
|
||||
ret
|
|
@ -55,5 +55,5 @@ EOF
|
|||
|
||||
create_hd_image()
|
||||
{
|
||||
|
||||
echo
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue