Buffer doesn't return the right value to [ebp+16]
Posted: Tue Feb 23, 2016 6:23 am
I'm writing in the third sector an integer value 104. I debugged my kernel and when I'm writing esi the last parameter of my writedisk function, has the right value, however when I'm reading my parameter isn't receiving the right values, eax is receiving "random" values, printing random characters each time I compile my OS. I saved [ebp+16] in the memory with the register eax and passed the values inside my buffer to eax.
Why is it returning me "random" values?
Why is it returning me "random" values?
Code: Select all
_readsector:
mov ebx, ecx
mov eax, [ebp+12] ;second parameter
cmp eax, 0
je _readsector_fail
push eax ;sector number
mov dx, 0x1f2
mov al, cl
out dx, al
inc dx ;dx = 0x1f3
pop eax
out dx, al
inc dx ;dx = 0x1f4
shr eax, 8
out dx, al
inc dx ;dx = 0x1f5
shr eax, 8
out dx, al
inc dx ;dx = 0x1f6
shr eax, 8
and al, 00001111b
or al, 01000000b
out dx, al
inc dx ;dx = 0x1f7
mov al, 0x20
out dx, al
mov ecx, 4
_readsector_wait:
in al, dx
test al, 0x80 ; BSY
jne _readsector_retry
test al, 0x08 ; DRQ
jne _readsector_ready
_readsector_retry:
dec ecx
jg _readsector_wait
_readsector_nextsector:
in al, dx
test al, 0x80
jne _readsector_nextsector
test al, 0x21
jne _readsector_fail
_readsector_ready:
sub dx, 7 ;0x1f0
mov ecx, 256
mov edi, buffer
rep insw
(...)
push eax
mov eax, [ebp+16]
_readdisk_eax:
mov [eax], long word buffer
pop eax
(...)
buffer: times 512 db ('V')