Esempio n. 1
0
/* Suspend the current running process, and launch a running process. May be the
 * same if no other process are currently running*/
void yield(void)
{
	LOG("Transfering processes (current, next) : ");
	struct processDescriptor* current = 
		(struct processDescriptor*) getIndex(&runningList, 0)->element;
	rotateForward(&runningList);
	struct processDescriptor* next = 
		(struct processDescriptor*) getIndex(&runningList, 0)->element;
	LOG_INT(current->pid);
	LOG_CONT("  ");
	LOG_INT(next->pid);
	LOG_CONT("\n");
	wait(1000000);
	transfer(&(next->processState), &(current->processState));
}
Esempio n. 2
0
/*
 * Launch the kernel, i.e. launch first process in the running list
 */
void startKernel(void)
{
	LOG("Gonna start the kernel, remind all processes :\n");
	
	int i = 0;
	int max = runningList.size;
	for( ; i < max ; i++)
	{
		struct processDescriptor* p = 
			(struct processDescriptor*) getIndex(&runningList, i)->element;
		printProcess(p);
	}
	struct processDescriptor* process = 
		(struct processDescriptor*) getIndex(&runningList, 0)->element;
	LOG("Starting process : ");
	LOG_INT(process->pid);
	LOG_CONT("\n");
/*	LOG_INT(process->ppid); */
	printProcess(process);
	LOG_CONT("\n");
	startProcess(&(process->processState));
}
Esempio n. 3
0
/*
 * Delete current process, i.e. remove from runningList, free the Cell, 
 * and switch process. Free the stack too.
 */
void deleteProcess()
{
	struct processDescriptor* process = (struct processDescriptor*)
		 removeCell(&runningList, getIndex(&runningList, 0));
	LOG("Deleting process : ");
	LOG_INT((int) process->pid);
	LOG_CONT("\n");
	free2M(process->map.baseAddress);
	if(process->baseAddress) /* If stored in kernel memory*/
	{
		kfree(process->baseAddress);
	}
	kfree(process);
	struct processDescriptor* next = 
		(struct processDescriptor *) getIndex(&runningList, 0)->element;
	restartProcess(&(next->processState));
}
Esempio n. 4
0
void printProcess(struct processDescriptor* process)
{
	LOG("Print process (map.baseAddress, pid, ppid, pc, sp, lr) :\n ");
	LOG_INT((int) process->map.baseAddress);
	LOG_CONT(" ");
	LOG_INT(process->pid);
	LOG_CONT(" ");
	LOG_INT(process->ppid);
	LOG_CONT(" ");
	LOG_INT((int)process->processState.pc);
	LOG_CONT(" ");
	LOG_INT((int)process->processState.sp);
	LOG_CONT(" ");
	LOG_INT((int)process->processState.lr);
	LOG_CONT("\n");
	wait(3000000);
}
Esempio n. 5
0
/* create new process and returns the cell containing the process */
struct cell * createProcess(void (*f)(void), void* baseAddress)
{
	void* area = get2M();
	LOG("Creating process at base address : ");
	LOG_INT((int)area);
	LOG_CONT("\n");
	/* Prepare initial processState*/
	struct processDescriptor * process =
		kalloc(sizeof(struct processDescriptor));
	
	process->processState.pc = f;
	process->processState.sp =  area + 2*SPACE - 4;
	/* When exiting, auto-delete process */
	process->processState.lr = &deleteProcess; 
	process->ppid = choosePPID();
	pidCounter++;
	process->pid = pidCounter;
	process->map.baseAddress = area;
	process->baseAddress = baseAddress;
	printProcess(process);
	insertAtEnd(&stoppedList, process);
	return getIndex(&stoppedList, 0)->previous;
}
Esempio n. 6
0
int
main( int argc, char** argv )
{
	//std::ofstream logFile( "Log.txt" );
        //SET_LOUT( logFile );

        //D_COMMAND( std::ofstream debugFile( "Debug.txt" ); );
        //SET_DOUT( debugFile );

	//XInitThreads();
	ApplicationManager appManager;

	boost::filesystem::path executablePath(argv[0]);
	boost::filesystem::path dataDirName = GET_SETTINGS( "application.data_directory", std::string, (boost::filesystem::path(argv[0]).parent_path() / "data").string() );
	//If we cannot locate data directory - try other posiible locations
	if (!boost::filesystem::exists(dataDirName) || !boost::filesystem::is_directory(dataDirName)) {
		std::vector<boost::filesystem::path> possibleDataDirs;
		possibleDataDirs.push_back(boost::filesystem::current_path() / "data");
		possibleDataDirs.push_back(executablePath.parent_path() / "data");
		possibleDataDirs.push_back(executablePath.parent_path().parent_path() / "data");

		std::vector<boost::filesystem::path>::const_iterator it = possibleDataDirs.begin();
		bool found = false;
		LOG( "Trying to locate 'data' directory:" );
		while (!found && it != possibleDataDirs.end()) {
			LOG_CONT( "\tChecking: " << it->string() << " ... ");
			if (boost::filesystem::exists(*it) && boost::filesystem::is_directory(*it)) {
				dataDirName = *it;
				SET_SETTINGS( "application.data_directory", std::string, dataDirName.string() );
				found = true;
				LOG( "SUCCESS" );
			} else {
				LOG( "FAILED" );
			}
			++it;
		}
		if (!found) {
			BOOST_THROW_EXCEPTION( M4D::ErrorHandling::EDirNotFound() );
		}
	}
	boost::filesystem::path dirName = GET_SETTINGS( "gui.icons_directory", std::string, ( dataDirName / "icons" ).string() );
	appManager.setIconsDirectory(dirName);
	appManager.initialize( argc, argv );

	try {
		//processCommandLine( argc, argv );
		ViewerWindow viewer;
		appManager.setMainWindow( viewer );

		createModules();

		appManager.loadModules();
		viewer.showMaximized();
		return appManager.exec();
	} catch ( std::exception &e )
	{
		QMessageBox::critical ( NULL, "Exception", QString( e.what() ) );
	} 
	catch (...) {
		QMessageBox::critical ( NULL, "Exception", "Unknown error" );
	}
	
	return 1;
}