BOOL DemDispatch (ULONG iSvc) { #if DBG if(iSvc < SVC_DEMLASTSVC && (fShowSVCMsg & DEMSVCTRACE) && apfnSVC[iSvc] != demNotYetImplemented){ sprintf(demDebugBuffer,"DemDispatch: Entering %s\n\tAX=%.4x BX=%.4x CX=%.4x DX=%.4x DI=%.4x SI=%.4x\n", aSVCNames[iSvc],getAX(),getBX(),getCX(),getDX(),getDI(),getSI()); OutputDebugStringOem(demDebugBuffer); sprintf(demDebugBuffer,"\tCS=%.4x IP=%.4x DS=%.4x ES=%.4x SS=%.4x SP=%.4x BP=%.4x\n", getCS(),getIP(), getDS(),getES(),getSS(),getSP(),getBP()); OutputDebugStringOem(demDebugBuffer); } #endif if (iSvc >= SVC_DEMLASTSVC){ #if DBG sprintf(demDebugBuffer,"Unimplemented SVC index %x\n",iSvc); OutputDebugStringOem(demDebugBuffer); #endif setCF(1); return FALSE; } if (pHardErrPacket) { pHardErrPacket->vhe_fbInt24 = 0; } CurrentISVC = iSvc; (apfnSVC [iSvc])(); #if DBG if((fShowSVCMsg & DEMSVCTRACE)){ sprintf(demDebugBuffer,"DemDispatch:On Leaving %s\n\tAX=%.4x BX=%.4x CX=%.4x DX=%.4x DI=%.4x SI=%.4x\n", aSVCNames[iSvc],getAX(),getBX(),getCX(),getDX(),getDI(),getSI()); OutputDebugStringOem(demDebugBuffer); sprintf(demDebugBuffer,"\tCS=%.4x IP=%.4x DS=%.4x ES=%.4x SS=%.4x SP=%.4x BP=%.4x CF=%x\n", getCS(),getIP(), getDS(),getES(),getSS(),getSP(),getBP(),getCF()); OutputDebugStringOem(demDebugBuffer); } #endif return TRUE; }
int main() { unsigned long sp; sp = getSP(); printf( "Application stack pointer = 0x%lx\n", sp ); Bar(); return 0; }
void testReferenceAddress(int &x) { clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} clang_analyzer_eval(&ref() != 0); // expected-warning{{TRUE}} struct S { int &x; }; extern S getS(); clang_analyzer_eval(&getS().x != 0); // expected-warning{{TRUE}} extern S *getSP(); clang_analyzer_eval(&getSP()->x != 0); // expected-warning{{TRUE}} }
FLQuant sp(int model, SEXP params, SEXP biomass) { FLQuant bio(biomass); FLQuant par(params); FLQuant rtn(1,1,par.minyr(),par.maxyr(),par.nareas(),par.nseasons(),par.nunits(),par.niters()); int i, j, k, l, m; int i, j, k, l, m; for(m=1; m <= bio.niters(); m++) { for (l = 1; l <= bio.nareas(); l++) { for (k = 1; k <= bio.nseasons(); k++) { for (j = 1; j <= bio.nunits(); j++) { for (i = bio.minyr(); i <= bio.maxyr(); i++) { switch(getSP(model)) { case FLRConst_fletcher: rtn(1,i,j,k,l,m) = spFletcher(bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; case FLRConst_fox: rtn(1,i,j,k,l,m) = spFox( bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_genfit: rtn(1,i,j,k,l,m) = spGenfit( bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; case FLRConst_gulland: rtn(1,i,j,k,l,m) = spGulland( bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_logistic: rtn(1,i,j,k,l,m) = spLogistic(bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_pellat: rtn(1,i,j,k,l,m) = spPellaT( bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; case FLRConst_schaefer: rtn(1,i,j,k,l,m) = spSchaefer(bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_shepherd: rtn(1,i,j,k,l,m) = spShepherd(bio(1,i,j,k,l,m),par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; } } } } } } return rtn; }
void nulluser(void) { int userpid; int ubrr = UBRR; unsigned int flash = (unsigned int)&_etext; int int_cnt = 100; reboot = (unsigned int)MCUSR; PORTB = 0x00; DDRB = 0x01; /* make the LED pin an output */ USART_Init(0, ubrr); /* initialize USART transmitter for kprintf */ kprintf_P(PSTR("\n\nXinu Version %s"), vers); kprintf_P(PSTR(" MCUCSR=%x\n"), reboot); MCUSR = 0; sysinit(); kprintf_P(PSTR("%u bytes Xinu code, SP=%p\n"), flash<<1, getSP()); kprintf_P(PSTR("clock %sabled\n\n"),clkruns==1?"en":"dis"); enable(); /* enable interrupts */ /* create a process to execute the user's avr-main program, "Xinu_main" */ userpid = create(main,INITSTK,INITPRIO,INITNAME,0); // kprintf("main: created %d\n", userpid); #ifdef NETDAEMON /* start the network input daemon process */ resume( create(NETIN, NETISTK, NETIPRI, NETINAM, 1, userpid) ); #else resume( userpid ); #endif while ( 1 ) { SMCR |= (1<<SE); /* enable sleep idle mode */ pause(); SMCR &= ~(1<<SE); if (--int_cnt <= 0) { int_cnt = 100; PORTB ^= 1; } } }
void MsBopF(){ UCHAR *Instruction; USHORT i; // Unimplemented interrupt bop Instruction = RMSEGOFFTOLIN(getSS(), getSP()); Instruction = RMSEGOFFTOLIN(*((PWORD)Instruction + 1), *(PWORD)(Instruction)); i = (USHORT)(*(Instruction - 1)); VDprint( VDP_LEVEL_WARNING, ("SoftPC Bop Support: Unimplemented Interrupt %x\n", i) ); }
FLQuant fmsy(int model, SEXP params) { FLQuant par(params); FLQuant rtn(1,1,par.minyr(),par.maxyr(),par.nareas(),par.nseasons(),par.nunits(),par.niters()); int i, j, k, l, m; for(m=1; m <= par.niters(); m++) { for (l = 1; l <= par.nareas(); l++) { for (k = 1; k <= par.nseasons(); k++) { for (j = 1; j <= par.nunits(); j++) { for (i = par.minyr(); i <= par.maxyr(); i++) { switch(getSP(model)) { case FLRConst_fletcher: rtn(1,i,j,k,l,m) = fmsyFletcher(par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; case FLRConst_fox: rtn(1,i,j,k,l,m) = fmsyFox( par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_genfit: rtn(1,i,j,k,l,m) = fmsyGenfit( par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; case FLRConst_gulland: rtn(1,i,j,k,l,m) = fmsyGulland( par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_logistic: rtn(1,i,j,k,l,m) = fmsyLogistic(par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_pellat: rtn(1,i,j,k,l,m) = fmsyPellaT( par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; case FLRConst_schaefer: rtn(1,i,j,k,l,m) = fmsySchaefer(par(1,i,j,k,l,m),par(2,i,j,k,l,m)); break; case FLRConst_shepherd: rtn(1,i,j,k,l,m) = fmsyShepherd(par(1,i,j,k,l,m),par(2,i,j,k,l,m),par(3,i,j,k,l,m)); break; } } } } } } return rtn; }
step_result step() { // Bottom of stack is defined as having no more unwind info. if (fUnwindInfoMissing) return UNW_STEP_END; // Apply unwinding to register set. switch (this->stepWithDwarfFDE()) { case UNW_STEP_FAILED: return UNW_STEP_FAILED; case UNW_STEP_END: return UNW_STEP_END; case UNW_STEP_SUCCESS: this->setInfoBasedOnIPRegister(true); if (fUnwindInfoMissing) return UNW_STEP_END; if (fInfo.extra_args) setSP(getSP() + fInfo.extra_args); return UNW_STEP_SUCCESS; } __builtin_unreachable(); }
void invokeNativeFunction(METHOD thisMethod) { #if INCLUDEDEBUGCODE int saved_TemporaryRootsLength; #endif NativeFunctionPtr native = thisMethod->u.native.code; if (native == NULL) { /* Native function not found; throw error */ /* The GC may get confused by the arguments on the stack */ setSP(getSP() - thisMethod->argCount); START_TEMPORARY_ROOTS DECLARE_TEMPORARY_ROOT(char*, className, getClassName((CLASS)(thisMethod->ofClass))); sprintf(str_buffer, KVM_MSG_NATIVE_METHOD_NOT_FOUND_2STRPARAMS, className, methodName(thisMethod)); END_TEMPORARY_ROOTS fatalError(str_buffer); }
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; }
/*========================================================================= * FUNCTION: tVM_Execute * TYPE: public interface * OVERVIEW: execute a basic function * INTERFACE: * parameters: * returns: * the result of the basic function *=======================================================================*/ int tVM_Execute() { int running = 1; u8 bytecode; u8 type; u8 ac_flag; s32 integer; s32 stackindex,index; tVMValue value1,value2,value3; tVMValue retValue;// = (tVMValue*)mem_alloc(sizeof(tVMValue)); /* initialize the running Stack FP */ setFP(FirstFP); /* seek to the entry function */ setFI(0); /* initialize the code reader */ tVM_InitializeCodeReader(); /* execute the byte codes in loop */ while(running) { bytecode = ReadCode(); switch(bytecode) { case C_NOP: break; case C_CONST: { ReadVMValue(&value1); PushVMValue(&value1); break; } case C_LOAD: { ac_flag =ReadAccessFlag(); if(ac_flag == ACCESS_FLAG_GLOBAL) stackindex = ReadIndex(); else stackindex = ReadIndex() + getFP(); LoadVMValue(stackindex,&value1); PushVMValue(&value1); break; } case C_STORE: { ac_flag =ReadAccessFlag(); if(ac_flag == ACCESS_FLAG_GLOBAL) stackindex = ReadIndex(); else stackindex = ReadIndex() + getFP(); PopVMValue(&value1); /* pop the source value */ StoreVMValue(stackindex,&value1); break; } case C_HEAP_LOAD: { type = ReadDataType(); PopVMValue(&value2); /* Pop Addr */ PopVMValue(&value1); /* Pop Base */ tVMValue_HeapLoad(value1.value.ptr_val+value2.value.int_val,type,&value3); /* load the heap memory */ PushVMValue(&value3); /* push the loaded value */ break; } case C_HEAP_STORE: { ptr32 addr; type = ReadDataType(); PopVMValue(&value3); /* Pop Addr */ PopVMValue(&value2); /* Pop Base */ PopVMValue(&value1); /* Pop Value */ addr = (ptr32)(value2.value.ptr_val + value3.value.int_val); if(value1.type != type) { tVMValue_ConvertType(&value1,type); } tVMValue_HeapStore(addr,&value1); break; } case C_FORCE_LOAD: { ac_flag =ReadAccessFlag(); if(ac_flag == ACCESS_FLAG_GLOBAL) stackindex = ReadIndex(); else stackindex = ReadIndex() + getFP(); type = ReadDataType(); ForceLoadVMValue(stackindex,type,&value1); PushVMValue(&value1); break; } case C_ALLOC: { PopVMValue(&value1); value2.type = PtrType; value2.value.ptr_val = (ptr32)mem_alloc(value1.value.int_val); memset(value2.value.ptr_val,0,value1.value.int_val); PushVMValue(&value2); break; } case C_ALLOC_ARRAY: { s32 i; s32 dimension; s32* index_ranges; dimension = ReadInteger(); if(dimension < 1) break; index_ranges = (s32*)mem_alloc(sizeof(s32)*dimension); for(i=0;i<dimension;i++) { PopVMValue(&value1); index_ranges[dimension-i-1] = value1.value.int_val; } value1.type = PtrType; value1.value.ptr_val = tVMValue_HeapAllocMultiArray(dimension,index_ranges,0); PushVMValue(&value1); mem_free(index_ranges); break; } case C_FREE: { PopVMValue(&value1); if(value1.value.ptr_val != NULL) mem_free(value1.value.ptr_val); break; } case C_FREE_ARRAY: { break; } case C_PUSH: { value1.type = ReadDataType(); value1.value.int_val = 0; PushVMValue(&value1); break; } case C_POP: { s32 i; integer = ReadInteger(); for(i=0;i<integer;i++) { PopVMValue(&value1); tVMValue_FreeSelf(&value1); } break; } case C_POP_RESTOP: { s32 i; integer = ReadInteger(); PopVMValue(&value2); /* reserve top value */ for(i=0;i<integer;i++) { PopVMValue(&value1); tVMValue_FreeSelf(&value1); } PushVMValue(&value2); /* push back top value */ break; } case C_CONVERT: { u8 type = (u8)ReadDataType(); PopVMValue(&value1); tVMValue_ConvertType(&value1,type); PushVMValue(&value1); break; } case C_ADD: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Add(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_SUB: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Sub(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_MUL: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Mul(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_DIV: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Div(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_MOD: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Mod(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_OPP: { PopVMValue(&value1); tVMValue_Opp(&value1,&value2); PushVMValue(&value2); tVMValue_FreeSelf(&value1); break; } case C_AND: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_AND(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_OR: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_OR(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_EQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_NOT_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_NOTEQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LT: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LT(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LG: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LG(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LT_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LTEQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LG_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LGEQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_FJP: { s32 size = ReadIndex(); PopVMValue(&value1); if(value1.value.int_val == 0) /* if it is false */ addIP(size); break; } case C_TJP: { s32 size = ReadIndex(); PopVMValue(&value1); if(value1.value.int_val != 0) /* if it is true */ addIP(size); break; } case C_JMP: { s32 size = ReadIndex(); addIP(size); break; } case C_CALL: { /* read function name */ integer = ReadIndex(); /* push the stack frame */ PushInteger(getIP()); PushInteger(getFI()); PushInteger(getFP()); /* goto the call function code */ tVM_ReleaseCodeReader(); setFI(integer); tVM_InitializeCodeReader(); /* set new FP,RP */ setFP(getSP()); break; } case C_INVOKE: { /* read function name */ index = ReadIndex(); /* execute the native function */ tNativeFunction_Invoke(index); break; } case C_RET: { u32 param_bytes = ReadIndex(); /* get the result of the function */ retValue.type = NullType; PopVMValue(&retValue); /* if this is the start function,then exit the loop */ if(getFP() == FirstFP) { running = 0; /* set flag to stop while */ break; } /* restore last stack frame and return to last function code */ tVM_ReleaseCodeReader(); PopInteger(integer); setFP(integer); PopInteger(integer); setFI(integer); tVM_InitializeCodeReader(); PopInteger(integer); setIP(integer); /* pop the old parameters */ PopBytes(param_bytes); /* push back result of last function */ PushVMValue(&retValue); break; } } } /* close the code reader */ tVM_ReleaseCodeReader(); return 1; }
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() */
static VOID WINAPI DosStart(LPWORD Stack) { BOOLEAN Success; DWORD Result; #ifndef STANDALONE INT i; #endif DPRINT("DosStart\n"); /* * We succeeded, deregister the DOS Starting BOP * so that no app will be able to call us back. */ RegisterBop(BOP_START_DOS, NULL); /* Initialize the callback context */ InitializeContext(&DosContext, BIOS_CODE_SEGMENT, 0x0010); Success = DosBIOSInitialize(); // Success &= DosKRNLInitialize(); if (!Success) { BiosDisplayMessage("DOS32 loading failed (Error: %u). The VDM will shut down.\n", GetLastError()); EmulatorTerminate(); return; } /* Load the mouse driver */ DosMouseInitialize(); #ifndef STANDALONE /* Parse the command line arguments */ for (i = 1; i < NtVdmArgc; i++) { if (wcsncmp(NtVdmArgv[i], L"-i", 2) == 0) { /* This is the session ID (hex format) */ SessionId = wcstoul(NtVdmArgv[i] + 2, NULL, 16); } } /* Initialize Win32-VDM environment */ Env = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, EnvSize); if (Env == NULL) { DosDisplayMessage("Failed to initialize the global environment (Error: %u). The VDM will shut down.\n", GetLastError()); EmulatorTerminate(); return; } /* Clear the structure */ RtlZeroMemory(&CommandInfo, sizeof(CommandInfo)); /* Get the initial information */ CommandInfo.TaskId = SessionId; CommandInfo.VDMState = VDM_GET_FIRST_COMMAND | VDM_FLAG_DOS; GetNextVDMCommand(&CommandInfo); #else /* Retrieve the command to start */ if (NtVdmArgc >= 2) { WideCharToMultiByte(CP_ACP, 0, NtVdmArgv[1], -1, AppName, sizeof(AppName), NULL, NULL); if (NtVdmArgc >= 3) WideCharToMultiByte(CP_ACP, 0, NtVdmArgv[2], -1, CmdLine, sizeof(CmdLine), NULL, NULL); else strcpy(CmdLine, ""); } else { DosDisplayMessage("Invalid DOS command line\n"); EmulatorTerminate(); return; } #endif /* * At this point, CS:IP points to the DOS BIOS exit code. If the * root command interpreter fails to start (or if it exits), DOS * exits and the VDM terminates. */ /* Start the root command interpreter */ // TODO: Really interpret the 'SHELL=' line of CONFIG.NT, and use it! /* * Prepare the stack for DosStartComSpec: * push Flags, CS and IP, and an extra WORD. */ setSP(getSP() - sizeof(WORD)); *((LPWORD)SEG_OFF_TO_PTR(getSS(), getSP())) = (WORD)getEFLAGS(); setSP(getSP() - sizeof(WORD)); *((LPWORD)SEG_OFF_TO_PTR(getSS(), getSP())) = getCS(); setSP(getSP() - sizeof(WORD)); *((LPWORD)SEG_OFF_TO_PTR(getSS(), getSP())) = getIP(); setSP(getSP() - sizeof(WORD)); Result = DosStartComSpec(TRUE, SEG_OFF_TO_PTR(SYSTEM_ENV_BLOCK, 0), MAKELONG(getIP(), getCS()), #ifndef STANDALONE &RootCmd.ComSpecPsp #else NULL #endif ); if (Result != ERROR_SUCCESS) { /* Unprepare the stack for DosStartComSpec */ setSP(getSP() + 4*sizeof(WORD)); DosDisplayMessage("Failed to start the Command Interpreter (Error: %u). The VDM will shut down.\n", Result); EmulatorTerminate(); return; } #ifndef STANDALONE RootCmd.Terminated = FALSE; InsertComSpecInfo(&RootCmd); #endif /**/ /* Attach to the console and resume the VM */ DosProcessConsoleAttach(); EmulatorResume(); /**/ return; }