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 ; memory type is enum
; in: al ; 00 - free
; out: al ; 01 - unknown
; destroys ah ; 02 - allocated by us
mm_type: ; 03 - reserved, like BIOS code or tables for the cpu
push bp ; 04 - unusable
push si
mov bp,.typechar ; search memory table for a item matching a segment addr
and ax,0x00FF ; in: ax: segment
mov si,ax ; out: bp: table start address
mov al,[bp+si] ; si: table item offset
pop si ; ax: offset from begin of memory block
pop bp 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 ret
.typechar:
db "F?ARU", 0
mm_print: mm_print:
push cs push cs
@ -34,7 +92,14 @@ mm_print:
push ax ; task id push ax ; task id
mov al,[bp+si+0x04] 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 push ax ; memory type
mov bx,cx mov bx,cx
@ -62,6 +127,8 @@ mm_print:
ret ret
.linefmt: .linefmt:
db "%X0 %XF %c %x %s", 0 db "%X0 %XF %c %x %s", 0
.typechar:
db "F?ARU", 0
; pre-filled table for memory management ; pre-filled table for memory management
align 16 align 16
@ -78,28 +145,30 @@ align 16
dw 0x0020 dw 0x0020
db 3 db 3
db 0 db 0
db "BIOS DATA", 0 db "BDA", 0
align 16 align 16
dw 0x9FB0 dw 0x9FB0
dw 0x0030 dw 0x0030
db 1 db 0
db 0 db 0
db 0 db 0
align 16 align 16
dw 0x2000 dw 0x5000
dw 0x0040 dw 0x0040
db 4 db 4
db 0 db 0
db "I/O BUS", 0
align 16
dw 0x3000
dw 0x0050
db 4
db 0 db 0
db "BIOS EXT", 0
align 16 align 16
dw 0x1000 dw 0x1000
dw 0x0000 dw 0x0000
db 4 db 4
db 0 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