Add malloc table dump

This commit is contained in:
Nero 2019-08-30 22:18:05 +00:00
parent aec0218ccf
commit 4e188235f9
3 changed files with 65 additions and 17 deletions

View File

@ -5,16 +5,20 @@ optrom_length:
db 0x00 db 0x00
jmp optrom_init jmp optrom_init
; reserved area
times (0x1A - ($-$$)) db 0 times (0x1A - ($-$$)) db 0
dw pnp dw pnp
align 16 align 16
pnp: pnp:
db "$PnP" db "$PnP"
.version:
db 1 ; version 1 db 1 ; version 1
.length:
db 2 ; 2 * 16 length db 2 ; 2 * 16 length
dw 0 ; offset of next header dw 0 ; offset of next header
db 0 db 0
.checksum:
db 0 ; checksum (filled by fix-rom) db 0 ; checksum (filled by fix-rom)
dd 0 ; device identifier dd 0 ; device identifier
dw str_vendor ; manufacturer string dw str_vendor ; manufacturer string
@ -32,7 +36,6 @@ str_vendor:
str_product: str_product:
db "Nero DOS ", 60, 234, 62, 0 db "Nero DOS ", 60, 234, 62, 0
align 16
optrom_init: optrom_init:
; setup data stack below code stack ; setup data stack below code stack
mov bp, sp mov bp, sp
@ -74,26 +77,21 @@ start:
mov ss, ax mov ss, ax
mov sp, ax mov sp, ax
mov bp, sp mov bp, sp
; data stack starts 512 bytes below code stack
sub bp, 0x200
call announce call announce
call malloc_reset
sub bp, 4 call malloc_dump
mov word [ss:bp], 3
mov word [ss:bp+2], isr_debug
call intr_register
sti
int 3
cli
.halt: .halt:
hlt hlt
jmp .halt jmp .halt
%include "ramdisk.inc"
%include "printf.inc" %include "printf.inc"
%include "print.asm"
%include "popcnt.asm"
%include "intr.asm" %include "intr.asm"
%include "debug.asm" %include "debug.asm"

View File

@ -1,11 +1,11 @@
; All these functions assume DS=0 ; All these functions assume DS=0
malloc_reserve_16: malloc_reserve:
push bx push bx
call malloc_mark_allocated call malloc_mark_allocated
pop bx pop bx
add bx, 0x10 add bx, 0x10
loop malloc_reserve_16 loop malloc_reserve
ret ret
malloc_reset: malloc_reset:
@ -18,17 +18,17 @@ malloc_reset:
; reserve IVT and BDA ; reserve IVT and BDA
xor bx, bx xor bx, bx
mov cx, 0x50 mov cx, 0x50
call malloc_reserve_16 call malloc_reserve
; reserve malloc table itself ; reserve malloc table itself
mov bx, 0x0600 mov bx, 0x0600
mov cx, 0x20 mov cx, 0x20
call malloc_reserve_16 call malloc_reserve
; reserve location for chainloaded boot sector ; reserve location for chainloaded boot sector
mov bx, 0x7C00 mov bx, 0x7C00
mov cx, 0x20 mov cx, 0x20
call malloc_reserve_16 call malloc_reserve
ret ret
; Input: ; Input:
@ -77,3 +77,23 @@ malloc_mark_free:
not al not al
and byte [bx+di], al and byte [bx+di], al
ret ret
malloc_dump:
call malloc_get_table
mov si, di
mov cx, 0x200
xor dx, dx
.loop:
lodsb
call print8
xor ah, ah
call popcnt
add dx, ax
loop .loop
mov cl, 6
shr dx, cl
push dx
call printf
db " data %UkB", 0x0A, 0x0D, 0x00
pop dx
ret

30
lib/popcnt.asm Normal file
View File

@ -0,0 +1,30 @@
popcnt:
push bx
push cx
mov bx, ax
and ax, 0x5555 ; 8x 01
and bx, 0xaaaa ; 8x 10
sar bx, 1
add ax, bx
mov bx, ax
and ax, 0x3333 ; 4x 0011
and bx, 0xcccc ; 4x 1100
mov cl, 2
sar bx, cl
add ax, bx
mov bx, ax
and ax, 0x0f0f ; 2x 00001111
and bx, 0xf0f0 ; 2x 11110000
mov cl, 4
sar bx, cl
add ax, bx
add al, ah
xor ah, ah
pop cx
pop bx
ret