refactor(kernel): remove old pmm/mm files
This commit is contained in:
parent
86b3e1fdc9
commit
f84f328828
10 changed files with 15 additions and 385 deletions
|
@ -62,7 +62,7 @@ bio_bread:
|
||||||
cmp ecx, aBlockDevices.end
|
cmp ecx, aBlockDevices.end
|
||||||
jb @f
|
jb @f
|
||||||
|
|
||||||
mov esi, szErrorInvalidDevid
|
mov eax, szErrorInvalidDevid
|
||||||
call klog
|
call klog
|
||||||
jmp .end
|
jmp .end
|
||||||
@@:
|
@@:
|
||||||
|
|
|
@ -23,7 +23,7 @@ kbd_init:
|
||||||
or al, al
|
or al, al
|
||||||
jz @f
|
jz @f
|
||||||
|
|
||||||
mov esi, szMsgKbdFound
|
mov eax, szMsgKbdFound
|
||||||
call klog
|
call klog
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -8,7 +8,7 @@ forward
|
||||||
forward
|
forward
|
||||||
isr_#name#:
|
isr_#name#:
|
||||||
cli
|
cli
|
||||||
mov esi, szIntName
|
mov eax, szIntName
|
||||||
call klog
|
call klog
|
||||||
if error eq 0
|
if error eq 0
|
||||||
push 0
|
push 0
|
||||||
|
@ -36,7 +36,7 @@ isr_common:
|
||||||
mov eax, [esp+IntFrame.intno]
|
mov eax, [esp+IntFrame.intno]
|
||||||
push eax
|
push eax
|
||||||
|
|
||||||
mov esi, szMsgInterrupt
|
mov eax, szMsgInterrupt
|
||||||
call klog
|
call klog
|
||||||
|
|
||||||
pop eax
|
pop eax
|
||||||
|
|
|
@ -76,23 +76,23 @@ kmain:
|
||||||
mov ax, 100 ; 100Hz
|
mov ax, 100 ; 100Hz
|
||||||
call pit_init
|
call pit_init
|
||||||
|
|
||||||
call bio_init
|
;call bio_init
|
||||||
|
|
||||||
call proc_init
|
;call proc_init
|
||||||
|
|
||||||
call dev_init
|
;call dev_init
|
||||||
|
|
||||||
call vfs_init
|
;call vfs_init
|
||||||
|
|
||||||
; Root inode
|
; Root inode
|
||||||
; rootino = newino(dev(0.0), BLK)
|
; rootino = newino(dev(0.0), BLK)
|
||||||
; fs_mountroot(rootino);
|
; fs_mountroot(rootino);
|
||||||
|
|
||||||
mov ah, 2
|
;mov ah, 2
|
||||||
call bio_bread
|
;call bio_bread
|
||||||
|
|
||||||
xor eax, eax
|
;xor eax, eax
|
||||||
call bio_bread
|
;call bio_bread
|
||||||
|
|
||||||
;mov eax, SYSCALL_EXIT
|
;mov eax, SYSCALL_EXIT
|
||||||
;int 0x42
|
;int 0x42
|
||||||
|
@ -104,7 +104,7 @@ kmain:
|
||||||
; hlt
|
; hlt
|
||||||
jmp $
|
jmp $
|
||||||
.error_magic:
|
.error_magic:
|
||||||
mov esi, szErrorBootProtocol
|
mov eax, szErrorBootProtocol
|
||||||
.error:
|
.error:
|
||||||
call klog
|
call klog
|
||||||
jmp .halt
|
jmp .halt
|
||||||
|
|
|
@ -1,217 +0,0 @@
|
||||||
;; File: mm.old.inc
|
|
||||||
;; StupidOS Memory Manager
|
|
||||||
;;
|
|
||||||
;; About: Memory Layout
|
|
||||||
;;
|
|
||||||
;; > Virtual
|
|
||||||
;; > 0xFFFFFFFF +---------------+
|
|
||||||
;; > | |
|
|
||||||
;; > | Device Memory |
|
|
||||||
;; > | |
|
|
||||||
;; > +---------------+
|
|
||||||
;; > | |
|
|
||||||
;; > | Kernel Heap |
|
|
||||||
;; > | |
|
|
||||||
;; > KERN_END +---------------+
|
|
||||||
;; > | |
|
|
||||||
;; > | Stupid Kernel |
|
|
||||||
;; > | |
|
|
||||||
;; > 0xC0100000 +---------------+
|
|
||||||
;; > | I/O Space and |
|
|
||||||
;; > | phys memory |
|
|
||||||
;; > | Lower than 1M | kernel mode only
|
|
||||||
;; > 0xC0000000 +---------------+
|
|
||||||
;; > | | user mode
|
|
||||||
;; > | userspace |
|
|
||||||
;; > | |
|
|
||||||
;; > 0x00000000 +---------------+
|
|
||||||
;;
|
|
||||||
|
|
||||||
include "pmm.old.inc"
|
|
||||||
include "../sys/mmu.inc"
|
|
||||||
|
|
||||||
;; Macro: KV2P
|
|
||||||
;; Convert virtual address to physical
|
|
||||||
macro KV2P reg {
|
|
||||||
sub reg, KERNEL_VIRT_BASE
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Macro: KP2V
|
|
||||||
;; Convert physical address to virtual
|
|
||||||
macro KP2V reg {
|
|
||||||
add reg, KERNEL_VIRT_BASE
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Function: mm_kmap
|
|
||||||
mm_kmap:
|
|
||||||
push esp
|
|
||||||
mov ebp, esp
|
|
||||||
sub esp, 0x10
|
|
||||||
|
|
||||||
call pmm_alloc_page
|
|
||||||
mov [ebp-4], eax
|
|
||||||
|
|
||||||
; clear page dir
|
|
||||||
mov edi, eax
|
|
||||||
mov ecx, 4096
|
|
||||||
xor al, al
|
|
||||||
rep stosb
|
|
||||||
|
|
||||||
call pmm_alloc_page
|
|
||||||
xor esi, esi
|
|
||||||
xor ecx, ecx
|
|
||||||
mov edi, eax
|
|
||||||
@@:
|
|
||||||
mov edx, esi
|
|
||||||
or edx, (PTE_P or PTE_W)
|
|
||||||
mov [edi], edx
|
|
||||||
add edi, 4
|
|
||||||
add esi, 4096
|
|
||||||
inc ecx
|
|
||||||
cmp ecx, 1024
|
|
||||||
jb @b
|
|
||||||
|
|
||||||
or eax, (PDE_P or PDE_W)
|
|
||||||
mov edx, [ebp-4]
|
|
||||||
add edx, (768 * 4)
|
|
||||||
KV2P eax
|
|
||||||
mov [edx], eax
|
|
||||||
|
|
||||||
mov eax, [ebp-4]
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: mm_clone_pte
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; EAX - source page table
|
|
||||||
;;
|
|
||||||
;; Out:
|
|
||||||
;; EAX - cloned page table
|
|
||||||
;;
|
|
||||||
mm_clone_pte:
|
|
||||||
push esp
|
|
||||||
mov ebp, esp
|
|
||||||
sub esp, 0x10
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: mm_clone_pgdir
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; EAX - source page dir
|
|
||||||
;;
|
|
||||||
;; Out:
|
|
||||||
;; EAX - cloned page dir
|
|
||||||
mm_clone_pgdir:
|
|
||||||
push esp
|
|
||||||
mov ebp, esp
|
|
||||||
sub esp, 0x10
|
|
||||||
|
|
||||||
mov [ebp-4], eax
|
|
||||||
call pmm_alloc_page
|
|
||||||
|
|
||||||
mov [ebp-8], eax
|
|
||||||
mov ecx, 4096
|
|
||||||
mov edi, eax
|
|
||||||
xor al, al
|
|
||||||
rep stosb
|
|
||||||
|
|
||||||
xor ecx, ecx
|
|
||||||
.loop:
|
|
||||||
mov eax, [ebp-4]
|
|
||||||
add eax, ecx
|
|
||||||
mov eax, [eax]
|
|
||||||
cmp eax, 0
|
|
||||||
je .next
|
|
||||||
cmp ecx, (768*4)
|
|
||||||
jb @f
|
|
||||||
mov edx, [ebp-8]
|
|
||||||
add edx, ecx
|
|
||||||
mov [edx], eax
|
|
||||||
jmp .next
|
|
||||||
@@:
|
|
||||||
mov edx, eax
|
|
||||||
call pmm_alloc_page
|
|
||||||
.next:
|
|
||||||
add ecx, 4
|
|
||||||
cmp ecx, 4096
|
|
||||||
jb .loop
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: mm_init
|
|
||||||
;; Initialize the memory manager
|
|
||||||
mm_init:
|
|
||||||
mov esi, szMsgMmInit
|
|
||||||
call klog
|
|
||||||
|
|
||||||
call mm_kmap
|
|
||||||
mov [pKernelPgDir], eax
|
|
||||||
|
|
||||||
; map whole memory
|
|
||||||
mov esi, 0x400000
|
|
||||||
mov ebx, (769 * 4)
|
|
||||||
.loop:
|
|
||||||
call pmm_alloc_page
|
|
||||||
xor ecx, ecx
|
|
||||||
mov edi, eax
|
|
||||||
@@:
|
|
||||||
mov edx, esi
|
|
||||||
or edx, (PTE_P or PTE_W)
|
|
||||||
mov [edi], edx
|
|
||||||
add edi, 4
|
|
||||||
add esi, 4096
|
|
||||||
inc ecx
|
|
||||||
cmp ecx, 1024
|
|
||||||
jb @b
|
|
||||||
|
|
||||||
or eax, (PDE_P or PDE_W)
|
|
||||||
mov edx, [pKernelPgDir]
|
|
||||||
add edx, ebx
|
|
||||||
add ebx, 4
|
|
||||||
KV2P eax
|
|
||||||
mov [edx], eax
|
|
||||||
|
|
||||||
cmp esi, [stBootInfo.high_mem]
|
|
||||||
jb .loop
|
|
||||||
|
|
||||||
; reload cr3
|
|
||||||
mov eax, [pKernelPgDir]
|
|
||||||
KV2P eax
|
|
||||||
mov cr3, eax
|
|
||||||
|
|
||||||
push eax
|
|
||||||
mov esi, szMsgMmKernelPgDir
|
|
||||||
call klog
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: mm_mmap
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; XXX - addr
|
|
||||||
;; XXX - length
|
|
||||||
;; XXX - prot
|
|
||||||
;; XXX - flags
|
|
||||||
mm_mmap:
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: mm_munmap
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; XXX - addr
|
|
||||||
;; XXX - length
|
|
||||||
;;
|
|
||||||
mm_munmap:
|
|
||||||
ret
|
|
||||||
|
|
||||||
mm_wallk_pagedir:
|
|
||||||
ret
|
|
||||||
|
|
||||||
szMsgMmInit db "MM: initialize", 0
|
|
||||||
szMsgMmKernelPgDir db "MM: Kernel page dir at %x phys", 0
|
|
||||||
pKernelPgDir dd 0
|
|
|
@ -1,140 +0,0 @@
|
||||||
;; File: pmm.old.inc
|
|
||||||
|
|
||||||
macro ALIGN reg {
|
|
||||||
local ..end
|
|
||||||
|
|
||||||
push reg
|
|
||||||
and reg, 0xFFF
|
|
||||||
pop reg
|
|
||||||
jz ..end
|
|
||||||
and reg, 0xFFFFF000
|
|
||||||
add reg, 0x1000
|
|
||||||
..end:
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Function: pmm_init
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; EAX - Start
|
|
||||||
;; EBX - End
|
|
||||||
pmm_init:
|
|
||||||
push eax
|
|
||||||
mov esi, szMsgPmmInit
|
|
||||||
call klog
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
call pmm_free_range
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: pmm_alloc_page
|
|
||||||
;;
|
|
||||||
;; Out:
|
|
||||||
;; EAX - page address (return zero on error)
|
|
||||||
pmm_alloc_page:
|
|
||||||
mov eax, uPmmLock
|
|
||||||
call lock_acquire
|
|
||||||
|
|
||||||
cmp [pFreeList], 0
|
|
||||||
je .error
|
|
||||||
mov eax, [pFreeList]
|
|
||||||
mov edx, [eax]
|
|
||||||
mov [pFreeList], edx
|
|
||||||
|
|
||||||
inc [cUsedPage]
|
|
||||||
dec [cFreePage]
|
|
||||||
|
|
||||||
|
|
||||||
push eax
|
|
||||||
mov eax, uPmmLock
|
|
||||||
call lock_release
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
ret
|
|
||||||
.error:
|
|
||||||
mov esi, szErrorNoMemLeft
|
|
||||||
call klog
|
|
||||||
|
|
||||||
mov eax, uPmmLock
|
|
||||||
call lock_release
|
|
||||||
xor eax, eax
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: pmm_free_page
|
|
||||||
;; push page back to free list
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; EAX - page to be freed
|
|
||||||
pmm_free_page:
|
|
||||||
mov eax, uPmmLock
|
|
||||||
call lock_acquire
|
|
||||||
or eax, eax
|
|
||||||
jz @f
|
|
||||||
mov edx, [pFreeList]
|
|
||||||
mov [eax], edx
|
|
||||||
mov [pFreeList], eax
|
|
||||||
|
|
||||||
inc [cFreePage]
|
|
||||||
dec [cUsedPage]
|
|
||||||
@@:
|
|
||||||
mov eax, uPmmLock
|
|
||||||
call lock_release
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: pmm_free_range
|
|
||||||
;;
|
|
||||||
;; In:
|
|
||||||
;; EAX - Start
|
|
||||||
;; EBX - End
|
|
||||||
pmm_free_range:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
sub esp, 0x10
|
|
||||||
ALIGN eax
|
|
||||||
ALIGN ebx
|
|
||||||
mov [ebp-4], eax
|
|
||||||
mov [ebp-8], ebx
|
|
||||||
|
|
||||||
push ebx
|
|
||||||
push eax
|
|
||||||
mov esi, szMsgPmmFreeRange
|
|
||||||
call klog
|
|
||||||
|
|
||||||
mov esi, [ebp-4]
|
|
||||||
.loop:
|
|
||||||
mov eax, [pFreeList]
|
|
||||||
mov [esi], eax
|
|
||||||
mov [pFreeList], esi
|
|
||||||
|
|
||||||
inc [cTotalPage]
|
|
||||||
inc [cFreePage]
|
|
||||||
|
|
||||||
add esi, 4096
|
|
||||||
cmp esi, [ebp-8]
|
|
||||||
jb .loop
|
|
||||||
|
|
||||||
call pmm_stats
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
;; Function: pmm_stats
|
|
||||||
pmm_stats:
|
|
||||||
push dword [cFreePage]
|
|
||||||
push dword [cUsedPage]
|
|
||||||
push dword [cTotalPage]
|
|
||||||
mov esi, szMsgPmmStats
|
|
||||||
call klog
|
|
||||||
ret
|
|
||||||
|
|
||||||
pFreeList dd 0
|
|
||||||
szMsgPmmInit db "PMM: initialize", 0
|
|
||||||
szMsgPmmFreeRange db "PMM: add free memory range %x - %x", 0
|
|
||||||
szErrorNoMemLeft db "Error: no free memory left", 0
|
|
||||||
szMsgPmmStats db "PMM: Total page: %x | Used page: %x | Free page: %x", 0
|
|
||||||
uPmmLock dd 0
|
|
||||||
|
|
||||||
; Some stats
|
|
||||||
cFreePage dd 0
|
|
||||||
cUsedPage dd 0
|
|
||||||
cTotalPage dd 0
|
|
|
@ -1,9 +0,0 @@
|
||||||
;; File: uvm.inc
|
|
||||||
|
|
||||||
include 'uvm_km.inc'
|
|
||||||
|
|
||||||
;; Function: uvm_init
|
|
||||||
;;
|
|
||||||
;; Sets up the UVM system
|
|
||||||
uvm_init:
|
|
||||||
ret
|
|
|
@ -1,5 +0,0 @@
|
||||||
;; File: uvm_map.inc
|
|
||||||
|
|
||||||
struc VmMap {
|
|
||||||
|
|
||||||
}
|
|
|
@ -115,8 +115,9 @@ vfs_register:
|
||||||
|
|
||||||
mov eax, [eax + VFS.name]
|
mov eax, [eax + VFS.name]
|
||||||
push eax
|
push eax
|
||||||
mov esi, szMsgVFSRegister
|
mov eax, szMsgVFSRegister
|
||||||
call klog
|
call klog
|
||||||
|
pop eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
vfs_init:
|
vfs_init:
|
||||||
|
|
Loading…
Add table
Reference in a new issue