From 958a301d18eb5dcd3698cdde0001d06910822abc Mon Sep 17 00:00:00 2001 From: nub31 Date: Mon, 3 Feb 2025 18:53:48 +0100 Subject: [PATCH] formating --- input/baseline/alloc.asm | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/input/baseline/alloc.asm b/input/baseline/alloc.asm index ddbcba9..be65199 100644 --- a/input/baseline/alloc.asm +++ b/input/baseline/alloc.asm @@ -1,18 +1,13 @@ global alloc, free -; metadata -; +0: size -; +8: next -; +16 data - section .bss - free_list: resq 1 ; head of free list - alloc_list: resq 1 ; head of allocation list + free_list_head: resq 1 ; head of free list + alloc_list_head: resq 1 ; head of allocation list section .text alloc: add rdi, 16 ; add space for metadata - mov rax, [free_list] ; load head of free list + mov rax, [free_list_head] ; load head of free list xor r8, r8 ; last block .loop: test rax, rax ; end of list? @@ -31,16 +26,16 @@ alloc: jz .remove_free_head ; yes? remove head mov [r8 + 8], rsi ; set prev.next to this.next jmp .done_remove_free_block -.remove_free_head - mov [free_list], rsi +.remove_free_head: + mov [free_list_head], rsi .done_remove_free_block: mov rsi, [rax] ; load size of block excluding the newly allocated object lea rax, [rax + rsi + 16] ; address of allocated block sub rdi, 16 mov [rax], rdi ; save size - mov rsi, [alloc_list] ; load head of allocated blocks + mov rsi, [alloc_list_head] ; load head of allocated blocks mov [rax + 8], rsi ; move head to be next item after this block - mov [alloc_list], rax ; set new head to this block + mov [alloc_list_head], rax ; set new head to this block lea rax, [rax + 16] ; skip metadata for return value ret .new_block: @@ -49,9 +44,9 @@ alloc: mov rdi, 4096 ; page size call sys_mmap ; allocate a page mov qword [rax], 4080 ; set size of block to block size - metadata - mov rsi, [free_list] + mov rsi, [free_list_head] mov qword [rax + 8], rsi ; move head to be the next item after this block - mov [free_list], rax ; set new head to this block + mov [free_list_head], rax ; set new head to this block pop r8 pop rdi jmp .found_block