分类: LINUX
2012-08-29 10:06:30
//
Linux IO access
compile : gcc hello.c -o hello
run : ./hello
debug : gcc -ggdb hello.c -o hello //compile for gdb
: gdb //run g debug
: file hello
: list //view source file
: break xxxx //set breakpoint at line XXXX
: r //run hello program
: s //if stace in same as TD F7
: n //if step same as TD F8
: q //exit debug
//
#include
#include
#include
#include
#include
#include
int main()
{
// out<<"hello world"<
// unsigned short wordvaule;
unsigned dwordport,dwordvaule;
printf(" -= PCI/SuperIO/CMOS data scan =- \n");
printf("00-00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
// PCI IO access
ioperm(0xcf8,8,1); //permit IO read and write
for(dwordport=0x80000000;dwordport<0x80000100;dwordport+=4)
{
outl(dwordport,0xcf8); //output a dword value to 0CF8 IOport
// dwordvaule=inl(0xcfc); //read a dword value from 0CFC IOport
// printf("%08x ",dwordvaule);
if(!(dwordport & 0x0f))
{
printf("\n%02x-",port);
}
value=inb(0xcfc);
printf("%02x ",value);
value=inb(0xcfd);
printf("%02x ",value);
value=inb(0xcfe);
printf("%02x ",value);
value=inb(0xcff);
printf("%02x ",value);
}
printf("\n");
//
#if 0 // ITE superIO access
ioperm(0x2e,2,1);
outb(0x87,0x2e);
outb(0x01,0x2e);
outb(0x55,0x2e);
outb(0x55,0x2e);
for(port=0;port<=0xfe;port++)
{
outb(port,0x2e);
value=inb(0x2f);
if(!(port & 0x0f))
{
printf("\n%02x-",port);
}
printf("%02x ",value);
}
printf("\n");
#endif
#if 0 // CMOS data access
ioperm(0x70,4,1);
for(port=0;port<0x80;port++)
{
outb(port,0x70);
value=inb(0x71);
if(!(port & 0x0f))
{
printf("\n%02x-",port);
}
printf("%02x ",value);
}
printf("\n");
#endif
}