//------------------------------------------------------------------------------ // Name: dump_code(const State &state) // Desc: //------------------------------------------------------------------------------ void DumpState::dump_code(const State &state) { QSettings settings; const int instructions_to_print = settings.value("DumpState/instructions_after_ip", 6).toInt(); const edb::address_t ip = state.instruction_pointer(); edb::address_t address = ip; for(int i = 0; i < instructions_to_print + 1; ++i) { quint8 buf[edb::Instruction::MAX_SIZE]; int size = sizeof(buf); if(edb::v1::get_instruction_bytes(address, buf, size)) { edb::Instruction insn(buf, size, address, std::nothrow); if(insn.valid()) { std::cout << ((address == ip) ? "> " : " ") << hex_string(address) << ": " << edisassm::to_string(insn) << "\n"; } else { break; } address += insn.size(); } else { break; } } }
//------------------------------------------------------------------------------ // Name: resolve_function_call(QHexView::address_t address) const // Desc: //------------------------------------------------------------------------------ QString CommentServer::resolve_function_call(QHexView::address_t address, bool &ok) const { QString ret; ok = false; // ok, we now want to locate the instruction before this one // so we need to look back a few bytes quint8 buffer[edb::Instruction::MAX_SIZE]; // TODO: portability warning, makes assumptions on the size of a call if(edb::v1::debugger_core->read_bytes(address - CALL_MAX_SIZE, buffer, sizeof(buffer))) { for(int i = (CALL_MAX_SIZE - CALL_MIN_SIZE); i >= 0; --i) { edb::Instruction insn(buffer + i, sizeof(buffer) - i, 0, std::nothrow); if(insn.valid() && insn.type() == edb::Instruction::OP_CALL) { const QString symname = edb::v1::find_function_symbol(address); if(!symname.isEmpty()) { ret = tr("return to %1 <%2>").arg(edb::v1::format_pointer(address)).arg(symname); } else { ret = tr("return to %1").arg(edb::v1::format_pointer(address)); } ok = true; break; } } } return ret; }
int main() { edisassm::FormatOptions options; options.syntax = edisassm::SyntaxIntel; options.capitalization = edisassm::LowerCase; options.smallNumFormat = edisassm::SmallNumAsHex; edisassm::Formatter formatter(options); for(size_t i = 0; i < sizeof(test64_data) / sizeof(test64_data[0]); ++i) { test_data_t *p = &test64_data[i]; std::cout << "performing test #" << i << "..."; insn64_t insn(p->bytes, p->bytes + p->size, 0x00000000, std::nothrow); if(!insn.valid() || formatter.to_string(insn) != p->result) { std::cout << "\n----------\n"; std::cout << "GOT : " << formatter.to_string(insn) << std::endl; std::cout << "EXPECTED : " << p->result << std::endl; std::cout << "FAIL" << std::endl; return -1; } if(insn.size() != p->size) { std::cout << "\n----------\n"; std::cout << formatter.to_byte_string(insn) << " incorrect size" << std::endl; std::cout << "FAIL" << std::endl; return -1; } if(insn.flags() != p->flags) { std::cout << "\n----------\n"; std::cout << formatter.to_byte_string(insn) << " wrong flags" << std::endl; std::cout << "FLAGS: " << insn.flags() << std::endl; std::cout << "FAIL" << std::endl; return -1; } std::cout << " " << formatter.to_byte_string(insn) << " '" << formatter.to_string(insn) << "' " << "OK" << std::endl; } }
void insnCodeGen::generateTrap(codeGen &gen) { instruction insn(BREAK_POINT_INSN); generate(gen,insn); }
void SFXController::_compileList( SFXPlayList* playList ) { mInsns.clear(); const bool isLooping = playList->getDescription()->mIsLooping; // Create a slot list that determines the order the slots will be // played in. U32 slotList[ SFXPlayList::NUM_SLOTS ]; bool isOrderedRandom = false; switch( playList->getRandomMode() ) { case SFXPlayList::RANDOM_OrderedRandom: isOrderedRandom = true; /* fallthrough */ case SFXPlayList::RANDOM_NotRandom: // Generate sequence 1-NUM_SLOTS. for( U32 i = 0; i < SFXPlayList::NUM_SLOTS; ++ i ) slotList[ i ] = i; if( isOrderedRandom ) { // Randomly exchange slots in the list. for( U32 i = 0; i < SFXPlayList::NUM_SLOTS; ++ i ) swap( slotList[ gRandGen.randI( 0, SFXPlayList::NUM_SLOTS - 1 ) ], slotList[ i ] ); } break; case SFXPlayList::RANDOM_StrictRandom: // Randomly generate NUM_SLOTS slot indices. for( U32 i = 0; i < SFXPlayList::NUM_SLOTS; ++ i ) slotList[ i ] = gRandGen.randI( 0, SFXPlayList::NUM_SLOTS - 1 ); break; } // Generate the instruction list. U32 slotCount = 0; for( U32 i = 0; i < SFXPlayList::NUM_SLOTS; ++ i ) { const U32 slotIndex = slotList[ i ]; const U32 slotStartIp = mInsns.size(); SFXState* state = playList->getSlots().mState[ slotIndex ]; // If there's no track in this slot, ignore it. if( !playList->getSlots().mTrack[ slotIndex ] ) continue; // If this is a looped slot and the list is not set to loop // indefinitly on single slots, start a loop. S32 loopStartIp = -1; if( playList->getSlots().mRepeatCount[ slotIndex ] > 0 && ( !isLooping || playList->getLoopMode() != SFXPlayList::LOOP_Single ) ) { Insn insn( OP_LoopBegin, slotIndex, state ); insn.mArg.mLoopCount = playList->getSlots().mRepeatCount[ slotIndex ]; mInsns.push_back( insn ); loopStartIp = mInsns.size(); } // Add in-delay, if any. if( playList->getSlots().mDelayTimeIn.mValue[ slotIndex ] > 0.0f ) { Insn insn( OP_Delay, slotIndex, state ); insn.mArg.mDelayTime.mValue[ 0 ] = playList->getSlots().mDelayTimeIn.mValue[ slotIndex ]; insn.mArg.mDelayTime.mVariance[ 0 ][ 0 ] = playList->getSlots().mDelayTimeIn.mVariance[ slotIndex ][ 0 ]; insn.mArg.mDelayTime.mVariance[ 0 ][ 1 ] = playList->getSlots().mDelayTimeIn.mVariance[ slotIndex ][ 1 ]; mInsns.push_back( insn ); } // Add the in-transition. const SFXPlayList::ETransitionMode transitionIn = playList->getSlots().mTransitionIn[ slotIndex ]; if( transitionIn != SFXPlayList::TRANSITION_None ) { Insn insn( slotIndex, state ); _genTransition( insn, transitionIn ); mInsns.push_back( insn ); } // Add the play instruction. { Insn insn( OP_Play, slotIndex, state ); mInsns.push_back( insn ); } // Add out-delay, if any. if( playList->getSlots().mDelayTimeOut.mValue[ slotIndex ] > 0.0f ) { Insn insn( OP_Delay, slotIndex, state ); insn.mArg.mDelayTime.mValue[ 0 ] = playList->getSlots().mDelayTimeOut.mValue[ slotIndex ]; insn.mArg.mDelayTime.mVariance[ 0 ][ 0 ] = playList->getSlots().mDelayTimeOut.mVariance[ slotIndex ][ 0 ]; insn.mArg.mDelayTime.mVariance[ 0 ][ 1 ] = playList->getSlots().mDelayTimeOut.mVariance[ slotIndex ][ 1 ]; mInsns.push_back( insn ); } // Add the out-transition. const SFXPlayList::ETransitionMode transitionOut = playList->getSlots().mTransitionOut[ slotIndex ]; if( transitionOut != SFXPlayList::TRANSITION_None ) { Insn insn( slotIndex, state ); _genTransition( insn, transitionOut ); mInsns.push_back( insn ); } // Loop, if necessary. if( loopStartIp != -1 ) { Insn insn( OP_LoopEnd, slotIndex, state ); insn.mArg.mJumpIp = loopStartIp; mInsns.push_back( insn ); } // If the list is on repeat-single, unconditionally // loop over the instruction sequence of each slot. if( isLooping && playList->getLoopMode() == SFXPlayList::LOOP_Single ) { Insn insn( OP_Jump, slotIndex, state ); insn.mArg.mJumpIp = slotStartIp; mInsns.push_back( insn ); } // If we have reached the limit of slots to play, // stop generating. slotCount ++; if( playList->getNumSlotsToPlay() == slotCount ) break; } // Set up for execution. mIp = 0; if( !mInsns.empty() ) _initInsn(); }
//------------------------------------------------------------------------------ // Name: do_find() // Desc: //------------------------------------------------------------------------------ void DialogReferences::do_find() { bool ok; const edb::address_t address = edb::v1::string_to_address(ui->txtAddress->text(), ok); const edb::address_t page_size = edb::v1::debugger_core->page_size(); if(ok) { edb::v1::memory_regions().sync(); const QList<MemRegion> regions = edb::v1::memory_regions().regions(); int i = 0; Q_FOREACH(const MemRegion ®ion, regions) { // a short circut for speading things up if(region.accessible() || !ui->chkSkipNoAccess->isChecked()) { const edb::address_t size_in_pages = region.size() / page_size; try { QVector<quint8> pages(size_in_pages * page_size); const quint8 *const pages_end = &pages[0] + size_in_pages * page_size; if(edb::v1::debugger_core->read_pages(region.start, &pages[0], size_in_pages)) { const quint8 *p = &pages[0]; while(p != pages_end) { if(static_cast<std::size_t>(pages_end - p) < sizeof(edb::address_t)) { break; } const edb::address_t addr = p - &pages[0] + region.start; edb::address_t test_address; memcpy(&test_address, p, sizeof(edb::address_t)); if(test_address == address) { QListWidgetItem *const item = new QListWidgetItem(edb::v1::format_pointer(addr)); item->setData(Qt::UserRole, 'D'); ui->listWidget->addItem(item); } edb::Instruction insn(p, pages_end - p, addr, std::nothrow); if(insn.valid()) { switch(insn.type()) { case edb::Instruction::OP_JMP: case edb::Instruction::OP_CALL: case edb::Instruction::OP_JCC: if(insn.operand(0).general_type() == edb::Operand::TYPE_REL) { if(insn.operand(0).relative_target() == address) { QListWidgetItem *const item = new QListWidgetItem(edb::v1::format_pointer(addr)); item->setData(Qt::UserRole, 'C'); ui->listWidget->addItem(item); } } break; default: break; } } emit updateProgress(util::percentage(i, regions.size(), p - &pages[0], region.size())); ++p; } } } catch(const std::bad_alloc &) { QMessageBox::information( 0, tr("Memroy Allocation Error"), tr("Unable to satisfy memory allocation request for requested region.")); } } else { emit updateProgress(util::percentage(i, regions.size())); } ++i; } } }
main () /*****/ /* main program, corresponds to procedures */ /* Main and Proc_0 in the Ada version */ { One_Fifty Int_1_Loc; REG One_Fifty Int_2_Loc; One_Fifty Int_3_Loc; REG char Ch_Index; Enumeration Enum_Loc; Str_30 Str_1_Loc; Str_30 Str_2_Loc; REG int Run_Index; REG int Number_Of_Runs; /* Initializations */ Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type)); Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type)); Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; Ptr_Glob->Discr = Ident_1; Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; Ptr_Glob->variant.var_1.Int_Comp = 40; strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING"); strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); Arr_2_Glob [8][7] = 10; /* Was missing in published program. Without this statement, */ /* Arr_2_Glob [8][7] would have an undefined value. */ /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ /* overflow may occur for this array element. */ printf ("\n"); printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n"); printf ("\n"); if (Reg) { printf ("Program compiled with 'register' attribute\n"); printf ("\n"); } else { printf ("Program compiled without 'register' attribute\n"); printf ("\n"); } printf ("Please give the number of runs through the benchmark: "); { int n; scanf ("%d", &n); Number_Of_Runs = n; } printf ("\n"); printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs); /***************/ /* Start timer */ /***************/ #ifdef TIMES times (&time_info); Begin_Time = (long) time_info.tms_utime; #endif #ifdef TIME Begin_Time = time ( (long *) 0); #ifdef RISCV Begin_Insn = insn ( (long *) 0); #endif #endif for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { Proc_5(); Proc_4(); /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ Int_1_Loc = 2; Int_2_Loc = 3; strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); Enum_Loc = Ident_2; Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc); /* Bool_Glob == 1 */ while (Int_1_Loc < Int_2_Loc) /* loop body executed once */ { Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; /* Int_3_Loc == 7 */ Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc); /* Int_3_Loc == 7 */ Int_1_Loc += 1; } /* while */ /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); /* Int_Glob == 5 */ Proc_1 (Ptr_Glob); for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) /* loop body executed twice */ { if (Enum_Loc == Func_1 (Ch_Index, 'C')) /* then, not executed */ { Proc_6 (Ident_1, &Enum_Loc); strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); Int_2_Loc = Run_Index; Int_Glob = Run_Index; } } /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ Int_2_Loc = Int_2_Loc * Int_1_Loc; Int_1_Loc = Int_2_Loc / Int_3_Loc; Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ Proc_2 (&Int_1_Loc); /* Int_1_Loc == 5 */ } /* loop "for Run_Index" */ /**************/ /* Stop timer */ /**************/ #ifdef TIMES times (&time_info); End_Time = (long) time_info.tms_utime; #endif #ifdef TIME End_Time = time ( (long *) 0); #ifdef RISCV End_Insn = insn ( (long *) 0); #endif #endif printf ("Execution ends\n"); printf ("\n"); printf ("Final values of the variables used in the benchmark:\n"); printf ("\n"); printf ("Int_Glob: %d\n", Int_Glob); printf (" should be: %d\n", 5); printf ("Bool_Glob: %d\n", Bool_Glob); printf (" should be: %d\n", 1); printf ("Ch_1_Glob: %c\n", Ch_1_Glob); printf (" should be: %c\n", 'A'); printf ("Ch_2_Glob: %c\n", Ch_2_Glob); printf (" should be: %c\n", 'B'); printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]); printf (" should be: %d\n", 7); printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); printf (" should be: Number_Of_Runs + 10\n"); printf ("Ptr_Glob->\n"); printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp); printf (" should be: (implementation-dependent)\n"); printf (" Discr: %d\n", Ptr_Glob->Discr); printf (" should be: %d\n", 0); printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp); printf (" should be: %d\n", 2); printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp); printf (" should be: %d\n", 17); printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp); printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); printf ("Next_Ptr_Glob->\n"); printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp); printf (" should be: (implementation-dependent), same as above\n"); printf (" Discr: %d\n", Next_Ptr_Glob->Discr); printf (" should be: %d\n", 0); printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp); printf (" should be: %d\n", 1); printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp); printf (" should be: %d\n", 18); printf (" Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp); printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); printf ("Int_1_Loc: %d\n", Int_1_Loc); printf (" should be: %d\n", 5); printf ("Int_2_Loc: %d\n", Int_2_Loc); printf (" should be: %d\n", 13); printf ("Int_3_Loc: %d\n", Int_3_Loc); printf (" should be: %d\n", 7); printf ("Enum_Loc: %d\n", Enum_Loc); printf (" should be: %d\n", 1); printf ("Str_1_Loc: %s\n", Str_1_Loc); printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); printf ("Str_2_Loc: %s\n", Str_2_Loc); printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); printf ("\n"); User_Time = End_Time - Begin_Time; #ifdef RISCV User_Insn = End_Insn - Begin_Insn; printf("Number_Of_Runs: %d\n", Number_Of_Runs); printf("User_Time: %d cycles, %d insn\n", User_Time, User_Insn); long runs=Number_Of_Runs*100; // printf("time %d %d\n",csr_timeh(),csr_time()); printf("DMIPS: %d\n",runs/(User_Time/1000/1000)/1757); /* int Cycles_Per_Instruction_x1000 = (1000 * User_Time) / User_Insn; printf("Cycles_Per_Instruction: %d.%d%d%d\n", Cycles_Per_Instruction_x1000 / 1000, (Cycles_Per_Instruction_x1000 / 100) % 10, (Cycles_Per_Instruction_x1000 / 10) % 10, (Cycles_Per_Instruction_x1000 / 1) % 10); int Dhrystones_Per_Second_Per_MHz = (Number_Of_Runs * 1000000) / User_Time; printf("Dhrystones_Per_Second_Per_MHz: %d\n", Dhrystones_Per_Second_Per_MHz); int DMIPS_Per_MHz_x1000 = (1000 * Dhrystones_Per_Second_Per_MHz) / 1757; printf("DMIPS_Per_MHz: %d.%d%d%d\n", DMIPS_Per_MHz_x1000 / 1000, (DMIPS_Per_MHz_x1000 / 100) % 10, (DMIPS_Per_MHz_x1000 / 10) % 10, (DMIPS_Per_MHz_x1000 / 1) % 10); */ #else if (User_Time < Too_Small_Time) { printf ("Measured time too small to obtain meaningful results\n"); printf ("Please increase number of runs\n"); printf ("\n"); } else { #ifdef TIME Microseconds = (float) User_Time * Mic_secs_Per_Second / (float) Number_Of_Runs; Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time; #else Microseconds = (float) User_Time * Mic_secs_Per_Second / ((float) HZ * ((float) Number_Of_Runs)); Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs) / (float) User_Time; #endif printf ("Microseconds for one run through Dhrystone: "); printf ("%6.1f \n", Microseconds); printf ("Dhrystones per Second: "); printf ("%6.1f \n", Dhrystones_Per_Second); printf ("\n"); } #endif }