void genif(SNODE *stmt) /* * generate code to evaluate an if statement. */ { int lab1, lab2; int areg, sreg; lab1 = nextlabel++; /* else label */ lab2 = nextlabel++; /* exit label */ InitRegs(); /* clear temps */ ChooseRegs(&areg, &sreg); falsejp(stmt->exp, areg, sreg, lab1); genstmt(stmt->s1); if (stmt->s2 != 0) /* else part exists */ { gen_codes(op_jmp, 0, make_label(lab2), 0); gen_label(lab1); genstmt(stmt->s2); gen_label(lab2); } else /* no else code */ gen_label(lab1); }
void CPUThread::Run() { if(IsRunning()) Stop(); if(IsPaused()) { Resume(); return; } #ifndef QT_UI wxGetApp().SendDbgCommand(DID_START_THREAD, this); #endif m_status = Running; SetPc(entry); InitStack(); InitRegs(); DoRun(); Emu.CheckStatus(); #ifndef QT_UI wxGetApp().SendDbgCommand(DID_STARTED_THREAD, this); #endif }
void gen_for(SNODE *stmt) /* * generate code to evaluate a for loop */ { int old_break, old_cont, exit_label, loop_label, start_label; int areg, sreg; old_break = breaklab; old_cont = contlab; loop_label = nextlabel++; contlab = nextlabel++; start_label = nextlabel++; exit_label = nextlabel++; InitRegs(); if (stmt->label != 0) { gen_void_external(stmt->label); } gen_codes(op_jmp, 0, make_label(start_label), 0); gen_label(loop_label); if (stmt->s1 != 0) { breaklab = exit_label; genstmt(stmt->s1); } if (stmt->lst) gen_line(stmt->lst); gen_label(contlab); InitRegs(); if (stmt->s2 != 0) { gen_void_external(stmt->s2); } gen_label(start_label); InitRegs(); ChooseRegs(&areg, &sreg); if (stmt->exp != 0) truejp(stmt->exp, areg, sreg, loop_label); else gen_codes(op_jmp, 0, make_label(loop_label), 0); gen_label(exit_label); breaklab = old_break; contlab = old_cont; }
void genbinaryswitch(SNODE *stmt, struct cases *cs) { AMODE *ap1; int size = natural_size(stmt->exp); InitRegs(); ap1 = gen_expr_external(stmt->exp, FALSE, F_DREG, BESZ_DWORD); gather_cases(stmt->s1,cs,FALSE); qsort(cs->ptrs,cs->count, sizeof(cs->ptrs[0]), size < 0 ? sortcmpsigned : sortcmpunsigned); bingen(0, (cs->count) / 2, cs->count, ap1, cs, size); }
void genwhile(SNODE *stmt) /* * generate code to evaluate a while statement. */ { int lab1, lab2, lab3; int areg, sreg; InitRegs(); /* initialize temp registers */ lab1 = contlab; /* save old continue label */ contlab = nextlabel++; /* new continue label */ if (stmt->s1 != 0) /* has block */ { lab2 = breaklab; /* save old break label */ breaklab = nextlabel++; gen_codes(op_jmp, 0, make_label(contlab), 0); lab3 = nextlabel++; gen_label(lab3); genstmt(stmt->s1); gen_label(contlab); if (stmt->lst) gen_line(stmt->lst); InitRegs(); ChooseRegs(&areg, &sreg); truejp(stmt->exp, areg, sreg, lab3); gen_label(breaklab); breaklab = lab2; /* restore old break label */ } else /* no loop code */ { if (stmt->lst) gen_line(stmt->lst); gen_label(contlab); InitRegs(); ChooseRegs(&areg, &sreg); truejp(stmt->exp, areg, sreg, contlab); } contlab = lab1; /* restore old continue label */ }
void CPUThread::Run() { if(!IsStopped()) Stop(); Reset(); SendDbgCommand(DID_START_THREAD, this); m_status = Running; SetPc(entry); InitStack(); InitRegs(); DoRun(); Emu.CheckStatus(); SendDbgCommand(DID_STARTED_THREAD, this); }
void PPCThread::Run() { if(IsRunned()) Stop(); if(IsPaused()) { Resume(); return; } wxGetApp().SendDbgCommand(DID_START_THREAD, this); m_status = Runned; SetPc(entry); InitStack(); InitRegs(); DoRun(); Emu.CheckStatus(); wxGetApp().SendDbgCommand(DID_STARTED_THREAD, this); }
void gencompactswitch(SNODE *stmt, struct cases *cs) { int tablab, size; AMODE *ap, *ap2; LLONG_TYPE i; tablab = nextlabel++; InitRegs(); size = natural_size(stmt->exp); if (size == BESZ_QWORD || size == - BESZ_QWORD) { ap = gen_expr_external(stmt->exp, FALSE, F_AXDX, BESZ_QWORD); if (cs->bottom) { gen_codes(op_sub, BESZ_DWORD, makedreg(EAX), make_immed(cs->bottom)); #if sizeof(LLONG_TYPE) == 4 gen_codes(op_sbb, BESZ_DWORD, makedreg(EDX), make_immed(cs->bottom < 0 ? - 1: 0)); #else gen_codes(op_sbb, BESZ_DWORD, makedreg(EDX), make_immed(cs->bottom >> 32)); #endif }
void gendo(SNODE *stmt) /* * generate code for a do - while loop. */ { int oldcont, oldbreak, looplab; int areg, sreg; oldcont = contlab; oldbreak = breaklab; looplab = nextlabel++; contlab = nextlabel++; breaklab = nextlabel++; gen_label(looplab); genstmt(stmt->s1); /* generate body */ gen_label(contlab); InitRegs(); ChooseRegs(&areg, &sreg); truejp(stmt->exp, areg, sreg, looplab); gen_label(breaklab); breaklab = oldbreak; contlab = oldcont; }
void loadregs(void) /* * initialize allocated registers */ { CSE *csp; ENODE *exptr; unsigned mask, rmask, i, fmask, frmask, size; AMODE *ap, *ap2; csp = olist; while (csp != 0) { int sz; if (csp->reg != - 1) { /* see if preload needed */ exptr = csp->exp; if (!lvalue(exptr) || ((SYM*)exptr->v.p[0]->v.p[0])->funcparm) { exptr = csp->exp; InitRegs(); sz = csp->size; ap = gen_expr_external(exptr, FALSE, F_MEM | F_DREG | F_IMMED, sz); if (csp->reg < 16) { if (ap->mode == am_dreg) peep_tail->oper1->preg = csp->reg; else { if (csp->reg > 3 && chksize(BESZ_WORD, sz)) DIAG("byte sized non-register in analyze"); ap2 = makedreg(csp->reg); ap2->length = BESZ_DWORD; if (ap->mode == am_immed || ap->length == BESZ_DWORD || ap ->length == - BESZ_DWORD) gen_codes(op_mov, BESZ_DWORD, ap2, ap); else if (sz < 0) gen_code(op_movsx, ap2, ap); else gen_code(op_movzx, ap2, ap); } } else if (csp->reg < 32) { if (ap->mode == am_dreg) peep_tail->oper1->preg = csp->reg - 12; else { if (csp->reg - 12 > 3 && chksize(BESZ_WORD, sz)) DIAG("byte sized non-register in analyze"); ap2 = makedreg(csp->reg - 12); ap2->length = BESZ_DWORD; if (ap->mode == am_immed || ap->length == BESZ_DWORD || ap ->length == - BESZ_DWORD) gen_codes(op_mov, BESZ_DWORD, ap2, ap); else if (sz < 0) gen_code(op_movsx, ap2, ap); else gen_code(op_movzx, ap2, ap); } } else { /* Should never get here */ DIAG("float reg assigned in analyze"); } if (lvalue(exptr) && ((SYM*)exptr->v.p[0]->v.p[0])->funcparm) { ((SYM*)exptr->v.p[0]->v.p[0])->mainsym->inreg = TRUE; ((SYM*)exptr->v.p[0]->v.p[0])->mainsym->value.i = - csp ->reg - (csp->size < 0 ? - csp->size: csp->size) *256; } } } csp = csp->next; } gen_label(startlab); }
DWORD HW_Init( PI2C_CONTEXT pI2C ) { DWORD dwErr = ERROR_SUCCESS; UINT32 Irq; // RETAILMSG(1,(TEXT("I2C Init\r\n"))); if ( !pI2C ) { return ERROR_INVALID_PARAMETER; } DEBUGMSG(ZONE_TRACE,(TEXT("+I2C_Init: %u, 0x%x, 0x%x \r\n"), pI2C->Mode, pI2C->SlaveAddress)); InitializeCriticalSection(&pI2C->RegCS); pI2C->Status = 0; pI2C->Data = NULL; pI2C->DataCount = INVALID_DATA_COUNT; pI2C->Flags.DropRxAddr = FALSE; pI2C->hProc = (HANDLE)GetCurrentProcessId(); InitRegs(pI2C); // create I/O Done Event if ( (pI2C->DoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) { dwErr = GetLastError(); DEBUGMSG(ZONE_ERR,(TEXT("I2C_Init ERROR: Unable to create Done event: %u \r\n"), dwErr)); goto _init_error; } // setup Operating Mode if ( pI2C->Mode == INTERRUPT ) { // create IST event if ( (pI2C->ISTEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) { dwErr = GetLastError(); DEBUGMSG(ZONE_ERR,(TEXT("I2C_Init ERROR: Unable to create IST event: %u \r\n"), dwErr)); goto _init_error; } // Obtain sysintr values from the OAL for the camera interrupt. // Irq = IRQ_I2C; if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &gIntrIIC, sizeof(UINT32), NULL)) { DEBUGMSG(ZONE_ERR, (TEXT("ERROR: Failed to request the IIC sysintr.\r\n"))); gIntrIIC = SYSINTR_UNDEFINED; return(FALSE); } // RETAILMSG(1, (TEXT("IIC IRQ mapping: [IRQ:%d->sysIRQ:%d].\r\n"), Irq, gIntrIIC)); // initialize the interrupt if( !InterruptInitialize(gIntrIIC, pI2C->ISTEvent, NULL, 0) ) { dwErr = GetLastError(); DEBUGMSG(ZONE_ERR,(TEXT("I2C_Init ERROR: Unable to initialize interrupt: %u\r\n"), dwErr)); goto _init_error; } InterruptDone(gIntrIIC); // create the IST if ( (pI2C->IST = CreateThread(NULL, 0, I2C_IST, (LPVOID)pI2C, 0, NULL)) == NULL) { dwErr = GetLastError(); DEBUGMSG(ZONE_ERR,(TEXT("I2C_Init ERROR: Unable to create IST: %u\r\n"), dwErr)); goto _init_error; } // TODO: registry override if ( !CeSetThreadPriority(pI2C->IST, I2C_THREAD_PRIORITY)) { dwErr = GetLastError(); DEBUGMSG(ZONE_ERR, (TEXT("I2C_Init ERROR: CeSetThreadPriority ERROR:%d\n"), dwErr)); goto _init_error; } } DEBUGMSG(ZONE_TRACE,(TEXT("-I2C_Init \r\n"))); return dwErr; _init_error: HW_Deinit(pI2C); return dwErr; }
static DWORD I2C_IST( LPVOID Context ) { PI2C_CONTEXT pI2C = (PI2C_CONTEXT)Context; DWORD i2cSt; BOOL bDone = FALSE; #ifdef DEBUG DWORD r = 0; #endif if ( !pI2C ) { TEST_TRAP; return ERROR_INVALID_PARAMETER; } //DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("+I2C_IST[%u, %u, %d] \r\n"), pI2C->Mode, pI2C->State, pI2C->DataCount)); do { if (pI2C->Mode == INTERRUPT) { DWORD we; bDone = FALSE; we = WaitForSingleObject(pI2C->ISTEvent, INFINITE); //DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("I2C_IST[%u, %d] \r\n"), pI2C->State, pI2C->DataCount)); // clear the interrupt here because we re-arm another below InterruptDone(gIntrIIC); // // Ensure correct state initiated by Read/Write // DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("I2C_IST[%u, %d] \r\n"), pI2C->State, pI2C->DataCount)); switch(pI2C->State) { case OFF: DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("I2C_IST: ExitThread \r\n"))); ExitThread(ERROR_SUCCESS); break; case IDLE: DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("I2C_IST: IDLE \r\n"))); continue; break; default: if (pI2C->State != WRITE_ACK && pI2C->State != RESUME && pI2C->DataCount == INVALID_DATA_COUNT) { DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("I2C_IST: INVALID_DATA_COUNT\r\n"))); continue; } break; } } // EnterCriticalSection(&pI2C->RegCS); i2cSt = rIICSTAT; if (i2cSt & 0x8) { DEBUGMSG(ZONE_ERR,(TEXT("I2C_IST[%u, %d]: bus arbitration failed \r\n"), pI2C->State, pI2C->DataCount)); // RETAILMSG(1, (TEXT("I2C_IST[%u, %d]: bus arbitration failed \r\n"), // pI2C->State, pI2C->DataCount)); } if (i2cSt & 0x4) { DEBUGMSG(ZONE_ERR,(TEXT("I2C_IST[%u, %d]: slave address matches IICADD \r\n"), pI2C->State, pI2C->DataCount)); // RETAILMSG(1, (TEXT("I2C_IST[%u, %d]: slave address matches IICADD \r\n"), // pI2C->State, pI2C->DataCount)); } if (i2cSt & 0x2) { DEBUGMSG(ZONE_ERR,(TEXT("I2C_IST[%u, %d]: received slave address 0x0 \r\n"), pI2C->State, pI2C->DataCount)); // RETAILMSG(1, (TEXT("I2C_IST[%u, %d]: received slave address 0x0 \r\n"), // pI2C->State, pI2C->DataCount)); } if (i2cSt & 0x1) { DEBUGMSG(ZONE_READ|ZONE_WRITE,(TEXT("I2C_IST[%u, %d]: ACK NOT received \r\n"), pI2C->State, pI2C->DataCount)); RETAILMSG(1, (TEXT("I2C_IST[%u, %d]: ACK NOT received \r\n"), pI2C->State, pI2C->DataCount)); } __try { switch(pI2C->State) { case IDLE: case SUSPEND: continue; break; case RESUME: DEBUGMSG(ZONE_WRN, (TEXT("I2C_IST: RESUME \r\n"))); // RETAILMSG(1, (TEXT("I2C_IST: RESUME \r\n"))); InitRegs(pI2C); pI2C->LastError = ERROR_OPERATION_ABORTED; SetEvent(pI2C->DoneEvent); break; case SET_READ_ADDR: if ( (pI2C->DataCount--) == 0 ) { DEBUGMSG(ZONE_READ|ZONE_TRACE, (TEXT("A2[%d] \r\n"), pI2C->DataCount )); // RETAILMSG(1, (TEXT("A2[%d] \r\n"), // pI2C->DataCount )); bDone = TRUE; break; } DEBUGMSG(ZONE_READ|ZONE_TRACE, (TEXT("A1[%d]: 0x%X \r\n"), pI2C->DataCount, pI2C->WordAddr)); // RETAILMSG(1, (TEXT("A1[%d]: 0x%X \r\n"), // pI2C->DataCount, pI2C->WordAddr)); // write word address // For setup time of SDA before SCL rising edge, rIICDS must be written // before clearing the interrupt pending bit. if (pI2C->Flags.WordAddr) { rIICDS = pI2C->WordAddr; // clear interrupt pending bit (resume) rIICCON = RESUME_ACK; pI2C->Flags.WordAddr = FALSE; } break; case READ_DATA: ASSERT(pI2C->Data); if ( (pI2C->DataCount--) == 0 ) { bDone = TRUE; *pI2C->Data = (UCHAR)rIICDS; #ifdef DEBUG r = *pI2C->Data; //RETAILMSG(1,(TEXT("R3_1:0x%X, pI2C->Data(0x%X) \r\n"), r, pI2C->Data)); //RETAILMSG(1,(_T("pI2C->Data(0x%X)\r\n"), pI2C->Data)); #endif pI2C->Data++; rIICSTAT = MRX_STOP; rIICCON = RESUME_ACK; // resume operation. //RETAILMSG(1,(_T("pI2C->Data(0x%X)\r\n"), pI2C->Data)); //RETAILMSG(1,(TEXT("R3_2:0x%X, pI2C->Data(0x%X) \r\n"), r, pI2C->Data)); //DEBUGMSG(ZONE_READ|ZONE_TRACE,(TEXT("R3:0x%X \r\n"), r)); //The pending bit will not be set after issuing stop condition. break; } // Drop the returned Slave WordAddr? if ( pI2C->Flags.DropRxAddr ) { pI2C->RxRetAddr = (UCHAR)rIICDS; pI2C->Flags.DropRxAddr = FALSE; DEBUGMSG(ZONE_READ|ZONE_TRACE,(TEXT("Drop: 0x%X \r\n"), pI2C->RxRetAddr)); } else { *pI2C->Data = (UCHAR)rIICDS; #ifdef DEBUG r = *pI2C->Data; #endif pI2C->Data++; } //RETAILMSG(1,(TEXT("R3_3:0x%X, pI2C->Data(0x%X) \r\n"), r, pI2C->Data)); // The last data is read with no ack. if ( pI2C->DataCount == 0 ) { rIICCON = RESUME_NO_ACK; // resume operation with NOACK. DEBUGMSG(ZONE_READ|ZONE_TRACE,(TEXT("R1:0x%X \r\n"), r)); } else { rIICCON = RESUME_ACK; // resume operation with ACK DEBUGMSG(ZONE_READ|ZONE_TRACE,(TEXT("R2:0x%X \r\n"), r)); } break; case WRITE_DATA: ASSERT(pI2C->Data); if ( (pI2C->DataCount--) == 0 ) { DEBUGMSG(ZONE_WRITE|ZONE_TRACE,(TEXT("W3[%d] \r\n"), pI2C->DataCount)); //RETAILMSG(1,(TEXT("W3[%d] \r\n"), pI2C->DataCount)); bDone = TRUE; rIICSTAT = MTX_STOP; rIICCON = RESUME_ACK; // resume operation. //The pending bit will not be set after issuing stop condition. break; } if (pI2C->Flags.WordAddr) { rIICDS = pI2C->WordAddr; DEBUGMSG(ZONE_WRITE|ZONE_TRACE,(TEXT("W1[%d]: 0x%X \r\n"), pI2C->DataCount, pI2C->WordAddr)); pI2C->Flags.WordAddr = FALSE; } else { DEBUGMSG(ZONE_WRITE|ZONE_TRACE,(TEXT("W2[%d]: 0x%X \r\n"), pI2C->DataCount, *pI2C->Data)); rIICDS = (UCHAR)*pI2C->Data; pI2C->Data++; } rIICCON = RESUME_ACK; // resume operation. break; case WRITE_ACK: DEBUGMSG(ZONE_WRITE|ZONE_TRACE,(TEXT("WRITE_ACK \r\n") )); //RETAILMSG(1,(TEXT("WRITE_ACK \r\n") )); pI2C->Status = i2cSt; bDone = TRUE; break; case IO_COMPLETE: DEBUGMSG(ZONE_IST, (TEXT("IO_COMPLETE \r\n"))); bDone = TRUE; break; case IO_ABANDONED: DEBUGMSG(ZONE_ERR|ZONE_WRN,(TEXT("IO_ABANDONED \r\n") )); bDone = TRUE; break; default: DEBUGMSG(ZONE_ERR,(TEXT("!!! I2C_IST ERROR: Invalid State: %u !!!\r\n"), pI2C->State)); bDone = TRUE; break; } } _except(EXCEPTION_EXECUTE_HANDLER) { rIICSTAT = (pI2C->State == READ_DATA) ? MRX_STOP : MTX_STOP; rIICCON = RESUME_ACK; pI2C->DataCount = INVALID_DATA_COUNT; pI2C->LastError = GetExceptionCode(); // RETAILMSG(1,(TEXT("!!! I2C_IST EXCEPTION: 0x%X !!!\r\n"), pI2C->LastError )); } if (bDone) { DEBUGMSG(ZONE_IST, (TEXT("SetEvent DONE\r\n"))); SetEvent(pI2C->DoneEvent); } // LeaveCriticalSection(&pI2C->RegCS); } while (pI2C->Mode == INTERRUPT); //DEBUGMSG(ZONE_IST|ZONE_TRACE,(TEXT("-I2C_IST[%u] \r\n"), pI2C->Mode)); return ERROR_SUCCESS; }