This commit is contained in:
Nero 2019-03-10 22:38:32 +00:00
parent 86b5b2a7aa
commit 816b44a417

121
mem.asm
View File

@ -1,19 +1,77 @@
; converts a memory block type code into char representation
; in: al
; out: al
; destroys ah
mm_type:
push bp
push si
mov bp,.typechar
and ax,0x00FF
mov si,ax
mov al,[bp+si]
pop si
pop bp
; memory type is enum
; 00 - free
; 01 - unknown
; 02 - allocated by us
; 03 - reserved, like BIOS code or tables for the cpu
; 04 - unusable
; search memory table for a item matching a segment addr
; in: ax: segment
; out: bp: table start address
; si: table item offset
; ax: offset from begin of memory block
mm_findtab:
push bx
push cx
push cs
pop ds
mov cx,0x0000
mov bp,memtab
mov si,0x0000
.loop:
add cx,[bp+si+0x00]
cmp cx,ax
jnbe .end
mov bx,[bp+si+0x02]
mov si,bx
jmp .loop
.end:
sub cx,[bp+si+0x00]
sub ax,cx
pop cx
pop bx
ret
; finds a place for a new item in the mm table
; out: si
mm_taballoc:
push ax
mov bp,memtab
mov si,0x0000
.loop:
cmp WORD [bp+si],0x0000
je .end
mov ax,si
add ax,0x0010
mov si,ax
jmp .loop
.end:
pop ax
ret
; force-sets the type of a memory block (dangerous)
; in: ax: segment
; bl: memory type
; cx: length in 16 byte blocks
mm_setup_range:
push dx
call mm_findtab ; i'll refer the item returned in si as 'base'
mov dx,[bp+si] ; get size from base
push si
; duplicate the base
call mm_taballoc
mov di,si
pop si
push ds
pop es
push cx
mov cx,0x0010
rep movsb ; copies 0x10 bytes from ES:SI to DS:DI
pop cx
pop dx
ret
.typechar:
db "F?ARU", 0
mm_print:
push cs
@ -34,7 +92,14 @@ mm_print:
push ax ; task id
mov al,[bp+si+0x04]
call mm_type
push bp
push si
mov bp,.typechar
and ax,0x00FF
mov si,ax
mov al,[bp+si]
pop si
pop bp
push ax ; memory type
mov bx,cx
@ -62,6 +127,8 @@ mm_print:
ret
.linefmt:
db "%X0 %XF %c %x %s", 0
.typechar:
db "F?ARU", 0
; pre-filled table for memory management
align 16
@ -78,28 +145,30 @@ align 16
dw 0x0020
db 3
db 0
db "BIOS DATA", 0
db "BDA", 0
align 16
dw 0x9FB0
dw 0x0030
db 1
db 0
db 0
db 0
align 16
dw 0x2000
dw 0x5000
dw 0x0040
db 4
db 0
db "I/O BUS", 0
align 16
dw 0x3000
dw 0x0050
db 4
db 0
db "BIOS EXT", 0
align 16
dw 0x1000
dw 0x0000
db 4
db 0
db "BIOS", 0
db "BIOS ROM", 0
align 16
dw 0x0000
align 16
dw 0x0000
align 16
dw 0x0000
align 16
dw 0x0000