OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 9:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Floppy driver receives no results
PostPosted: Mon Oct 22, 2018 1:29 pm 
Offline

Joined: Mon Oct 22, 2018 12:42 pm
Posts: 2
Hello all,

I am new to this forum but I have been reading the contents here with great pleasure for long time.

Now I decided to join the forum to possibly share my knownledge and make others profit as I have also profited from this forum often times in the past.

However I would also like to receive some help in solving a problem I have not been able to solve for a long time.

This problem is about a floppy driver for my hobby operating system which I try to get to work.

I am booting my OS from a floppy image which already works fine. However reading sectors from a protected mode floppy driver always results in bochs printing the message "port 0x3f5: no results to read".

The error message can be found in the bochs source code here: http://bochs.sourceforge.net/cgi-bin/lxr/source/iodev/floppy.cc#L475

However I cannot really deduce the error from the code snippet - Because it checks that the pending command bitand 0x4f equals to 0x46 (which allows the cmd to be 0xe6, which is the synthesis of bitflags used to read a sector in my case).
Thats fine so far for my understanding. But why does it check that the NDMA bit is set. Shouldn't it be unset when using DMA mode?

I can also observe that the PTE which identity maps the DMA buffer is probably accessed as the dirty flag is set after the read operation of the FDC.

However the data of the sector is not written to the DMA buffer.

My floppy image is actually just binary files which are appended and organized by a very primitive file table. There is no special floppy disk format applied.

I have already searched alot but I did not find anything which solves my problem and the floppy driver itself should be fine. I have compared the implementation to others and I really cannot find any error.

Can somebody give me a hint where to look for the corresponding error? Maybe there is a common reason for this behaviour?

Let me just give give You some basic info about the system which might be useful:

- Custom bootloader (no grub or anything comparable)
- GDT with flat setup, code and data descriptors for both ring0 and ring3
- IDT setup and working
- Paging is enabled and identity maps 128MB starting from physical address 0
- Currently no scheduler is implemented
- DMA buffer for the floppy driver is 0x1000 or 0x2000 (I tried both, the addresses do not conflict with other components of the OS.. e.g. no code or data is overwritten)
- Toolchain is nasm, gcc and ld
- Filesystem and floppy image are created using my own tooling (basically appends files and stores starting sectors and file sizes in a table)
- Floppy image is exactly 1.44 MB of size and bochs is configured to a 1.44 MB 3.5" floppy drive
- Bochs version is 2.6.7
- Please let me know if more information is needed ...

Thanks in advance.

Very best regards,
pointer


Top
 Profile  
 
 Post subject: Re: Floppy driver receives no results
PostPosted: Sat Oct 27, 2018 10:00 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
My initial guess is that Bochs wants to be able to switch between DMA and PIO mode, and thus has some cleanup code stored somewhere to make sure some OSes work. Even if its an oddity, stock OSes work just fine with it.

But the real problem is that you're trying to read port 0x3f5 at a time that the floppy drive has either not started doing work or hasn't finished whatever it was supposed to do. Are you actually monitoring interrupts and did you get any? Are you monitoring status registers to see how their values change? Logging progress regarding both of these should help you get more information on where the process got stuck or not.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Floppy driver receives no results
PostPosted: Sat Oct 27, 2018 4:38 pm 
Offline

Joined: Mon Oct 22, 2018 12:42 pm
Posts: 2
Thank You for the suggestions.

I tried to summarize the flow of execution and the corresponding changes in the st0 register below:

Code:
disable fdc
enable fdc
irq6_handler
send sense interrupt command
st0 = 0xC0
send sense interrupt command
st0 = 0xC1
send sense interrupt command
st0 = 0xC2
send sense interrupt command
st0 = 0xC3

send specify command

start motor
send calibrate command
irq6_handler
send sense interrupt command
st0 = 0x20
stop motor

start motor
send seek command
irq6_handler
st0 = 0x20
send read sector command
irq6_handler
st0 = 0x00
send sense interrupt command
st0 = 0x80
stop_motor

I think the 0x80 value of st0 denotes an error. According to [0] an invalid command was dedected.

The command looks like this:

Code:
write_cmd(0xe6);  // read sector | multitrack mode | skip deleted | double density mode
write_cmd((head << 2) | DRIVE_NUMBER));
write_cmd(track);
write_cmd(head);
write_cmd(sector);
write_cmd(0x02);  // sector size 512 byte
if ((sector+1) >= SECTORS_PER_TRACK) {
   end_of_track = SECTORS_PER_TRACK;
} else {
   end_of_track = sector + 1;
}
write_cmd(end_of_track);
write_cmd(0x1b);  // gap length 3.5"
write_cmd(0xff);

Is the command really invalid? Is it only about the command number or also the parameters? How should I continue from here to further investigate the error?

Thanks in advance.

Very best regards,
pointer

[0]: https://www.lowlevel.eu/wiki/Floppy_Disk_Controller#ST0


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 148 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group