Alloc'ing from the memory map
This commit is contained in:
parent
51502e07d4
commit
5fab4ba6c3
2 changed files with 20 additions and 10 deletions
9
lboot.S
9
lboot.S
|
|
@ -108,7 +108,7 @@ _start: cli
|
||||||
call print
|
call print
|
||||||
mov $fn_initrd, %esi
|
mov $fn_initrd, %esi
|
||||||
call read_file
|
call read_file
|
||||||
mov %ebx, initrd_ptr
|
mov %ebx, bb_ird_ptr
|
||||||
|
|
||||||
mov $msg_long, %si
|
mov $msg_long, %si
|
||||||
call print
|
call print
|
||||||
|
|
@ -503,8 +503,6 @@ server_ip: .space 4
|
||||||
heap_ptr: .long 0
|
heap_ptr: .long 0
|
||||||
heap_end: .long 0
|
heap_end: .long 0
|
||||||
|
|
||||||
initrd_ptr: .long 0
|
|
||||||
|
|
||||||
// Long mode initial page tables
|
// Long mode initial page tables
|
||||||
pd_ptr: .long 0
|
pd_ptr: .long 0
|
||||||
pdp_ptr: .long 0
|
pdp_ptr: .long 0
|
||||||
|
|
@ -541,8 +539,8 @@ trampo64:
|
||||||
mov $2, %ebx
|
mov $2, %ebx
|
||||||
2: mov type_table(%rbx), %bl
|
2: mov type_table(%rbx), %bl
|
||||||
|
|
||||||
and $-16, %rax
|
and $-16, %rcx
|
||||||
or %rbx, %rax
|
or %rbx, %rcx
|
||||||
|
|
||||||
mov %rax, 0(%rdi)
|
mov %rax, 0(%rdi)
|
||||||
mov %rcx, 8(%rdi)
|
mov %rcx, 8(%rdi)
|
||||||
|
|
@ -568,7 +566,6 @@ type_table: .byte 0
|
||||||
// ToDo List:
|
// ToDo List:
|
||||||
// - Sorting the memmap
|
// - Sorting the memmap
|
||||||
// - Sanitizing the memmap
|
// - Sanitizing the memmap
|
||||||
// - Translating the memmap to bootboot format
|
|
||||||
// - Parsing a config file
|
// - Parsing a config file
|
||||||
|
|
||||||
.section .data.bootboot
|
.section .data.bootboot
|
||||||
|
|
|
||||||
21
loader.c
21
loader.c
|
|
@ -185,13 +185,24 @@ load_elf(file_t file, uintptr_t *entry)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static void *
|
static void *
|
||||||
alloc(size_t size, size_t align)
|
alloc(BOOTBOOT *bootboot_ptr, size_t size, size_t align)
|
||||||
{
|
{
|
||||||
|
MMapEnt *mmap_end = (MMapEnt *)((char *)bootboot_ptr + bootboot_ptr->size);
|
||||||
|
for (MMapEnt *ent = &bootboot_ptr->mmap; ent < mmap_end; ent++) {
|
||||||
|
if (!MMapEnt_IsFree(ent)) continue;
|
||||||
|
int64_t mstart = MMapEnt_Ptr(ent);
|
||||||
|
int64_t msize = MMapEnt_Size(ent);
|
||||||
|
int64_t mend = mstart + msize;
|
||||||
|
mend -= size;
|
||||||
|
mend &= -align;
|
||||||
|
if (mend < mstart) continue;
|
||||||
|
ent->size = ((mend - mstart) & INT64_C(-16)) | MMAP_FREE;
|
||||||
|
return (void *)mend;
|
||||||
|
}
|
||||||
|
panic("panic: Could not allocate from memory map.");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
loader_main(BOOTBOOT *bootboot_ptr)
|
loader_main(BOOTBOOT *bootboot_ptr)
|
||||||
|
|
@ -202,6 +213,8 @@ loader_main(BOOTBOOT *bootboot_ptr)
|
||||||
panic("panic: Malformed ELF64 executable");
|
panic("panic: Malformed ELF64 executable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alloc(bootboot_ptr, PAGES(1), PAGES(1));
|
||||||
|
|
||||||
uint64_t stack = 0;
|
uint64_t stack = 0;
|
||||||
|
|
||||||
__asm__ __volatile__ (
|
__asm__ __volatile__ (
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue