Add malloc_sector
This commit is contained in:
parent
126e3aae74
commit
ffe6eb0904
@ -86,11 +86,11 @@ malloc_dump:
|
|||||||
pop dx
|
pop dx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; allocate a 16 byte section
|
; Allocate a paragraph
|
||||||
; out BX ptr
|
; out BX ptr
|
||||||
malloc:
|
malloc:
|
||||||
; search for a byte that is not 0xFF
|
; search for a byte that is not 0xFF
|
||||||
mov di, 0x0600
|
call malloc_get_table
|
||||||
mov cx, 0x0200
|
mov cx, 0x0200
|
||||||
mov al, 0xFF
|
mov al, 0xFF
|
||||||
repe scasb
|
repe scasb
|
||||||
@ -119,6 +119,7 @@ malloc:
|
|||||||
mov bx, di
|
mov bx, di
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; Free a paragraph
|
||||||
; IN: 0:BX ptr to paragraph to be marked as free
|
; IN: 0:BX ptr to paragraph to be marked as free
|
||||||
free:
|
free:
|
||||||
call malloc_calc_offsets
|
call malloc_calc_offsets
|
||||||
@ -126,6 +127,31 @@ free:
|
|||||||
and byte [bx+di], al
|
and byte [bx+di], al
|
||||||
ret
|
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:
|
fatal_oom:
|
||||||
call printf
|
call printf
|
||||||
db "PANIC OOM", 0x0A, 0x0D, 0x00
|
db "PANIC OOM", 0x0A, 0x0D, 0x00
|
||||||
|
Loading…
Reference in New Issue
Block a user