Mistake in DMA wiki?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jadam
Posts: 4
Joined: Mon Dec 27, 2010 3:41 am

Mistake in DMA wiki?

Post by jadam »

Greetings,

I was browsing the wiki of DMA (trying to figure out how to write a floppy driver) and this part of the example code I could not figure out:

Code: Select all

out 0x0a, 0x05      ; mask DMA channel 2 and 0
Should not it be

Code: Select all

out 0x0f, 0x05      ; mask DMA channel 2 and 0
?

Since 0x0a is Single Channel Mask Register, while the comment says we mask dma channels 2 and 0, so as far as I see it should use the multi-channel mask register which is 0x0f. Or it could also be done by issuing:

Code: Select all

out 0x0a, 0x04
out 0x0a, 0x06
Am I missing something? (Before posting here I was trying to see if I really miss something but so far I did not get it how could it be right that way.)

Thank you.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Mistake in DMA wiki?

Post by Brendan »

Hi,

"out 0x0A, 0x05" uses the single-channel mask register to change the mask for channel 2 without changing the mask for any other channel. It is like "out 0x0A, (MASK_FLAG << 2) | (channel - 1)".

"out 0x0F, 0x05" uses the multi-channel mask register to change the mask for all 4 channels at the same time. It is like "out 0x0F, (MASK3 << 3) | (MASK2 << 2) | (MASK1 << 1) | MASK0". To use this you need to keep track of what the masks for all other channels should be at any given time, which is a pain in the neck if you only want to set or clear the mask for one channel.

The wiki article clearly describes this, and describes it correctly.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Mistake in DMA wiki?

Post by bewing »

We can assume that since channel 0 is hardwired and unusable that it is always basically masked. Or we can assume that channel 0 was previously masked with another "out" in the code snippet that we cannot see.

So before the out 0x0a, only channel 0 is masked. The "out" opcode is supposed to additionally mask channel 2 -- however, I think you are correct that the AL value should be 6, and not 5. In any case, that ASM code is not really possible with two immediate values in it like that.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Mistake in DMA wiki?

Post by Brendan »

Hi,

Doh - ignore my last post (too many mistakes, including the "out 0x0A, (MASK_FLAG << 2) | (channel - 1)" which should've been "out 0x0A, (MASK_FLAG << 2) | channel").

I think I understand now. The article has correct descriptions of registers, etc, but has a misleading comment in some example code; and the problem is that someone thinks example code is useful for more than just an example.

I guess there's only 2 ways to fix this problem - remove all example code from the wiki so people don't keep making the mistake of thinking example code is real code suitable for a real OS; or replace the wiki with a code repository so people can copy & paste guaranteed correct code that's suitable for every situation imaginable (and so people don't need to bother with reading or understanding how anything actually works). ;)

For a real OS, there probably shouldn't be any reason to mask and unmask any DMA channel every time you setup a DMA transfer to/from floppy. It's only if you want to cancel a DMA transfer that is currently in progress (including cancelling DMA transfers that were aborted by the floppy controller due to things like read errors).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
jadam
Posts: 4
Joined: Mon Dec 27, 2010 3:41 am

Re: Mistake in DMA wiki?

Post by jadam »

I do not want to copy and paste code from the wiki, rather the code was not matching the comment next to it. That's all. Just because I have 2 posts I am not necessarily copy/pasting code from Wiki, I felt your from your tone you mean something like this, I might be wrong though...
I find these resources very useful and wanted to point out this mistake, that's all.
jadam
Posts: 4
Joined: Mon Dec 27, 2010 3:41 am

Re: Mistake in DMA wiki?

Post by jadam »

bewing wrote:We can assume that since channel 0 is hardwired and unusable that it is always basically masked. Or we can assume that channel 0 was previously masked with another "out" in the code snippet that we cannot see.

So before the out 0x0a, only channel 0 is masked. The "out" opcode is supposed to additionally mask channel 2 -- however, I think you are correct that the AL value should be 6, and not 5. In any case, that ASM code is not really possible with two immediate values in it like that.
Thank you, this is what I meant, this is confusing in that article.
For channel 0 is masked by default, this is an important point I did not take into consideration (simply skipped my attention), even though it was clearly described there.
Post Reply