From ffe6eb09045d5e46810a80dda0a1fbd1693d73d4 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sat, 31 Aug 2019 11:57:15 +0000 Subject: [PATCH] Add malloc_sector --- kernel/malloc.asm | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/kernel/malloc.asm b/kernel/malloc.asm index 1fe4474..df634cf 100644 --- a/kernel/malloc.asm +++ b/kernel/malloc.asm @@ -86,11 +86,11 @@ malloc_dump: pop dx ret -; allocate a 16 byte section +; Allocate a paragraph ; out BX ptr malloc: ; search for a byte that is not 0xFF - mov di, 0x0600 + call malloc_get_table mov cx, 0x0200 mov al, 0xFF repe scasb @@ -119,6 +119,7 @@ malloc: mov bx, di ret +; Free a paragraph ; IN: 0:BX ptr to paragraph to be marked as free free: call malloc_calc_offsets @@ -126,6 +127,31 @@ free: and byte [bx+di], al ret +; Allocate a sector, 512 bytes or 32 paragraphs +malloc_sector: + call malloc_get_table + mov cx, 0x0200 + xor ax, ax +.continue: + repne scasw + jne fatal_oom + + ; we need a second word to be 0, otherwise continue search + scasw + jne .continue + + sub di, 4 + not ax + stosw + stosw + + sub di, 0x604 + mov cl, 7 + shl di, cl + + xchg bx, di + ret + fatal_oom: call printf db "PANIC OOM", 0x0A, 0x0D, 0x00