/* Read node from memory and continue with remaining nodes. */ void VertexBufferNode::fromMemory( char** addr, VertexBufferData& globalData ) { // read node itself size_t nodeType; memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( size_t ) ); if( nodeType != NODE_TYPE ) throw MeshException( "Error reading binary file. Expected a regular " "node, but found something else instead." ); VertexBufferBase::fromMemory( addr, globalData ); // read left child (peek ahead) memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( size_t ) ); if( nodeType != NODE_TYPE && nodeType != LEAF_TYPE ) throw MeshException( "Error reading binary file. Expected either a " "regular or a leaf node, but found neither." ); *addr -= sizeof( size_t ); if( nodeType == NODE_TYPE ) _left = new VertexBufferNode; else _left = new VertexBufferLeaf( globalData ); static_cast< VertexBufferNode* >( _left )->fromMemory( addr, globalData ); // read right child (peek ahead) memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( size_t ) ); if( nodeType != NODE_TYPE && nodeType != LEAF_TYPE ) throw MeshException( "Error reading binary file. Expected either a " "regular or a leaf node, but found neither." ); *addr -= sizeof( size_t ); if( nodeType == NODE_TYPE ) _right = new VertexBufferNode; else _right = new VertexBufferLeaf( globalData ); static_cast< VertexBufferNode* >( _right )->fromMemory( addr, globalData ); }
/* Read node from memory and continue with remaining nodes. */ void VertexBufferNode::fromMemory( char** addr, VertexBufferData& globalData ) { // read node itself Type nodeType; memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( nodeType )); if( nodeType != Type::node ) throw MeshException( "Error reading binary file. Expected a node, got "+ std::to_string( unsigned( nodeType ))); VertexBufferBase::fromMemory( addr, globalData ); // read left child (peek ahead) memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( nodeType )); if( nodeType != Type::node && nodeType != Type::leaf ) throw MeshException( "Error reading binary file. Expected either a " "regular or a leaf node, but found neither." ); *addr -= sizeof( nodeType ); if( nodeType == Type::node ) _left.reset( new VertexBufferNode ); else _left.reset( new VertexBufferLeaf( globalData )); _left->fromMemory( addr, globalData ); // read right child (peek ahead) memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( nodeType )); if( nodeType != Type::node && nodeType != Type::leaf ) throw MeshException( "Error reading binary file. Expected either a " "regular or a leaf node, but found neither." ); *addr -= sizeof( nodeType ); if( nodeType == Type::node ) _right.reset( new VertexBufferNode ); else _right.reset( new VertexBufferLeaf( globalData )); _right->fromMemory( addr, globalData ); }
/* Read root node from memory and continue with other nodes. */ void VertexBufferRoot::fromMemory( char* start ) { char** addr = &start; size_t version; memRead( reinterpret_cast< char* >( &version ), addr, sizeof( size_t ) ); if( version != FILE_VERSION ) throw MeshException( "Error reading binary file. Version in file " "does not match the expected version." ); size_t nodeType; memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( size_t ) ); if( nodeType != ROOT_TYPE ) throw MeshException( "Error reading binary file. Expected the root " "node, but found something else instead." ); _data.fromMemory( addr ); VertexBufferNode::fromMemory( addr, _data ); }
/** * Function: memoryStage * This driver function updates the values in writebackStage */ void memoryStage(forwardType * forward, statusType * status, bubbleType * bubble) { unsigned int valM; unsigned int valE; bool memError = FALSE; valE = memAddr(); valM = memCond(valE,&memError); if(!memRead()) valM = 0; //Forwarding from memoryStage (*forward).m_valM = valM; (*forward).M_valE = M.valE; (*forward).M_dstE = M.dstE; (*forward).M_dstM = M.dstM; (*forward).M_Cnd = M.Cnd; (*forward).M_icode = M.icode; (*forward).M_valA = M.valA; unsigned int mStat; mStat = setStat(memError); //Updating stat in the statusType struct //and the bubbleType struct (*status).m_stat = mStat; (*bubble).M_icode = M.icode; if(!(W_stall(*bubble,*status))) updateWStage(mStat,M.icode,M.valE,valM,M.dstE,M.dstM); }
int dispmemPlage(uint32_t start_addr,uint32_t size) { //Affiche une plage memoire if(memory==NULL) { WARNING_MSG("No memory loaded"); return -1; } uint32_t i=0; uint32_t current_addr=start_addr; int value; while (i<size) { if (i%16==0) { printf("\n0x%8.8X ",current_addr); } // printf("j= %d i=%d, current_addr= %d ,start= %d, size = %d, diff=%d \n",j,i,current_addr,memory->seg[j-1].start._32,memory->seg[j-1].size._32,current_addr-memory->seg[j-1].start._32+memory->seg[j-1].size._32); if(memRead(current_addr,0,&value)==0) { //on verifie qu'il soit dans une plage memoire valide printf("%2.2X ",value); } else printf("XX "); current_addr++; i++; } printf("\n"); return 0; }
/* Read leaf node from memory. */ void VertexBufferLeaf::fromMemory( char** addr, VertexBufferData& globalData ) { size_t nodeType; memRead( reinterpret_cast< char* >( &nodeType ), addr, sizeof( size_t ) ); if( nodeType != LEAF_TYPE ) throw MeshException( "Error reading binary file. Expected a leaf " "node, but found something else instead." ); VertexBufferBase::fromMemory( addr, globalData ); memRead( reinterpret_cast< char* >( &_vertexStart ), addr, sizeof( Index ) ); memRead( reinterpret_cast< char* >( &_vertexLength ), addr, sizeof( ShortIndex ) ); memRead( reinterpret_cast< char* >( &_indexStart ), addr, sizeof( Index ) ); memRead( reinterpret_cast< char* >( &_indexLength ), addr, sizeof( Index ) ); }
int getInstr(uint32_t adress, instruction* instr_ptr) { int32_t temp; if(memRead(adress,1,&temp)==-1) { temp=-1; //En cas de depassement de la zone .text on ne recupere aucune instr } //FLIP_ENDIANNESS(temp); memcpy(instr_ptr,&temp,4); //printf("content : %8.8X\t",temp); printf("adress %8.8X\n", adress); return 1; }
/** * Function: memCond * This function returns the value to be sent as valM * and reads or writes from memory if needed * Return: value to be used as valM */ unsigned int memCond(unsigned int valE,bool * memError) { bool tempEr = FALSE; unsigned int ret = M.valA; if(memRead()){ ret = getWord(valE,&tempEr); *memError = tempEr; } else if(memWrite()){ putWord(valE,M.valA,&memError); ret = M.valA; } return ret; }
int test() { #define WINDOWSIZ 100 char buf[WINDOWSIZ]; char ttt[100]; int i; getctime( ttt ); printf( "start 1 %s\n" ,ttt); for(i=0;i<BUFSZ/1024;i+=100 ){ buf[0] = i; memWrite( buf , i * 1024 , WINDOWSIZ ); } for(i=0;i<BUFSZ/1024;i+=100 ){ buf[0] = i; memRead( buf , (i + 50) * 1024 , WINDOWSIZ ); } getctime(ttt); printf( "start 2 %s\n" ,ttt); for(i=0;i<BUFSZ/1024;i+=100 ){ buf[0] = i; memWrite( buf , (i + 10 )* 1024 , WINDOWSIZ ); } for(i=0;i<BUFSZ/1024;i+=100 ){ buf[0] = i; memRead( buf , (i + 10) * 1024 , WINDOWSIZ ); } getctime(ttt); printf( "start 3 %s\n" ,ttt); }
/* Shift left - Shift Right - Shift arithmetic right */ void i8086ShlShrSar(i8086core *core, unsigned char opcode, i8086Parameter para, i8086Parameter data) { i8086SingleRegister sreg,clreg; i808616BitAdr ea; unsigned short disp,oldmsb,msb,shldata; unsigned char wData,vData,destReg,shifts=1,shr=0,sar=0; wData=opcode & i8086_BIT_0;//16 oder 8 Bit Operation vData=opcode & i8086_BIT_1;//SHL/SHR um 1 oder um n bits shr=para.b[0] & i8086_BIT_3; //soll ein SHR ausgefuehrt werden? sar=para.b[0] & i8086_BIT_4; //soll ein SAR ausgefuehrt werden? if(vData) //mehr als 1 shift { i8086GetRegisterRef(&clreg,core,0,i8086_REG_CL); //CL Register shifts=clreg.b[0]; //anzahl der shifts } if((para.b[0] & i8086_BIT_7) && (para.b[0] & i8086_BIT_6)) //SHL/SHR REG { destReg=getBitSnipped(para.b[0], 2, 3);//nummer des Registers i8086GetRegisterRef(&sreg,core,wData,destReg); //destination Register if(wData)//16 Bit Operation shldata=sreg.x;//zu shiftende daten else shldata=sreg.b[0]; } else//SHL/SHR MEM { disp=joinBytes(para.b[1],para.b[2]); ea=decodeMemAdr(core, para.b[0],disp); //Adresse berechnen shldata=memRead(core,ea,wData,i8086_REG_DS);//zu shiftende daten } oldmsb=GET_MSB(shldata,wData);//nur für 1bit shift notwenidg if(shifts) //shifts > 0 { if(shr)//SHR oder SAR { if(sar) shldata=((signed short)shldata)>>(shifts-1);//bis shifts-1 arithmetisch shiften else shldata=shldata>>(shifts-1);//bis shifts-1 shiften } else//SHL
// Dump a portion of memory to file static void memDump(uint8 *vaddr, uint32 size, uint32 base = (uint32)-1) { uint32 offs = 0; char chrdump[17]; chrdump[16] = 0; if (base == (uint32)-1) base = (uint32)vaddr; while (offs < size) { if ((offs & 15) == 0) { if (offs) Output(" | %s", chrdump); Output("%08x |\t", base + offs); } uint32 d = memRead(vaddr + offs, MO_SIZE32); Output(" %08x\t", d); chrdump[(offs & 15) + 0] = dump_char((d ) & 0xff); chrdump[(offs & 15) + 1] = dump_char((d >> 8) & 0xff); chrdump[(offs & 15) + 2] = dump_char((d >> 16) & 0xff); chrdump[(offs & 15) + 3] = dump_char((d >> 24) & 0xff); offs += 4; } while (offs & 15) { Output(" \t"); chrdump[offs & 15] = 0; offs += 4; } Output(" | %s", chrdump); }
static void* demux_thread(void* arg) { unsigned char read_data[TSPACKAGELEN]; unsigned char* es_data = (unsigned char*) CStb_Malloc(MAX_ES_LEN); while (ts_param.m_exit) { int read_len = memRead(read_data, 1, sizeof(read_data), &(ts_param.file)); if (read_len > 0) { if (read_data[0] != 0x47) { LOGE("lt--->ts packet error \n"); } if (get_pack_pid(read_data) == ts_param.m_cur_param->video_pid) { int ret = mVideodemuxer->Put(read_data, read_len); if (ret > 0) { int len = mVideodemuxer->Get(es_data, MAX_ES_LEN); while (len > 0) { // struct timeval tv_start ; // struct timeval tv_end ; // gettimeofday(&tv_start,NULL); ts_param.m_cur_param->video_decoder(es_data, len); // gettimeofday(&tv_end,NULL); // int use_time = (tv_end.tv_sec - tv_start.tv_sec)*1000 + (tv_end.tv_usec - tv_start.tv_usec)/1000; // if(use_time > 40){ // LOGD("lt---> decoder ust time :%d\n",use_time); // } len = mVideodemuxer->Get(es_data, MAX_ES_LEN); } } } else if (get_pack_pid(read_data) == ts_param.m_cur_param->audio_pid) { int ret = mAudiodemuxer->Put(read_data, read_len); if (ret > 0) { int len = mAudiodemuxer->Get(es_data, MAX_ES_LEN); while (len > 0) { ts_param.m_cur_param->audio_decoder(es_data, len); len = mAudiodemuxer->Get(es_data, MAX_ES_LEN); } } else if (ret < 0) { LOGD("lt---> get pid audio :%d ret:%d\n", get_pack_pid(read_data), ret); } } } else { usleep(5000); } } CStb_Free(es_data); return NULL; }
/** * @param fp le fichier elf original * @param seg le segment a reloger * @param mem l'ensemble des segments * @param endianness le boutisme du programme * @param symtab la table des symbole du programme * @param symtab_libc la table des symbole de la libc (NULL si inutile) * @param fp_libc le fichier elf de la libc (NULL si inutile) * @brief Cette fonction effectue la relocation du segment passe en parametres * @brief l'ensemble des segments doit deja avoir ete charge en memoire. * * VOUS DEVEZ COMPLETER CETTE FONCTION POUR METTRE EN OEUVRE LA RELOCATION !! */ void reloc_segment(FILE* fp, segment seg, mem memory,unsigned int endianness,stab* symtable,stab* symtab_libc,FILE* fp_libc) { byte *ehdr = __elf_get_ehdr( fp ); uint32_t scnsz = 0; Elf32_Rel *rel = NULL; char* reloc_name = malloc(strlen(seg.name)+strlen(RELOC_PREFIX_STR)+1); scntab section_tab; scntab section_tab_libc; // on recompose le nom de la section memcpy(reloc_name,RELOC_PREFIX_STR,strlen(RELOC_PREFIX_STR)+1); strcat(reloc_name,seg.name); // on recupere le tableau de relocation et la table des sections rel = (Elf32_Rel *)elf_extract_scn_by_name( ehdr, fp, reloc_name, &scnsz, NULL ); elf_load_scntab(fp ,32, §ion_tab); if (symtab_libc!=NULL && fp_libc!=NULL) elf_load_scntab(fp_libc ,32, §ion_tab_libc); if (rel != NULL &&seg.content!=NULL && seg.size._32!=0) { if(verbose>0) { INFO_MSG("--------------Relocation of %s-------------------\n",seg.name) ; INFO_MSG("Number of symbol to relocate: %ld\n",scnsz/sizeof(*rel)) ; } //------------------------------------------------------ int i=0; uint sym; uint type; uint info; uint offset; //display : if(verbose>0) { //printf("scnsz=%d\n", scnsz); //print_scntab(section_tab); printf("Offset Info Type Sym.Value Sym.Name\n"); while(i<scnsz/sizeof(*rel)) { info=rel[i].r_info; offset=rel[i].r_offset; FLIP_ENDIANNESS(info) ; FLIP_ENDIANNESS(offset) ; sym=ELF32_R_SYM(info); type=ELF32_R_TYPE(info); if (type>32) { WARNING_MSG("Unknown type : %d",type); } else { printf("%08X %08X %-14s %08X %s\n",offset,info,MIPS32_REL[type],sym,(*symtable).sym[sym].name); i++; } } } i=0; //------------------------------------------------------ //Reloc : int A,V,P; //int segnum; uint32_t S; while(i<scnsz/sizeof(*rel)) { info=rel[i].r_info; offset=rel[i].r_offset; FLIP_ENDIANNESS(info) ; FLIP_ENDIANNESS(offset) ; sym=ELF32_R_SYM(info); type=ELF32_R_TYPE(info); //printf("Relocating symbol %d\n",i ); //segnum=seg_from_scnidx((*symtable).sym[sym].scnidx,(*symtable),memory); //if(segnum==-1){ // WARNING_MSG("Couldn't resolve scndix correspondance"); // break; //} //S=memory->seg[segnum].start._32+(*symtable).sym[sym].addr._32;//a verif //printf("sym=%d, symbtable size=%d\n", sym,(*symtable).size); if(addr_from_symnb(sym, (*symtable), memory,&S)==-1) { WARNING_MSG("Trying to resolve scndix correspondance in libcsymtab"); } P=seg.start._32+offset; memRead(P,1,&A); //printf("Relocation type %s\n",MIPS32_REL[type] ); switch (type) { case 2: V=S+A; //printf("V= %X,S=%X,A=%X,P=%X\n",V,S,A,P); memWrite(P,1,V); break; case 4: V=(A&0xFC00000)|((((A<<2)|((P&0xF0000000)+S))>>2)&0x3FFFFFF); //printf("V= %X,S=%X,A=%X,P=%X\n",V,S,A,P); memWrite(P,1,V); break; case 5: ; uint nexttype=rel[i+1].r_info; uint nextoffset=rel[i+1].r_offset; FLIP_ENDIANNESS(nexttype); FLIP_ENDIANNESS(nextoffset); nexttype=ELF32_R_TYPE(nexttype); if(nexttype!=6) { WARNING_MSG("R_MIPS_HI16 not followed by R_MIIPS_LO16 : %s",MIPS32_REL[nexttype]); } else { int P2=seg.start._32+nextoffset,A2; memRead(P2,1,&A2); int AHL; AHL=(A<<16)+(short)(A2); //printf("A2=%X short A2=%X\n",A2, (short)A2 ); //printf("AHL : %X\n",AHL ); //printf("Total=%X AHL+S=%X, (AHL+S)&0xFFFF=%X, diff=%X\n",((AHL+S-(short)(AHL+S))>>16),AHL+S,(AHL+S)&0xFFFF,AHL+S-(short)AHL+S) ; V=(A & 0xFFFF0000)|( ((AHL+S-(short)(AHL+S))>>16) &0xFFFF); //printf("V= %X,S=%X,A=%X,A2=%X,P=%X,P2=%X, AHL=%X\n",V,S,A,A2,P,P2,AHL); memWrite(P,1,V); } break; case 6: ; int previoustype=rel[i-1].r_info; int previousoffset=rel[i-1].r_offset; FLIP_ENDIANNESS(previoustype); FLIP_ENDIANNESS(previousoffset); previoustype=ELF32_R_TYPE(previoustype); if(previoustype!=5) { WARNING_MSG("R_MIPS_LO16 not preceded by R_MIPS_HI16 : %s",MIPS32_REL[previoustype]); } else { int32_t P2=seg.start._32+previousoffset,A2; memRead(P2,1,&A2); int32_t AHL=(A2<<16)+(short)(A); V=(A&0xFFFF0000)|((short)(AHL+S)&0xFFFF); //printf("V= %X,S=%X,A=%X,P=%X\n",V,S,A,P); memWrite(P,1,V); } break; default: if (type>32) { WARNING_MSG("Unknown type : %d, relocation impossible for element %d",type,i); } else { WARNING_MSG("Unknown type : %s(code : %d), relocation impossible for element %d",MIPS32_REL[type],type,i); } break; } i++; } //------------------------------------------------------ } del_scntab(section_tab); free( rel ); free( reloc_name ); free( ehdr ); }