StupidOS/kernel/mm/mm.inc

62 lines
829 B
PHP
Raw Normal View History

2024-07-07 09:44:51 +00:00
;; File: mm.inc
2024-07-07 13:29:41 +00:00
;; StupidOS Memory Manager
include "pmm.inc"
2024-02-04 19:18:52 +00:00
2024-07-08 16:48:31 +00:00
macro KV2P reg {
sub reg, KERNEL_VIRT_BASE
}
2024-02-04 19:18:52 +00:00
mm_init:
mov esi, szMsgMmInit
call klog
call pmm_alloc_page
mov [pKernelPgDir], eax
2024-07-07 13:29:41 +00:00
; clear page dir
mov ecx, 4096
xor al, al
mov edi, [pKernelPgDir]
rep stosb
;; Map kernel and kmemory
call pmm_alloc_page
2024-07-08 16:48:31 +00:00
xor esi, esi
xor ecx, ecx
2024-07-07 13:29:41 +00:00
mov edi, eax
2024-07-08 16:48:31 +00:00
@@:
mov edx, esi
or edx, 0x3
mov [edi], edx
add edi, 4
add esi, 4096
inc ecx
cmp ecx, 1024
jb @b
or eax, 0x03
mov edx, [pKernelPgDir]
add edx, (768 * 4)
KV2P eax
mov [edx], eax
2024-07-07 09:44:51 +00:00
;; Map free memory
2024-07-08 16:48:31 +00:00
mov eax, [pKernelPgDir]
KV2P eax
mov cr3, eax
push eax
mov esi, szMsgMmKernelPgDir
call klog
2024-07-07 09:44:51 +00:00
ret
mm_wallk_pagedir:
2024-04-28 06:41:36 +00:00
ret
szMsgMmInit db "MM: initialize", 0
2024-07-08 16:48:31 +00:00
szMsgMmKernelPgDir db "MM: Kernel page dir at %x phys", 0
pKernelPgDir dd 0