inb & outb woes...

I'm trying to write a short program that will display/modify I/O ports depending on the number of command line args... this is for a PC104 board I'm tinkering with. It's not working as expected and I can't find documentation more in depth than the man page... here's the code... yeah, it's crude...

#include #include #include #include #include

int main(int argc, char **argv) { unsigned int addr, val; switch (argc) { case 2: addr = strtol(argv[1], (char**)NULL, 16); if (addr < 0x400 && ioperm(addr, 1, 1) < 0) { printf("ioperm failed: %s\n", strerror(errno)); return -1; } else if (iopl(3) < 0) { printf("iopl failed: %s\n", strerror(errno)); return -1; } printf("address 0x%x : value 0x%02x\n", addr, inb(addr)); break; case 3: addr = strtol(argv[1], (char**)NULL, 16); val = strtol(argv[2], (char**)NULL, 16); if (addr < 0x400 && ioperm(addr, 1, 1) < 0) { printf("ioperm failed: %s\n", strerror(errno)); return -1; } else if (iopl(3) < 0) { printf("iopl failed: %s\n", strerror(errno)); return -1; } outb(val&0xff, addr); break; default: printf("invalid args\n"); return -1; break; } return 0; }

For what it's worth, I've tried compiling with both -O and -O2, I run as root, etc. Any suggestions, help, references to documentation or anything else would be greatly appreciated. TIA

Reply to
jahurt
Loading thread data ...

If addr >= 0x400, ioperm() is never called and then the iopl() in the else-if clause will fail. If you change the '&&' to '||' (which also would make more sense) it probably will work.

Regards, Jens

--
      _  _____  _____
     | ||_   _||_   _|        Jens.Toerring@physik.fu-berlin.de
 Click to see the full signature
Reply to
Jens.Toerring

This is by design... ioperm sets the port access permission bits for the first 0x3ff i/o ports. If I have an address > 0x3ff, then the plan is to call iopl (rather than ioperm), which, according to the man page, grants access to all the i/o ports. At least this is my understanding from the man pages...

Reply to
jahurt

Sorry, I was a bit too careless. So I now compiled your program (after removing '#include' and replacing it by '#include ' (that's where ioperm() and iopl() are declared) and adding '#include ' (for strtol()) to keep the compiler from complaining) and, if I run it as root, it works without any error messages getting output, both when I read and write. What exactly are you expecting it to do and what happens? Regards, Jens

--
      _  _____  _____
     | ||_   _||_   _|        Jens.Toerring@physik.fu-berlin.de
 Click to see the full signature
Reply to
Jens.Toerring

Well, I wasn't able to get outb() to work correctly, although now it seems that the main problem was between the chair and the keyboard :) Works fine now (knock wood) Thanks for your help

Reply to
jahurt

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.