flat assembler
Message board for the users of flat assembler.

Index > OS Construction > FDC programming with DMA

Author
Thread Post new topic Reply to topic
ManOfSteel



Joined: 02 Feb 2005
Posts: 1155
ManOfSteel
Hello,

I've been programming my FDC driver for weeks and it seems it doesn't work as it's supposed to.

On Bochs, it will print a part of a sector to the screen (as it is supposed to), but will not work more than once and in the output file, it will show me the following lines:
Quote:

...
00000218500i[FDD ] partial read() on floppy image returns 385/512
00000219012i[FDD ] read() on floppy image returns 0
00004763829e[DMA ] DMA: write to 0x08: value(14h) not 04h
00004763858e[DMA ] DMA: write to 0x08: value(10h) not 04h
...


Most of the time I get more than a hundred
Quote:
00003864104i[FDD ] read() on floppy image returns 0


On a real computer, it's called more than once but doesn't print the bytes in the sector, it seems that when it prints characters it replaces some existing letters on the screen so I presume it is printing zeros which means there's no sector data where it is supposed to be. Sometimes, when I change the memory location at which the DMA puts data and the IRQ reads it, I get different results, mostly garbage instead of the sector contents.

I would like to know what every line in Bochs output file means.
Also, I don't understand why Bochs tells me to use 0x4 (disable controller) instead of 0x14 and 0x10.

These are the steps I follow:
00011100b to 0x3f2: select drive 0, enable FDC with DMA, turn motor on
Check for busy bit on MSR
Check MSR for MRQ set and DIO cleared
00001111b to 0x3f5: seek
Check MSR for MRQ set and DIO cleared
0 to 0x3f5 (drive/head 0)
Check MSR for MRQ set and DIO cleared
0 to 0x3f5 (cylinder 0)
Check MSR for busy bit? off
00000110b to 0x0a: mask DMA channel 2
00010100b to 0x08: rotating priority, controller disabled
01010110b to 0x0b: write to memory using channel 2, autoinitialization enabled, single mode
0 to 0x0c: reset flip-flop
Address bits 0-7 to 0x04
Address bits 8-15 to 0x04
Address bits 16-19 (page) to 0x04
0 to 0x0c: reset flip-flop
Count bits 0-7 to 0x05
Count bits 8-15 to 0x05
00000010b to 0x0a: unmask DMA channel 2
00010000b to 0x08: enable DMA, rotating priority, memory to memory disabled
Check MSR for MRQ set and DIO cleared
01100110b to 0x3f5
Check MSR for MRQ set and DIO cleared
0 to 0x3f5 (drive/head 0)
Check MSR for MRQ set and DIO cleared
0 to 0x3f5 (cylinder 0)
Check MSR for MRQ set and DIO cleared
0 to 0x3f5 (head 0)
Check MSR for MRQ set and DIO cleared
4 to 0x3f5 (sector 4)
Check MSR for MRQ set and DIO cleared
2 to 0x3f5 (sector size = 512 bytes)
Check MSR for MRQ set and DIO cleared
18 to 0x3f5 (maximum sector per track)
Check MSR for MRQ set and DIO cleared
27 to 0x3f5 (GAP for 3.5' floppies)
Check MSR for MRQ set and DIO cleared
0xff to 0x3f5 (whole sector)
0 to 0x3f2: unselect drives, disable floppy drive controlers, reset drives

The floppy IRQ is what reads a few bytes from the memory where the DMA puts the sectors and prints them to the screen. The master PIC is acknowledged after that.

What am I missing here? Did I forget a step or did a step before another?

Thank you for any help.
Post 02 Feb 2005, 06:46
View user's profile Send private message Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu
You have example of a functional FDC driver in SolarOS.

I has become a little more advanced/cmplicated lately (state machine by IRQ) to speed up things but I can explain FDC operation to you bit by bit -- and in this regard to anybody eles that need to understand it Wink

Bassically you have to read the documentation and assume nothing, since people have a strange tendency to assume that things work much simpler or easyer than they really are in hardware devices.

First you should do a Recalibrate command since you do not know where the Floppy drive read head is located at OS startup do you?
And then after the SEEK command you should LAways do a SENSEI comand on the IRQ-6 that signals the end of SEEK/RECALIBRATE.

If you read and interpret the status register corectly then you should have dedeucted that also. The floppy expects some oredr in the commands you are sending and receiving from it and failing to folow that strict order result in no fucntion or stall of the controller.

I did played with it a lot without the DMA just to have a single unknown variable in the equation. I have enabled DMA only after i have understood it method of operation .

Today CPUs are fast enough to read the data from the floppy controler without any DMA whatsoever but since that DMA is linked to floppy anyway i finnaly used it.

Also using Bochs or other emulators to test real hardware device is not the best solution because emulatore act most of the time slightly diffrent that real devices and you can have surprises later on either ways: either it runs on the emulator but it doesent run on real hardware or it runs on real hardware and is not running in emulators.

For example lately Eugen has some problems with QEMU generating an IRQ from its network board in the middle of CLI ... STI instructions Razz imagine THAT Very Happy ...
Post 02 Feb 2005, 13:04
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
bogdanontanu, I agree with you about it work on a real hardware or it works on a emulator, but not on both, my floppy driver work on real PC's, but not on most emulators Crying or Very sad, same with my atapi driver.

But do you know how to test for floppy change, with out reading floppy, as windows can.
I can not find any command, for doing this .

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 02 Feb 2005, 19:19
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio
bogdanontanu: you have a floppy driver ,but your os is loaded using bios
and you must provide some application to test this driver.
Also the only computer where my floppy driver doesn't work is too old
for your os.

ManOfSteel: autoinitialize dma mode is not for floppies ,it can work on read operation but you will get dma errors on write operations.

ASHLEY4: to detect disk change just after set motor on read port 3f7h
if bit 7 is set the disk is changed.
i don´t know how windows does, but in linux you have to manually mount and umount the floppy, on my os i will do the same than in linux, since the cache design is very similar.


i have seen in some sources that after a seek operation the driver must wait 15 ms before read/write operations.
and why nobody uses implicit seeks ? this is simpler and more efficient.


Last edited by Octavio on 02 Feb 2005, 19:56; edited 1 time in total
Post 02 Feb 2005, 19:43
View user's profile Send private message Visit poster's website Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1155
ManOfSteel
Hello,
Quote:

First you should do a Recalibrate command since you do not know where the Floppy drive read head is located at OS startup do you?
And then after the SEEK command you should LAways do a SENSEI comand on the IRQ-6 that signals the end of SEEK/RECALIBRATE.

Recalibrating consists of adjusting the drive and seeking is about adjusting the head, right? I'm currently sending these commands with zeros as parameters since I'm only using drive A for now.
I don't really understand the 'sensei' thing. What steps should I follow to do it?

Quote:
If you read and interpret the status register corectly then you should have dedeucted that also. The floppy expects some oredr in the commands you are sending and receiving from it and failing to folow that strict order result in no fucntion or stall of the controller.

I already read the MSR (0x3f4) before sending commands as you've probably seen in my original post. Should I read other ports? Which ones? And when?
Also, I've heard about some ports ST1/2/3/4. They are status ports, right? What are their addresses? Should they be read and interpreted? If yes, when?

Quote:
I did played with it a lot without the DMA just to have a single unknown variable in the equation. I have enabled DMA only after i have understood it method of operation.

Very interesting. I would like to know how to do it, because I already tried it and so far I was unable to achieve anything even under Bochs Sad . That's why I actually switched to the DMA technique thinking it will work better but I finally realized I was mistaken. To read a sector, for example, I used to send the read command to the command port then the parameters (head, sector, track, gap, ...) but then I don't know what to do next. I tried to read from the command port but it didn't give me any result. How do you do it?

Quote:
For example lately Eugen has some problems with QEMU generating an IRQ from its network board in the middle of CLI ... STI instructions imagine THAT ...

Wow! I've already noticed that emulators are not always so accurate, but that is too much!

Thanks for your replies.
Post 02 Feb 2005, 19:50
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1155
ManOfSteel
Hello again,

Octavio,
Quote:
autoinitialize dma mode is not for floppies ,it can work on read operation but you will get dma errors on write operations.

So, I will disable autoinitialization (bit 4 on mode register cleared). Where do I have to enable it? For sound transfers?

Quote:

i have seen in some sources that after a seek operation the driver must wait 15 ms before read/write operations.
and why nobody uses implicit seeks ? this is simpler and more efficient.

"Implicit seeks"? What do you mean by that? And how are they any different from "standard seeks"?
Post 02 Feb 2005, 20:22
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
ManOfSteel wrote:

"Implicit seeks"? What do you mean by that? And how are they any different from "standard seeks"?
"Implicit seeks" is the same as seeks, but done automatically, if set, "seeks" needs calling.
The reason people do not use Implicit seeks much, is it is not available on all controllers.

PS: Thanks Octavio, i will give it a try.

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 02 Feb 2005, 20:59
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio
Yes, sound cards suports autoinitialize mode.
the implicit seek is enabled with the configure command with this byte secuence:
db 13h,0,6fh,0 ;this also enables fifo
then you don´t need to issue a seek +sensei commands before read or write operations.

here you will finds more info:
http://www.osdever.net/cottontail/
Ashley: do you mean that there are still computers with type 1 controller?
do you know how to detect them?
also i have read that this controllers don´t support relative seek, but relative seek is needed for formating,so it must be some errors on my docs or what ?
Post 02 Feb 2005, 22:04
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
@Octavio, when i wrtten my floppy driver, i used implicit seek, i have lots of test PC's, half them it work on, on others it give a error to do with not moving the head to the right track, so i used seeks and it works on all test PC's.

PS: I have implemented only reading from the floppy, not write, but the read/write command are basically the same, most people use bacically the same function.

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 03 Feb 2005, 03:12
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio
ASHLEY4 wrote:
@Octavio, when i wrtten my floppy driver, i used implicit seek, i have lots of test PC's, half them it work on, on others it give a error to do with not moving the head to the right track, so i used seeks and it works on all test PC's.

PS: I have implemented only reading from the floppy, not write, but the read/write command are basically the same, most people use bacically the same function.

Yes, this was the problem one of my computers has type 1 controller, so i rewrote the driver using explicits seeks and now my OS works on all my computers and also in microsoft virtual pc2004 ,but not in bochs.
about the 15 ms off delay time affter the seek it seems to be unneded
or done automatically with the head load time parameter.
seek and relative seek(type 2 only) both can be used to format floppies.
and write operations works in the same way than reads, but the filesystem
implementation is a lot complex.
Post 07 Feb 2005, 17:12
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
Octavio wrote:

Write operations works in the same way than reads, but the filesystem
implementation is a lot complex.

Thats the part i am not looking forward to the "filesystem implementation" of write Crying or Very sad .

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Feb 2005, 17:25
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.