My O/S is now in protected mode so i can not access to disk using interrupts now.And I do not know how to switch to v86 mode.I need to use ports to disk access.
I decided to try the code which i found on the forum.osdev.org.In the emulator,It shows Disk Read or Write successfuly Done.But when i check the HDD it is empty or when i test reading,Buffer is all empty.
What is the problem with this code or my O/S? (Maybe Stack Problem Causes That?) CODE:
set_up_buffer:
xor ax,ax
mov es,ax
mov di,[buffer]
mov al,0xCD
stosb
mov al,0x19
stosb
WriteToMbr:
mov dx,1f6h ;Drive and head port
mov al,0a0h ;Drive 0, head 0
out dx,al
mov dx,1f2h ;Sector count port
mov al,1 ;Write one sector
out dx,al
mov dx,1f3h ;Sector number port
mov al,1 ;Wrote to sector one
out dx,al
mov dx,1f4h ;Cylinder low port
mov al,0 ;Cylinder 0
out dx,al
mov dx,1f5h ;Cylinder high port
mov al,0 ;The rest of the cylinder 0
out dx,al
mov dx,1f7h ;Command port
mov al,30h ;Write with retry.
out dx,al
oogle:
in al,dx
test al,8 ;Wait for sector buffer ready.
jz oogle
mov cx,512/2 ;One sector /2
mov si,[buffer]
mov dx,1f0h ;Data port - data comes in and out of here.
rep outsw ;Send it.
leave
ret
buffer:
times 512 db 0