Exemple #1
0
int main(int argc, char *argv[])
{
    Core *core;
    int option;
    bool enableMemoryDump = false;
    uint32_t memDumpBase = 0;
    uint32_t memDumpLength = 0;
    char *memDumpFilename = NULL;
    size_t memDumpFilenameLen = 0;
    bool verbose = false;
    uint32_t fbWidth = 640;
    uint32_t fbHeight = 480;
    bool blockDeviceOpen = false;
    bool enableFbWindow = false;
    uint32_t totalThreads = 4;
    char *separator;
    uint32_t memorySize = 0x1000000;
    const char *sharedMemoryFile = NULL;
    struct stat st;

    enum
    {
        MODE_NORMAL,
        MODE_COSIMULATION,
        MODE_GDB_REMOTE_DEBUG
    } mode = MODE_NORMAL;

    while ((option = getopt(argc, argv, "f:d:vm:b:t:c:r:s:i:o:")) != -1)
    {
        switch (option)
        {
            case 'v':
                verbose = true;
                break;

            case 'r':
                gScreenRefreshRate = parseNumArg(optarg);
                break;

            case 'f':
                enableFbWindow = true;
                separator = strchr(optarg, 'x');
                if (!separator)
                {
                    fprintf(stderr, "Invalid framebuffer size %s\n", optarg);
                    return 1;
                }

                fbWidth = parseNumArg(optarg);
                fbHeight = parseNumArg(separator + 1);
                break;

            case 'm':
                if (strcmp(optarg, "normal") == 0)
                    mode = MODE_NORMAL;
                else if (strcmp(optarg, "cosim") == 0)
                    mode = MODE_COSIMULATION;
                else if (strcmp(optarg, "gdb") == 0)
                    mode = MODE_GDB_REMOTE_DEBUG;
                else
                {
                    fprintf(stderr, "Unkown execution mode %s\n", optarg);
                    return 1;
                }

                break;

            case 'd':
                // Memory dump, of the form: filename,start,length
                separator = strchr(optarg, ',');
                if (separator == NULL)
                {
                    fprintf(stderr, "bad format for memory dump\n");
                    usage();
                    return 1;
                }

                memDumpFilenameLen = (size_t)(separator - optarg);
                memDumpFilename = (char*) malloc(memDumpFilenameLen + 1);
                strncpy(memDumpFilename, optarg, memDumpFilenameLen);
                memDumpFilename[memDumpFilenameLen] = '\0';
                memDumpBase = parseNumArg(separator + 1);

                separator = strchr(separator + 1, ',');
                if (separator == NULL)
                {
                    fprintf(stderr, "bad format for memory dump\n");
                    usage();
                    return 1;
                }

                memDumpLength = parseNumArg(separator + 1);
                enableMemoryDump = true;
                break;

            case 'b':
                if (openBlockDevice(optarg) < 0)
                    return 1;

                blockDeviceOpen = true;
                break;

            case 'c':
                memorySize = parseNumArg(optarg);
                break;

            case 't':
                totalThreads = parseNumArg(optarg);
                if (totalThreads < 1 || totalThreads > 32)
                {
                    fprintf(stderr, "Total threads must be between 1 and 32\n");
                    return 1;
                }

                break;

            case 's':
                sharedMemoryFile = optarg;
                break;

            case 'i':
                recvInterruptFd = open(optarg, O_RDWR);
                if (recvInterruptFd < 0)
                {
                    perror("main: failed to open receive interrupt pipe");
                    return 1;
                }

                if (fstat(recvInterruptFd, &st) < 0)
                {
                    perror("main: stat failed on receive interrupt pipe");
                    return 1;
                }

                if ((st.st_mode & S_IFMT) != S_IFIFO)
                {
                    fprintf(stderr, "%s is not a pipe\n", optarg);
                    return 1;
                }

                break;

            case 'o':
                sendInterruptFd = open(optarg, O_RDWR);
                if (sendInterruptFd < 0)
                {
                    perror("main: failed to open send interrupt pipe");
                    return 1;
                }

                if (fstat(sendInterruptFd, &st) < 0)
                {
                    perror("main: stat failed on send interrupt pipe");
                    return 1;
                }

                if ((st.st_mode & S_IFMT) != S_IFIFO)
                {
                    fprintf(stderr, "%s is not a pipe\n", optarg);
                    return 1;
                }

                break;

            case '?':
                usage();
                return 1;
        }
    }

    if (optind == argc)
    {
        fprintf(stderr, "No image filename specified\n");
        usage();
        return 1;
    }

    // Don't randomize memory for cosimulation mode, because
    // memory is checked against the hardware model to ensure a match

    core = initCore(memorySize, totalThreads, mode != MODE_COSIMULATION,
                    sharedMemoryFile);
    if (core == NULL)
        return 1;

    if (loadHexFile(core, argv[optind]) < 0)
    {
        fprintf(stderr, "Error reading image %s\n", argv[optind]);
        return 1;
    }

    if (enableFbWindow)
    {
        if (initFramebuffer(fbWidth, fbHeight) < 0)
            return 1;
    }

    switch (mode)
    {
        case MODE_NORMAL:
            if (verbose)
                enableTracing(core);

            setStopOnFault(core, false);
            if (enableFbWindow)
            {
                while (executeInstructions(core, ALL_THREADS, gScreenRefreshRate))
                {
                    updateFramebuffer(core);
                    pollFbWindowEvent();
                    checkInterruptPipe(core);
                }
            }
            else
            {
                while (executeInstructions(core, ALL_THREADS, 1000000))
                    checkInterruptPipe(core);
            }

            break;

        case MODE_COSIMULATION:
            setStopOnFault(core, false);
            if (runCosimulation(core, verbose) < 0)
                return 1;	// Failed

            break;

        case MODE_GDB_REMOTE_DEBUG:
            setStopOnFault(core, true);
            remoteGdbMainLoop(core, enableFbWindow);
            break;
    }

    if (enableMemoryDump)
        writeMemoryToFile(core, memDumpFilename, memDumpBase, memDumpLength);

    dumpInstructionStats(core);
    if (blockDeviceOpen)
        closeBlockDevice();

    if (stoppedOnFault(core))
        return 1;

    return 0;
}
Exemple #2
0
/*******************************************
 Name  : initVolume
 Descr.: maybe a better name would be mountVolume
         allocate resources for a new mounted device
 Input : device      - device pointer
         blockdevice - name of blockdevice
         unit        - unit number of blockdevice
         devicedef   - medium geometry data
         error       - return error code
 Output: 0 on error (error set dos dos error);
         pointer to struct Volume on success
********************************************/
struct Volume *initVolume
	(
		struct AFSBase *afsbase,
		struct Device *device,
		CONST_STRPTR blockdevice,
		ULONG unit,
		struct DosEnvec *devicedef,
		ULONG *error
	)
{
struct Volume *volume;

	volume = AllocMem(sizeof(struct Volume),MEMF_PUBLIC | MEMF_CLEAR);
	if (volume != NULL)
	{
		volume->device = device;
		volume->ioh.blockdevice = blockdevice;
		volume->ioh.unit = unit;
		volume->ioh.flags = 0;
		volume->SizeBlock=devicedef->de_SizeBlock;
		if (devicedef->de_TableSize>=20)
			volume->bootblocks=devicedef->de_BootBlocks;
		else
			volume->bootblocks=devicedef->de_Reserved;
		volume->blockcache=initCache(afsbase, volume, devicedef->de_NumBuffers);
		if (volume->blockcache != NULL)
		{
			if (openBlockDevice(afsbase, &volume->ioh)!= NULL)
			{
				volume->countblocks =
					(
						(
							devicedef->de_HighCyl-devicedef->de_LowCyl+1
						)*devicedef->de_Surfaces*devicedef->de_BlocksPerTrack
					);
				volume->rootblock =(volume->countblocks-1+devicedef->de_Reserved)/2;
				volume->startblock=
						devicedef->de_LowCyl*
						devicedef->de_Surfaces*
						devicedef->de_BlocksPerTrack;
				volume->lastblock=
						(
							(devicedef->de_HighCyl+1)
							*devicedef->de_Surfaces
							*devicedef->de_BlocksPerTrack
						)-1;
				check64BitSupport(afsbase, volume);
				volume->ah.volume=volume;
				if (mediumPresent(&volume->ioh))
				{
					*error = newMedium(afsbase, volume);
				}
				else
					*error = 0;
				if ((*error == 0) || (*error == ERROR_NOT_A_DOS_DISK))
				{
					D(bug("[afs] initVolume: BootBlocks=%d\n",volume->bootblocks));
					D(bug("[afs] initVolume: RootBlock=%ld\n",volume->rootblock));
					volume->ah.header_block = volume->rootblock;
					return volume;
				}
			}
			else
			{
				*error=ERROR_NO_FREE_STORE;
			}
			freeCache(afsbase, volume->blockcache);
		}
		else
		{
			*error=ERROR_NO_FREE_STORE;
		}
		FreeMem(volume,sizeof(struct Volume));
	}
	else
		*error=ERROR_NO_FREE_STORE;
	return NULL;
}