Sunday, September 21, 2008

Much-needed dirty work

Okay, some much needed dirty work has been done. I moved a bunch of logic out to smi.c, and put together a lot of defines in reg-82801b.h as created from Intel's documentation. There are a few subregisters that need to be trawled, and I need to work out a system to register interest in a type of event, and have a callback for it.

Of note also is that we now have 'printf' and 'dologf', which should eliminate disgusting blocks of code like this:
                strcpy(s, "READxxxxxxxxxxxxxxxx");
tohex(s+4, cts);
b = inb(cts & 0xFFFF);
tohex(s+12, b);
dolog(s);

To be replaced with:
                b = inb(cts & 0xFFFF);
dologf("READ: %08x (%02x)", cts, b);

This gives much cleaner code, and much cleaner output, too!

I'm undecided on this whole 'no magic number' business again. On one hand, things like this: return pci_read32(0, 31, 0, 0x40) & 0xFF80; do look pretty magic and hard to maintain; indeed, it has even been the source of a bug, since '31' was originally typoed as '21'! But on the other hand, replacing with named constants is pretty ugly too; my RSI is acting up just thinking about this: return pci_read32(ICH2_LPC_BUS, ICH2_LPC_DEV, ICH2_LPC_FN, ICH2_LPC_PCI_PMBASE) & ICH2_PMBASE_MASK;. Yikes.

So I guess the next step after this stuff gets cleaned up is to start trying to hide the NIC. Since PCI interception doesn't work, I guess we get to turn off the BARs, and hope that Linux does not turn them back on for us. We shall see...

No comments: