Ejemplo n.º 1
0
int LoadImage(FILE * img) {

	int status = 0;

	status = LoadBPB(img);
	status = SetRootDir(img);
	status = LoadFSInfo(img);

	if(status != 0) printf("\n\nLoadImage error: %d\n", status);

#ifdef _DEBUGGING_BOOT_SECT
	PrintBootSectInfo();
#endif

	return status;
}
Ejemplo n.º 2
0
int main(int argc, char * argv[])
{	
	// process command-line options
	const char * program = "runvx.exe";
	bool verbose = false;
	bool enableMultiFrameProcessing = false;
	bool framesEofRequested = true;
	bool enableDumpGDF = false, enableScheduleGraph = false;
	bool pauseBeforeExit = false;
	bool enableDumpProfile = false;
	bool disableVirtual = false;
	bool discardCompareErrors = false;
	vx_uint32 defaultTargetAffinity = 0;
	vx_uint32 defaultTargetInfo = 0;
	bool doSetGraphOptimizerFlags = false;
	vx_uint32 graphOptimizerFlags = 0;
	int arg, frameStart = 0, frameEnd = 1;
	bool frameCountSpecified = false;
	int waitKeyDelayInMilliSeconds = -1; // -ve indicates no user preference
	for (arg = 1; arg < argc; arg++){
		if (argv[arg][0] == '-'){
			if (!_stricmp(argv[arg], "-h")) {
				show_usage(program, true);
				exit(0);
			}
			else if (!_stricmp(argv[arg], "-v")) {
				verbose ^= true;
			}
			else if (!strncmp(argv[arg], "--", 2)) { // skip specified number of arguments: --[#] (default just skip --)
				arg += atoi(&argv[arg][2]);
			}
			else if (!_strnicmp(argv[arg], "-root:", 6)) {
				SetRootDir(argv[arg] + 6);
			}
			else if (!_strnicmp(argv[arg], "-frames:", 8)) {
				int spos = 8;
				while (argv[arg][spos]) {
					if (argv[arg][spos] == ',')
						spos++;
					else if (!_strnicmp(argv[arg], "live", 4)) {
						enableMultiFrameProcessing = true;
						spos += 4;
					}
					else if (!_strnicmp(argv[arg], "eof", 3)) {
						framesEofRequested = true;
						spos += 3;
					}
					else {
						int k = sscanf(&argv[arg][spos], "%d:%d", &frameStart, &frameEnd);
						if (k == 1) { frameEnd = frameStart, frameStart = 0; }
						else if (k != 2) { printf("ERROR: invalid -frames option\n"); return -1; }
						frameCountSpecified = true;
						while (argv[arg][spos] && argv[arg][spos] != ',')
							spos++;
					}
				}
			}
			else if (!_strnicmp(argv[arg], "-affinity:", 10)) {
				if (!_strnicmp(&argv[arg][10], "cpu", 3)) defaultTargetAffinity = AGO_TARGET_AFFINITY_CPU;
				else if (!_strnicmp(&argv[arg][10], "gpu", 3)) defaultTargetAffinity = AGO_TARGET_AFFINITY_GPU;
				else { printf("ERROR: unsupported affinity target: %s\n", &argv[arg][10]); return -1; }
				if (argv[arg][13] >= '0' && argv[arg][13] <= '9')
					defaultTargetInfo = atoi(&argv[arg][13]);
			}
			else if (!_stricmp(argv[arg], "-dump-profile")) {
				enableDumpProfile = true;
			}
			else if (!_stricmp(argv[arg], "-dump-gdf") || !_stricmp(argv[arg], "-ago-dump")) { // TBD: remove -ago-dump
				enableDumpGDF = true;
			}
			else if (!_stricmp(argv[arg], "-discard-compare-errors")) {
				discardCompareErrors = true;
			}
			else if (!_stricmp(argv[arg], "-use-schedule-graph")) {
				enableScheduleGraph = true;
			}
			else if (!_stricmp(argv[arg], "-disable-virtual")) {
				disableVirtual = true;
			}
			else if (!_strnicmp(argv[arg], "-graph-optimizer-flags:", 23)) {
				if (sscanf(&argv[arg][23], "%i", &graphOptimizerFlags) == 1) {
					doSetGraphOptimizerFlags = true;
				}
				else { printf("ERROR: invalid graph optimizer flags: %s\n", argv[arg]); return -1; }
			}
			else if (!_strnicmp(argv[arg], "-key-wait-delay:", 16)) {
				(void)sscanf(&argv[arg][16], "%i", &waitKeyDelayInMilliSeconds);
			}
			else if (!_stricmp(argv[arg], "-pause")) {
				pauseBeforeExit = true;
			}
			else { printf("ERROR: invalid option: %s\n", argv[arg]); return -1; }
		}
		else break;
	}
	if (arg == argc) { show_usage(program, false); return -1; }
	int argCount = argc - arg - 2;
	fflush(stdout);

	CVxEngine engine;
	int errorCode = 0;
	try {
		// initialize engine
		if (engine.Initialize(argCount, defaultTargetAffinity, defaultTargetInfo, enableScheduleGraph, disableVirtual) < 0) throw - 1;
		if (doSetGraphOptimizerFlags) {
			engine.SetGraphOptimizerFlags(graphOptimizerFlags);
		}
		engine.SetConfigOptions(verbose, discardCompareErrors, enableDumpProfile, enableDumpGDF, waitKeyDelayInMilliSeconds);
		engine.SetFrameCountOptions(enableMultiFrameProcessing, framesEofRequested, frameCountSpecified, frameStart, frameEnd);
		fflush(stdout);
		// pass parameters to the engine: note that shell takes no extra parameters whereas node and file take extra parameter
		int argParamOffset = (!_stricmp(argv[arg], "shell")) ? 1 : 2;
		for (int i = 0, j = 0; i < argCount; i++) {
			char * param = argv[arg + argParamOffset + i];
			if (engine.SetParameter(j++, param) < 0)
				throw -1;
		}
		fflush(stdout);
		// get full GDF text
		char * fullText = nullptr;
		if (!_stricmp(argv[arg], "file")) {
			if ((arg+1) == argc)
				ReportError("ERROR: missing file name on command-line (see help for details)\n");
			arg++;
			const char * fileName = RootDirUpdated(argv[arg]);
			size_t size = strlen("include") + 1 + strlen(fileName) + 1;
			fullText = new char[size];
			sprintf(fullText, "include %s", fileName);
		}
		else if (!_stricmp(argv[arg], "node")) {
			if ((arg + 1) == argc)
				ReportError("ERROR: missing kernel name on command-line (see help for details)\n");
			int paramCount = argc - arg - 2;
			arg++;
			size_t size = strlen("node") + 1 + strlen(argv[arg]) + paramCount*6 + 1;
			fullText = new char[size];
			sprintf(fullText, "node %s", argv[arg]);
			for (int i = 0, j = 0; i < paramCount; i++)
				sprintf(fullText + strlen(fullText), " $%d", j++ + 1);
		}
		else if (!_stricmp(argv[arg], "shell")) {
			// nothing to do
		}
		else {
			printf("ERROR: invalid command: %s (see help for details)\n", argv[arg]);
			throw -1;
		}

		if (fullText) {
			// process the GDF
			if (engine.BuildAndProcessGraph(0, fullText, false) < 0)
				throw - 1;
			delete[] fullText;
		}
		else {
			// run shell
			if (engine.Shell(0) < 0)
				throw - 1;
		}
		fflush(stdout);

		if (engine.Shutdown() < 0) throw -1;
		fflush(stdout);
	}
	catch (int errorCode_) {
		fflush(stdout);
		engine.DisableWaitForKeyPress();
		errorCode = errorCode_;
	}
	if (pauseBeforeExit) {
		fflush(stdout);
		printf("Press ENTER to exit ...\n");
		while (getchar() != '\n')
			;
	}
	return errorCode;
}