Write sector failure - where is my error?

Programming, for all ages and all languages.
Post Reply
MuayThai
Posts: 2
Joined: Wed Aug 06, 2014 1:49 pm

Write sector failure - where is my error?

Post by MuayThai »

When I try to write a sector this code dont works:

Code: Select all

mov dx,BAR
add dx,6
mov ax,E0h
out dx,ax
sub dx,4
mov ax,1
out dx,ax
inc dx
mov ax,0
out dx,ax
inc dx
mov ax,0
out dx,ax
inc dx
xor ax,ax
out dx,ax
mov ax,30h
mov dx,BAR
add dx,7
out dx,ax
sub dx,7
mov cx,256
Start:
cmp cx,0
jz End
mov ax,0
out dx,ax
dec cx
jmp Start
End:
retn
This code above doNOT write any data in boot sector. Where is my error???
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: write sector failure

Post by SpyderTL »

What is BAR set to? Try replacing it with the actual port number to make sure the rest of the code is working properly.

Have you tried debugging this code with something like Bochs?

You are also supposed to check the status register and wait for the controller to tell you that the data is ready.

You need to step through this code, and you need to check your status registers to make sure the controller is ready to receive data.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
MuayThai
Posts: 2
Joined: Wed Aug 06, 2014 1:49 pm

Re: write sector failure

Post by MuayThai »

SpyderTL wrote:What is BAR set to? Try replacing it with the actual port number to make sure the rest of the code is working properly.

Have you tried debugging this code with something like Bochs?

You are also supposed to check the status register and wait for the controller to tell you that the data is ready.

You need to step through this code, and you need to check your status registers to make sure the controller is ready to receive data.
The BAR is the Base Address Reguister from PCI.
I've debugged my code but cannot find any error.
When I check the status register and the BSY clear and DRQ is set then I can and receive data.
The weird thing is that the same code above works only to read sectors(20h) or identify(ECh) Why my code only read sectors but don't write sectors?
Post Reply