Squash commits for public release

This commit is contained in:
2025-02-12 09:54:05 -05:00
commit 7118adc514
1108 changed files with 80873 additions and 0 deletions

67
boot/x86/stage1/boot.s Normal file
View File

@@ -0,0 +1,67 @@
[org 0x7c00]
KERNEL_OFFSET equ 0x1000
KERNEL_SIZE equ 32 ; (KBytes) 32KB
MEMORY_MAP_REGION equ 0xA00
mov [BOOT_DISK], dl ; saving boot disk
mov bp, 0x8000 ; stack init in 16bits
mov sp, bp
mov bx, MSG_REAL_MODE
call print_string
mov eax, 0
mov es, ax
mov di, MEMORY_MAP_REGION
call bios_get_memory_map
call load_kernel
call switch_to_pm
jmp $
%include "boot/x86/stage1/utils16/print.s"
%include "boot/x86/stage1/utils16/smm.s"
%include "boot/x86/stage1/utils16/disk_load.s"
%include "boot/x86/stage1/utils16/switch_to_pm.s"
%include "boot/x86/stage1/utils32/print.s"
%include "boot/x86/stage1/utils32/gdt.s"
[bits 16]
load_kernel:
mov bx, MSG_KERNEL_LOAD
call print_string
mov bx, KERNEL_OFFSET
mov dh, 50
mov dl, [BOOT_DISK]
call disk_load
ret
[bits 32]
begin_pm:
mov ebx, MSG_PROT_MODE
call print_string_pm
mov eax, dword [memory_map_size]
push eax
mov eax, dword KERNEL_SIZE
push eax
push esp
call KERNEL_OFFSET
jmp $
MSG_REAL_MODE:
db 'Starting real mode', 0
MSG_PROT_MODE:
db 'Switched to prot mode', 0
MSG_KERNEL_LOAD:
db ' Loading kernel from drive', 0
BOOT_DISK: db 0
times (510-($-$$)) db 0
db 0x55
db 0xaa

View File

@@ -0,0 +1,23 @@
[bits 16]
disk_load:
push dx
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
int 0x13
jc disk_error
pop dx
cmp al, dh
jne disk_error
ret
disk_error:
mov bx, MSG_DISK_ERROR
call print_string
jmp $
MSG_DISK_ERROR: db 'disk ERROR!', 0

View File

@@ -0,0 +1,15 @@
[bits 16]
print_string:
pusha
mov ah, 0x0e
print_string_cycle:
cmp [bx], BYTE 0
je print_string_end
mov al, [bx]
int 0x10
add bx, 1
jmp print_string_cycle
print_string_end:
popa
ret

View File

@@ -0,0 +1,55 @@
[bits 16]
memory_map_entry:
base_address:
dq 0x0
length:
dq 0x0
type:
dq 0x0
acpi_null:
dq 0x0
memory_map_entry_end:
memory_map_size: dw 0
bios_get_memory_map:
pushad
xor ebx, ebx
xor bp, bp
mov edx, 'PAMS'
mov eax, 0xe820
mov ecx, 24
int 0x15
jc memory_map_error
cmp eax, 'PAMS'
jne memory_map_error
test ebx, ebx
je memory_map_error
jmp memory_map_start
memory_map_next:
mov edx, 'PAMS'
mov ecx, 24
mov eax, 0xe820
int 0x15
memory_map_start:
jcxz memory_map_skip_entry
memory_map_common:
mov ecx, [es:di + 8]
test ecx, ecx
jne memory_map_good_entry
mov ecx, [es:di + 12]
jecxz memory_map_skip_entry
memory_map_good_entry:
inc bp
add di, 24
memory_map_skip_entry:
cmp ebx, 0
jne memory_map_next
jmp memory_map_done
memory_map_error:
stc
memory_map_done:
mov [memory_map_size], bp
popad
ret

View File

@@ -0,0 +1,22 @@
[bits 16]
switch_to_pm:
cli ; turn off interupts
lgdt [gdt_descriptor]
mov eax, cr0
or eax, 0x1
mov cr0, eax
call CODE_SEG:init_pm
[bits 32]
init_pm:
mov ax, DATA_SEG
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000 ; stack's init
mov esp, ebp
call begin_pm

View File

@@ -0,0 +1,27 @@
gdt_begin:
gdt_null:
dd 0x00
dd 0x00
gdt_code:
dw 0xffff
dw 0x0000
db 0x0
db 10011010b
db 11001111b
db 0x0
gdt_data:
dw 0xffff
dw 0x0000
db 0x0
db 10010010b
db 11001111b
db 0x0
gdt_end:
gdt_descriptor:
dw gdt_end - gdt_begin - 1
dd gdt_begin
CODE_SEG equ gdt_code - gdt_begin
DATA_SEG equ gdt_data - gdt_begin

View File

@@ -0,0 +1,22 @@
[bits 32]
VIDEO_MEMORY equ 0xb8000
WHITE_ON_BLACK equ 0x0f
print_string_pm:
pusha
mov edx, VIDEO_MEMORY
print_string_pm_cycle:
cmp [ebx], BYTE 0
je print_string_pm_end
mov ah, WHITE_ON_BLACK
mov al, [ebx]
mov [edx], ax
add ebx, 1
add edx, 2
jmp print_string_pm_cycle
print_string_pm_end:
popa
ret