void AddGlobalName(struct idrec *ptr) { if(ptr!=NULL){ AddGlobalName(ptr->right); if((ptr->rectok==tk_proc&&ptr->recsegm>=NOT_DYNAMIC)|| (ptr->rectok>=tk_bits&&ptr->rectok<=tk_doublevar)|| (ptr->rectok==tk_structvar)){ AddNameToPul(ptr->recid); numsymbols++; if(ptr->rectok==tk_proc){ outword(0x1c); //size outdword(0x20); //type } else{ outword(0x18); outdword(0x21); } outword(0); outdword(0); outdword(numsymbols); //name outdword(0); if(ptr->recpost==0){ outdword(ptr->recnumber); //offset outword(segcode); //segm } else{ outdword(ptr->recnumber+(wbss!=FALSE?0:ooutptr)); outword(1); } if(ptr->rectok==tk_proc)outdword(0); } AddGlobalName(ptr->left); } }
// source: NUL/NRE void x86Machine::rebootACPI() { size_t len; FACP *facp = reinterpret_cast<FACP*>(mapTable("FACP",&len)); if(facp == NULL || len < 129) { if(len < 129) printe("FACP too small (%zu)",len); return; } if(~facp->flags & RESET_REG_SUP) { printe("ACPI reset unsupported"); return; } if(facp->RESET_REG.regBitWidth != 8) { printe("Register width invalid (%u)",facp->RESET_REG.regBitWidth); return; } if(facp->RESET_REG.regBitOffset != 0) { printe("Register offset invalid (%u)",facp->RESET_REG.regBitOffset); return; } if(facp->RESET_REG.accessSize > 1) { printe("We need byte access"); return; } uint8_t method = facp->RESET_REG.addressSpace; uint8_t value = facp->RESET_VALUE; uint64_t addr = facp->RESET_REG.address; printe("Using method=%#x, value=%#x, addr=%#Lx",method,value,addr); switch(method) { case SYS_MEM: { uintptr_t phys = addr; volatile uint8_t *virt = reinterpret_cast<volatile uint8_t *>( mmapphys(&phys,1,0,MAP_PHYS_MAP)); if(!virt) { printe("Unable to map %p",addr); return; } *virt = value; break; } case SYS_IO: { if(reqport(addr) < 0) { printe("Unable to request port %#Lx",addr); return; } outbyte(addr,value); break; } case PCI_CONF_SPACE: { if(reqports(0xcf8,8) < 0) { printe("Unable to request ports %#x..%#x",0xcf8,0xcf8 + 7); return; } uint32_t val = (addr & 0x1f00000000ull) >> (32 - 11); val |= (addr & 0x70000) >> (16 - 8); val |= addr & 0x3c; outdword(0xcf8,val); outbyte(0xcf8 + (4 | (addr & 0x3)),val); break; } default: printe("Unknown reset method %#x",method); break; } }
int CreateW32Debug() { int sstNames,sstDirectory; int startcode=outptr; int sstGlobalSym; int sstsrc; unsigned int i,j,jj,ofs; for(;numsymbols<(short)totalmodule;numsymbols++)AddNameToPul((startfileinfo+numsymbols)->filename); segcode=(wbss==FALSE?1:2); outptr=0; outdword(0x41304246); // TDS - signature outdword(0); // offset of Subsection Directory (fill later) //sstModule subsection outdword(0); // OvlNum=0 & LibIndex=0 outword(segcode); // SegCount outword(0x5643); // CV-style outdword(1); // Name for(i=0;i<4;i++)outdword(0); // outdword(0); //Time // outdword(0); // outdword(0); // outdword(0); if(wbss){ outword(0x0001); // SegNumber outword(0); // flag outdword(0); // start outdword(postsize); // len } outword(segcode); // SegNumber outword(0x0001); // flag outdword(startptr); // start outdword(startcode); // len sstsrc=outptr; //sstSrcModule subsection outword((short)numcorrel); //cFile - количество SRC-файлов(сегментов) outword((short)numcorrel); // SegCount (see SegCount in sstModule ofs=14*numcorrel+4; for(i=0,jj=0;i<(unsigned int)numcorrel;i++){ if(i!=0)jj=jj+((corinfo+i-1)->count+1)*6+22; outdword(ofs+jj); } for(i=0;i<(unsigned int)numcorrel;i++){ outdword((corinfo+i)->ofs); outdword((corinfo+i)->end); } for(i=0;i<(unsigned int)numcorrel;i++)outword(segcode); // массив индексов сегментов for(i=0;i<(unsigned int)numcorrel;i++){ outword(1); // Segm# outdword((corinfo+i)->file+1);// File# outdword(outptr-sstsrc+12); outdword((corinfo+i)->ofs); outdword((corinfo+i)->end); outword(segcode); //Segm# jj=(corinfo+i)->count; outword(jj+1); // Lines count ofs=(corinfo+i)->startline; for(j=0;j<jj;j++)outdword(dbgloc[j+ofs]); outdword((corinfo+i)->end); for(j=0;j<jj;j++)outword(dbgnum[j+ofs]); outword(0); } //таблица глобальных символов sstGlobalSym=outptr; for(i=0;i<8;i++)outdword(0); // outdword(0); //modindex // outdword(0); //size correct later // outdword(0); // outdword(0); // outdword(0); // outdword(0); //num others correct later // outdword(0); //total correct later // outdword(0); //SymHash, AddrHash outdword(0x02100008); //S_ENTRY32 outdword(EntryPoint()); outword(segcode); AddGlobalName(treestart); sstNames=outptr; outdword(numsymbols); outptr=sstGlobalSym+4; outdword(sstNames-sstGlobalSym-32); outptr+=12; outdword(numsymbols-totalmodule); outdword(numsymbols-totalmodule); outptr=4; sstDirectory=sstNames+4+lastofspul; outdword(sstDirectory); if(fwrite(output,sstNames+4,1,hout)!=1)return -1; if(fwrite(bufname,lastofspul,1,hout)!=1)return -1; free(bufname); // Subsection Directory outptr=0; outdword(0x0C0010); outdword(4); // cDir - number of subsections outdword(0); outdword(0); //sstModule outdword(0x10120); outdword(8); //start outdword(sstsrc-8); // size // sstSrcModule outdword(0x10127); outdword(sstsrc); //start outdword(sstNames-sstsrc);//size //sstGlobalSym outdword(0x129); outdword(sstGlobalSym); //start outdword(sstNames-sstGlobalSym); //size // sstNames outdword(0x130); outdword(sstNames); outdword(sstDirectory-sstGlobalSym); outdword(0x41304246); // TDS - signature outdword(sstDirectory+outptr+4); // TDS-len return 0; }