lboot now sets up an initial bootboot struct

This commit is contained in:
Thomas Oltmann 2025-07-08 15:43:19 +02:00
parent 1ba17d852b
commit 51502e07d4
3 changed files with 73 additions and 9 deletions

View file

@ -1,3 +1,4 @@
ENTRY(_start)
PHDRS {
all PT_LOAD;
}
@ -7,6 +8,7 @@ SECTIONS {
*(.text, .rodata*)
*(.data)
*(.bss, COMMON)
. = ALIGN(4K);
lboot.o(.data.bootboot)
} :all
memmap = ALIGN(8);
}

66
lboot.S
View file

@ -165,7 +165,7 @@ _urunreal: pop %es
ret
// get_map: Retrieve memory map using e820 BIOS function
get_map: mov $memmap, %di
get_map: mov $bb_memmap, %edi
xor %ebx, %ebx
mov $0x534D4150, %edx // e820 magic number
_gmnext: movl $0, 20(%di)
@ -178,7 +178,8 @@ _gmnext: movl $0, 20(%di)
add $24, %di
jmp _gmnext
_gmdone: add $24, %di
mov %di, memmap_end
sub $bootboot, %edi
mov %edi, bb_size
ret
// paging: Set up initial page tables for long mode
@ -236,9 +237,11 @@ _pgnext: mov %ecx, %eax
ret
// make_heap: find a memory range suitable for heap usage
make_heap: mov $memmap-24, %si
make_heap: mov $bb_memmap-24, %si
_mhnext: add $24, %si
cmp memmap_end, %si
mov $bootboot, %eax
add bb_size, %eax
cmp %ax, %si
jae _mhdone
cmpl $1, 16(%si)
@ -508,7 +511,7 @@ pdp_ptr: .long 0
pml4_ptr: .long 0
// Points to the end of the memory map
memmap_end: .word 0
memmap_end: .short 0
tx_buf: .space PACKET_SIZE
@ -523,11 +526,62 @@ trampo64:
mov %eax, %gs
mov %eax, %ss
mov initrd_ptr, %edi
// Mangle e820 memmap into bootboot's format
mov $bb_memmap, %rsi
mov $bb_memmap, %rdi
mov $bootboot, %edx
add bb_size, %edx
1:
mov 0(%rsi), %rax
mov 8(%rsi), %rcx
mov 16(%rsi), %ebx
cmp $6, %ebx
jb 2f
mov $2, %ebx
2: mov type_table(%rbx), %bl
and $-16, %rax
or %rbx, %rax
mov %rax, 0(%rdi)
mov %rcx, 8(%rdi)
add $24, %rsi
add $16, %rdi
cmp %rdx, %rsi
jb 1b
sub $bootboot, %edi
mov %edi, bb_size
mov $bootboot, %edi
jmp loader_main
type_table: .byte 0
.byte 1
.byte 0
.byte 2
.byte 2
.byte 0
// ToDo List:
// - Sorting the memmap
// - Sanitizing the memmap
// - Translating the memmap to bootboot format
// - Parsing a config file
.section .data.bootboot
bootboot: .ascii "BOOT"
bb_size: .long 128
.byte 1
.byte 0
.short 1
.short 0
.space 10, 0
bb_ird_ptr: .quad 0
bb_ird_size:.quad 0
.space 24, 0
.space 64, 0
bb_memmap:
.space 4096-128, 0

View file

@ -185,11 +185,19 @@ load_elf(file_t file, uintptr_t *entry)
return 0;
}
/*
static void *
alloc(size_t size, size_t align)
{
}
*/
void
loader_main(void *initrd)
loader_main(BOOTBOOT *bootboot_ptr)
{
uint64_t entry = 0;
file_t elf = { initrd, MEG(2) };
file_t elf = { (void *)bootboot_ptr->initrd_ptr, MEG(2) };
if (load_elf(elf, &entry) < 0) {
panic("panic: Malformed ELF64 executable");
}