Add lib function for MCB allocation from bootsectors

This commit is contained in:
Nero 2019-09-26 14:57:20 +00:00
parent e878ad0880
commit 7f9820bace
1 changed files with 65 additions and 0 deletions

65
lib/earlymcb.asm Normal file
View File

@ -0,0 +1,65 @@
%define mcb_first 0x5F
; This alloc uses an MCB-like list always starting at a fixed offset.
; Boot components may use it to allocate space during early boot.
; The list ends with the most recently allocated arena at its end,
; contrary to how the MCBs work on DOS.
; Memory Layout:
; 0000 Interrupt table
; 0400 BIOS data area
; 05F0 16 bytes Arena header 1
; 0600 BX paragraphs Arena 1
; .... 16 bytes Arena header 2
; .... BX paragraphs Arena 2
; ...
; .... 16 bytes Arena header n
; .... BX paragraphs Arena n
; Unmanaged memory
; Take note that this mechanism works differently than under DOS -
; but this one is optimized for fast and small alloc.
; Typical usecases:
; - Diskette Parameter Table (See interrupt 1Eh)
; - Partition table
; - Boot sector relocations
; - Boot sector data (FAT table, rootdir)
; Allocate paragraphs in unmanaged memory
; IN BX requested memory in paragraphs
; OUT AX output segment
early_alloc:
push ds
push bx
push si
; si is used as zero register
; this allows the opcodes to use a byte as disp instead of word
xor si, si
mov ax, mcb_first
.next:
mov ds, ax
inc ax
; DS is seg of arena header
; AX is seg of arena
cmp BYTE [si], 0x4D
jne .here
add ax, WORD [si+3]
jmp .next
.here:
; mark as item
mov BYTE [si], 0x4D
; write segment length in paragraphs
mov WORD [si+3], bx
; if allocation is higher than CS, then we are in managed memory
; set ourself as owner then, otherwise use dummy value 8
mov bx, cs
cmp ax, bx ; CF = CS in unmanaged memory
jnc .setup_owner
mov bx, 8
.setup_owner:
mov WORD [si+1], bx
pop si
pop bx
pop ds
ret