Watcom C 的笔记5 Watcom C (5)
DOS/4GW PCI 配置空间的读取 参考 http://www.openwatcom.org/index.php/PCI_Device_access_under_32-Bit_PM_DOS 很奇怪的是原文是编译不过的,需要将 Example 中的 #include "pci.h" 改为 #include "pci.c" 才能编译通过。 第一个程序:getpci.c 使用二维数组保存结果,在后面输出: #include <stdio.h> #include "pci.c" int main() { char pcicon[0x10][0x10]; uint8_t bus, dev, func; short int i,j; printf("Please input BUS DEV FUN"); scanf("%hx %hx %hx",&bus,&dev,&func); for (i=0;i<0x10;i++) for (j=0;j<0x10;j++) { pcicon[j][i]=PciReadConfigByte(bus,dev,func,(char) (j+i*16)); } for (i=0;i<0x10;i++) { printf("\n"); for (j=0;j<0x10;j++) { printf("%02x ",pcicon[j][i]); } } return( 0 ); } 第二个程序:getpci1.c 动态分配内存,使用指针保存分配的内存首地址。 #include <stdio.h> #include <stdlib.h> #include "pci.c" int main() { char *pcicon; //指针 uint8_t bus, dev, func; short int i,j; printf("Please input BUS DEV FUN"); scanf("%hx %hx %hx",&bus,&dev,&func); pcicon=malloc(0x100); if (pcicon==NULL) {printf("Error");} for (i=0;i<0x10;i++) for (j=0;j<0x10;j++) { *(pcicon+i*16+j)=PciReadConfigByte(bus,dev,func,(short int) (j+i*16)); } for (i=0;i<0x10;i++) { printf("\n"); for (j=0;j<0x10;j++) { printf("%02X ",*(pcicon+i*16+j)); } } free(pcicon); return( 0 ); } 第二个程序:getpci2.c 动态分配内存,使用数组指针。 #include <stdio.h> #include <stdlib.h> #include "pci.c" int main() { char (*pcicon)[0x10][0x10]; //数组指针(指向数组的指针) uint8_t bus, dev, func; short int i,j; printf("Please input BUS DEV FUN"); scanf("%hx %hx %hx",&bus,&dev,&func); pcicon=malloc(0x200); if (pcicon==NULL) {printf("Error");} for (i=0;i<0x10;i++) for (j=0;j<0x10;j++) { (*pcicon)[i][j]=PciReadConfigByte(bus,dev,func,(short int) (j+i*16)); } for (i=0;i<0x10;i++) { printf("\n"); for (j=0;j<0x10;j++) { printf("%02X ",(*pcicon)[i][j]); } } free(pcicon); return( 0 ); } 编译后的程序都是无法在XP下面运行的(运行结果不确定),只能在DOS下运行。 另外,参考的访问PCI配置空间的方法是调用PCI BIOS中断。 Z.t 2008-1-17