Beispiel #1
0
BOOL
OSCreateThread(OSThread *thread, ThreadEntryPoint entry, uint32_t argc, void *argv, uint8_t *stack, uint32_t stackSize, uint32_t priority, OSThreadAttributes::Flags attributes)
{
   // Create new fiber
   auto fiber = gProcessor.createFiber();

   // Setup OSThread
   memset(thread, 0, sizeof(OSThread));
   thread->entryPoint = entry;
   thread->userStackPointer = stack;
   thread->stackStart = gMemory.untranslate(stack);
   thread->stackEnd = thread->stackStart - stackSize;
   thread->basePriority = priority;
   thread->attr = attributes;
   thread->fiber = fiber;
   thread->id = gThreadId++;
   fiber->thread = thread;

   // Write magic stack ending!
   gMemory.write(thread->stackEnd, 0xDEADBABE);

   // Setup thread state
   InitialiseThreadState(thread, entry, argc, argv);

   // Initialise tracer
   traceInit(&fiber->state, 128);

   return TRUE;
}
Beispiel #2
0
#include "c.h"

static char rcsid[] = "$Name: v4_2 $($Id: main.c,v 1.1 2002/08/28 23:12:44 drh Exp $)";

static void typestab(Symbol, void *);

static void stabline(Coordinate *);
static void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *);
Interface *IR = NULL;

int Aflag;		/* >= 0 if -A specified */
int Pflag;		/* != 0 if -P specified */
int glevel;		/* == [0-9] if -g[0-9] specified */
int xref;		/* != 0 for cross-reference data */
Symbol YYnull;		/* _YYnull  symbol if -n or -nvalidate specified */
Symbol YYcheck;		/* _YYcheck symbol if -nvalidate,check specified */

static char *comment;
static Interface stabIR;
static char *currentfile;       /* current file name */
static int currentline;		/* current line number */
static FILE *srcfp;		/* stream for current file, if non-NULL */
static int srcpos;		/* position of srcfp, if srcfp is non-NULL */
int main(int argc, char *argv[]) {
	int i, j;
	for (i = argc - 1; i > 0; i--)
		if (strncmp(argv[i], "-target=", 8) == 0)
			break;
	if (i > 0) {
		char *s = strchr(argv[i], '\\');
		if (s != NULL)
			*s = '/';
		for (j = 0; bindings[j].name && bindings[j].ir; j++)
			if (strcmp(&argv[i][8], bindings[j].name) == 0) {
				IR = bindings[j].ir;
				break;
			}
		if (s != NULL)
			*s = '\\';
	}
	if (!IR) {
		fprint(stderr, "%s: unknown target", argv[0]);
		if (i > 0)
			fprint(stderr, " `%s'", &argv[i][8]);
		fprint(stderr, "; must specify one of\n");
		for (i = 0; bindings[i].name; i++)
			fprint(stderr, "\t-target=%s\n", bindings[i].name);
		exit(EXIT_FAILURE);
	}
	init(argc, argv);
	t = gettok();
	(*IR->progbeg)(argc, argv);
	for (i = 1; i < argc; i++)
		if (strcmp(argv[i], "-n") == 0) {
			if (!YYnull) {
				YYnull = install(string("_YYnull"), &globals, GLOBAL, PERM);
				YYnull->type = func(voidptype, NULL, 1);
				YYnull->sclass = EXTERN;
				(*IR->defsymbol)(YYnull);
			}
		} else if (strncmp(argv[i], "-n", 2) == 0) {	/* -nvalid[,check] */
			char *p = strchr(argv[i], ',');
			if (p) {
				YYcheck = install(string(p+1), &globals, GLOBAL, PERM);
				YYcheck->type = func(voidptype, NULL, 1);
				YYcheck->sclass = EXTERN;
				(*IR->defsymbol)(YYcheck);
				p = stringn(argv[i]+2, p - (argv[i]+2));
			} else
				p = string(argv[i]+2);
			YYnull = install(p, &globals, GLOBAL, PERM);
			YYnull->type = func(voidptype, NULL, 1);
			YYnull->sclass = EXTERN;
			(*IR->defsymbol)(YYnull);
		} else {
			profInit(argv[i]);
			traceInit(argv[i]);
		}
	if (glevel && IR->stabinit)
		(*IR->stabinit)(firstfile, argc, argv);
	program();
	if (events.end)
		apply(events.end, NULL, NULL);
	memset(&events, 0, sizeof events);
	if (glevel || xref) {
		Symbol symroot = NULL;
		Coordinate src;
		foreach(types,       GLOBAL, typestab, &symroot);
		foreach(identifiers, GLOBAL, typestab, &symroot);
		src.file = firstfile;
		src.x = 0;
		src.y = lineno;
		if ((glevel > 2 || xref) && IR->stabend)
			(*IR->stabend)(&src, symroot,
				ltov(&loci,    PERM),
				ltov(&symbols, PERM), NULL);
		else if (IR->stabend)
			(*IR->stabend)(&src, NULL, NULL, NULL, NULL);
	}
	finalize();
	(*IR->progend)();
	deallocate(PERM);
	return errcnt > 0;
}
Beispiel #3
0
int main()
{
	timeInit();
	ledInit();
	traceInit();

	// Enable global interrupts.
	// Needed for RST and ATN interrupt handlers.
	CyGlobalIntEnable;

	// Set interrupt handlers.
	scsiPhyInit();

	configInit(&scsiDev.boardCfg);
	debugInit();

	scsiInit();
	scsiDiskInit();

	// Optional bootup delay
	int delaySeconds = 0;
	while (delaySeconds < scsiDev.boardCfg.startupDelay) {
		// Keep the USB connection working, otherwise it's very hard to revert
		// silly extra-long startup delay settings.
		int i;
		for (i = 0; i < 200; i++) {
			CyDelay(5);
			scsiDev.watchdogTick++;
			configPoll();
		}
		++delaySeconds;
	}

	uint32_t lastSDPoll = getTime_ms();
	sdCheckPresent();

	while (1)
	{
		scsiDev.watchdogTick++;

		scsiPoll();
		scsiDiskPoll();
		configPoll();
		sdPoll();

		if (unlikely(scsiDev.phase == BUS_FREE))
		{
			if (unlikely(elapsedTime_ms(lastSDPoll) > 200))
			{
				lastSDPoll = getTime_ms();
				sdCheckPresent();
			}
			else
			{
				// Wait for our 1ms timer to save some power.
				// There's an interrupt on the SEL signal to ensure we respond
				// quickly to any SCSI commands. The selection abort time is
				// only 250us, and new SCSI-3 controllers time-out very
				// not long after that, so we need to ensure we wake up quickly.
				uint8_t interruptState = CyEnterCriticalSection();
				if (!SCSI_ReadFilt(SCSI_Filt_SEL))
				{
					__WFI(); // Will wake on interrupt, regardless of mask
				}
				CyExitCriticalSection(interruptState);
			}
		}
		else if (scsiDev.phase >= 0)
		{
			// don't waste time scanning SD cards while we're doing disk IO
			lastSDPoll = getTime_ms();
		}
	}
	return 0;
}