コード例 #1
0
/*
@brief TLB (Translation Look Aside Buffer) handler.
@return Void.
*/
EXTERN void tlbHandler()
{
	/* If a process is running, load Program Trap Old Area into the Current Process state */
	(CurrentProcess)? saveCurrentState(TLB_Old, &(CurrentProcess->p_s)) : PANIC(); /* Anomaly */

	/* Distinguish whether SYS5 has been invoked or not */
	checkSYS5(TLB_EXCEPTION, TLB_Old);
}
コード例 #2
0
/**
@brief (SYS1) Creates a new process.
@param state Processor state from which create a new process.
@return -1 in case of failure; 0 in case of success.
*/
EXTERN int createProcess(state_t *state)
{
	pcb_t *process;

	/* Allocate a new PCB */
	if (!(process = allocPcb())) return -1; /* Failure */

	/* Load processor state into process state */
	saveCurrentState(state, &(process->p_s));

	/* Update process counter, process tree and process queue */
	ProcessCount++;
	insertChild(CurrentProcess, process);
	insertProcQ(&ReadyQueue, process);

	return 0; /* Success */
}
    void appendCompactResult(std::string filename,int time)
    {
        assert((int)stateOwnStart.units.size()==ownUnitCount);
        assert((int)stateEnemyStart.units.size()==enemyUnitCount);
        
        std::ofstream data(filename, std::ios_base::app | std::ios_base::out);

        data<<stateOwnStart;
        data<<stateEnemyStart;
        data<<stateOwnEnd;
        data<<stateEnemyEnd;
        data<<researchOwn;
        data<<researchEnemy;
        data<<"t"<<time<<";\n";

        saveCurrentState();

        LOG << "Result: "<<stateOwnStart.unitCount()<<" vs "<<stateEnemyStart.unitCount()<<": "<<(stateOwnEnd.unitCount()>stateEnemyEnd.unitCount()?"WIN":"LOS");
    }
コード例 #4
0
/**
@brief This function handles a system call request coming from a process running in User Mode.
@return Void.
*/
HIDDEN void syscallUserMode()
{
	/* [Case 1] A privileged system call has been raised */
	if (SYSBP_Old->a1 > 0 && SYSBP_Old->a1 < 9)
	{
		/* Save SYS/BP Old Area into PgmTrap Old Area */
		saveCurrentState(SYSBP_Old, PGMTRAP_Old);

		/* Set program trap cause to RI (Reserved Instruction) */
		PGMTRAP_Old->CP15_Cause = CAUSE_EXCCODE_SET(PGMTRAP_Old->CP15_Cause, EXC_RESERVEDINSTR);

		/* Call the trap handler in order to trigger the PgmTrap exception response */
		pgmTrapHandler();
	}
	/* [Case 2] A non privileged system call has been raised */
	else
		/* Distinguish whether SYS5 has been invoked or not */
		checkSYS5(SYSBK_EXCEPTION, SYSBP_Old);
}
コード例 #5
0
/**
@brief The function will undertake one of the following actions:
(1) If the offending process has NOT issued a SYS5, then invoke SYS2;
(2) If the offending process has issued a SYS5, then pass up the exception.
@return Void.
*/
HIDDEN void checkSYS5(int exceptionType, state_t *exceptionOldArea)
{
	/* [Case 1] SYS5 has not been issued */
	if (CurrentProcess->exceptionState[exceptionType] == 0)
	{
		/* Terminate the current process (SYS2) */
		terminateProcess();

		/* Call the scheduler */
		scheduler();
	}
	/* [Case 2] SYS5 has been issued */
	else
	{
		/* Move current process Exception State Area into the processor Exception State Area */
		saveCurrentState(exceptionOldArea, CurrentProcess->p_stateOldArea[exceptionType]);

		/* Load the processor state in order to start execution */
		LDST(CurrentProcess->p_stateNewArea[exceptionType]);
	}
}
コード例 #6
0
/**
@brief This function handles SYSCALL or Breakpoint exceptions, which occurs when a SYSCALL or BREAK assembler
instruction is executed.
@return Void.
*/
EXTERN void sysBpHandler()
{
	/* Save SYS/BP Old Area state */
	saveCurrentState(SYSBP_Old, &(CurrentProcess->p_s));

	/* Select handler accordingly to the exception type */
	switch (CAUSE_EXCCODE_GET(SYSBP_Old->CP15_Cause))
	{
		/* [Case 1] The exception is a system call */
		case EXC_SYSCALL:
			/* Distinguish between User Mode and Kernel Mode */
			((SYSBP_Old->cpsr & STATUS_SYS_MODE) == STATUS_USER_MODE)? syscallUserMode() : syscallKernelMode();
			break;

		/* [Case 2] The exception is a breakpoint */
		case EXC_BREAKPOINT:
			/* Distinguish whether SYS5 has been invoked or not */
			checkSYS5(SYSBK_EXCEPTION, SYSBP_Old);
			break;

		default: PANIC(); /* Anomaly */
	}
}
コード例 #7
0
ファイル: testApp.cpp プロジェクト: imclab/SoundPainter
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button)
{
	int h = ofGetHeight();
	if (debugMode)
	{
		//ofRect(10, ofGetHeight()-100, 20, 20);

		if (x >= 10 && x <= 30 && y >= (h-130) && y <= (h-110) ) {
			buttonPushed = true;
			saveCurrentState();
			//clearAll();
			if (debugOutput) {printf("saved current state!\n");}
		}
	}
	if ( m_run && m_currentSample < MAX_SAMPLES)
	{
		if (x >= 10 && x <= 30 && y >= (h-130) && y <= (h-110) ) 
		{
		}
		else
		{
			ofxVec3f tmpVec;
			tmpVec.x = x;
			tmpVec.y = y;
			m_sampleVector[m_currentSample].push_back(tmpVec);
			//m_sampleVectorBackup[m_currentSample].push_back(tmpVec);

			++m_numSamples[m_currentSample];
			m_playStatuses[m_currentSample].push_back(false);
			//m_playStatusesBackup[m_currentSample].push_back(false);
		}
	}
	else
	{
		nPts = 0;
	}
}
コード例 #8
0
ファイル: exceptions.c プロジェクト: ob2410/uArm_GAOS
void sysBpHandler(){
	
	int cause;
	int mode;
	
	//1-dovremmo salvare lo stato del registro
	
	//2-boh -> il tipo dice per evitare loop syscall :/
	currentProcess->p_s.cpsr += //qualcosa;
	
	//3-prendiamo il mode
	mode= ((sysBp_old->cpsr & STATUS_SYS_MODE) >> 0x3); //forse funziona -> STATUS_SYS_MODE in uarmConst.h
	
	//4-cause interrupt
	cause=getCAUSE();
	
	if(cause == EXC_SYSCALL){ //caso system call
		
		//controlla se è in user mode
		if(mode==TRUE){ //è definito da qualche parte il true?
			
			//controllo se è una delle 11 syscall
			if((sysBp_old->reg_a0 >= 1) && (sysBp_old->reg_a0 <= SYSCALL_MAX)){ //SYSCALL_MAX sta in const.h
			
				sysBp_old->CP15_Cause = setCAUSE(); //siamo sicuri non ci vadano parametri?
				
				//salva il sysbp old in pgmtrap old
				
				pgmTrapHandler();
				
			}
			else{
				//ERRORE!!! FACCIAMO UN ALTRA VOLTA!!!
			}
		}
		else{//caso kernel mode
			
			int ret;
			
			/* Salva i parametri delle SYSCALL */
			U32 argv1 = sysBp_old->a2;
			U32 argv2 = sysBp_old->a3;
			U32 argv3 = sysBp_old->a4;
			
			
			
			/* Gestisce ogni singola SYSCALL */
			switch(sysBp_old->a1)
			{
				case CREATEPROCESS:
					//currentProcess->p_state.reg_v0 = createProcess((state_t *) arg1);
					break;
					
				case TERMINATEPROCESS:
					//ris = terminateProcess((int) arg1);
					//if(currentProcess != NULL) currentProcess->p_state.reg_v0 = ris;
					break;
					
				case SEMOP:
					semaphoreOperation((int *) argv1, (int) argv2);
					break;
				
				case SPECSYSHDL:
					
					break;
					
				case SPECTLBHDL:
					
					break;
					
				case SPECPGMTHDL:
					
					break;
					
					
				case EXITTRAP:
					
					break;
					
				case GETCPUTIME:
					//currentProcess->p_state.reg_v0 = getCPUTime();
					break;
					
				case WAITCLOCK:
					//waitClock();
					break;
					
				case IODEVOP:
					
					break;
					
				case GETPID:
					currentProcess->p_state.reg_v0 = getPid();
					break;
					
				
				/*
					
				case WAITIO:
					currentProcess->p_state.reg_v0 = waitIO((int) arg1, (int) arg2, (int) arg3);
					break;
					
				case GETPPID:
					currentProcess->p_state.reg_v0 = getPpid();
					break;
					
				case SPECTLBVECT:
					specTLBvect((state_t *) arg1, (state_t *)arg2);
					break;
					
				case SPECPGMVECT:
					specPGMvect((state_t *) arg1, (state_t *)arg2);
					break;
					
				case SPECSYSVECT:
					specSYSvect((state_t *) arg1, (state_t *)arg2);
					break;
					
				 */
					
				default:
					/* Se non è già stata eseguita la SYS12, viene terminato il processo corrente */
					if(currentProcess->ExStVec[ESV_SYSBP] == 0)
					{
						int ris;
						
						ris = terminateProcess(-1);
						if(currentProcess != NULL) currentProcess->p_state.reg_v0 = ris;
					}
					/* Altrimenti viene salvata la SysBP Old Area all'interno del processo corrente */
					else
					{
						saveCurrentState(sysBp_old, currentProcess->sysbpState_old);
						LDST(currentProcess->sysbpState_new);
					}
			}
			
			scheduler();
			
		}
	}
	else{ //caso breakpoint
	
 
	}
}
コード例 #9
0
ファイル: testApp.cpp プロジェクト: imclab/SoundPainter
//--------------------------------------------------------------
void testApp::keyPressed  (int key)
{
	if (debugOutput) {printf("Pressed key number: %i\n", key);}
	if ( key == ' ' )
	{
		if ( m_run )
		{
			m_run = false;
			ofxOscMessage m;
			m.setAddress("/stop");
			m.addIntArg(0);
			sender.sendMessage ( m );
			setOscDebugMessage(m);
		}
		else
		{
			m_run = true;
			ofxOscMessage m;
			m.setAddress("/start");
			m.addIntArg(1);
			sender.sendMessage ( m );
			setOscDebugMessage(m);
		}
	}
	else if (key == 'r' || key == 'R')
	{
		m_numSamples[m_currentSample] = 0;
		m_sampleVector[m_currentSample].clear();
	}
	else if (key == 'z')
	{
		if (m_numSamples[m_currentSample] > 0)
		{
			--m_numSamples[m_currentSample];
			m_sampleVectorPopped[m_currentSample].push_back(m_sampleVector[m_currentSample].back());
			m_sampleVector[m_currentSample].pop_back();
		}
	}
	else if (key == 'Z')
	{
		if (m_sampleVectorPopped[m_currentSample].size() > 0) {
			m_sampleVector[m_currentSample].push_back(m_sampleVectorPopped[m_currentSample].back());
			m_sampleVectorPopped[m_currentSample].pop_back();
			++m_numSamples[m_currentSample];
		}
	}
	else if ( key == 'c' )
	{
		// clear all samples
		for (int i = 0; i < MAX_SAMPLES; ++i) {
			m_numSamples[i] = 0;
			m_sampleVector[i].clear();
		}
	}
	else if ( key == 'C' )
	{
		clearAll();
	}
	else if ( key == 'F' )
	{
		isFullScreen = !isFullScreen;
		ofSetFullscreen(isFullScreen);
	}
	else if (key >= 48 && key <=57)
	{
		m_currentSample = key - 48;
		if (debugOutput) {printf("set sample: %i\n", m_currentSample);}
	}
	else if (key == 'd')
	{
		if (debugOutput) {printf("debug mode\n");}
		debugMode = !debugMode;
	}
	else if (key == 'f')
	{
		showColors = !showColors;
	}
	else if (key == 'g')
	{
		for (int i = 0; i < MAX_SAMPLES; ++i) {
			m_sampleColors[i].r = ofRandom(0, 255);
			m_sampleColors[i].g = ofRandom(0, 255);
			m_sampleColors[i].b = ofRandom(0, 255);
			m_sampleColors[i].a = 127;
		}
	}
	else if (key == 'h')
	{
		if (debugOutput) {printf("help mode\n");}
		helpMode = !helpMode;
		usageMode = false;
	}
	else if (key == 'm')
	{
		showOscDebugPosition = !showOscDebugPosition;
	}
	else if (key == OF_KEY_UP)
	{
		if (m_currentState == 0) {
			nPtsBackup = nPts;
			for (int i = 0; i < MAX_N_PTS; ++i) {
				ptsBackup[i] = 0;
			}

			for (int i = 0; i < nPts; ++i) {
				ptsBackup[i] = pts[i];
			}
			for (int i = 0; i < MAX_SAMPLES; ++i) {
				m_sampleVectorBackup[i] = m_sampleVector[i];
				m_numSamplesBackup[i] = m_numSamples[i];
				m_playStatusesBackup[i] = m_playStatuses[i];
			}
		}
		++m_currentState;

		if (m_currentState > XMLstates.getNumTags("STATE"))
		{
			m_currentState = 0;
		}
		loadState(m_currentState);
		if (debugOutput) {printf("current state : %i\n", m_currentState);}

	}
	else if (key == OF_KEY_DOWN)
	{
		if (m_currentState == 0) {
			nPtsBackup = nPts;
			for (int i = 0; i < MAX_N_PTS; ++i) {
				ptsBackup[i] = 0;
			}

			for (int i = 0; i < nPts; ++i) {
				ptsBackup[i] = pts[i];
			}
			for (int i = 0; i < MAX_SAMPLES; ++i) {
				m_sampleVectorBackup[i] = m_sampleVector[i];
				m_numSamplesBackup[i] = m_numSamples[i];
				m_playStatusesBackup[i] = m_playStatuses[i];
			}
		}
		--m_currentState;
		if (m_currentState < 0)
		{
			m_currentState =  XMLstates.getNumTags("STATE");
		}
		loadState(m_currentState);
		if (debugOutput) {printf("current state : %i\n", m_currentState);}
	}
	else if (key == OF_KEY_RETURN)
	{
		usageMode = !usageMode;
	}
	else if (key == 'w')
	{
		if (debugMode) {
			saveCurrentState();
			if (debugOutput) {printf("saved current state!\n");}
			buttonPushed = true;
		}
	}
	else if (key == 'e')
	{
		if (debugMode)
		{
			readStates();
		}
	}
	else if (key >= 257 && key <= 266)
	{
		if (m_currentState == 0) {
			nPtsBackup = nPts;
			for (int i = 0; i < MAX_N_PTS; ++i) {
				ptsBackup[i] = 0;
			}
			
			for (int i = 0; i < nPts; ++i) {
				ptsBackup[i] = pts[i];
			}
			for (int i = 0; i < MAX_SAMPLES; ++i) {
				m_sampleVectorBackup[i] = m_sampleVector[i];
				m_numSamplesBackup[i] = m_numSamples[i];
				m_playStatusesBackup[i] = m_playStatuses[i];
			}
		}
		
		m_currentState = (key - 256) + stateTen;
		printf("current state %i\n", m_currentState);
		printf("lastTagNumber: %i\n", lastTagNumber);
		if (m_currentState > XMLstates.getNumTags("STATE")) 
		{
			m_currentState = lastTagNumber;
		}
		loadState(m_currentState);
		stateTenMsg = "";
		if (debugOutput) {printf("current state : %i\n", m_currentState);}
	}
	else if (key == OF_KEY_F11)
	{
		printf("bla %i",(XMLstates.getNumTags("STATE")));
		if ((XMLstates.getNumTags("STATE") - stateTen) > 10 )
		{
			stateTen += 10;
			std::stringstream str;
			str << ", +";
			str << stateTen;
			str << "...";
			stateTenMsg = str.str();
		}
//		if (stateTen% <= XMLstates.getNumTags("STATE")) {
//			m_currentState += stateTen
//		}
//		m_currentState 
	}
	else if (key == OF_KEY_F12) 
	{
		if (stateTen != 0){
			stateTen -= 10;
			std::stringstream str;
			str << ", -";
			str << stateTen;
			str << "...";			
			stateTenMsg = str.str();
		}
	}
}
コード例 #10
0
void WidgetMain::slotClickSave()
{
    saveCurrentState();
}
コード例 #11
0
ファイル: gocodeformatter.cpp プロジェクト: qfw/qgo
void GoCodeFormatter::recalculateStateAfter(const QTextBlock &block)
{
    restoreCurrentState(block.previous());

    const LexerState lexerState(tokenizeBlock(block));

    m_newStates.clear();

    int currentState;
    for (m_index = 0; m_index < m_tokens.count(); ++m_index) {
        currentState = m_currentState.top().state;
        m_tk = m_tokens.at(m_index);
        switch (currentState) {
        case TopMost:
            tryDeclaration();
            break;
        case PackageClause:
            switch (m_tk.kind()) {
            case T_IDENTIFIER:  leave(); break;
            default:            break;
            }
            break;
        case ImportDecl:
            switch (m_tk.kind()) {
            case T_LPAREN:      enter(ImportOpen); break;
            case T_STRING:      leave(); break;
            default:            break;
            }
            break;
        case ImportOpen:
            switch (m_tk.kind()) {
            case T_RPAREN:      leave(); leave(); break;
            default:            break;
            }
            break;
        case InterfaceDecl:
            switch (m_tk.kind()) {
            case T_LBRACE:      enter(InterfaceOpen); break;
            default:            break;
            }
            break;
        case InterfaceOpen:
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); leave(); break;
            default:            break;
            }
            break;
        case StructDecl:
            switch (m_tk.kind()) {
            case T_LBRACE:      enter(StructOpen); break;
            default:            break;
            }
            break;
        case StructOpen:
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); leave(); break;
            default:            break;
            }
            break;
        case TypeDecl:
            switch (m_tk.kind()) {
            case T_LPAREN:      enter(TypeOpen); break;
            case T_INTERFACE:   leave(); enter(InterfaceDecl); break;
            case T_STRUCT:      leave(); enter(StructDecl); break;
            default:            leave(); break;
            }
            break;
        case TypeOpen:
            switch (m_tk.kind()) {
            case T_INTERFACE:   leave(); enter(InterfaceDecl); break;
            case T_STRUCT:      enter(StructDecl); break;
            case T_RPAREN:      leave(); leave(); break;
            default:            break;
            }
            break;
        case IdentDecl:
            leave(); break; // TODO: implement
            /*
            switch (m_tk.kind()) {
            case T_LPAREN:      enter(IdentArgs); break;
            case T_LBRACE:      enter(IdentFields); break;
            default:            leave(); break;
            }
            break;
        case IdentArgs:
            switch (m_tk.kind()) {
            case T_RPAREN:      leave(); break;
            default:            break;
            }
            break;
        case IdentFields:
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); break;
            default:            break;
            }
            break;*/
        case ConstDecl:
            leave(); break; // TODO: implement
        case VarDecl:
            leave(); break; // TODO: implement
            /*
            switch (m_tk.kind()) {
            case T_LPAREN:      enter(VarOpen); break;
            case T_EQUAL:       enter(VarExpr); break;
            default:            break;
            }
            break;
        case VarOpen:
            switch (m_tk.kind()) {
            case T_RPAREN:      leave(); leave(); break;
            default:            if (!tryDeclaration()) leave(); break;
            }
            break;
        case VarExpr:
            if (tryDeclaration())
                break;
            else
                leave();
            break;*/
        case FuncDecl:
            switch (m_tk.kind()) {
            case T_LBRACE:      enter(FuncOpen); break;
            case T_LPAREN:      enter(FuncParams); break;
            default:            break;
            }
            break;
        case FuncOpen:
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); leave(); break;
            default:            tryStatement(); break;
            }
            break;
        case FuncParams:
            switch (m_tk.kind()) {
            case T_RPAREN:      leave(); break;
            default:            break;
            }
            break;
        case BlockOpen:
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); break;
            default:            tryStatement(); break;
            }
            break;
        case GroupOpen:
            switch (m_tk.kind()) {
            case T_RPAREN:      leave(); break;
            default:            tryStatement(); break;
            }
            break;
        case ForStmt:
            switch (m_tk.kind()) {
            case T_LBRACE:      enter(ForOpen); break;
            default:            break;
            }
            break;
        case ForOpen:
            // TODO: parse arguments
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); leave(); break;
            default:            tryStatement(); break;
            }
            break;
        case IfStmt:
            switch (m_tk.kind()) {
            case T_LBRACE:      enter(IfOpen); break;
            default:            break;
            }
            break;
        case IfOpen:
            // TODO: parse arguments
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); leave(); break;
            default:            tryStatement(); break;
            }
            break;
        case SwitchStmt:
            switch (m_tk.kind()) {
            case T_LBRACE:      enter(SwitchOpen); break;
            default:            break;
            }
            break;
        case SwitchOpen:
            switch (m_tk.kind()) {
            case T_RBRACE:      leave(); leave(); break;
            case T_DEFAULT:
            case T_CASE:        enter(CaseClause); break;
            default:            break;
            }
            break;
        case CaseClause:
            switch (m_tk.kind()) {
            case T_COLON:       leave(); enter(CaseOpen); break;
            default:            break;
            }
            break;
        case CaseOpen:
            switch (m_tk.kind()) {
            case T_DEFAULT:
            case T_CASE:        leave(); enter(CaseClause); break;
            case T_RBRACE:      leave(); leave(); leave(); break;
            default:            tryStatement(); break;
            }
            break;
        case Label:
            switch (m_tk.kind()) {
            case T_COLON:       leave(); break;
            default:            leave(); continue; // shouldn't happen
            } break;
        case MultilineCommentStart:
        case MultilineCommentCont:
            if (m_tk.kind() != T_COMMENT) {
                leave();
                continue;
            } else if (m_index == m_tokens.size() - 1
                    && lexerState.multiLine() == LexerState::NoMultiLine) {
                leave();
            } else if (m_index == 0 && m_tk.is(T_COMMENT)) {
                // to allow enter/leave to update the indentDepth
                leave();
                enter(MultilineCommentCont);
            }
            break;
        default:
            break;
        }
    }

    currentState = m_currentState.top().state;
    if (currentState != MultilineCommentStart
            && currentState != MultilineCommentCont
            && (lexerState.multiLine() == LexerState::MultiLineComment)) {
        enter(MultilineCommentStart);
    }

    saveCurrentState(block);
}