chore: random docs

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-07 15:29:41 +02:00
parent d764fe4666
commit 4d5bbe3003
8 changed files with 303 additions and 4 deletions

53
kernel/dev/at/intro.txt Normal file
View file

@ -0,0 +1,53 @@
File: IBM PC/AT
About: I/O Address Map
> +---------------+-------------------------+
> | 0x000 - 0x01F | DMA controller 1 |
> +---------------+-------------------------+
> | 0x020 - 0x03F | 8259A, Primary |
> +---------------+-------------------------+
> | 0x040 - 0x05F | Timer |
> +---------------+-------------------------+
> | 0x060 - 0x06F | Keyboard |
> +---------------+-------------------------+
> | 0x070 - 0x07F | CMOS |
> +---------------+-------------------------+
> | 0x080 - 0x09F | DMA page register |
> +---------------+-------------------------+
> | 0x0A0 - 0x0BF | 8259A, Secondary |
> +---------------+-------------------------+
> | 0x0C0 - 0x0DF | DMA controller 2 |
> +---------------+-------------------------+
> | 0x0F0 | Clear Math Coprocessor |
> +---------------+-------------------------+
> | 0x0F1 | Reset Math Coprocessor |
> +---------------+-------------------------+
> | 0x0F8 - 0x0FF | Math Coprocessor |
> +---------------+-------------------------+
> | 0x1F0 - 0x1F8 | Fixed Disk |
> +---------------+-------------------------+
> | 0x200 - 0x207 | Game I/O |
> +---------------+-------------------------+
> | 0x278 - 0x27F | Parallel printer port 2 |
> +---------------+-------------------------+
> | 0x2F8 - 0x2FF | Serial port 2 |
> +---------------+-------------------------+
> | 0x300 - 0x31F | Prototype card |
> +---------------+-------------------------+
> | 0x360 - 0x363 | PC Network (low) |
> +---------------+-------------------------+
> | 0x368 - 0x36B | PC Network (high) |
> +---------------+-------------------------+
> | 0x378 - 0x37F | Parallel printer port 1 |
> +---------------+-------------------------+
> | 0x380 - 0x38F | SDLC, bisynchronous 2 |
> +---------------+-------------------------+
> | 0x3B0 - 0x3BF | Monochrome Display |
> +---------------+-------------------------+
> | 0x3D0 - 0x3DF | Color Monitor Adapter |
> +---------------+-------------------------+
> | 0x3F0 - 0x3F7 | Diskette controller |
> +---------------+-------------------------+
> | 0x3F8 - 0x3FF | Serial port 1 |
> +---------------+-------------------------+

View file

@ -1,3 +1,5 @@
;; File: vga_console.inc
VGA_COLUMNS = 80
VGA_LINES = 25
VGA_BASE = 0xC03B0000

View file

@ -0,0 +1,10 @@
idt_set_table:
ret
idt_setup:
ret
pIdt:
dw ?
dd ?

View file

@ -2,6 +2,14 @@ File: Introduction
About: kernel memory map
Kernel Source Overview:
> kernel
> ├── dev
> ├── fs
> └── mm
>
> Physical map virtual map
> +---------------+

17
kernel/lock.inc Normal file
View file

@ -0,0 +1,17 @@
;;
lock_acquire:
lock bts [eax], 0
jnc .end
@@:
pause
test [eax], 1
jne @b
lock bts [eax], 0
jc @b
.end:
ret
release:
mov [eax], 0

View file

@ -1,5 +1,6 @@
;; File: mm.inc
;; StupidOS Memory Manager
include "pmm.inc"
mm_init:
@ -13,11 +14,23 @@ mm_init:
mov esi, szMsgMmKernelPgDir
call klog
;; Map kernel
; clear page dir
mov ecx, 4096
xor al, al
mov edi, [pKernelPgDir]
rep stosb
;; Map kernel and kmemory
call pmm_alloc_page
push eax
mov ecx, 4096
mov edi, eax
xor al, al
rep stosb
pop eax
;; Map video
;; Map low memory at ????
;; Map free memory

70
kernel/sys/mmu.inc Normal file
View file

@ -0,0 +1,70 @@
;; File: mmu.inc
;;
;; About: Address Translation
;;
;; Since we don't use segmentation, this is how address translation works
;; > 31 21 11 0
;; > +--------+--------+--------+
;; > | DIR | PAGE | OFFSET |
;; > +--------+--------+--------+
;; > |
;; > v
;; > Page Translation
;; > |
;; > 31 v 0
;; > +--------------------------+
;; > | Pyshical address |
;; > +--------------------------+
;;
;; About: Page Translation
;;
;; > +--------+--------+--------+ +--------+
;; > | DIR | PAGE | OFFSET |-----+ | Phys |
;; > +--------+--------+--------+ +------>| addr |
;; > | | | |
;; > | +----+ +--------+
;; > | Page Dir | +---> Page Frame
;; > | +---------+ | +--------+ |
;; > | | | | | | |
;; > +->| PDE |-+ +->| PTE |-+
;; > | | | | |
;; > +---------+ | +--------+
;; > +----> Page Table
;; >
;;
;; Defines: Page Directory Flags
;; PDE_P - Present
;; PDE_W - Writable
;; 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
;; Defines: Page Table Flags
;; PTE_P - Present
;; PTE_W - Writable
;; PTE_U - User
;; PTE_PWT - Write-Through
;; PTE_PCD - Cache Disable
;; PTE_A - Accessed
;; 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

126
kernel/sys/register.inc Normal file
View file

@ -0,0 +1,126 @@
;; File: registers.inc
;; =========================================================================
;; Control Registers
;; =========================================================================
;; Defines: CR0
;; CR0_PE - Protected Mode Enable
;; CR0_MP - Monitor co-processor
;; CR0_EM - x87 FPU Emulation
;; CR0_TS - Task switched
;; CR0_ET - Extension type
;; CR0_NE - Numeric error
;; CR0_WP - Write protect
;; CR0_AM - Alignment mask
;; CR0_NW - Not-write through
;; CR0_CD - Cache disable
;; CR0_PG - Paging
CR0_PE equ 1 << 0
CR0_MP equ 1 << 1
CR0_EM equ 1 << 2
CR0_TS equ 1 << 3
CR0_ET equ 1 << 4
CR0_NE equ 1 << 5
CR0_WP equ 1 << 16
CR0_AM equ 1 << 18
CR0_NW equ 1 << 29
CR0_CD equ 1 << 30
CR0_PG equ 1 << 31
;; Defines: CR3
;; CR3_PWT - Page-level Write-Through
;; CR3_PCD - Page-level Cache Disable
CR3_PWT equ 1 << 3
CR3_PCD equ 1 << 4
;; Defines: CR4
;; CR4_VME - Virtual 8086 Mode Extensions
;; CR4_PVI - Protected-mode Virtual Interrupts
;; CR4_TSD - Time Stamp Disable
;; CR4_DE - Debugging Extensions
;; CR4_PSE - Page Size Extension
;; CR4_PAE - Physical Address Extension
;; CR4_MCE - Machine Check Exception
;; CR4_PGE - Page Global Enabled
;; CR4_PCE - Performance-Monitoring Counter enable
;; CR4_OSFXSR - Operating system support for FXSAVE and FXRSTOR
;; instructions
;; CR4_OSXMMEXCPT - Operating System Support for Unmasked SIMD
;; Floating-Point Excepions
;; CR4_UMIP - User-Mode Instruction Prevention
;; CR4_VMXE - Virtual Machine Extensions Enable
;; CR4_SMXE - Safer Mode Extensions Enable
;; CR4_FSGSBASE -
;; CR4_PCIDE - PCID Enable
;; CR4_OSXSSAVE - XSAVE and Processor Extended States Enable
;; CR4_SMEP - Supervisor Mode Execution Protection Enable
;; CR4_SMAP - Supervisor Mode Access Prevention Enable
;; CR4_PKE - Protection Key Enable
;; CR4_CET - Control-flow Enforcement Technology
;; CR4_PKS - Enable Protection Keys for Supervisor-Mode Pages
CR4_VME equ 1 << 0
CR4_PVI equ 1 << 1
CR4_TSD equ 1 << 2
CR4_DE equ 1 << 3
CR4_PSE equ 1 << 4
CR4_PAE equ 1 << 5
CR4_MCE equ 1 << 6
CR4_PGE equ 1 << 7
CR4_PCE equ 1 << 8
CR4_OSDXSR equ 1 << 9
CR4_OSXMMEXCPT equ 1 << 10
CR4_UMIP equ 1 << 11
CR4_VMXE equ 1 << 13
CR4_SMXE equ 1 << 14
CR4_FSGSBASE equ 1 << 16
CR4_PCIDE equ 1 << 17
CR4_OSXSAVE equ 1 << 18
CR4_SMEP equ 1 << 20
CR4_SMAP equ 1 << 21
CR4_PKE equ 1 << 22
CR4_CET equ 1 << 23
CR4_PKS equ 1 << 24
;; =========================================================================
;; eflags
;; =========================================================================
;; Defines: EFLAGS
;; EFLAGS_CF - Carry flag
;; EFLAGS_PF - Parity flag
;; EFLAGS_AF - Auxiliary flag
;; EFLAGS_ZF - Zero flag
;; EFLAGS_SF - Sign flag
;; EFLAGS_TF - Trap flag
;; EFLAGS_IF - Interrupt enable flag
;; EFLAGS_DF - Direction flag
;; EFLAGS_OF - Overflow flag
;; EFLAGS_IOPL1 - I/O privilege flag
;; EFLAGS_IOPL2 - I/O privilege flag
;; EFLAGS_NT - Nested task flag
;; EFLAGS_RF - Resume flag
;; EFLAGS_VM - Virtual 8086 mode flag
;; EFLAGS_AC - Alignment check
;; EFLAGS_VIF - Virtual Interrupt flag
;; EFLAGS_VIP - Virtual Interrupt pending
;; EFLAGS_ID - CPUID instruction available
EFLAGS_CF equ 1 << 0
EFLAGS_PF equ 1 << 2
EFLAGS_AF equ 1 << 4
EFLAGS_ZF equ 1 << 6
EFLAGS_SF equ 1 << 7
EFLAGS_TF equ 1 << 8
EFLAGS_IF equ 1 << 9
EFLAGS_DF equ 1 << 10
EFLAGS_OF equ 1 << 11
EFLAGS_IOPL1 equ 1 << 12
EFLAGS_IOPL2 equ 1 << 13
EFLAGS_NT equ 1 << 14
EFLAGS_RF equ 1 << 16
EFLAGS_VM equ 1 << 17
EFLAGS_AC equ 1 << 18
EFLAGS_VIF equ 1 << 19
EFLAGS_VIP equ 1 << 20
EFLAGS_ID equ 1 << 21