Re: Strange code in 2.0.pre35 - apricot.c

sinster@darkwater.com
Sun, 12 Jul 1998 00:43:56 -0700 (PDT)


Sprach Ion Badulescu <ionut@moisil.cs.columbia.edu>:
[...]
> >> while (lp->scb.status, lp->scb.command)
[...]
> If it's intentional, what is it supposed to do then?

One common trick with memory-mapped device programming is to define a
structure that aligns with the control registers of the device, and
then to access the device through that structure. A lot of these
devices require two reads to get status information: a read from one
address tells the hardware to prepare the proper data at another
address. More commonly, though, it's a write at one address to tell
the device which data to prepare for a read at another address (VGA
cards and many UARTs use this).

This could (hypothetically: I know nothing about the apricot) be what
the author was trying to do, though if so then this code is broken
anyway. It should've been something more along the lines of:
register int hold;
while ((hold = lp->scb.status), lp->scb.command);
or if you prefer:
register int hold;
do {
hold = lp->scb.status;
} while (lp->scb.command);
The 'hold' variable is needed in both cases to prevent the optimizer
from dropping the first clause, because some compilers don't
understand 'volatile' as meaning that seemingly ineffectual reads
shouldn't be dropped. Borland was notorious for this.

-- 
Jon Paul Nollmann ne' Darren Senn                      sinster@balltech.net
Unsolicited commercial email will be archived at $1/byte/day.
"To live, to learn, to strive, and not to yield."                  Tennyson

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html