diff --git a/mem.asm b/mem.asm index e01ef5e..8d03ae6 100644 --- a/mem.asm +++ b/mem.asm @@ -14,7 +14,9 @@ mtab_ref: ret ; finds a place for a new item in the mm table -; out: bx +; this detects 'empty' slots by the size field being zero +; in: ds:si: pointer to first mtab item +; out: bx: offset for empty slot mtab_alloc: push ax call mtab_ref @@ -27,6 +29,38 @@ mtab_alloc: pop ax ret +; splits a mtab item at offset +; in: ds:si: pointer mtab item +; ax: split position in 16 byte blocks +; out: ds:si: pointer to lower half +; ds:di: pointer to upper half +mtab_split: + push cx ; remaining memory block length + mov cx,[ds:si] + + mov [ds:si],ax ; this resizes the first item + sub cx, ax + + push bx + call mtab_alloc + mov di,bx + pop bx + + push si ; backup because movsw increments them + push di ; ^ + push cx ; counter for movsb + mov es,ds + mov cx,0x08 ; 8 words = 16 bytes + rep movsw ; repeat cx times + pop cx + pop di + pop si + + mov [ds:di],cx + + pop cx + ret + ; in: ax: segment ; bh: task id (0 for non-task memory) ; bl: memory type (see enum at top of file)