pcNode* IntervalMap::getPC(pcNode* leaf, int index, int& count) { if (leaf== NULL) { return NULL; } if (leaf->left != NULL) { pcNode* tmp = getPC(leaf->left, index, count); if(tmp) { return tmp; } } if(count == index) { return leaf; } ++count; if (leaf->right != NULL) { pcNode* tmp = getPC(leaf->right, index, count); if(tmp) { return tmp; } } return NULL; }
void PIC::runCode() { int pc=getPC(); //CodeModel* codeModel=this->parent()->findChild<CodeModel *>(QString("codeModel")); while( pc< m_CmdList.size() && (!stop || singleStep) /* && codeModel->code[codeModel->findPCIdx(pc)][0].isEmpty()*/) { decodeCmd(pc); pc=getPC(); if(singleStep==true) qDebug()<<"---------------------------------------------------------------------------Single Step"; singleStep=false; int zeile=codeModel->findPCIdx(pc); if(!codeModel->code[zeile][0].isEmpty()) { qDebug() << "Breakpoint bei Programmzeile : "<<pc; stop=true; emit breakPoint(); } } }
void ScriptFunctions::jumpTo(Object *object, Area *area, float x, float y, float z) { // Sanity check if (!object->getArea() || !area) { warning("ScriptFunctions::jumpTo(): No area?!? (%d, %d)", object->getArea() != 0, area != 0); return; } GfxMan.lockFrame(); // Are we moving between areas? if (object->getArea() != area) { const Common::UString &areaFrom = object->getArea()->getResRef(); const Common::UString &areaTo = area->getResRef(); warning("TODO: ScriptFunctions::jumpTo(): Moving from \"%s\" to \"%s\"", areaFrom.c_str(), areaTo.c_str()); Object *pc = convertObject(getPC()); if (pc) { const Common::UString &pcArea = pc->getArea()->getResRef(); if (areaFrom == pcArea) { // Moving away from the currently visible area. object->hide(); object->unloadModel(); } else if (areaTo == pcArea) { // Moving into the currently visible area. object->loadModel(); object->show(); } } object->setArea(area); } // Update position object->setPosition(x, y, z); GfxMan.unlockFrame(); if (object == getPC() && _module) _module->movedPC(); }
/** * Initialize the system * * @param none * @return none * * @brief Setup the microcontroller system. * Initialize the System. */ void SystemInit (void) { #if defined(CORE_M4) || defined(CORE_M3) // Enable VTOR register to point to vector table SCB->VTOR = getPC() & 0xFFFF0000; #endif }
/* * generates branch opcodes * * opcode : opcode of the branch (for instance 0x8f for BR7) * str : operand string */ static void generate_branch(unsigned char opcode, char *str) { unsigned long target_adr; long disp; programlabel(); /* get target address */ if (parse_value(str, &target_adr)) { /* unresolved target address, reserve space */ emit_opcode2(0, 0); return; } /* calculate displacement */ if (isPCKnown()) { disp = target_adr - getPC() - 1; if (disp > 127 || disp < -128) { char buf[64]; sprintf(buf, "%d", (int)disp); asmerr(ERROR_BRANCH_OUT_OF_RANGE, false, buf); } } else { /* unknown pc, will be (hopefully) resolved in future passes */ disp = 0; } emit_opcode2(opcode, disp & 255); }
static UInt8 read(RomMapperKonamiWordPro* rm, UInt16 address) { #if 0 if (address < getPC() - 2 || address > getPC() + 4) { printf("R %.4x :\n", address); } if (rm->control == 0xdb && address < 0x8000) { return 0x00; } #endif if (address < 0x4000 || address >= 0xc000) { return 0xc0; } return rm->romData[address - 0x4000]; }
/** * Initialize the system * * @param none * @return none * * @brief Setup the microcontroller system. * Initialize the System. */ void SystemInit (void) { #ifdef KEIL #if defined(CORE_M4) || defined(CORE_M3) // Enable VTOR register to point to vector table SCB->VTOR = getPC() & 0xFFF00000; #else // code red // CodeRed startup code will modify VTOR register to match // when code has been linked to run from. // Check whether we are running from external flash if (SCB->VTOR == 0x1C000000) /*Enable Buffer for External Flash*/ LPC_EMC->STATICCONFIG0 |= 1<<19; // Call clock initialisation code CGU_Init(); #endif /*Enable Buffer for External Flash*/ LPC_EMC->STATICCONFIG0 |= 1<<19; #endif }
/** * Initialize the system * * @param none * @return none * * @brief Setup the microcontroller system. * Initialize the System. */ void SystemInit (void) { SystemCoreClock = __IRC; // Enable VTOR register to point to vector table SCB->VTOR = getPC() & 0xFF000000; /*Enable Buffer for External Flash*/ LPC_EMC->STATICCONFIG0 |= 1<<19; //*(unsigned int*)0x40005200 |= 1<<19; }
void System6502::Execute(uint8_t cell) { auto oldCycles = getCycles(); CheckPoll(); // XXXX Fetch byte has already incremented PC. auto executingAddress = (uint16_t)(getPC() - 1); AddressEventArgs e(executingAddress, cell); ExecutingInstruction.fire(e); __super::Execute(cell); ExecutedInstruction.fire(e); auto deltaCycles = getCycles() - oldCycles; intervalCycles += deltaCycles; }
static void signalHandler_npe_so(int signum, siginfo_t* info, void* context) { // rvmGetEnv() uses pthread_getspecific() which isn't listed as // async-signal-safe. Others (e.g. mono) do this too so we assume it is safe // in practice. Env* env = rvmGetEnv(); if (env && rvmIsNonNativeFrame(env)) { // We now know the fault occurred in non-native code and not in our // native code or in any non-async-signal-safe system function. It // should be safe to do things here that would normally be unsafe to do // in a signal handler. void* faultAddr = info->si_addr; void* stackAddr = env->currentThread->stackAddr; Class* exClass = NULL; if (faultAddr < stackAddr && faultAddr >= (void*) (stackAddr - THREAD_STACK_GUARD_SIZE)) { // StackOverflowError exClass = java_lang_StackOverflowError; } else { // At least on Linux x86 it seems like si_addr isn't always 0x0 even // if a read of address 0x0 triggered SIGSEGV so we assume // everything that isn't a stack overflow is a read of address 0x0 // and throw NullPointerException. exClass = java_lang_NullPointerException; } if (exClass) { Object* throwable = rvmAllocateObject(env, exClass); if (!throwable) { throwable = rvmExceptionClear(env); } Frame fakeFrame; fakeFrame.prev = (Frame*) getFramePointer((ucontext_t*) context); fakeFrame.returnAddress = getPC((ucontext_t*) context); CallStack* callStack = captureCallStackFromFrame(env, &fakeFrame); rvmSetLongInstanceFieldValue(env, throwable, stackStateField, PTR_TO_LONG(callStack)); rvmRaiseException(env, throwable); } } struct sigaction sa; sa.sa_flags = 0; sa.sa_handler = SIG_DFL; sigaction(signum, &sa, NULL); kill(0, signum); }
static void signalHandler_npe_so(int signum, siginfo_t* info, void* context) { // SIGSEGV/SIGBUS are synchronous signals so we shouldn't have to worry about only calling // async-signal-safe functions here. Env* env = rvmGetEnv(); if (env && rvmIsNonNativeFrame(env)) { // We now know the fault occurred in non-native code. void* faultAddr = info->si_addr; void* stackAddr = env->currentThread->stackAddr; Class* exClass = NULL; if (faultAddr < stackAddr && faultAddr >= (void*) (stackAddr - THREAD_STACK_GUARD_SIZE)) { // StackOverflowError exClass = java_lang_StackOverflowError; } else { // At least on Linux x86 it seems like si_addr isn't always 0x0 even // if a read of address 0x0 triggered SIGSEGV so we assume // everything that isn't a stack overflow is a read of address 0x0 // and throw NullPointerException. exClass = java_lang_NullPointerException; } if (exClass) { Frame fakeFrame; fakeFrame.prev = (Frame*) getFramePointer((ucontext_t*) context); fakeFrame.returnAddress = getPC((ucontext_t*) context); Object* throwable = NULL; CallStack* callStack = captureCallStackFromFrame(env, &fakeFrame); if (callStack) { throwable = rvmAllocateObject(env, exClass); if (throwable) { rvmCallVoidClassMethod(env, exClass, throwableInitMethod, throwable, PTR_TO_LONG(callStack)); if (rvmExceptionCheck(env)) { throwable = NULL; } } } if (!throwable) { throwable = rvmExceptionClear(env); } rvmRaiseException(env, throwable); // Never returns! } } }
static void signalHandler_dump_thread(int signum, siginfo_t* info, void* context) { Env* env = rvmGetEnv(); if (env) { Frame fakeFrame; if (rvmIsNonNativeFrame(env)) { // Signalled in non-native code fakeFrame.prev = (Frame*) getFramePointer((ucontext_t*) context); fakeFrame.returnAddress = getPC((ucontext_t*) context); } else { // The thread was signalled while in native code, possibly a system // function. We cannot trust that this code uses proper frame // pointers so we cannot use the context's frame pointer. The top // most GatewayFrame in env was pushed when native code was entered. // Use its frame as frame pointer. fakeFrame = *(Frame*) env->gatewayFrames->frameAddress; } captureCallStack(env, &fakeFrame, dumpThreadStackTraceCallStack, MAX_CALL_STACK_LENGTH); } sem_post(&dumpThreadStackTraceCallSemaphore); }
/* * BPatch_frame::findFunction() * * Returns the function associated with the stack frame, or NULL if there is * none. */ BPatch_function *BPatch_frame::findFunctionInt() { if (!getPC()) return NULL; return thread->findFunctionByAddr(getPC()); }
Frame Frame::getCallerFrame() { int status = 0; assert( lwp_->status() != running ); /* Initialize the unwinder. */ if( getProc()->unwindAddressSpace == NULL ) { // /* DEBUG */ fprintf( stderr, "Creating unwind address space for process pid %d\n", proc->getPid() ); getProc()->unwindAddressSpace = (unw_addr_space *)getDBI()->createUnwindAddressSpace( & _UPT_accessors, 0 ); assert( getProc()->unwindAddressSpace != NULL ); } /* Initialize the thread-specific accessors. */ unsigned lid = lwp_->get_lwp_id(); if( ! getProc()->unwindProcessArgs.defines( lid ) ) { getProc()->unwindProcessArgs[ lid ] = getDBI()->UPTcreate( lid ); assert( getProc()->unwindProcessArgs[ lid ] != NULL ); } /* Generating the synthetic frame above the instrumentation is in cross-platform code. */ Frame currentFrame; if( ! this->hasValidCursor ) { /* DEBUG */ fprintf( stderr, "%s[%d]: no valid cursor in frame, regenerating.\n", __FILE__, __LINE__ ); /* Allocate an unwindCursor for this stackwalk. */ unw_cursor_t * unwindCursor = (unw_cursor_t *)malloc( sizeof( unw_cursor_t ) ); assert( unwindCursor != NULL ); /* Initialize it to the active frame. */ status = getDBI()->initFrame( unwindCursor, getProc()->unwindAddressSpace, getProc()->unwindProcessArgs[ lid ] ); assert( status == 0 ); /* Unwind to the current frame. */ currentFrame = createFrameFromUnwindCursor( unwindCursor, lwp_, lid ); while( ! currentFrame.isUppermost() ) { if( getFP() == currentFrame.getFP() && getSP() == currentFrame.getSP() && getPC() == currentFrame.getPC() ) { currentFrame = createFrameFromUnwindCursor( unwindCursor, lwp_, lid ); break; } /* end if we've found this frame */ currentFrame = createFrameFromUnwindCursor( unwindCursor, lwp_, lid ); } /* createFrameFromUnwindCursor() copies the unwind cursor into the Frame it returns. */ free( unwindCursor ); } /* end if this frame was copied before being unwound. */ else { /* Don't try to walk off the end of the stack. */ assert( ! this->uppermost_ ); /* Allocate an unwindCursor for this stackwalk. */ unw_cursor_t * unwindCursor = (unw_cursor_t *)malloc( sizeof( unw_cursor_t ) ); assert( unwindCursor != NULL ); /* Initialize it to this frame. */ * unwindCursor = this->unwindCursor; /* Unwind the cursor to the caller's frame. */ int status = getDBI()->stepFrameUp( unwindCursor ); /* We unwound from this frame once before to get its FP. */ assert( status > 0 ); /* Create a Frame from the unwound cursor. */ currentFrame = createFrameFromUnwindCursor( unwindCursor, lwp_, lid ); /* createFrameFromUnwindCursor() copies the unwind cursor into the Frame it returns. */ free( unwindCursor ); } /* end if this frame was _not_ copied before being unwound. */ /* Make sure we made progress. */ if( getFP() == currentFrame.getFP() && getSP() == currentFrame.getSP() && getPC() == currentFrame.getPC() ) { /* This will forcibly terminate the stack walk. */ currentFrame.fp_ = (Address)NULL; currentFrame.pc_ = (Address)NULL; currentFrame.sp_ = (Address)NULL; currentFrame.uppermost_ = false; fprintf( stderr, "%s[%d]: detected duplicate stack frame, aborting stack with zeroed frame.\n", __FILE__, __LINE__ ); } if( thread_ != NULL ) { currentFrame.thread_ = thread_; } /* Return the result. */ return currentFrame; } /* end getCallerFrame() */
//************************************************************************** void control_inst_t::Retire( abstract_pc_t *a ) { #ifdef DEBUG_DYNAMIC_RET DEBUG_OUT("control_inst_t:Retire BEGIN, proc[%d]\n",m_proc); #endif #ifdef DEBUG_DYNAMIC char buf[128]; s->printDisassemble(buf); DEBUG_OUT("\tcontrol_inst_t::Retire BEGIN %s seq_num[ %lld ] cycle[ %lld ] fetchPC[ 0x%llx ] fetchNPC[ 0x%llx ] PredictedPC[ 0x%llx ] PredictedNPC[ 0x%llx ]\n", buf, seq_num, m_pseq->getLocalCycle(), m_actual.pc, m_actual.npc, m_predicted.pc, m_predicted.npc); for(int i=0; i < SI_MAX_DEST; ++i){ reg_id_t & dest = getDestReg(i); reg_id_t & tofree = getToFreeReg(i); if( !dest.isZero() ){ DEBUG_OUT("\tDest[ %d ] Vanilla[ %d ] Physical[ %d ] Arf[ %s ] ToFree: Vanilla[ %d ] physical[ %d ] Arf[ %s ]\n", i, dest.getVanilla(), dest.getPhysical(), dest.rid_type_menomic( dest.getRtype() ), tofree.getVanilla(), tofree.getPhysical(), tofree.rid_type_menomic( tofree.getRtype() ) ); } } #endif ASSERT( !getEvent( EVENT_FINALIZED ) ); STAT_INC( m_pseq->m_stat_control_retired[m_proc] ); // Need this bc we place fetch barrier on retry instead of stxa: if ( (s->getOpcode() == i_retry) || (s->getFlag( SI_FETCH_BARRIER)) ) { // if we have a branch misprediction, we already unstalled the fetch in partialSquash(): if(getEvent(EVENT_BRANCH_MISPREDICT) == false){ m_pseq->unstallFetch(m_proc); } } STAT_INC( m_pseq->m_branch_seen_stat[s->getBranchType()][2] ); STAT_INC( m_pseq->m_branch_seen_stat[s->getBranchType()][m_priv? 1:0] ); // record when execution takes place m_event_times[EVENT_TIME_RETIRE] = m_pseq->getLocalCycle() - m_fetch_cycle; // update dynamic branch prediction (predicated) instruction statistics static_inst_t *s_instr = getStaticInst(); if (s_instr->getType() == DYN_CONTROL) { uint32 inst; int op2; int pred; switch (s_instr->getBranchType()) { case BRANCH_COND: // conditional branch STAT_INC( m_pseq->m_nonpred_retire_count_stat[m_proc] ); break; case BRANCH_PCOND: // predictated conditional inst = s_instr->getInst(); op2 = maskBits32( inst, 22, 24 ); pred = maskBits32( inst, 19, 19 ); if ( op2 == 3 ) { // integer register w/ predication STAT_INC( m_pseq->m_pred_reg_retire_count_stat[m_proc] ); if (pred) { STAT_INC( m_pseq->m_pred_reg_retire_taken_stat[m_proc] ); } else { STAT_INC( m_pseq->m_pred_reg_retire_nottaken_stat[m_proc] ); } } else { STAT_INC( m_pseq->m_pred_retire_count_stat[m_proc] ); if (pred) { STAT_INC( m_pseq->m_pred_retire_count_taken_stat[m_proc] ); } else { STAT_INC( m_pseq->m_pred_retire_count_nottaken_stat[m_proc] ); } } if (pred == true && m_isTaken == false || pred == false && m_isTaken == true) { STAT_INC( m_pseq->m_branch_wrong_static_stat ); } break; default: ; // ignore non-predictated branches } } #ifdef DEBUG_RETIRE m_pseq->out_info("## Control Retire Stage\n"); printDetail(); m_pseq->printPC( &m_actual ); #endif bool mispredict = (m_events & EVENT_BRANCH_MISPREDICT); if (mispredict) { // incorrect branch prediction STAT_INC( m_pseq->m_branch_wrong_stat[s->getBranchType()][2] ); STAT_INC( m_pseq->m_branch_wrong_stat[s->getBranchType()][m_priv? 1:0] ); //train BRANCH_PRIV predictor if( (s->getBranchType() == BRANCH_PRIV) ){ if (m_predicted.cwp != m_actual.cwp) { m_pseq->getRegstatePred()->update(getVPC(), CONTROL_CWP, m_actual.cwp, m_predicted.cwp); } if (m_predicted.tl != m_actual.tl) { m_pseq->getRegstatePred()->update(getVPC(), CONTROL_TL, m_actual.tl, m_predicted.tl); } if (m_predicted.pstate != m_actual.pstate) { m_pseq->getRegstatePred()->update(getVPC(), CONTROL_PSTATE, m_actual.pstate, m_predicted.pstate); } } //****************************** print out mispredicted inst ***************** if(s->getBranchType() == BRANCH_PRIV){ char buf[128]; s->printDisassemble( buf ); bool imm = s->getFlag(SI_ISIMMEDIATE); #if 0 if(m_predicted.pc != m_actual.pc){ m_pseq->out_info("CONTROLOP: PC mispredict: predicted[ 0x%llx ] actual[ 0x%llx ] type=%s seqnum[ %lld ] VPC[ 0x%llx ] PC[ 0x%llx ] fetched[ %lld ] executed[ %lld ] correctPC[ 0x%llx ] imm[ %d ] %s\n", m_predicted.pc, m_actual.pc, pstate_t::branch_type_menomic[s->getBranchType()], seq_num, getVPC(), getPC(), m_fetch_cycle, m_event_times[EVENT_TIME_EXECUTE] + m_fetch_cycle, m_actual.pc, imm, buf); } #endif #if 0 if(m_predicted.npc != m_actual.npc){ m_pseq->out_info("CONTROLOP: NPC mispredict: predicted[ 0x%llx ] actual[ 0x%llx ] type=%s seqnum[ %lld ] VPC[ 0x%llx ] PC[ 0x%llx ] fetched[ %lld ] executed[ %lld ] correctPC[ 0x%llx ] imm[ %d ] %s\n", m_predicted.npc, m_actual.npc, pstate_t::branch_type_menomic[s->getBranchType()], seq_num, getVPC(), getPC(), m_fetch_cycle, m_event_times[EVENT_TIME_EXECUTE] + m_fetch_cycle, m_actual.pc, imm, buf); } #endif #if 0 if (m_predicted.cwp != m_actual.cwp) { m_pseq->out_info("CONTROLOP: CWP mispredict: predicted[ %d ] actual[ %d ] type=%s seqnum[ %lld ] VPC[ 0x%llx ] PC[ 0x%llx ] fetched[ %lld ] executed[ %lld ] correctPC[ 0x%llx ] imm[ %d ] %s\n", m_predicted.cwp, m_actual.cwp, pstate_t::branch_type_menomic[s->getBranchType()], seq_num, getVPC(), getPC(), m_fetch_cycle, m_event_times[EVENT_TIME_EXECUTE] + m_fetch_cycle, m_actual.pc, imm, buf); } #endif #if 0 if (m_predicted.tl != m_actual.tl) { m_pseq->out_info("CONTROLOP: TL mispredict: predicted[ %d ] actual[ %d ] type=%s seqnum[ %lld ] VPC[ 0x%llx ] PC[ 0x%llx ] fetched[ %lld ] executed[ %lld ] correctPC[ 0x%llx ] imm[ %d ] %s\n", m_predicted.tl, m_actual.tl, pstate_t::branch_type_menomic[s->getBranchType()], seq_num, getVPC(), getPC(), m_fetch_cycle, m_event_times[EVENT_TIME_EXECUTE] + m_fetch_cycle, m_actual.pc, imm, buf); } #endif #if 0 if (m_predicted.pstate != m_actual.pstate) { m_pseq->out_info("CONTROLOP: PSTATE mispredict: predicted[ 0x%0x ] actual[ 0x%0x ] type=%s seqnum[ %lld ] VPC[ 0x%llx ] PC[ 0x%llx ] fetched[ %lld ] executed[ %lld ] correctPC[ 0x%llx ] imm[ %d ] %s\n", m_predicted.pstate, m_actual.pstate, pstate_t::branch_type_menomic[s->getBranchType()], seq_num, getVPC(), getPC(), m_fetch_cycle, m_event_times[EVENT_TIME_EXECUTE] + m_fetch_cycle, m_actual.pc, imm, buf); } #endif } //************************************************************************** // train ras's exception table if (ras_t::EXCEPTION_TABLE && s->getBranchType() == BRANCH_RETURN) { my_addr_t tos; ras_t *ras = m_pseq->getRAS(m_proc); ras->getTop(&(m_pred_state.ras_state), &tos); if(tos == m_actual.npc) { ras->markException(m_predicted.npc); // update RAS state ras->pop(&(m_pred_state.ras_state)); m_pseq->setSpecBPS(m_pred_state); if (ras_t::DEBUG_RAS) m_pseq->out_info("*********** DEBUG_RAS ***********\n"); } else { ras->unmarkException(m_actual.npc); } } // XU DEBUG if (0 && s->getBranchType() == BRANCH_RETURN) { m_pseq->out_info("**** %c:mispred 0x%llx, pred 0x%llx target 0x%llx, " "next %d TOS %d\n", m_priv? 'K':'U', getVPC(), m_predicted.npc, m_actual.npc, m_pred_state.ras_state.next_free, m_pred_state.ras_state.TOS); // print 5 instr after mis-pred generic_address_t addr = m_predicted.npc-8; for(uint32 i = 0; i < 5; i++, addr+=4) { //get the actual seq number for the pointer to m_state: int32 seq_num = m_pseq->getID() / CONFIG_LOGICAL_PER_PHY_PROC; assert(seq_num >= 0 && seq_num < system_t::inst->m_numSMTProcs); tuple_int_string_t *disassemble = SIM_disassemble((processor_t *) system_t::inst->m_state[seq_num]->getSimicsProcessor(m_proc), addr, /* logical */ 1); if (disassemble) m_pseq->out_info(" %s\n", disassemble->string); } } } else { // correct or no prediction STAT_INC( m_pseq->m_branch_right_stat[s->getBranchType()][2] ); STAT_INC( m_pseq->m_branch_right_stat[s->getBranchType()][m_priv? 1:0] ); } /* update branch predictor tables at retirement */ if (s->getBranchType() == BRANCH_COND || s->getBranchType() == BRANCH_PCOND) { m_pseq->getDirectBP()->Update(getVPC(), (m_pseq->getArchBPS()->cond_state), s->getFlag( SI_STATICPRED ), m_isTaken, m_proc); } else if (s->getBranchType() == BRANCH_INDIRECT || (s->getBranchType() == BRANCH_CALL && s->getOpcode() != i_call) ) { // m_actual.npc is the indirect target m_pseq->getIndirectBP()->Update( getVPC(), &(m_pseq->getArchBPS()->indirect_state), m_actual.npc, m_proc ); } m_pseq->setArchBPS(m_pred_state); // no need to update call&return, since we used checkpointed RAS // no update on traps right now SetStage(RETIRE_STAGE); /* retire any register overwritten by link register */ retireRegisters(); #if 0 if(m_actual.pc == (my_addr_t) -1){ char buf[128]; s->printDisassemble(buf); ERROR_OUT("\tcontrol_inst_t::Retire %s seq_num[ %lld ] cycle[ %lld ] fetchPC[ 0x%llx ] fetchNPC[ 0x%llx ] fetched[ %lld ] executed[ %lld ]\n", buf, seq_num, m_pseq->getLocalCycle(), m_actual.pc, m_actual.npc, m_fetch_cycle, m_fetch_cycle+getEventTime(EVENT_TIME_EXECUTE_DONE)); //print out writer cycle for(int i=0; i < SI_MAX_SOURCE; ++i){ reg_id_t & source = getSourceReg(i); if(!source.isZero()){ uint64 written_cycle = source.getARF()->getWrittenCycle( source, m_proc ); uint64 writer_seqnum = source.getARF()->getWriterSeqnum( source, m_proc ); ERROR_OUT("\tSource[ %d ] Vanilla[ %d ] Physical[ %d ] Arf[ %s ] written_cycle[ %lld ] writer_seqnum[ %lld ]\n", i, source.getVanilla(), source.getPhysical(), source.rid_type_menomic( source.getRtype() ), written_cycle, writer_seqnum); } } } #endif ASSERT( m_actual.pc != (my_addr_t) -1 ); /* return pc, npc pair which are the results of execution */ a->pc = m_actual.pc; a->npc = m_actual.npc; markEvent( EVENT_FINALIZED ); #ifdef DEBUG_DYNAMIC_RET DEBUG_OUT("control_inst_t:Retire END, proc[%d]\n",m_proc); #endif }
pcNode* IntervalMap::getPCfromInterval(int interval, int index) { node* intvl = getInterval(map, interval); int count = 0; return getPC(intvl->tracks, index, count); }
int runCPUCycle(){ //Both used in DAA char correction; char beforeA; unsigned short beforeHL; char temp; opcodeInstruction instruction; unsigned char currentInterrupts; if(delayCyclesLeft!=0){ delayCyclesLeft--; return 0; } //Check for Interrupts if(IME == 1){ currentInterrupts = (*interruptFlags)&interruptER; if(currentInterrupts&INT_VBLANK){ writeSP(getSP()-2); writeShortToMem(getSP(),getPC()); writePC(0x40); IME = 0; *interruptFlags = (*interruptFlags)& ~(INT_VBLANK); } else if(currentInterrupts&INT_LCD){ writeSP(getSP()-2); writeShortToMem(getSP(),getPC()); writePC(0x48); IME = 0; *interruptFlags = (*interruptFlags)& ~(INT_LCD); } else if(currentInterrupts&INT_TIMER){ writeSP(getSP()-2); writeShortToMem(getSP(),getPC()); writePC(0x50); IME = 0; *interruptFlags = (*interruptFlags)& ~(INT_TIMER); } else if(currentInterrupts&INT_SERIAL){ writeSP(getSP()-2); writeShortToMem(getSP(),getPC()); writePC(0x58); IME = 0; *interruptFlags = (*interruptFlags)& ~(INT_SERIAL); } else if(currentInterrupts&INT_JOYPAD){ writeSP(getSP()-2); writeShortToMem(getSP(),getPC()); writePC(0x60); IME = 0; *interruptFlags = (*interruptFlags)& ~(INT_JOYPAD); } } delayCyclesLeft = instructionClockCycles[readCharFromMem(getPC())]; //Will be overwritten is instruction is CB if(delayCyclesLeft == -1){ delayCyclesLeft = 20; //My not need any actual implementation } //Add the instruction to the list of called instructions PCRecallAdd(PCRecallHead,getPC()); //Get the instruction from the jump table if((readCharFromMem(getPC())&0xFF)==0xCB){ instruction = opcodes[readCharFromMem(getPC()+1)+0x100]; writePC(getPC()+1); incrementInstructionCount(readCharFromMem(getPC())+0x100); delayCyclesLeft = CBInstructionClockCycles[readCharFromMem(getPC())]; //printf("Using CB instruction at PC: %hX\n",getPC()); } else { if((readCharFromMem(getPC())&0xFF)==0x10){ return 0x10; } //printf("Instruction Index: %hhX PC: %hX\n",readCharFromMem(getPC()),getPC()); incrementInstructionCount(readCharFromMem(getPC())); instruction = opcodes[readCharFromMem(getPC())]; } //Call the instruction if(instruction!=0){ instruction(); } else { printf("Unknown Instruction: %hhX at PC: %hhX\n",readCharFromMem(getPC()),getPC()); return 0x10; //Stop writePC(getPC()+1); } return 0; }
str MDBStkTrace(Client cntxt, MalBlkPtr m, MalStkPtr s, InstrPtr p) { BAT *b, *bn; str msg; char *buf; bat *ret = getArgReference_bat(s, p, 0); bat *ret2 = getArgReference_bat(s, p, 1); int k = 0; size_t len,l; b = BATnew(TYPE_void, TYPE_int, 256, TRANSIENT); if ( b== NULL) throw(MAL, "mdb.getStackTrace", MAL_MALLOC_FAIL); bn = BATnew(TYPE_void, TYPE_str, 256, TRANSIENT); if ( bn== NULL) { BBPreclaim(b); throw(MAL, "mdb.getStackTrace", MAL_MALLOC_FAIL); } BATseqbase(b,0); BATseqbase(bn,0); (void) cntxt; msg = instruction2str(s->blk, s, p, LIST_MAL_DEBUG); len = strlen(msg); buf = (char*) GDKmalloc(len +1024); if ( buf == NULL){ GDKfree(msg); throw(MAL,"mdb.setTrace",MAL_MALLOC_FAIL); } snprintf(buf,len+1024,"%s at %s.%s[%d]", msg, getModuleId(getInstrPtr(m,0)), getFunctionId(getInstrPtr(m,0)), getPC(m, p)); BUNappend(b, &k, FALSE); BUNappend(bn, buf, FALSE); GDKfree(msg); for (s = s->up, k++; s != NULL; s = s->up, k++) { msg = instruction2str(s->blk, s, getInstrPtr(s->blk,s->pcup),LIST_MAL_DEBUG); l = strlen(msg); if (l>len){ GDKfree(buf); len=l; buf = (char*) GDKmalloc(len +1024); if ( buf == NULL){ GDKfree(msg); BBPunfix(b->batCacheid); BBPunfix(bn->batCacheid); throw(MAL,"mdb.setTrace",MAL_MALLOC_FAIL); } } snprintf(buf,len+1024,"%s at %s.%s[%d]", msg, getModuleId(getInstrPtr(s->blk,0)), getFunctionId(getInstrPtr(s->blk,0)), s->pcup); BUNappend(b, &k, FALSE); BUNappend(bn, buf, FALSE); GDKfree(msg); } GDKfree(buf); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); if (!(bn->batDirty&2)) BATsetaccess(bn, BAT_READ); pseudo(ret,b,"view","stk","trace"); pseudo(ret2,bn,"view","stk","traceB"); return MAL_SUCCEED; }
int dump(char *fname) { Flist df, newdf; char c, *txt; int i, r, n; if ((df = loaddf(fname)) == (Flist) 0) return 1; for (c = -Home; c != ESC; c = getPC()) { switch (c) { case -PgDn: if (ncur(df) < nempty(df)) txt = nextdptr(df,(void *) 0); else continue; break; case -PgUp: if (ncur(df) > 1) txt = prevdptr(df,(void *) 0); else continue; break; case -Home: txt = mkcdptr(df,1); break; case -EndKey: txt = mkcdptr(df,nempty(df)); break; case -F1: textcolor(mcolor); textbackground(mbgrd); gotoxy(1,25); clreol(); cprintf("Keys: PgUp, PgDn, Home = top," " End = bottom, F3 = new file, ESC = Quit"); continue; case -F3: if ((newdf = loaddf(newFile())) != (Flist) 0) { rmFlist(&df); df = newdf; txt = mkcdptr(df,1); } break; default: continue; } textcolor(color); textbackground(bgrd); window(1,1,80,24); clrscr(); cprintf(" Addr Dword Dword " " Dword Dword ASCII" "\n\r\n\r\n\r"); for (n = ncur(df) - 1, r = 0; r < 16; r++, txt += 16) { cprintf("\n\r%06x ",n * NSIZE + r * 16); for (i = 0; i < 16; i++) { if (i % 4 == 0) putch(' '); cprintf("%02X ",(unsigned char) txt[i]); } cprintf(" "); for (i = 0; i < 16; i++) switch (txt[i]) { case 7: case 8: case 9: case 10: case 13: putch(' '); break; default: if (txt[i] < 26) { /* ctrl char */ textcolor(ccolor); textbackground(cbgrd); putch(txt[i] + 'A' - 1); textcolor(color); textbackground(bgrd); } else putch(txt[i]); } } textcolor(mcolor); textbackground(mbgrd); window(1,1,80,25); gotoxy(1,25); clreol(); cprintf("Dump file: %s",(char *) Flistdptr(df)); } rmFlist(&df); return 0; }
void fluxes(const Cons1DS Ul, const Cons1DS Ur, const Prim1DS Wl, const Prim1DS Wr, const Real Bxi, Cons1DS *pF) { Real pc, fr, fl; Real dc, dcl, dcr, Vxc; Real sl, sr; /* Left and right going shock velocity */ Real hdl, hdr; /* Left and right going rarefaction head velocity */ Real tll, tlr; /* Left and right going rarefaction tail velocity */ Real al = sqrt((double) Gamma*Wl.P/Wl.d); /* left sound speed */ Real ar = sqrt((double) Gamma*Wr.P/Wr.d); /* right sound speed */ Real tmp1, tmp2; Real e, V, E; if(!(Ul.d > 0.0)||!(Ur.d > 0.0)) ath_error("[exact flux]: Non-positive densities: dl = %e dr = %e\n", Ul.d, Ur.d); pc = getPC(Wl, Wr); /*----------------------------------------------------------------*/ /* calculate Vxc */ fr = PFunc(Wr, pc); fl = PFunc(Wl, pc); Vxc = 0.5*(Wl.Vx + Wr.Vx) + 0.5*(fr - fl); /*-----------------------------------------------------------------*/ /* calucate density to left of contact (dcl) */ if (pc > Wl.P) { /* left shock wave */ Real tmp = (Gamma - 1.0) / (Gamma + 1.0); dcl = Wl.d*(pc/Wl.P + tmp)/(tmp*pc/Wl.P + 1); } else { /* left rarefaction wave */ dcl = Wl.d*pow((double) (pc/Wl.P), (double) (1/Gamma)); } if (dcl < 0.0) ath_error("[exact flux]: Solver finds negative density %5.4e\n", dcl); /*-----------------------------------------------------------------*/ /* calculate density to the right of contact (dcr) */ if (pc > Wr.P) { /* right shock wave */ Real tmp = (Gamma - 1)/(Gamma + 1); dcr = Wr.d*(pc/Wr.P + tmp)/(tmp*pc/Wr.P + 1); } else { /* right rarefaction wave */ dcr = Wr.d*pow((double) (pc/Wr.P), (double) (1/Gamma)); } if (dcr < 0.0) ath_error("[exact flux]: Solver finds negative density %5.4e\n", dcr); /*----------------------------------------------------------------- * Calculate the Interface Flux if the wave speeds are such that we aren't * actually in the intermediate state */ if (pc > Wl.P) { /* left shock wave */ /* left shock speed */ sl = Wl.Vx - al*sqrt((double)(pc*(Gamma+1)/(2*Gamma*Wl.P) + (Gamma-1)/(2*Gamma))); if (sl >= 0.0) { /* to left of shock */ e = Wl.P/(Wl.d*(Gamma-1)); V = Wl.Vx*Wl.Vx + Wl.Vy*Wl.Vy + Wl.Vz*Wl.Vz; E = Wl.d*(0.5*V + e); pF->E = Wl.Vx*(E + Wl.P); pF->d = Ul.Mx; pF->Mx = Ul.Mx*(Wl.Vx) + Wl.P; pF->My = Ul.My*(Wl.Vx); pF->Mz = Ul.Mz*(Wl.Vx); return; } } else { /* left rarefaction */ Real alc = al*pow((double)(pc/Wl.P), (double)(Gamma-1)/(2*Gamma)); hdl = Wl.Vx - al; tll = Vxc - alc; if (hdl >= 0.0) { /* To left of rarefaction */ e = Wl.P/(Wl.d*(Gamma-1)); V = Wl.Vx*Wl.Vx + Wl.Vy*Wl.Vy + Wl.Vz*Wl.Vz; E = Wl.d*(0.5*V + e); pF->E = Wl.Vx*(E + Wl.P); pF->d = Ul.Mx; pF->Mx = Ul.Mx*(Wl.Vx) + Wl.P; pF->My = Ul.My*(Wl.Vx); pF->Mz = Ul.Mz*(Wl.Vx); return; } else if (tll >= 0.0) { /* Inside rarefaction fan */ tmp1 = 2/(Gamma + 1); tmp2 = (Gamma - 1)/(al*(Gamma+1)); dc = Wl.d*pow((double)(tmp1 + tmp2*Wl.Vx), (double)(2/(Gamma-1))); Vxc = tmp1*(al + Wl.Vx*(Gamma-1)/2); pc = Wl.P*pow((double)(tmp1+tmp2*Wl.Vx),(double)(2*Gamma/(Gamma-1))); e = pc/(dc*(Gamma-1)); V = Vxc*Vxc + Wl.Vy*Wl.Vy + Wl.Vz*Wl.Vz; E = dc*(0.5*V + e); pF->E = Vxc*(E + pc); pF->d = dc*Vxc; pF->Mx = dc*Vxc*Vxc + pc; pF->My = dc*Vxc*Wl.Vy; pF->Mz = dc*Vxc*Wl.Vz; return; } } if (pc > Wr.P) { /* right shock wave */ /* right shock speed */ sr = Wr.Vx + ar*sqrt((double)(pc*(Gamma+1)/(2*Gamma*Wr.P) + (Gamma-1)/(2*Gamma))); if (sr <= 0.0) { /* to right of shock */ e = Wr.P/(Wr.d*(Gamma-1)); V = Wr.Vx*Wr.Vx + Wr.Vy*Wr.Vy + Wr.Vz*Wr.Vz; E = Wr.d*(0.5*V + e); pF->E = Wr.Vx*(E + Wr.P); pF->d = Ur.Mx; pF->Mx = Ur.Mx*(Wr.Vx) + Wr.P; pF->My = Ur.My*(Wr.Vx); pF->Mz = Ur.Mz*(Wr.Vx); return; } } else { /* right rarefaction */ Real arc = ar*pow((double)(pc/Wr.P), (double)(Gamma-1)/(2*Gamma)); hdr = Wr.Vx + ar; tlr = Vxc + arc; if (hdr <= 0.0) { /* To right of rarefaction */ e = Wr.P/(Wr.d*(Gamma-1)); V = Wr.Vx*Wr.Vx + Wr.Vy*Wr.Vy + Wr.Vz*Wr.Vz; E = Wr.d*(0.5*V + e); pF->E = Wr.Vx*(E + Wr.P); pF->d = Ur.Mx; pF->Mx = Ur.Mx*(Wr.Vx) + Wr.P; pF->My = Ur.My*(Wr.Vx); pF->Mz = Ur.Mz*(Wr.Vx); return; } else if (tlr <= 0.0) { /* Inside rarefaction fan */ tmp1 = 2/(Gamma + 1); tmp2 = (Gamma - 1)/(ar*(Gamma+1)); dc = Wr.d*pow((double)(tmp1 - tmp2*Wr.Vx), (double)(2/(Gamma-1))); Vxc = tmp1*(-ar + Wr.Vx*(Gamma-1)/2); pc = Wr.P*pow((double)(tmp1-tmp2*Wr.Vx), (double)(2*Gamma/(Gamma-1))); e = pc/(dc*(Gamma-1)); V = Vxc*Vxc + Wr.Vy*Wr.Vy + Wr.Vz*Wr.Vz; E = dc*(0.5*V + e); pF->E = Vxc*(E + pc); pF->d = dc*Vxc; pF->Mx = dc*Vxc*Vxc + pc; pF->My = dc*Vxc*Wr.Vy; pF->Mz = dc*Vxc*Wr.Vz; return; } } /* We are in the intermediate state */ /*--------------------------------------------------------------------- * Calculate the Interface Flux */ if (Vxc >= 0.0) { e = pc/(dcl*(Gamma-1)); V = Vxc*Vxc + Wl.Vy*Wl.Vy + Wl.Vz*Wl.Vz; E = dcl*(0.5*V + e); pF->E = Vxc*(E + pc); pF->d = dcl*Vxc; pF->Mx = dcl*Vxc*Vxc + pc; pF->My = dcl*Vxc*Wl.Vy; pF->Mz = dcl*Vxc*Wl.Vz; } else { e = pc/(dcr*(Gamma-1)); V = Vxc*Vxc + Wr.Vy*Wr.Vy + Wr.Vz*Wr.Vz; E = dcr*(0.5*V + e); pF->E = Vxc*(E + pc); pF->d = dcr*Vxc; pF->Mx = dcr*Vxc*Vxc + pc; pF->My = dcr*Vxc*Wr.Vy; pF->Mz = dcr*Vxc*Wr.Vz; } return; }
/* * THe choice operator first searches the next one to identify * the fragment to be optimized and to gain access to the variables * without the need to declare them upfront. */ str RUNchoice(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { int target; lng cost, mincost; int i, j, pc; char *nme; InstrPtr q; pc = getPC(mb, p); for (i = pc + 1; i < mb->stop; i++) { q = getInstrPtr(mb, i); if (getModuleId(p) == getModuleId(q) && getFunctionId(p) == getFunctionId(q)) { p = q; break; } } if (i == mb->stop) return MAL_SUCCEED; target = getArg(p, 2); if (getArgType(mb, p, 1) == TYPE_int && p->argc >= 3 && (p->argc - 1) % 2 == 0) { /* choice pairs */ mincost = *getArgReference_int(stk, p, 1); for (i = 3; i < p->argc; i += 2) { cost = *getArgReference_int(stk, p, i); if (cost < mincost && !isVarDisabled(mb, getArg(p, i + 1))) { mincost = cost; target = getArg(p, i + 1); } } } else if (getArgType(mb, p, 1) == TYPE_str) { nme = *getArgReference_str(stk, p, 1); /* should be generalized to allow an arbitrary user defined function */ if (strcmp(nme, "getVolume") != 0) throw(MAL, "scheduler.choice", ILLEGAL_ARGUMENT "Illegal cost function"); mincost = -1; for (j = 2; j < p->argc; j++) { if (!isVarDisabled(mb, getArg(p, j))) for (i = pc + 1; i < mb->stop; i++) { InstrPtr q = getInstrPtr(mb, i); if (p->token >= 0 && getArg(q, 0) == getArg(p, j)) { cost = getVolume(stk, q, 1); if (cost > 0 && (cost < mincost || mincost == -1)) { mincost = cost; target = getArg(p, j); } break; } } } } #ifdef DEBUG_RUN_MEMORUN mnstr_printf(cntxt->fdout, "#function target %s cost %d\n", getVarName(mb, target), mincost); #else (void) cntxt; #endif /* remove non-qualifying variables */ for (i = 2; i < p->argc; i += 2) if (getArg(p, i) != target) { setVarDisabled(mb, getArg(p, i - 1)); setVarDisabled(mb, getArg(p, i)); } propagateNonTarget(mb, pc + 1); #ifdef DEBUG_RUN_MEMORUN mnstr_printf(cntxt->fdout, "#cost choice selected %s %d\n", getVarName(mb, target), mincost); printFunction(cntxt->fdout, mb, 1); #endif return MAL_SUCCEED; }