/* Entry point */ int module_start(SceSize args, void *argp) { int thid; int retv; retv = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0); if(retv){ return 0; } retv = sceUsbStart(HOSTFSDRIVER_NAME, 0, 0); if(retv){ return 0; } retv = sceUsbActivate(HOSTFSDRIVER_PID); usbAsyncRegister(ASYNC_SHELL, &g_endp); usbAsyncRegister(ASYNC_STDOUT, &g_stdin); usbWaitForConnect(); retv = stdioTtyInit(); stdioInstallStdoutHandler(usbStdoutPrint); stdioInstallStderrHandler(usbStderrPrint); printk("Usbshell Start!\n"); /* Create a high priority thread */ thid = sceKernelCreateThread("USBShell", main_thread, 12, 0x2000, 0, NULL); if(thid >= 0) { sceKernelStartThread(thid, args, argp); } return 0; }
int usbShellInit(void) { usbAsyncRegister(ASYNC_SHELL, &g_endp); usbAsyncRegister(ASYNC_STDOUT, &g_stdin); ttySetUsbHandler(usbStdoutPrint, usbStderrPrint, usbStdinRead); usbWaitForConnect(); psplinkPrintPrompt(); return 0; }
int main(int argc, char *argv[]) { int chan; int running = 1; pspDebugScreenInit(); chan = usbAsyncRegister(ASYNC_ALLOC_CHAN, &g_endp); if(chan < 0) { printf("Could not allocate async channel\n"); return 0; } usbWaitForConnect(); printf("Allocated channel %d, connect to localhost port %d and start typing\n", chan, 10000 + chan); while(running) { unsigned char buf[512]; int len; len = usbAsyncRead(chan, buf, sizeof(buf)); if(len < 0) { /* Error, most likely shutdown */ break; } if(len > 0) { pspDebugScreenPrintf("Read: %.*s\n", len, buf); usbAsyncWrite(chan, buf, len); } } usbAsyncUnregister(chan); return 0; }
int main_thread(SceSize args, void *argp) { unsigned char cli[MAX_CLI]; int cli_pos = 0; usbAsyncRegister(ASYNC_SHELL, &g_endp); ttySetUsbHandler(usbShellPrint, usbStdoutPrint, usbStderrPrint); usbWaitForConnect(); psplinkPrintPrompt(); while(1) { if(usbAsyncRead(ASYNC_SHELL, &cli[cli_pos], 1) < 1) { sceKernelDelayThread(250000); continue; } if(cli[cli_pos] == '\n') { cli[cli_pos] = 0; if(psplinkParseCommand(cli) == 1) { psplinkExitShell(); } cli_pos = 0; } else { if(cli_pos < (MAX_CLI-1)) { cli_pos++; } } } return 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; }