openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

sysinfo.cpp (1865B)


      1 #include <blt/Message.h>
      2 #include <blt/Connection.h>
      3 
      4 #include <blt/syscall.h>
      5 
      6 #include <stdio.h>
      7 
      8 #define PCI_STUB
      9 
     10 #include <pci.h>
     11 #include <string.h>
     12 #include <stdlib.h>
     13 
     14 using namespace BLT;
     15 
     16 int pci_dump(PCI *pci)
     17 {
     18 	Message msg;
     19 	pci_cfg cfg;
     20 	int n;
     21 	
     22 	printf("bus  dev  func vndr devc cls  sub  ifc  irq  base[0]  size[0]  base[1]  size[1] \n");
     23 	printf("---- ---- ---- ---- ---- ---- ---- ---- ---- -------- -------- -------- --------\n");
     24  
     25 	for(n=0;pci->get_nth_cfg(n,&cfg) == 0;n++){		
     26 		printf("%U %U %U %S %S %U %U %U ",
     27 			   cfg.bus, cfg.dev, cfg.func,
     28 			   cfg.vendor_id, cfg.device_id,
     29 			   cfg.base_class, cfg.sub_class, cfg.interface);
     30 		switch(cfg.header_type & 0x7f){
     31 		case 0:
     32 			printf("%U %x %x %x %x\n", cfg.irq,
     33 				   cfg.base[0], cfg.size[0],
     34 				   cfg.base[1], cfg.size[1]);
     35 			break;
     36 			
     37 		case 1:
     38 			printf(" (pci <-> pci bridge)\n");
     39 			break;
     40 			
     41 		default:
     42 			printf(" (unknown header type)\n");
     43 		}
     44 	}
     45 }
     46 	
     47 void dump_rom(PCI *pci, int bus, int dev, int func)
     48 {
     49 	int i;
     50 	uchar *rom = (uchar *) 0xf0000000;
     51 	
     52 	area_create(4096, 0, (void**) &rom, AREA_PHYSMAP);
     53 	printf("device: %d / %d / %d\n",bus,dev,func);
     54 	
     55 	pci->write(bus,dev,func,0x30,0xf0000001,4);
     56 	
     57 	for(i=0;i<256;i+=16){
     58 		printf("%S: %X %X %X %X %X %X %X %X %X %X %X %X %X %X %X %X\n",
     59 			   i, rom[i+0], rom[i+1], rom[i+2], rom[i+3],
     60 			   rom[i+4], rom[i+5], rom[i+6], rom[i+7],
     61 			   rom[i+8], rom[i+9], rom[i+10], rom[i+11],
     62 			   rom[i+12], rom[i+13], rom[i+14], rom[i+15]);
     63 	}
     64 }
     65 
     66 int main(int argc, char *argv[])
     67 {
     68 	PCI *pci = PCI::FindService();
     69 	
     70 	if(argc == 5){
     71 		char *cmd = argv[1];
     72 		int bus = atoi(argv[2]);
     73 		int dev = atoi(argv[3]);
     74 		int func = atoi(argv[4]);
     75 		
     76 		if(!strcmp(cmd,"rom")){
     77 			dump_rom(pci,bus,dev,func);
     78 		}
     79 		
     80 		return 0;	
     81 	}
     82 	
     83 	if(!pci) {
     84 		printf("sysinfo: cannot find pci service\n");
     85 	} else {
     86 		pci_dump(pci);
     87 	}
     88 	
     89 	return 0;
     90 }