IDE Tutorial Again

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
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

IDE Tutorial Again

Post by ateno3 »

I want to make you a question, I hope you could understand me because my English is poor ( I am spanish ). At the beginning of the function "ide_initialize" you have written this:

Code: Select all

   channels[ATA_PRIMARY  ].base  = (BAR0 & 0xFFFFFFFC) + 0x1F0 * (!BAR0);
   channels[ATA_PRIMARY  ].ctrl  = (BAR1 & 0xFFFFFFFC) + 0x3F4 * (!BAR1);
   channels[ATA_SECONDARY].base  = (BAR2 & 0xFFFFFFFC) + 0x170 * (!BAR2);
   channels[ATA_SECONDARY].ctrl  = (BAR3 & 0xFFFFFFFC) + 0x374 * (!BAR3);
And you said that base should be 0x1F0, but I don't know why you do these operations ( channels[ATA_PRIMARY ].base = (BAR0 & 0xFFFFFFFC) + 0x1F0 * (!BAR0); ) Wouldn't it be better if put:

Code: Select all

channels[ATA_PRIMARY  ].base  = BAR0;
??
I think it, because I have done the operation you have written and the base is not what has BAR0.

Could you explain me the reason of this operations?

Thanks a lot :)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: IDE Tutorial

Post by Combuster »

Learn to read, thanks.
BAR0: Base address of primary channel (I/O space), if it is 0x0 or 0x1, the port is 0x1F0.
BAR1: Base address of primary channel control port (I/O space), if it is 0x0 or 0x1, the port is 0x3F4.
BAR2: Base address of secondary channel (I/O space), if it is 0x0 or 0x1, the port is 0x170.
BAR3: Base address of secondary channel control port, if it is 0x0 or 0x1, the port is 0x374.
"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 ]
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Re: IDE Tutorial

Post by ateno3 »

Combuster wrote:Learn to read, thanks.
BAR0: Base address of primary channel (I/O space), if it is 0x0 or 0x1, the port is 0x1F0.
BAR1: Base address of primary channel control port (I/O space), if it is 0x0 or 0x1, the port is 0x3F4.
BAR2: Base address of secondary channel (I/O space), if it is 0x0 or 0x1, the port is 0x170.
BAR3: Base address of secondary channel control port, if it is 0x0 or 0x1, the port is 0x374.
Thanks for your answer.
But, you have not answered my question. If we suppose that the parameter BAR0, which I send to the function, is 0x1F0:

( BAR0 & 0xFFFFFFFC ) + 0x1F0 * ( !BAR0 );
( 0x1F0 & 0xFFFFFFFC ) + 0x1F0 * ( !0x1F0) =
= 0x1F0 + 0x1F0 * 0xFFFFFE0F = 0x1F0 + 0xFFFC3D10 = 0xFFFF3F00 (???)

And if we suppose that the parameter is 0x00:

( 0x00 & 0xFFFFFFFC ) + 0x1F0 * ( !0x00) =
= 0x00 + 0x1F0 * 0xFFFFFFFF = 0xFFFFFE10 ( ??? )

As I can see it, the results aren't the correct ( I think )
Moreover, you haven't answered the another question: Why this??

But, Thanks a lot for answer. :)
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: IDE Tutorial

Post by Griwes »

You seem to fail to differentiate operators ! and ~ in C...

(tip: logical vs bitwise negation)
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Re: IDE Tutorial

Post by ateno3 »

Griwes wrote:You seem to fail to differentiate operators ! and ~ in C...

(tip: logical vs bitwise negation)
ahhh....
Thank you very much, I have already understood. :)
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: IDE Tutorial

Post by qw »

Griwes wrote:You seem to fail to differentiate operators ! and ~ in C...
He may, but using boolean operators like this is considered bad practice for good reason.
Post Reply