コード例 #1
0
ファイル: fatload.c プロジェクト: soywiz/psp_ipl_sdk
/****************************************************************************
	save file
****************************************************************************/
int ms_save_file(const char *path,const void *data,int size)
{
	FRESULT result;
	WORD writed;
	int num_write;
	int block_cnt = 0;

	//
	result = f_mount(0,&FileSystem);
	if(result!=0)
	{
#if __VERBOSE__
Kprintf("f_mount error %08X\n",result);
#endif
		return -1;
	}

	result = f_open(&FileObject,path,FA_WRITE|FA_CREATE_ALWAYS);
	if(result!=0)
	{
#if __VERBOSE__
Kprintf("f_open %s error\n",path);
#endif
		return -1;
	}

	while(size)
	{
		num_write = size>0x8000 ? 0x8000 : size;
		result = f_write(&FileObject,data,num_write,&writed);
		if(result!=0 || num_write!=writed)
		{
#if __VERBOSE__
Kprintf("f_write error\n");
#endif
			return -1;
		}
//Kprintf("f_write %08X:%04X\n",(int)data,writed);
		data += num_write;
		size -= num_write;

		if( ms_poll_access(block_cnt++) )
		{
#if __VERBOSE__
Kprintf("Left %08X\n",size);
#endif
		}
	}
//Kprintf("readed %d bytes\n",ttl_read);
	f_close(&FileObject);
	REG32(0xbe24000c)  = 0x40;

	return 0;
}
コード例 #2
0
ファイル: fatload.c プロジェクト: soywiz/psp_ipl_sdk
/****************************************************************************
	save file
****************************************************************************/
int ms_save_file(const char *path,const void *data,int size)
{
	FRESULT result;
	WORD writed;
	int num_write;
	int block_cnt = 0;

	//
	result = f_mount(0,&FileSystem);
	if(result!=0)
	{
Kprintf("f_mount error %08X\n",result);
		return -1;
	}

	result = f_open(&FileObject,path,FA_WRITE|FA_CREATE_ALWAYS);
	if(result!=0)
	{
Kprintf("f_open %s error\n",path);
		return -1;
	}

	while(size)
	{
		num_write = size>0x8000 ? 0x8000 : size;
		result = f_write(&FileObject,data,num_write,&writed);
		if(result!=0 || num_write!=writed)
		{
Kprintf("f_write error\n");
			return -1;
		}
//Kprintf("f_write %08X:%04X\n",(int)data,writed);
		data += num_write;
		size -= num_write;

		// flip LED
		block_cnt++;
		if(block_cnt&1)
			REG32(0xbe24000c)  = 0x40;
		else
			REG32(0xbe240008)  = 0x40;
		if( (block_cnt%32)==0)
		{
			// clear WDT
			pspSysconNop();
Kprintf("Left %08X\n",size);
		}
	}
//Kprintf("readed %d bytes\n",ttl_read);
	f_close(&FileObject);

	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: soywiz/psp_ipl_sdk
/****************************************************************************
	reset PSP
****************************************************************************/
void reboot_psp(void)
{
	// reset reboot
	Kprintf("Reset PSP\n\n");
	pspSysconResetDevice(1);
	while(1);
}
コード例 #4
0
ファイル: main.c プロジェクト: yin8086/psplinkusb
int unload_loader(void)
{
	SceModule *mod;
	SceUID modid;
	int ret = 0;
	int status;

	mod = sceKernelFindModuleByName(BOOTLOADER_NAME);
	if(mod != NULL)
	{
		DEBUG_PRINTF("Loader UID: %08X\n", mod->modid);
		/* Stop module */
		modid = mod->modid;
		ret = sceKernelStopModule(modid, 0, NULL, &status, NULL);
		if(ret >= 0)
		{
			ret = sceKernelUnloadModule(modid);
		}
	}
	else
	{
		Kprintf("Couldn't find bootloader\n");
	}

	return 0;
}
コード例 #5
0
ファイル: config.c プロジェクト: FTPiano/psplinkusb
void configLoad(const char *bootpath, struct ConfigContext *ctx)
{
	char cnf_path[256];
	struct ConfigFile cnf;

	memset(ctx, 0, sizeof(*ctx));
	strcpy(cnf_path, bootpath);
	strcat(cnf_path, "psplink.ini");
	Kprintf("Config Path %s\n", cnf_path);
	if(psplinkConfigOpen(cnf_path, &cnf))
	{
		const char *name;
		const char *val;

		while((val = psplinkConfigReadNext(&cnf, &name)))
		{
			int config;

			config = 0;
			while(config_names[config].name)
			{
				if(strcmp(config_names[config].name, name) == 0)
				{
					unsigned int iVal = 0;
					if(config_names[config].isnum)
					{
						char *endp;

						iVal = strtoul(val, &endp, 0);
						if(*endp != 0)
						{
							Kprintf("Error, line %d value should be a number\n", cnf.line); 
							break;
						}
					}

					config_names[config].handler(ctx, val, iVal);
				}
				config++;
			}

			/* Ignore anything we don't care about */
		}

		psplinkConfigClose(&cnf);
	}
}
コード例 #6
0
ファイル: main.c プロジェクト: FTPiano/psplinkusb
int main_thread(SceSize args, void *argp)
{
	SceUID block_id;
	void *vram;

	block_id = sceKernelAllocPartitionMemory(4, "debugmenu", PSP_SMEM_Low, 512*272*2, NULL);
	if(block_id < 0)
	{
		Kprintf("Error could not allocate memory buffer 0x%08X\n", block_id);
		goto error;
	}
	 
	vram = (void*) (0xA0000000 | (unsigned int) sceKernelGetBlockHeadAddr(block_id));
	g_eventflag = sceKernelCreateEventFlag("DebugMenuEvent", 0, 0, NULL);
	if(g_eventflag < 0)
	{
		Kprintf("Could not create event flag %08X\n", g_eventflag);
		goto error;
	}

	//sceCtrlRegisterButtonCallback(0, PSP_CTRL_HOME, button_callback, NULL);
	sceCtrlRegisterButtonCallback(3, TRIGGER, button_callback, NULL);
	while(1)
	{
		unsigned int bits;
		if(sceKernelWaitEventFlag(g_eventflag, START_MENU,
					PSP_EVENT_WAITOR | PSP_EVENT_WAITCLEAR, &bits, NULL) < 0)
		{
			break;
		}
		sceCtrlSetButtonMasks(0xFFFF, 1);  // Mask lower 16bits
		sceCtrlSetButtonMasks(0x10000, 2); // Always return HOME key
		sceDisplaySetFrameBufferInternal(0, vram, 512, 0, 1);
		pspDebugScreenInitEx(vram, 0, 0);
		do_menu();
		sceDisplaySetFrameBufferInternal(0, 0, 512, 0, 1);
		sceCtrlSetButtonMasks(0x10000, 0); // Unset HOME key
		sceCtrlSetButtonMasks(0xFFFF, 0);  // Unset mask
		sceKernelClearEventFlag(g_eventflag, ~START_MENU);
	}

error:
	sceKernelExitDeleteThread(0);

	return 0;
}
コード例 #7
0
ファイル: assert.c プロジェクト: esxgx/uofw
void sceKernelAssert(int test, int lvl)
{
    if (test)
        return;
    // CFD0
    if (sceKernelDipsw(8) == 0)
    {
        // D00C
        Kprintf("assertion ignore (level %d)\n", lvl);
        return;
    }
    void (*assertFunc)(int) = g_assertHandler;
    if (assertFunc == NULL)
    {  
        // CFFC
        Kprintf("There is no assert handler, stop\n");
        for (;;) // D004
            ;
    }
    assertFunc(0);
}
コード例 #8
0
ファイル: main.c プロジェクト: joel16/utopia
int sceHibariInit()
{
	Kprintf("Hibari Display Driver Clone v 0.1\n");
	Kprintf("Copyright (C) 2007, Dark_AleX\n");
	
	int tachyon = sceSysregGetTachyonVersion();

	Kprintf("Tachyon version = 0x%08X.\n", tachyon);

	if (tachyon < 0x00500000)
		return 0x80000004;

	_Init();

	hibari_struct[0] = 0;
	st2.ptr = NULL;
	st2.unk1 = 0;	
	sceKernelRegisterSysEventHandler(&event_handler);
	
	return 0;
}
コード例 #9
0
ファイル: malloc.c プロジェクト: mrcmunir/cspspemu
// 24MB to use
int main(int argc, char** argv) {
    unsigned int sum;
    int n, m;
    unsigned int *buffers[NUM_BUFFERS];
    unsigned int *buffer;
    char *temp;
    Kprintf("STARTED\n");
    {
        for (n = 0; n < NUM_BUFFERS; n++) {
            buffers[n] = calloc(BUFFER_SIZE, sizeof(unsigned int));
            buffer = buffers[n];
            Kprintf("%s\n", (buffer == NULL) ? "NULL" : "NOT NULL");
            for (m = 0; m < BUFFER_SIZE; m++) buffer[m] = n;
        }
        for (n = 0; n < NUM_BUFFERS; n++) {
            sum = 0;
            buffer = buffers[n];
            for (m = 0; m < BUFFER_SIZE; m++) sum += buffer[m];
            Kprintf("%d: %d\n", n, sum);
        }
        temp = malloc(10 * 1024 * 1024);
        Kprintf("%s\n", (temp == NULL) ? "NULL" : "NOT NULL");
        for (n = 0; n < NUM_BUFFERS; n++) {
            free(buffers[n]);
        }
        temp = malloc(10 * 1024 * 1024);
        Kprintf("%s\n", (temp == NULL) ? "NULL" : "NOT NULL");
    }
    Kprintf("ENDED\n");

    sceKernelExitGame();
    return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: azuwis/xreader
unsigned long FindProc(const char *szMod, const char *szLib, unsigned long nid)
{
	unsigned int k = pspSdkSetK1(0);
	struct SceLibraryEntryTable *entry;
	SceModule *pMod;
	void *entTab;
	int entLen;

	pMod = (SceModule *) sceKernelFindModuleByName(szMod);

	if (!pMod) {
		Kprintf("Cannot find module %s\n", szMod);
		pspSdkSetK1(k);
		return 0;
	}

	int i = 0;

	entTab = pMod->ent_top;
	entLen = pMod->ent_size;

	while (i < entLen) {
		int count;
		int total;
		u32 *vars;

		entry = (struct SceLibraryEntryTable *) (entTab + i);

		if (entry->libname && !strcmp(entry->libname, szLib)) {
			total = entry->stubcount + entry->vstubcount;
			vars = entry->entrytable;

			if (entry->stubcount > 0) {
				for (count = 0; count < entry->stubcount; count++) {
					if (vars[count] == nid) {
						pspSdkSetK1(k);
						return vars[count + total];
					}
				}
			}
		}

		i += (entry->len * 4);
	}

	pspSdkSetK1(k);
	return 0;
}
コード例 #11
0
ファイル: dmacman.c プロジェクト: madnessw/thesnow
int  dmacDeinit(){
	int x;
	register int ch, value;

	CpuSuspendIntr(&x);					//intrman

	dmacSetBF801578(0);
	for (ch=0; ch<13; ch++){
		value=dmacGetD_CHCR(ch);
		if (value & DMAf_TR)				//sysmem
			Kprintf("WARNING:DMA %dch has been continued until shutdown\n", ch);
		dmacSetD_CHCR(ch, value & 0xFEFFFFFF);
	}

	CpuResumeIntr(x);					//intrman
	return 1;
}
コード例 #12
0
ファイル: main.c プロジェクト: soywiz/psp_ipl_sdk
/****************************************************************************
	entry point
****************************************************************************/
int main(void)
{
	Kprintf("ENTER:%s\n",__title__);

	// init I/O
	pspSyscon_init();
	pspSysconCtrlLED(0,1);
	pspSysconCtrlLED(1,1);
	pspSysconCtrlMsPower(1);

	// MS/FAT system
	ms_fat_init();

	ms_save_file(BIOS_FILE_NAME,(void *)0xbfc00000,0x1000);

	// reset reboot
	reboot_psp();

	return 0;
}
コード例 #13
0
ファイル: tty.c プロジェクト: FTPiano/psplinkusb
void ttyInit(void)
{
	SceUID uid;

	if(stdioTtyInit() < 0)
	{
		Kprintf("Could not initialise tty\n");
		return;
	}

	stdioInstallStdoutHandler(stdoutHandler);
	stdioInstallStderrHandler(stderrHandler);
	stdioInstallStdinHandler(inputHandler);
	/* Install a patch to prevent a naughty app from closing stdout */
	uid = refer_module_by_name("sceIOFileManager", NULL);
	if(uid >= 0)
	{
		apiHookByNid(uid, "IoFileMgrForUser", 0x810c4bc3, close_func);
		libsPatchFunction(uid, "IoFileMgrForKernel", 0x3c54e908, 0xFFFF);
	}
}
コード例 #14
0
ファイル: fatload.c プロジェクト: soywiz/psp_ipl_sdk
/****************************************************************************
	universal IPL/file  loader

1.encrypted IPL BLOCK DATA
2.decrypted IPL BLOCK DATA
3.binary included header of single decrypted IPL BLOCK DATA.

****************************************************************************/
void *ms_load_bootloader(const char *path)
{
	FRESULT result;
	WORD readed;
	DWORD *src;

	DWORD *top;
	DWORD size;
	void *entry;
	DWORD sum;
	int file_type;

	result = f_mount(0,&FileSystem);
	if(result!=0)
	{
#if __VERBOSE__
Kprintf("f_mount error %08X\n",result);
#endif
		return 0;
	}

	// check file format
	result = f_open(&FileObject,path,FA_READ|FA_OPEN_EXISTING);
	if(result!=0)
	{
#if __VERBOSE__
Kprintf("f_open %s error\n",path);
#endif
		return 0;
	}

	// check 1st block
	result = f_read(&FileObject,ipl_buf,0x10,&readed);

	// chech decrypted IPL HEADER
	top  = (DWORD *)(ipl_buf[0]);
	size = (ipl_buf[1]);
	entry= (void *)(ipl_buf[2]);
	sum  = (ipl_buf[3]);
	if(
		check_ipl_address(top) &&
		check_ipl_address(top+size) && 
		(entry==0 || ( entry >= top && entry<=(top+size))) &&
		sum == 0
	){
		// decrypted with header
Kprintf("Decrypted Format\n");
		if(entry==NULL)
		{
			// multi header == decrypted IPL
			f_close(&FileObject);
			return ms_load_ipl(path);
		}

		// single decrypted binary
#if __VERBOSE__
Kprintf("Single Binary Format\n");
#endif
		while(size>0)
		{
			result = f_read(&FileObject,top,0x8000,&readed);
			if(result!=0)
			{
//Kprintf("f_read error\n");
				return -1;
			}
#if __VERBOSE__
Kprintf("f_read addr=%08X size=%08X\n",(int)top,readed);
#endif
			top  += readed/4;
			size -= readed;
		}
		f_close(&FileObject);
		return entry;
	}

	// check encrypted IPL format
	result = f_read(&FileObject,ipl_buf+0x10/4,0x1000-0x10,&readed);
	f_close(&FileObject);

	if( pspKirkProc(ipl_buf,0x1000,ipl_buf,0x1000,0x01) ==0)
	{
Kprintf("Encrypted Format\n");
		return ms_load_ipl(path);
	}

	//
Kprintf("Unsuported Format\n");
	return NULL;
}
コード例 #15
0
ファイル: fatload.c プロジェクト: soywiz/psp_ipl_sdk
void *ms_load_ipl(const char *path)
{
	FRESULT result;
	WORD readed;
	DWORD *src;

	DWORD *top;
	DWORD size;
	void *entry;
	DWORD sum;
	int binary_type = 0;

	result = f_mount(0,&FileSystem);
	if(result!=0)
	{
#if __VERBOSE__
Kprintf("f_mount error %08X\n",result);
#endif
		return 0;
	}

	result = f_open(&FileObject,path,FA_READ|FA_OPEN_EXISTING);
	if(result!=0)
	{
#if __VERBOSE__
Kprintf("f_open %s error\n",path);
#endif
		return 0;
	}

	do{
		result = f_read(&FileObject,ipl_buf,0x1000,&readed);
		if(result!=0)
		{
#if __VERBOSE__
Kprintf("f_read error\n");
#endif
			entry = 0;
			goto error;
		}

		if(binary_type==0)
		{
			// chech decrypted HEADER
			top  = (DWORD *)(ipl_buf[0]);
			size = (ipl_buf[1]);
			entry= (void *)(ipl_buf[2]);
			sum  = (ipl_buf[3]);
			if(
				check_ipl_address(top) &&
				check_ipl_address(top+size) && 
				(entry==0 || ( entry >= top && entry<=(top+size))) &&
				sum == 0
			){
				// decrypted with header
				binary_type = 2;
			} else if(
				ipl_buf[0x60/4]==0x01 &&
				ipl_buf[0x64/4]==0    &&
				ipl_buf[0x68/4]==0
			)
			{
				// encrypted IPL
				binary_type = 1;
			}
		}

		// decrypt block
		if(binary_type==1)
		{
			if( pspKirkProc(ipl_buf,0x1000,ipl_buf,0x1000,0x01) < 0)
			{
#if __VERBOSE__
Kprintf("Decrypt error\n");
#endif
				entry = 0;
				goto error;
			}
		}

		// load BLOCK
		top  = (ipl_buf[0]);
		size = (ipl_buf[1]);
		entry= (ipl_buf[2]);
		sum  = (ipl_buf[3]);
		src  = &(ipl_buf[4]);
#if __VERBOSE__
Kprintf("TOP %08X SIZE %08X ENTRY %08X SUM %08X\n",top,size,entry,sum);
#endif
		while(size)
		{
			*top++ = *src++;
			size -= 4;
		}

	}while(entry==0);
//Kprintf("readed %d bytes\n",ttl_read);
error:
	f_close(&FileObject);

	return entry;
}