From 517fcba43bf6f6527f4bbddd0cdc278607f18d75 Mon Sep 17 00:00:00 2001 From: Thomas Oltmann Date: Sat, 5 Jul 2025 19:34:54 +0200 Subject: [PATCH] Alloc'ing from heap we set up. --- lboot.S | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lboot.S b/lboot.S index ce723ce..13e8255 100644 --- a/lboot.S +++ b/lboot.S @@ -40,8 +40,6 @@ _start: cli mov $msg_fin, %si call print - // hang: sleep indefinitely -hang: hlt jmp hang .set COM1, 0x3F8 @@ -179,22 +177,14 @@ _mhnext: add $24, %si _mhdone: ret - // alloc: take ECX bytes from usable space in memmap + // alloc: take ECX bytes from heap, return ptr in EAX + // The allocation does not get marked in the memmap. // No realignment is performed, so only alloc aligned sizes. -alloc: mov $memmap-24, %si -_anext: add $24, %si - cmp memmap_end, %si // ran over end of memmap? - jae _aerr - cmpl $1, 16(%si) - jne _anext - // TODO check that entry has enough space - cmpl $0, 4(%si) // memory is above 4Gb? - jne _aerr - mov 0(%si), %eax - addl %ecx, 0(%si) - adcl $0, 4(%si) - subl %ecx, 8(%si) - sbbl $0, 12(%si) +alloc: cmp heap_size, %ecx + ja _aerr + mov heap_start, %eax + add %ecx, heap_start + sub %ecx, heap_size ret _aerr: mov $msg_aerr, %si call print @@ -247,6 +237,10 @@ gdt: // entry 0: null descriptor gdt_ptr: .word gdt_size-1 .long gdt + // hang: sleep indefinitely +hang: hlt + jmp hang + // Messages to print msg_start: .asciz "Netboot via fernlader v1 ...\r\n" msg_a20: .asciz " * Enabling A20\r\n" @@ -255,7 +249,7 @@ msg_getmap: .asciz " * Memory Map\r\n" msg_mkheap: .asciz " * Making Space\r\n" msg_paging: .asciz " * Paging\r\n" msg_fin: .asciz "Finished.\r\n" -msg_aerr: .asciz "panic: Unable to allocate memory.\r\n" +msg_aerr: .asciz "panic: Out of heap space.\r\n" heap_start: .long 0 heap_size: .long 0