コード例 #1
0
ファイル: mach_main.c プロジェクト: LemonBoy/greenLeaf
int main(int argc, char *argv[])
{
	char* filename;
	s32 ret;
	mipsCpu* cpu;
	
	printf("greenLeaf 0.1\n");
	printf("mips emulator by The Lemon Man and SquidMan\n");

	if(argc < 2) {	/* No arguments passed. */
		filename = calloc(5, 1);
		sprintf(filename, "test/mmon");
	}else{
		filename = calloc(strlen(argv[1]) + 1, 1);
		sprintf(filename, argv[1]);
	}

#ifdef DEBUG
	printf("Debug mode enabled\n");
#endif
	printf("Initializing the CPU core...\n");
	cpu = initializeCPU(ENDIANNESS_LE, 0x80000000);
	
	printf("Mapping the ram...\n");
	
	printf("Main memory %d\n",	mapMemory(cpu, 0x80000000, 0x40000, FLAG_RAM));
	printf("Reset vector %d\n",	mapMemory(cpu, 0xBFC00000, 0x40000, FLAG_RAM));
	printf("Additional mem %d\n",	mapMemory(cpu, 0xA0000010, 0x2000, FLAG_RAM));
	
//	ret = openRaw(cpu, filename, 0xBFC00000);
	ret = openElf32(cpu, filename);

	printf("Entry %#x\n",	(u32)ret);
	
	printf("Uart %i\n",	setupUart(cpu, 0xB40003f8));
	
	setPC(cpu, ret);
	
	printf("Press enter to run a tick and print the registers...\n");
	printf("Press enter to continue.\n");
	for(;;) {
#ifdef TICK_AT_A_TIME
		fgetc(stdin);
#endif
		runProcessor(cpu, 1);		/* Run a single cycle at a time */
		//~ printRegisters(cpu);
	}
	
	printf("Execution finished... unmapping the ram\n");
	
	unmapMemory(cpu);
	
	free(filename);
	
	return 1;
}
コード例 #2
0
//This function does a branch on equal
void ControlUnit::BEQ(int a, int b, int newPC, Register &r1, MainFrame* theFrame)
{
	if(r1.get(a)==r1.get(b))
	{
		cout<<"BEQ jumping."<<endl;
		setPC(newPC);
	}
	else
		pc++;
};
コード例 #3
0
ファイル: winstack.cpp プロジェクト: albfan/kdbg
bool WinStack::activatePath(QString pathName, int lineNo, const DbgAddr& address)
{
    // check whether the file is already open
    SourceWindow* fw = 0;
    for (int i = count()-1; i >= 0; i--) {
	if (windowAt(i)->fileName() == pathName) {
	    fw = windowAt(i);
	    break;
	}
    }
    if (fw == 0) {
	// not found, load it
	fw = new SourceWindow(pathName, this);

	// slurp the file in
	if (!fw->loadFile()) {
	    // read failed
	    delete fw;
	    return false;
	}

	int idx = addTab(fw, QFileInfo(pathName).fileName());
	setTabToolTip(idx, pathName);

	connect(fw, SIGNAL(clickedLeft(const QString&,int,const DbgAddr&,bool)),
		SIGNAL(toggleBreak(const QString&,int,const DbgAddr&,bool)));
	connect(fw, SIGNAL(clickedMid(const QString&,int,const DbgAddr&)),
		SIGNAL(enadisBreak(const QString&,int,const DbgAddr&)));

	// disassemble code
	connect(fw, SIGNAL(disassemble(const QString&, int)),
		SIGNAL(disassemble(const QString&, int)));
	connect(fw, SIGNAL(expanded(int)), SLOT(slotExpandCollapse(int)));
	connect(fw, SIGNAL(collapsed(int)), SLOT(slotExpandCollapse(int)));

	// tab width
	connect(this, SIGNAL(setTabWidth(int)), fw, SLOT(setTabWidth(int)));
	fw->setTabWidth(m_tabWidth);
	fw->setFocusPolicy(Qt::WheelFocus);

	// set PC if there is one
	emit newFileLoaded();
	if (m_pcLine >= 0) {
	    setPC(true, m_pcFile, m_pcLine, DbgAddr(m_pcAddress), m_pcFrame);
	}
    }
コード例 #4
0
ファイル: Story.Execution.cpp プロジェクト: foxesknow/zork
void Story::returnFromCall(Word result)
{
	// First up, put the stack and PC back to what they should be
	auto returnFrame = m_Frames.top();
	m_Frames.pop();

	m_StackSpace.revertToFrame(returnFrame);
	setPC(returnFrame.getReturnAddress());

	// The result goes back into a variable...
	auto resultVariableID = returnFrame.getResultVariable();
	
	if(resultVariableID != DiscardResultsVariable)
	{
		storeVariable(static_cast<Byte>(resultVariableID), result);
	}
}
コード例 #5
0
ファイル: Story.Execution.cpp プロジェクト: foxesknow/zork
void Story::callRoutine(Address routineAddress, Word returnVariable, const std::vector<Word> &arguments)
{
	// NOTE: special case! A call to address 0 means return false!
	if(routineAddress == 0)
	{
		returnFromCall(0);
		return; // NOTE: Early return
	}

	Address returnAddress = m_PC;

	auto normalizedAddress = expandPackedRoutineAddress(routineAddress);

	// Point to the new routine
	setPC(normalizedAddress);

	auto numberOfLocals = readNextByte();
	auto stackFrame = allocateNewFrame(returnAddress, arguments.size(), numberOfLocals, returnVariable);

	// The local default values are stored next
	if(m_Version <= 4)
	{
		// The defaults are next
		for(Byte i = 0; i < numberOfLocals; i++)
		{
			auto value = readNextWord();
			storeVariable(i + 1, value);
		}
	}
	else
	{
		// They all default to 0
		for(Byte i = 0; i < numberOfLocals; i++)
		{
			storeVariable(i + 1, 0);
		}
	}

	// Now layer the arguments on top
	auto argumentsToCopy = std::min(numberOfLocals, static_cast<Byte>(arguments.size()));
	for(Byte i = 0; i < argumentsToCopy; i++)
	{
		storeVariable(i + 1, arguments[i]);
	}

}
コード例 #6
0
ファイル: Story.Execution.cpp プロジェクト: foxesknow/zork
void Story::applyBranch(SWord offset)
{
	if(offset == 0)
	{
		// Return false
		returnFromCall(0);
	}
	else if(offset == 1)
	{
		// Return true
		returnFromCall(1);
	}
	else
	{
		Address newPC = m_PC + (offset - 2);
		setPC(newPC);
	}
}
コード例 #7
0
// This function changes the PC
void ControlUnit::JMP(int newPC, MainFrame* theFrame)
{
	setPC(newPC);
};
コード例 #8
0
// -----------------------------------------------------------------------------
// CzxEmuleAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CzxEmuleAppUi::HandleCommandL(TInt aCommand)
{
    switch (aCommand)
    {
    case EEikCmdExit:
    case EAknSoftkeyExit:
        Exit();
        break;

    case ECommand1:
    {

        // Load a string from the resource file and display it
        HBufC* textResource = StringLoader::LoadLC(R_COMMAND1_TEXT);
        CAknInformationNote* informationNote;

        informationNote = new (ELeave) CAknInformationNote;

        // Show the information Note with
        // textResource loaded with StringLoader.
        informationNote->ExecuteLD(*textResource);

        // Pop HBuf from CleanUpStack and Destroy it.
        CleanupStack::PopAndDestroy(textResource);
    }
    break;
    case ECommand2:
    {
        RFile rFile;

        //Open file where the stream text is
        User::LeaveIfError(rFile.Open(CCoeEnv::Static()->FsSession(),
                                      KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
        CleanupClosePushL(rFile);

        // copy stream from file to RFileStream object
        RFileReadStream inputFileStream(rFile);
        CleanupClosePushL(inputFileStream);

        // HBufC descriptor is created from the RFileStream object.
        HBufC* fileData = HBufC::NewLC(inputFileStream, 32);

        CAknInformationNote* informationNote;

        informationNote = new (ELeave) CAknInformationNote;
        // Show the information Note
        informationNote->ExecuteLD(*fileData);

        // Pop loaded resources from the cleanup stack
        CleanupStack::PopAndDestroy(3); // filedata, inputFileStream, rFile
    }
    break;
    case EReset:
        ResetZX();
        OutPortZX(0x7ffd,7+16);
        setPC(0); //pc=PopZX();
        EnableTrdos();
        break;
    case EHelp:
    {

        CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
        HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
    }
    break;
    case EAbout:
    {

        CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog();
        dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
        HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
        dlg->QueryHeading()->SetTextL(*title);
        CleanupStack::PopAndDestroy(); //title
        HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
        dlg->SetMessageTextL(*msg);
        CleanupStack::PopAndDestroy(); //msg
        dlg->RunLD();
    }
    break;
    default:
        Panic(EzxEmuleUi);
        break;
    }
}