hschumann2/TempleOS-Source-Code
0847
1 2#help_index "PCI;Processor;Devices;Info"3 4//The file was downloaded from5//http://www.pcidatabase.com/reports.php?type=tab-delimeted6 7#define PCI_DEV_FILE "::/Misc/PCIDevices.DD.Z"8 9/****10//1) Download http://www.pcidatabase.com/reports.php?type=tab-delimeted11//2) Rename to ::/Misc/PCIDevices.DD.Z12//3) ToDolDoc("::/Misc/PCIDevices.DD.Z");13//4) Edit and remove file header and tail14//5) Text find-and-replace "=0A=" with "". (Doesn't seem necessary anmore.)15//6) Run PCIDevFileGen(). (Doesn't seem necessary anmore.)16 17public U0 PCIDevFileGen()18{19 Bool first=TRUE,del=FALSE,del2=FALSE,cont=FALSE;20 CDoc *doc=DocRead(PCI_DEV_FILE,21 DOCF_PLAIN_TEXT|DOCF_DBL_DOLLARS|DOCF_NO_CURSOR);22 CDocEntry *doc_e=doc->head.next,*doc_e2;23 while (doc_e!=doc) {24 doc_e2=doc_e->next;25 if (first) {26 if (doc_e->type_u8==DOCT_TEXT) {27 if (doc_e->tag[0]==';')28 del=TRUE;29 }30 first=FALSE;31 }32 if (doc_e->type_u8==DOCT_TEXT && doc_e->tag[StrLen(doc_e->tag)-1]=='=' &&33 doc_e2->type_u8==DOCT_NEW_LINE) {34 doc_e->tag[StrLen(doc_e->tag)-1]=CH_SPACE;35 cont=TRUE;36 }37 del2=del;38 if (doc_e->type_u8==DOCT_NEW_LINE) {39 first=TRUE;40 del2=FALSE;41 if (cont) {42 del=TRUE;43 cont=FALSE;44 }45 }46 if (del)47 DocEntryDel(doc,doc_e);48 del=del2;49 doc_e=doc_e2;50 }51 DocWrite(doc);52}53****/54 55//::/Misc/PCIDevices.DD56U0 PCILookUpSingle(CDoc *doc,I64 m,I64 d,U8 **_vendor,U8 **_dev)57{58 Bool first=TRUE;59 U8 buf[8],*vendor=NULL,*dev=NULL;60 CDocEntry *doc_e=doc->head.next;61 while (doc_e!=doc) {62 if (first) {63 if (doc_e->type_u8==DOCT_TEXT && doc_e->tag[0]!=';' &&64 StrLen(doc_e->tag)>=4) {65 buf[0](U16)='0x';66 buf[2](U32)=doc_e->tag(U32 *)[0];67 buf[6]=0;68 if (Str2I64(buf)==m) {69 doc_e=doc_e->next->next;70 if (doc_e->type_u8==DOCT_TEXT) {71 vendor=AStrNew(doc_e->tag);72 first=FALSE;73 break;74 }75 }76 }77 first=FALSE;78 }79 if (doc_e->type_u8==DOCT_NEW_LINE)80 first=TRUE;81 doc_e=doc_e->next;82 }83 84 if (vendor) {85 while (doc_e!=doc) {86 if (first) {87 if (doc_e->type_u8==DOCT_TAB) {88 doc_e=doc_e->next;89 if (doc_e->type_u8==DOCT_TEXT && StrLen(doc_e->tag)>=4) {90 buf[0](U16)='0x';91 buf[2](U32)=doc_e->tag(U32 *)[0];92 buf[6]=0;93 if (Str2I64(buf)==d) {94 doc_e=doc_e->next->next;95 if (doc_e->type_u8==DOCT_TEXT) {96 dev=AStrNew(doc_e->tag);97 break;98 }99 }100 }101 } else102 break;103 first=FALSE;104 }105 if (doc_e->type_u8==DOCT_NEW_LINE)106 first=TRUE;107 doc_e=doc_e->next;108 }109 }110 111 if (vendor)112 *_vendor=vendor;113 else114 *_vendor=AStrNew("Unknown");115 116 if (dev)117 *_dev=dev;118 else119 *_dev=AStrNew("Unknown");120}121 122U0 PCILookUpDevs()123{124 CPCIDev *tmppci;125 I64 w1,w2,b,d,f,timeout=32*8*2;126 CDoc *doc;127 if (dev.pci_head.next!=&dev.pci_head)128 return;129 doc=DocRead(PCI_DEV_FILE,DOCF_PLAIN_TEXT|DOCF_NO_CURSOR);130 for (b=0;b<sys_pci_busses;b++)131 for (d=0;d<32;d++)132 for (f=0;f<8;f++) {133 w1=PCIReadU16(b,d,f,0);134 if (w1!=0xFFFF) {135 tmppci=ACAlloc(sizeof(CPCIDev));136 tmppci->bus=b;137 tmppci->dev=d;138 tmppci->fun=f;139 tmppci->vendor=w1;140 tmppci->dev_id=w2=PCIReadU16(b,d,f,2);141 tmppci->sub_code=PCIReadU8(b,d,f,0xA);142 tmppci->base_code=PCIReadU8(b,d,f,0xB);143 PCILookUpSingle(doc,w1,w2,&tmppci->vendor_str,&tmppci->dev_id_str);144 QueIns(tmppci,dev.pci_head.last);145 timeout=32*8*2;146 } else if (sys_pci_busses==256 && --timeout<=0)147 goto lud_done;148 }149lud_done:150 DocDel(doc);151}152 153public U0 PCIRep()154{//Report description of PCI devices.155 CPCIDev *tmppci;156 "PCI Busses:%d\n",sys_pci_busses;157 if (!FileFind(PCI_DEV_FILE)) {158 "You don't have the PCI device file.\n";159 return;160 }161 PCILookUpDevs;162 tmppci=dev.pci_head.next;163 while (tmppci!=&dev.pci_head) {164 "%02X:%02X:%01X %02X%02X $GREEN$%s $CYAN$%s$FG$\n",165 tmppci->bus,tmppci->dev,tmppci->fun,166 tmppci->base_code,tmppci->sub_code,167 tmppci->vendor_str,tmppci->dev_id_str;168 tmppci=tmppci->next;169 }170}171 172#help_index "Info;Memory/Info"173public U0 MemBIOSRep()174{//Report the memory ranges reported by the BIOS at boot.175 U16 *m01=MEM_E801;176 CMemE820 *m20=MEM_E820;177 CMemRange *tmpmr;178 "Standard Addresses\n"179 "000A0000-000BFFFF VGA\n"180 "FEE00000-FEE00FFF See $LK,\"APIC\",A=\"MN:LAPIC_BASE\"$\n\n"181 "32 Bit Device Mem\n";182 while (LBts(&sys_semas[SEMA_DEV_MEM],0))183 Yield;184 tmpmr=dev.mem32_head.next;185 while (tmpmr!=&dev.mem32_head) {186 "%02X:%016X-%016X\n",187 tmpmr->type,tmpmr->base,tmpmr->base+tmpmr->size-1;188 tmpmr=tmpmr->next;189 }190 LBtr(&sys_semas[SEMA_DEV_MEM],0);191 192 "\nBIOS Memory Report 15:E801\n"193 "01:0000000000000000-%016X\n",0x100000+m01[0]<<10-1;194 "01:0000000001000000-%016X\n",SYS_16MEG_AREA_LIMIT+m01[1]<<16-1;195 196 if (m20->type) {197 '\n';198 "BIOS Memory Report 15:E820\n";199 while (m20->type) {200 "%02X:%016X-%016X\n",m20->type,m20->base,m20->base+m20->len-1;201 m20++;202 }203 }204}205 206public U0 MemPageRep()207{//Page Table Report.208 "MAPPED\t :%010X with ",mem_mapped_space;209 if (Bt(&mem_page_size,30))210 "$RED$1GIG$FG$ pages\n";211 else212 "$RED$2MEG$FG$ pages\n";213 "PML2\t :%010X 2MEG :%08X\n",214 *MEM_PML2(U64 *),*MEM_2MEG_NUM(U64 *);215 "PML3\t :%010X 1GIG :%08X\n",216 *MEM_PML3(U64 *),*MEM_1GIG_NUM(U64 *);217 "PML4\t :%010X 512GIG:%08X\n",218 *MEM_PML4(U64 *),*MEM_512GIG_NUM(U64 *);219 "FIXED_AREA:%010X\n",SYS_FIXED_AREA;220 "HEAP_BASE :%010X\nHEAP_LIMIT:%010X\n",mem_heap_base,mem_heap_limit;221}222 