transfer to local git!

This commit is contained in:
2025-12-30 18:49:57 +00:00
commit 2305de8699
302 changed files with 3100 additions and 0 deletions

96
boot/boot.asm Normal file
View File

@@ -0,0 +1,96 @@
global start
extern rust_handshake
section .text
bits 32
start:
; Grab stack pointer from GRUB
mov esp, stack_top
; Setup paging for long mode
call set_up_page_tables
call enable_paging
; load the 64-bit GDT
lgdt [gdt64.pointer]
jmp gdt64.code:rust_handshake
; move 'ok' characters to VGA buffer
mov dword [0xb8000], 0x2f4b2f4f
hlt
set_up_page_tables:
; map first page-map table to page pointer table
mov eax, page_pointer_table
or eax, 0b11
mov [page_map_table], eax
; map first page pointer table entry to page table table
mov eax, page_table
or eax, 0b11
mov [page_pointer_table], eax
; map each page table entry to a 2M page
mov ecx, 0
.map_page_table:
; map ecx-th page_table entry to a page that starts at address 2MiB*ecx
mov eax, 0x200000 ; 2MiB
mul ecx ; start address of ecx-th page
or eax, 0b10000011 ; present + writable + huge
mov [page_table + ecx * 8], eax ; map entry
; This is a for loop to map all 512 entries
; inside the page table
inc ecx ; i++
cmp ecx, 512 ; i != 512
jne .map_page_table ; loop!
ret
enable_paging:
; load page map table to cr3 reg
mov eax, page_map_table
mov cr3, eax
; enable physical address extension flag to cr4 reg
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
; set the long mode bit in the MSR
mov ecx, 0xC0000080
rdmsr
or eax, 1 << 8
wrmsr
; enable paging in the cr0 reg
mov eax, cr0
or eax, 1 << 31
mov cr0, eax
ret
; Align each table
section .bss
align 4096
page_map_table:
resb 4096
page_pointer_table:
resb 4096
page_table:
resb 4096
stack_bottom:
resb 64
stack_top:
; Global Descriptor Table Setup
section .rodata
gdt64:
dq 0
.code: equ $ - gdt64
dq (1<<43) | (1<<44) | (1<<47) | (1<<53) ; code segment
.pointer:
dw $ - gdt64 - 1
dq gdt64

7
boot/grub.cfg Normal file
View File

@@ -0,0 +1,7 @@
set timeout=5
set default=0
menuentry "Scarab" {
multiboot2 /boot/kernel.bin
boot
}

16
boot/linker.ld Normal file
View File

@@ -0,0 +1,16 @@
ENTRY(start)
SECTIONS {
. = 1M;
.boot :
{
/* ensure that the multiboot header is at the beginning */
KEEP(*(.multiboot_header))
}
.text :
{
*(.text)
}
}

15
boot/multiboot_header.asm Normal file
View File

@@ -0,0 +1,15 @@
section .multiboot_header
header_start:
dd 0xe85250d6 ; magic number (multiboot 2)
dd 0 ; architecture 0 (protected mode i386)
dd header_end - header_start ; header length
; checksum
dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start))
; insert optional multiboot tags here
; required end tag
dw 0 ; type
dw 0 ; flags
dd 8 ; size
header_end:

20
boot/rust_handshake.asm Normal file
View File

@@ -0,0 +1,20 @@
global rust_handshake
extern rust_main
section .text
bits 64
rust_handshake:
; load 0 into all data segment registers
mov ax, 0
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; Offload to rust
extern rust_main
call rust_main
hlt