refactor: replace magic values with consts

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-08 19:10:37 +02:00
parent 6b89f3c48b
commit c5ea67ad1d
4 changed files with 63 additions and 55 deletions

View file

@ -148,6 +148,7 @@ _start:
include 'gdt.inc' include 'gdt.inc'
include '../common/bootinfo.inc' include '../common/bootinfo.inc'
include '../../kernel/sys/register.inc' include '../../kernel/sys/register.inc'
include '../../kernel/sys/mmu.inc'
uDrive rb 1 uDrive rb 1
bDriveLBA db FALSE bDriveLBA db FALSE
@ -192,7 +193,7 @@ common32:
mov edi, boot_0_page_table mov edi, boot_0_page_table
@@: @@:
mov edx, esi mov edx, esi
or edx, 0x3 or edx, (PTE_P or PTE_W)
mov [edi], edx mov [edi], edx
add edi, 4 add edi, 4
add esi, 4096 add esi, 4096
@ -200,15 +201,15 @@ common32:
cmp ecx, 1024 cmp ecx, 1024
jb @b 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 eax, boot_page_directory
mov cr3, eax mov cr3, eax
mov eax, cr0 mov eax, cr0
or eax, CR0_PG or CR0_WP or eax, (CR0_PG or CR0_WP)
mov cr0, eax mov cr0, eax
mov eax, STPDBOOT_MAGIC mov eax, STPDBOOT_MAGIC

View file

@ -1,32 +1 @@
File: Introduction 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 +---------------+
>

View file

@ -1,12 +1,50 @@
;; File: mm.inc ;; File: mm.inc
;; StupidOS Memory Manager ;; 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 "pmm.inc"
include "../sys/mmu.inc"
;; Macro: KV2P
;; Convert virtual address to physical
macro KV2P reg { macro KV2P reg {
sub reg, KERNEL_VIRT_BASE sub reg, KERNEL_VIRT_BASE
} }
;; Macro: KP2V
macro KP2V reg {
add reg, KERNEL_VIRT_BASE
}
mm_kmap:
ret
;; Function: mm_init
mm_init: mm_init:
mov esi, szMsgMmInit mov esi, szMsgMmInit
call klog call klog
@ -27,7 +65,7 @@ mm_init:
mov edi, eax mov edi, eax
@@: @@:
mov edx, esi mov edx, esi
or edx, 0x3 or edx, (PTE_P or PTE_W)
mov [edi], edx mov [edi], edx
add edi, 4 add edi, 4
add esi, 4096 add esi, 4096
@ -35,7 +73,7 @@ mm_init:
cmp ecx, 1024 cmp ecx, 1024
jb @b jb @b
or eax, 0x03 or eax, (PDE_P or PDE_W)
mov edx, [pKernelPgDir] mov edx, [pKernelPgDir]
add edx, (768 * 4) add edx, (768 * 4)
KV2P eax KV2P eax

View file

@ -39,15 +39,15 @@
;; PDE_U - User ;; PDE_U - User
;; PDE_PWT - Write-Through ;; PDE_PWT - Write-Through
;; PDE_PS - 4MiB page ;; PDE_PS - 4MiB page
PDE_P equ 1 << 0 PDE_P = 0x001
PDE_W equ 1 << 1 PDE_W = 0x002
PDE_U equ 1 << 2 PDE_U = 0x004
PDE_PWT equ 1 << 3 PDE_PWT = 0x008
PDE_PCD equ 1 << 4 PDE_PCD = 0x010
PDE_A equ 1 << 5 PDE_A = 0x020
PDE_D equ 1 << 6 PDE_D = 0x040
PDE_PS equ 1 << 7 PDE_PS = 0x080
PDE_G equ 1 << 8 PDE_G = 0x100
;; Defines: Page Table Flags ;; Defines: Page Table Flags
;; PTE_P - Present ;; PTE_P - Present
@ -59,12 +59,12 @@ PDE_G equ 1 << 8
;; PTE_D - Dirty ;; PTE_D - Dirty
;; PTE_PAT - TODO ;; PTE_PAT - TODO
;; PTE_G - TODO ;; PTE_G - TODO
PTE_P equ 1 << 0 PTE_P = 0x001
PTE_W equ 1 << 1 PTE_W = 0x002
PTE_U equ 1 << 2 PTE_U = 0x004
PTE_PWT equ 1 << 3 PTE_PWT = 0x008
PTE_PCD equ 1 << 4 PTE_PCD = 0x010
PTE_A equ 1 << 5 PTE_A = 0x020
PTE_D equ 1 << 6 PTE_D = 0x040
PTE_PAT equ 1 << 7 PTE_PAT = 0x080
PTE_G equ 1 << 8 PTE_G = 0x100