Esempio n. 1
0
static void execPriorityTests(int attr, int changePriority) {
	printf("For attr %08X%s:\n", attr, changePriority ? " and changed priorities" : "");

	schedulingLogPos = 0;

	SceUID threads[7];
	int test[7] = {1, 2, 3, 4, 5, 6, 7};

	mbx = sceKernelCreateMbx("mbx1", attr, NULL);
	PRINT_MBX(mbx);

	sendMbx(mbx, 0x20);
	sendMbx(mbx, 0x10);

	int i;
	for (i = 0; i < 7; i++) {
		threads[i] = CREATE_PRIORITY_THREAD(threadFunction, 0x18 - i);
		sceKernelStartThread(threads[i], sizeof(int), (void*)&test[i]);
	}

	sceKernelDelayThread(10 * 1000);

	// What we're gonna do now is change the threads' priorities to see whether
	// priority at time of wait (already happened) or at time of send matters.
	if (changePriority) {
		for (i = 0; i < 7; i++) {
			sceKernelChangeThreadPriority(threads[i], 0x18 - 7 + i);
		}
		printf("Priorities reversed.  Have a nice day.\n");
	}

	schedf("---\n");
	PRINT_MBX(mbx);
	schedf("---\n");
	sendMbx(mbx, 0x15);

	sceKernelDelayThread(10 * 1000);

	schedf("---\n");
	PRINT_MBX(mbx);
	schedf("---\n");

	sendMbx(mbx, 0x20);
	sendMbx(mbx, 0x10);

	sceKernelDelayThread(10 * 1000);

	schedf("---\n");
	PRINT_MBX(mbx);
	schedf("---\n");

	sceKernelDeleteMbx(mbx);
	schedf("\n\n");

	printf("%s", schedulingLog);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	SceUID thid;
	int error;
	void *data;

	pspDebugScreenInit();
	if (argc > 0) {
		printf("Bootpath: %s\n", argv[0]);
	}
	SetupCallbacks();

	/* Create a messagebox */
	myMessagebox = sceKernelCreateMbx("pspSDK-testMBX", 0, 0);
	printf("MAIN: created messagebox %08x\n", myMessagebox);

	/* Create a task that will post in the messagebox */
	thid = sceKernelCreateThread("subthread", SubThread, 17, 8192, THREAD_ATTR_USER, 0);
	sceKernelStartThread(thid, 0, NULL);
	printf("MAIN: started task %08x\n", thid);

	/* Wait for a message */
	printf("MAIN: waiting for message\n");
	error = sceKernelReceiveMbx(myMessagebox, &data, NULL);
	if(error < 0)
		printf("MAIN: ERROR %08x\n", error);
	else
		printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text);

	/* Wait for a message with timeout */
	printf("MAIN: waiting with timeout (will fail the first couple of times)\n");
	for(;;) {
		SceUInt timeout = 300000; /* microseconds */
		error = sceKernelReceiveMbx(myMessagebox, &data, &timeout);
		if(error < 0)
			printf("MAIN: ERROR %08x\n", error);
		else {
			printf("MAIN: got message: \"%s\" (timeout remaining %d us)\n",
			       ((MyMessage *)data)->text, timeout);
			break;
		}
	}

	/* Poll for messages */
	printf("MAIN: polling for message (non-blocking)\n");
	for(;;) {
		error = sceKernelPollMbx(myMessagebox, &data);
		if(error < 0) {
			printf("MAIN: ERROR %08x\n", error);
			/* Sleep for a little while to give the message
			   a chance to arrive */
			sceKernelDelayThread(300000);			
		} else {
			printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text);
			break;
		}		
	}

	/* This call to sceKernelReceiveMbx() will be interrupted
	   by the sub task without a message being sent */
	printf("MAIN: waiting for a message that will not arrive\n");
	error = sceKernelReceiveMbx(myMessagebox, &data, NULL);
	if(error < 0)
		printf("MAIN: ERROR %08x\n", error);
	else
		printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text);	

	/* Prepare to shutdown */
	printf("MAIN: waiting for sub task to exit\n");
	sceKernelWaitThreadEnd(thid, NULL);
	printf("MAIN: sub task exited, deleting messagebox\n");
	error = sceKernelDeleteMbx(myMessagebox);
	if(error < 0)
		printf("MAIN: ERROR %08x\n", error);
	else
		printf("MAIN: all done\n");

	sceKernelSleepThread();

	return 0;
}
Esempio n. 3
0
int main_thread(SceSize args, void *argp)
{
	struct PsplinkContext *ctx;
	int ret;
	SceUInt timeout;
	SceUID thids[20];
	int count;
	int intc;

	printf("PSPLink USB GDBServer (c) 2k7 TyRaNiD\n");
	if(!initialise(args, argp))
	{
		printf("Usage: usbgdb.prx program [args]\n");
		sceKernelExitDeleteThread(0);
	}

	if(usbAsyncRegister(ASYNC_GDB, &g_endp) < 0)
	{
		printf("Could not register GDB provider\n");
		sceKernelExitDeleteThread(0);
	}

	usbWaitForConnect();
	memset(&g_handler, 0, sizeof(g_handler));
	g_handler.size = sizeof(g_handler);
	g_handler.membase = g_context.info.text_addr;
	g_handler.memtop = g_context.info.text_addr + g_context.info.text_size;
	g_handler.mbox = sceKernelCreateMbx("GDBMbx", 0, NULL);
	if(g_handler.mbox < 0)
	{
		printf("Could not create message box\n");
		sceKernelExitDeleteThread(0);
	}

	if(debugRegisterEventHandler(&g_handler) < 0)
	{
		printf("Could not register event handler\n");
		sceKernelExitDeleteThread(0);
	}

	if(GdbHandleException(&g_context.ctx))
	{
		while(1)
		{
			timeout = GDB_POLL_TIMEOUT;
			ret = debugWaitDebugEvent(&g_handler, &ctx, &timeout);
			
			if(ret == 0)
			{
				DEBUG_PRINTF("ctx %p, epc 0x%08X\n", ctx, ctx->regs.epc);
				ret = GdbHandleException(ctx);
				sceKernelWakeupThread(ctx->thid);
				if(ret == 0)
				{
					break;
				}
			}
			else if(ret == SCE_KERNEL_ERROR_WAIT_TIMEOUT)
			{
				unsigned char ch;

				if(peekDebugChar(&ch) && (ch == 3))
				{
					DEBUG_PRINTF("Break Issued\n");
					intc = pspSdkDisableInterrupts();
					count = psplinkReferThreadsByModule(SCE_KERNEL_TMID_Thread, g_context.uid, thids, 20);
					if(count > 0)
					{
						/* We just break the first thread */
						/* Could in theory break on the thread which we are interested in ? */
						debugBreakThread(thids[0]);
					}
					pspSdkEnableInterrupts(intc);

					/* Should have a fallback if it just wont stop
						GdbHandleException(&g_context.ctx);
					*/
				}
				continue;
			}
			else
			{
				printf("Error waiting for debug event 0x%08X\n", ret);
				break;
			}
		}
	}

	debugUnregisterEventHandler(&g_handler);
	sceKernelExitDeleteThread(0);

	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
	SceCtrlData pad;
	int oldButtons = 0;
#define SECOND	   1000000
#define REPEAT_START (1 * SECOND)
#define REPEAT_DELAY (SECOND / 5)
	struct timeval repeatStart;
	struct timeval repeatDelay;
	int result;
	int msgCount = 0;

	repeatStart.tv_sec = 0;
	repeatStart.tv_usec = 0;
	repeatDelay.tv_sec = 0;
	repeatDelay.tv_usec = 0;

	printHeader();

	int receiveThreadId = sceKernelCreateThread("ReceiveMbx", receiveMbxThread, 0x50, 0x1000, 0, 0);
	sceKernelStartThread(receiveThreadId, 0, 0);

	while (!done) {
		sceCtrlReadBufferPositive(&pad, 1);
		int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons;

		if (pad.Buttons == oldButtons) {
			struct timeval now;
			gettimeofday(&now, NULL);
			if (repeatStart.tv_sec == 0) {
				repeatStart.tv_sec = now.tv_sec;
				repeatStart.tv_usec = now.tv_usec;
				repeatDelay.tv_sec = 0;
				repeatDelay.tv_usec = 0;
			} else {
				long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND;
				usec += (now.tv_usec - repeatStart.tv_usec);
				if (usec >= REPEAT_START) {
					if (repeatDelay.tv_sec != 0) {
						usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND;
						usec += (now.tv_usec - repeatDelay.tv_usec);
						if (usec >= REPEAT_DELAY) {
							repeatDelay.tv_sec = 0;
						}
					}

					if (repeatDelay.tv_sec == 0) {
						buttonDown = pad.Buttons;
						repeatDelay.tv_sec = now.tv_sec;
						repeatDelay.tv_usec = now.tv_usec;
					}
				}
			}
		} else {
			repeatStart.tv_sec = 0;
		}

		if (buttonDown & PSP_CTRL_CROSS) {
			printHeader();
			mbxId = sceKernelCreateMbx("Mbx", 0, NULL);
			pspDebugScreenPrintf("sceKernelCreateMbx = 0x%08X\n", mbxId);
			printMbxStatus(mbxId);
		}

		if (buttonDown & PSP_CTRL_CIRCLE) {
			printHeader();
			msgCount++;
			MyMessage *msg = malloc(sizeof(MyMessage));
			msg->header.next = (void *) 0x12345678;
			msg->header.msgPriority = 1;
			msg->header.dummy[0] = 2;
			msg->header.dummy[1] = 3;
			msg->header.dummy[2] = 4;
			sprintf(msg->text, "Hello %d", msgCount);
			result = sceKernelSendMbx(mbxId, msg);
			pspDebugScreenPrintf("sceKernelSendMbx msg=0x%08X, msgCount=%d: 0x%08X\n", (int) msg, msgCount, result);
			printMbxStatus(mbxId);
		}

		if (buttonDown & PSP_CTRL_SQUARE) {
			printHeader();
			printMbxStatus(mbxId);
		}

		if (buttonDown & PSP_CTRL_LEFT) {
			sceKernelWakeupThread(receiveThreadId);
			printHeader();
		}

		if (buttonDown & PSP_CTRL_TRIANGLE) {
			done = 1;
		}

		oldButtons = pad.Buttons;
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}