feat(boot/loader): move kernel to 0x100000

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-06 15:19:35 +02:00
parent 41676291fe
commit a0c99799e8
13 changed files with 73 additions and 26 deletions

View file

@ -10,7 +10,7 @@ struc BootInfoRange {
;;
;; StupidOS boot protocol structure
struc BootInfo {
.mmap dd 4*2*40 dup(0)
.mmap dd 4*2*20 dup(0)
.kernel_start dd ?
.kernel_size dd ?
}

View file

@ -8,6 +8,7 @@ FALSE = 0
MBR_BASE = 0x0600
BOOTSECT_BASE = 0x7C00
LOADER_BASE = 0x1000
KERNEL_BASE = 0x100000
MULTIBOOT_BASE = 0x100000
DISK_BUFFER = 0x8000
KERNEL_PRELOAD = 0xF000

View file

@ -179,6 +179,12 @@ multiboot:
common32:
mov [0xB8000], dword 0x07690748
; move kernel to 0x100000
mov ecx, [uKernelSize]
mov esi, KERNEL_PRELOAD
mov edi, KERNEL_BASE
rep movsb
; identity map first 1MB
xor esi, esi
xor ecx, ecx
@ -196,7 +202,7 @@ common32:
mov dword [boot_page_directory], boot_0_page_table + 0x3 ; preset and writable
; map kernel at 0xC0000000
mov esi, KERNEL_PRELOAD
mov esi, KERNEL_BASE
mov edi, boot_768_page_table
xor ecx, ecx
@@:
@ -225,6 +231,8 @@ common32:
mov eax, STPDBOOT_MAGIC
mov ebx, boot_structure
xchg bx, bx
mov ecx, 0xC0000000
jmp ecx

View file

@ -56,10 +56,10 @@ memory_e820_get_map:
mov di, pE280AddrRange
mov ecx, 20
mov eax, 0xE820
mov edx, 0x534D4150
mov edx, 'PAMS'
int 0x15
jc .error
cmp eax, 0x534D4150
cmp eax, 'PAMS'
jne .error
or ebx, ebx
jz .end

View file

@ -1,7 +1,7 @@
PE_PRESENT = (1 shl 0)
PE_WRITABLE = (1 shl 1)
PE_USERMODE = (1 shl 2)
PE_ACCESSED = (1 shl 5)
PE_DIRTY = (1 shl 6)
PE_PRESENT = (1 shl 0)
PE_WRITABLE = (1 shl 1)
PE_USERMODE = (1 shl 2)
PE_ACCESSED = (1 shl 5)
PE_DIRTY = (1 shl 6)

View file

@ -7,7 +7,8 @@ SRCS = kernel.asm \
const.inc \
klog.inc \
dev/vga_console.inc \
mm/mm.inc
mm/mm.inc \
mm/pmm.inc
.PHONY: all
all: $(KERNEL)

16
kernel/bootinfo.inc Normal file
View file

@ -0,0 +1,16 @@
;; File: bootinfo.inc
;; Struct: BootInfoRange
struc BootInfoRange {
.base dd ?
.length dd ?
}
;; Struct: BootInfo
;;
;; StupidOS boot protocol structure
struc BootInfo {
.mmap dd 4*2*20 dup(0)
.kernel_start dd ?
.kernel_size dd ?
}

0
kernel/idt.inc Normal file
View file

View file

@ -3,7 +3,7 @@ File: Introduction
About: kernel memory map
>
> Physical map
> Physical map virtual map
> +---------------+
> | |
> +---------------+

View file

@ -19,16 +19,17 @@ db 32 dup(0)
;; EBX - Boot structure address
;;
kmain:
xchg bx, bx
mov esp, stack_top
cmp eax, STPDBOOT_MAGIC
jne .halt
jne .error_magic
; init memory manager
; init idt, gdt
; copy boot structure
xchg bx, bx
call vga_console_clear
;call vga_console_clear
mov [0xC03B0000], dword 0x08740953
mov [0xC03B0004], dword 0x05700675
@ -44,12 +45,18 @@ kmain:
.halt:
hlt
jmp $
.error_magic:
mov esi, szErrorBootProtocol
.error:
call klog
jmp .halt
include 'klog.inc'
include 'dev/vga_console.inc'
include 'mm/mm.inc'
szMsgKernelAlive db "Kernel is alive", 0
szErrorBootProtocol db "Error: wrong magic number", 0
align 4
stack_bottom:

View file

@ -1,4 +1,5 @@
free_block_head dd 0x0
include "pmm.inc"
mm_init:
ret

View file

@ -1,3 +1,16 @@
struc
{
}
align 4
;aPhysPageBitmap:
; dd 32769 dup(0)
pmm_init:
ret
pmm_alloc_page:
ret
pmm_free_range:
ret
pmm_free_page:
ret

View file

@ -1,7 +1,7 @@
struc VMStat
{
total_page dd 0
free_pages dd 0
used_pages dd 0
}
struc VMStat
{
total_page dd 0
free_pages dd 0
used_pages dd 0
}