Strange problem with memory functions...
Posted: Sun Nov 28, 2010 11:09 pm
Ok I FINALLY managed to get a couple semi-working functions for memory management:
This works fine in an emulator such as qemu but locks up the computer when run on actual hardware.
Hm... Minded me this was just a first attempt so I may have messed up something really obvious.
I wasn't sure how many bits were in each RAM address so I assumed that it was 1 bit per address.
I have a feeling it has something to do with 16-bit and 32-bit register problems. I was told I could mix them and I didn't really have much of a choice in this case but to use a few 32-bit registers.
It works until I check for these ranges:
0x00007E00 to 0x0007FFFF
0x00080000 to 0x0009FBFF
It hangs during the checking of those ranges of addresses for data.
hm.... I am puzzled.
Is this a problem with those addresses or my code?
Code: Select all
getmem:
mov ax, 0
mov si, 0
xor ax, ax ; Nullify the A-register.
int 0x12 ; Switch to the BIOS (request memory size).
jc .Error ; The carry flag is set, it failed.
test ax, ax ; Test the A-register with itself.
jz .Error ; The zero flag is set, it failed.
mov si, ax
.Error:
ret
proberam:
wbinvd
mov si, 0
mov ax, 0
mov ecx, 0
mov ebx, 0
mov ebx, 0x00000500 ;Beginning value of RAM to test
jmp .checkram
.checkram:
wbinvd
cmp [ebx], ax
je .empty ;Jump if bx is null
add ecx, 1 ;Add 1 bits to total
jmp .empty
.empty:
cmp ebx, 0x00007BFF ;Ending value of RAM to test
je .check2 ;Jump out if bx is equal
cmp ebx, 0x0007FFFF ;Ending value of RAM to test
je .check3 ;Jump out if bx is equal
cmp ebx, 0x0009FBFF ;Ending value of RAM to test
je .endme ;Jump out if bx is equal
add ebx, 0x00000001
jmp .checkram
.check2:
mov ebx, 0x00007E00
jmp .checkram
.check3:
mov ebx, 0x00080000
jmp .checkram
.endme:
;Convert bits to KB \ DIVIDE cx by 8192
mov si, 8192
mov ax,cx
mov dx,0
idiv si
mov cx,ax
mov si, cx ;put value in si
ret
ramleft:
call getmem ;Returns total RAM in si
mov di, si ;Value of the total RAM
call proberam ;Returns used RAM in si
;SUBTRACT \ return si \ si=cx-si
mov ax,di
sub ax,si
mov si,ax
ret
Hm... Minded me this was just a first attempt so I may have messed up something really obvious.
I wasn't sure how many bits were in each RAM address so I assumed that it was 1 bit per address.
I have a feeling it has something to do with 16-bit and 32-bit register problems. I was told I could mix them and I didn't really have much of a choice in this case but to use a few 32-bit registers.
It works until I check for these ranges:
0x00007E00 to 0x0007FFFF
0x00080000 to 0x0009FBFF
It hangs during the checking of those ranges of addresses for data.
hm.... I am puzzled.
Is this a problem with those addresses or my code?