Add malloc_sector

This commit is contained in:
Nero 2019-08-31 11:57:15 +00:00
parent 126e3aae74
commit ffe6eb0904
1 changed files with 28 additions and 2 deletions

View File

@ -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