diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index ac7890c..b874371 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -148,6 +148,7 @@ _start: include 'gdt.inc' include '../common/bootinfo.inc' include '../../kernel/sys/register.inc' + include '../../kernel/sys/mmu.inc' uDrive rb 1 bDriveLBA db FALSE @@ -192,7 +193,7 @@ common32: mov edi, boot_0_page_table @@: mov edx, esi - or edx, 0x3 + or edx, (PTE_P or PTE_W) mov [edi], edx add edi, 4 add esi, 4096 @@ -200,15 +201,15 @@ common32: cmp ecx, 1024 jb @b - mov dword [boot_page_directory], boot_0_page_table + 0x3 ; preset and writable + mov dword [boot_page_directory], boot_0_page_table + (PDE_P or PDE_W) ; preset and writable - mov dword [boot_page_directory + (768 * 4)], boot_0_page_table + 0x3 + mov dword [boot_page_directory + (768 * 4)], boot_0_page_table + (PDE_P or PDE_W) mov eax, boot_page_directory mov cr3, eax mov eax, cr0 - or eax, CR0_PG or CR0_WP + or eax, (CR0_PG or CR0_WP) mov cr0, eax mov eax, STPDBOOT_MAGIC diff --git a/kernel/intro.txt b/kernel/intro.txt index b0c12e1..bb9c92b 100644 --- a/kernel/intro.txt +++ b/kernel/intro.txt @@ -1,32 +1 @@ File: Introduction - -About: kernel memory map - -Kernel Source Overview: - -> kernel -> ├── dev -> ├── fs -> └── mm - - -> -> Physical map virtual map -> +---------------+ -> | | -> +---------------+ -> | ISA hole ? | -> 0x00F00000 +---------------+ -> | RAM | -> +---------------+ -> | kernel | -> 0x00100000 +---------------+ -> | ROM | -> 0x000BFFFF +---------------+ -> | video display | -> | memory | -> 0x0009FFFF +---------------+ -> | RAM | -> | | -> 0x00000000 +---------------+ -> diff --git a/kernel/mm/mm.inc b/kernel/mm/mm.inc index a034a46..0e53c97 100644 --- a/kernel/mm/mm.inc +++ b/kernel/mm/mm.inc @@ -1,12 +1,50 @@ ;; File: mm.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.inc" +include "../sys/mmu.inc" + ;; Macro: KV2P + ;; Convert virtual address to physical macro KV2P reg { sub reg, KERNEL_VIRT_BASE } + ;; Macro: KP2V +macro KP2V reg { + add reg, KERNEL_VIRT_BASE +} + +mm_kmap: + ret + + ;; Function: mm_init mm_init: mov esi, szMsgMmInit call klog @@ -27,7 +65,7 @@ mm_init: mov edi, eax @@: mov edx, esi - or edx, 0x3 + or edx, (PTE_P or PTE_W) mov [edi], edx add edi, 4 add esi, 4096 @@ -35,7 +73,7 @@ mm_init: cmp ecx, 1024 jb @b - or eax, 0x03 + or eax, (PDE_P or PDE_W) mov edx, [pKernelPgDir] add edx, (768 * 4) KV2P eax diff --git a/kernel/sys/mmu.inc b/kernel/sys/mmu.inc index 2d004e1..c330fca 100644 --- a/kernel/sys/mmu.inc +++ b/kernel/sys/mmu.inc @@ -39,15 +39,15 @@ ;; PDE_U - User ;; PDE_PWT - Write-Through ;; PDE_PS - 4MiB page -PDE_P equ 1 << 0 -PDE_W equ 1 << 1 -PDE_U equ 1 << 2 -PDE_PWT equ 1 << 3 -PDE_PCD equ 1 << 4 -PDE_A equ 1 << 5 -PDE_D equ 1 << 6 -PDE_PS equ 1 << 7 -PDE_G equ 1 << 8 +PDE_P = 0x001 +PDE_W = 0x002 +PDE_U = 0x004 +PDE_PWT = 0x008 +PDE_PCD = 0x010 +PDE_A = 0x020 +PDE_D = 0x040 +PDE_PS = 0x080 +PDE_G = 0x100 ;; Defines: Page Table Flags ;; PTE_P - Present @@ -59,12 +59,12 @@ PDE_G equ 1 << 8 ;; PTE_D - Dirty ;; PTE_PAT - TODO ;; PTE_G - TODO -PTE_P equ 1 << 0 -PTE_W equ 1 << 1 -PTE_U equ 1 << 2 -PTE_PWT equ 1 << 3 -PTE_PCD equ 1 << 4 -PTE_A equ 1 << 5 -PTE_D equ 1 << 6 -PTE_PAT equ 1 << 7 -PTE_G equ 1 << 8 +PTE_P = 0x001 +PTE_W = 0x002 +PTE_U = 0x004 +PTE_PWT = 0x008 +PTE_PCD = 0x010 +PTE_A = 0x020 +PTE_D = 0x040 +PTE_PAT = 0x080 +PTE_G = 0x100