Commits

Anonymous committed 057a7e9

*Optimized CDVDMAN (Declared internal structures and functions as static).
*Replaced inline assembly code that invokes syscall #14 with a call to SetVCommonHandler.
*Removed the code that plays with the system initialization/restarting functions. That was put in place because the unpatched Protokernels had a ExecPS2() syscall that didn't clean up the kernel. With the complete Protokernel patch, this entire system is redundant.
*Replaced code within the UI that manually powers off the DEV9 interface and the console with a simple call to poweroffShutdown().
*Modified the TLB initialization code to use _InitTLB (syscall #130) instead, if the amount of EE RAM is not 32MB. This is for compatibility with the PSX (DVR unit).
*(doctorxyz): Fixed the Kingdom Hearts 2 Final Mix JPN Gummi Ship missions patch.
*(doctorxyz): Exiting from the main menu will use the IGR exit path as well.
*(doctorxyz): All coloured debug screens within the EE core will be disabled, when they are to be disabled.
*(doctorxyz): Fixed Makefiles of those modules that generate map files to delete the mapfiles when they are cleaned up.

  • Participants
  • Parent commits 2bb1f9b

Comments (0)

Files changed (16)

File ee_core/Makefile

 	$(EE_BIN)
 
 clean:
-	rm -f $(EE_OBJS_DIR)*.* *.map *.bak *.elf
+	rm -f $(EE_OBJS_DIR)*.* $(EE_BIN) $(MAPFILE)
 
 clean_all:
-	rm -f $(EE_OBJS_DIR)*.* *.map *.bak *.elf
+	rm -f $(EE_OBJS_DIR)*.* $(EE_BIN) $(MAPFILE)
 
 
 include $(PS2SDK)/samples/Makefile.pref

File ee_core/Makefile.alt

 	$(EE_BIN)
 
 clean:
-	rm -f $(EE_OBJS_DIR)*.* *.map *.bak *.elf
+	rm -f $(EE_OBJS_DIR)*.* $(EE_BIN) $(MAPFILE)
 
 clean_all:
-	rm -f $(EE_OBJS_DIR)*.* *.map *.bak *.elf
+	rm -f $(EE_OBJS_DIR)*.* $(EE_BIN) $(MAPFILE)
 
 
 include $(PS2SDK)/samples/Makefile.pref

File ee_core/src/asm.S

 	daddu	$s1, $a1, $zero /* argc 	*/
 	daddu	$s2, $a2, $zero /* argv 	*/
 
+	lw	$v0, DisableDebug
+	bne	$v0, $zero, 1f
+	nop
+
 	/* dark blue BG color */
 	lui	$v0, 0x1200
 	ori	$v0, $v0, 0x00e0
 	lui	$v1, 0x0040
 	sd	$v1, 0x0000($v0)
 
+1:
 	/* disable Intr */
 	mfc0	$v1, EE_COP0_Status
 	lui	$v0, 0x0010
 	and	$v1, $v1, $v0
 	daddu	$a0, $zero, $zero
-	beq	$v1, $zero, 2f
+	beq	$v1, $zero, 3f
 	nop
-1:
+2:
 	di
 	sync.p
 	mfc0	$v1, EE_COP0_Status
 	nop	
 	and	$v1, $v1, $v0
 	nop
-	bne	$v1, $zero, 1b
+	bne	$v1, $zero, 2b
 	nop
-2:
+3:
 	/* entering Kernel mode */
 	mfc0	$v0, EE_COP0_Status
 	lui	$v1, 0xffff
 	sw	$v0, 0x0000($v1)
 
 	/* copy args from main ELF to args buffer */
-	blez	$s4, 4f
+	blez	$s4, 5f
 	daddu	$s5, $zero, $zero /* counter */
-3:
+4:
 	/* get arg len and increment it */
 	daddu	$a0, $s2, $zero
 	sll	$v0, $s5, 2
 	/* loop on every args */
 	addiu	$s5, $s5, 1
 	slt	$v1, $s5, $s4
-	bne	$v1, $zero, 3b
+	bne	$v1, $zero, 4b
 	nop
-4:
+5:
 	/* exiting Kernel mode */
 	mfc0	$v0, EE_COP0_Status
 	ori	$v0, $v0, 0x0010
 
 	lw	$v0, DisableDebug
 	bne	$v0, $zero, 2f
+	nop
 
 	/* black BG color */
 	lui	$v0, 0x1200

File ee_core/src/padhook.c

 		// Init TLB
 		if(Cop0_Index != 0x26)
 		{
-			DI();
-			ee_kmode_enter();
-			InitializeTLB();
-			ee_kmode_exit();
-			EI();
+			if(GetMemorySize()==0x02000000){
+				DI();
+				ee_kmode_enter();
+				InitializeTLB();
+				ee_kmode_exit();
+				EI();
+			}
+			else{
+				_InitTLB();
+			}
 		}
 
 		// Check Performance Counter

File ee_core/src/patches.c

 	{ "SLES_542.34", ALL_MODE, { 0xdeadbee2, 0x00100000, 0x001ac60c }}, // Kingdom Hearts 2 IT
 	{ "SLES_542.35", ALL_MODE, { 0xdeadbee2, 0x00100000, 0x001ac60c }}, // Kingdom Hearts 2 ES
 	{ "SLPM_662.33", ALL_MODE, { 0xdeadbee2, 0x00100000, 0x001ac44c }}, // Kingdom Hearts 2 JPN
-	{ "SLPM_666.75", ALL_MODE, { 0xdeadbee2, 0x00100000, 0x001adf64 }}, // Kingdom Hearts 2 Final Mix JPN
+	{ "SLPM_666.75", ALL_MODE, { 0xdeadbee2, 0x00149210, 0x001adf64 }}, // Kingdom Hearts 2 Final Mix JPN
 	{ "SLUS_212.87", ETH_MODE, { 0xdeadbee2, 0x000c0000, 0x006cd15c }}, // Prince of Persia: The Two Thrones NTSC U - slow down cdvd reads
 	{ "SLUS_212.87", HDD_MODE, { 0xdeadbee2, 0x00040000, 0x006cd15c }}, // Prince of Persia: The Two Thrones NTSC U - slow down cdvd reads
 	{ "SLES_537.77", ETH_MODE, { 0xdeadbee2, 0x000c0000, 0x006cd6dc }}, // Prince of Persia: The Two Thrones PAL - slow down cdvd reads

File ee_core/src/syshook.c

 int g_argc;
 char *g_argv[1 + MAX_ARGS];
 static char g_ElfPath[1024];
-static void *g_patchInitializeUserMem_addr;
-static u32 g_patchInitializeUserMem_val;
 
 int set_reg_hook;
 int set_reg_disabled;
 
 int padOpen_hooked = 0;
 
-static u32 systemRestartpattern[] = {
-	0x00000000,		//	nop
-	0x0c000000,		//	jal	restartEE()
-	0x00000000,		//	nop
-	0x8fa30010,		//	lw	v1, $0010(sp)
-	0x0240302d,		//	daddu	a2, s2, zero
-	0x8fa50014,		//	lw	a1, $0014(sp)
-	0x8c67000c,		//	lw	a3, $000c(v1)
-	0x18e00009,		//	blez	a3, 2f
-	0x0000202d,		//	daddu	a0, zero, zero
-	0x00000000,		//	nop
-	0x8ca30000,		//	lw	v1, $0000(a1)
-	0x24840004,		//	addiu	a0, a0, $0004
-	0x24a50004,		//	addiu	a1, a1, $0004
-	0x0087102a,		//	slt	v0, a0, a3
-	0xacc30000		//	sw	v1, $0000(a2)
-};
-static u32 systemRestartpattern_mask[] = {
-	0xffffffff,
-	0xfc000000,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff
-};
-
-static void (*systemRestart)(void);
-
-static u32 InitializeUserMempattern[] = {
-	0x27bdffe0,		//	addiu	sp, sp, $ffe0
-	0xffb00000,		//	sd	s0, $0000(sp)
-	0xffbf0010,		//	sd	ra, $0010(sp)
-	0x0c000000,		//	jal 	GetMemorySize
-	0x00000000,		//	daddu	s0, a0, zero	<-- some modchips are patching here, so we'll repatch
-	0x0040202d,		//	daddu	a0, v0, zero
-	0x0204102b,		//	sltu	v0, s0, a0
-	0x1040000a,		//	beq	v0, zero, 2f
-	0xdfbf0010,		//	ld	ra, $0010(sp)
-	0x700014a9,		//	por	v0, zero, zero
-	0x7e020000,		//	sq	v0, $0000(s0)
-	0x26100010,		//	addiu	s0, s0, $10
-	0x0204102b,		//	sltu	v0, s0, a0
-	0x00000000,		//	nop
-	0x00000000,		//	nop
-	0x1440fffa,		//	bne	v0, zero, 1b
-	0x700014a9		//	por	v0, zero, zero 
-/*
-	0xdfbf0010,		//	ld	ra, $0010(sp)
-	0xdfbf0000,		//	ld	s0, $0000(sp)
-	0x03e00008,		//	jr	ra
-	0x27bd0020		//	addiu	sp, sp, $0020
-*/
-};
-
-static u32 InitializeUserMempattern_mask[] = {
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xfc000000,
-	0x00000000,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff,
-	0xffffffff
-};
-
 static u32 InitializeTLBpattern[] = {
 	0x3c027000,		//	lui	v0, $7000
 	0x8c423ff0,		//	lw	v0, $3ff0(v0)
 
 void (*InitializeTLB)(void);
 
-
 /*----------------------------------------------------------------------------------------*/
 /* This fonction is call when SifSetDma catch a reboot request.                           */
 /*----------------------------------------------------------------------------------------*/
 */
 
 /*----------------------------------------------------------------------------------------*/
-/* This fonction unhook SifSetDma/SifSetReg sycalls		                          */
+/* This function unhook SifSetDma/SifSetReg sycalls		                          */
 /*----------------------------------------------------------------------------------------*/
 /*
 void Apply_Mode3(void)
 
 
 /*----------------------------------------------------------------------------------------*/
-/* This fonction replace SifSetReg syscall in kernel.                                     */
+/* This function replace SifSetReg syscall in kernel.                                     */
 /*----------------------------------------------------------------------------------------*/
 /*
 int Hook_SifSetReg(u32 register_num, int register_value)
 */
 
 // ------------------------------------------------------------------------
-static void init_systemRestart(void)
+static void init_initializeTLB(void)
 {
 	u32 *ptr;
 
+	if(GetMemorySize()!=0x02000000){
+		return;	//Consoles that don't have 32MB of EE RAM will have the _InitTLB() syscall, and Sony uses it under this condition anyway.
+	}
+
 	DIntr();
 	ee_kmode_enter();
 
-	// scan to find kernel InitializeUserMemory()
-	ptr = (u32 *)0x80001000;
-	ptr = find_pattern_with_mask(ptr, 0x7f000, InitializeUserMempattern, InitializeUserMempattern_mask, sizeof(InitializeUserMempattern));
-	if (!ptr)
-		goto err;
-	// keep original opcode address and value
-	g_patchInitializeUserMem_addr = (void *)&ptr[4];
-	g_patchInitializeUserMem_val = ptr[4];
-	// patch InitializeUserMemory() to avoid user mem to be cleared
-	_sw(0x3c100200, (u32)g_patchInitializeUserMem_addr); // it will exit at first s0/a0 comparison
-
-	// scan to find kernel systemRestart() function
-	ptr = (u32 *)0x80001000;
-	ptr = find_pattern_with_mask(ptr, 0x7f000, systemRestartpattern, systemRestartpattern_mask, sizeof(systemRestartpattern));
-	if (!ptr)
-		goto err;
-	// get systemRestart function pointer
-	systemRestart = (void *)(((ptr[1] & 0x03ffffff) << 2) | 0x80000000);
-
 	// scan to find kernel InitializeTLB() function
 	ptr = (u32 *)0x80001000;
 	ptr = find_pattern_with_mask(ptr, 0x7f000, InitializeTLBpattern, InitializeTLBpattern_mask, sizeof(InitializeTLBpattern));
 	ee_kmode_exit();
 	EIntr();
 
-	FlushCache(0);
-
 	return;
 
 err:
 }
 
 // ------------------------------------------------------------------------
-static void deinit_systemRestart(void)
-{
-	DIntr();
-	ee_kmode_enter();
-
-	// unpatch InitializeUserMemory()
-	_sw(g_patchInitializeUserMem_val, (u32)g_patchInitializeUserMem_addr);
-
-	ee_kmode_exit();
-	EIntr();
-
-	FlushCache(0);
-}
-
-// ------------------------------------------------------------------------
 void t_loadElf(void)
 {
 	int i, r;
 
 	DPRINTF("t_loadElf: elf path = '%s'\n", g_ElfPath);
 
-	DPRINTF("t_loadElf: System Restart...\n");
-	DIntr();
-	ee_kmode_enter();
-	systemRestart();
-	while (!(*(vu32 *)R_EE_SBUS_SMFLAG & SBUS_CTRL_MSINT)) {;}
-	*(vu32 *)R_EE_SBUS_SMFLAG = SBUS_CTRL_MSINT;
-	ee_kmode_exit();
-	EIntr();
-
 	if(!DisableDebug)
 		GS_BGCOLOUR = 0x00ff00;
 
 /*----------------------------------------------------------------------------------------*/
 void Install_Kernel_Hooks(void)
 {
-	init_systemRestart();
+	init_initializeTLB();
 
 	Old_SifSetDma  = GetSyscallHandler(__NR_SifSetDma);
 	SetSyscall(__NR_SifSetDma, &Hook_SifSetDma);
 /*----------------------------------------------------------------------------------------*/
 void Remove_Kernel_Hooks(void)
 {
-	deinit_systemRestart();
-
 	SetSyscall(__NR_SifSetDma, Old_SifSetDma);
 	SetSyscall(__NR_SifSetReg, Old_SifSetReg);	
 	SetSyscall(__NR_LoadExecPS2, Old_LoadExecPS2);

File modules/iopcore/cdvdman/Makefile.hdd

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/Makefile.hdd.hdpro

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/Makefile.hdd.pcmcia

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/Makefile.smb

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/Makefile.smb.pcmcia

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/Makefile.usb

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/Makefile.usb.4Ksectors

 all: $(IOP_BIN)
 
 clean:
-	rm -f $(IOP_BIN) $(IOP_OBJS)
+	rm -f $(IOP_BIN) $(IOP_OBJS) cdvdman.map
 
 rebuild: clean all
 

File modules/iopcore/cdvdman/atad.c

 	u8	type;
 } ata_cmd_info_t;
 
-static ata_cmd_info_t ata_cmd_table[] = {
+static const ata_cmd_info_t ata_cmd_table[] = {
 	{ATA_C_READ_DMA, 0x04}, {ATA_C_IDENTIFY_DEVICE, 0x02}, {ATA_C_IDENTIFY_PKT_DEVICE, 0x02}, {ATA_C_SMART, 0x07}, {ATA_C_SET_FEATURES, 0x01}, {ATA_C_READ_DMA_EXT, 0x04}, {ATA_C_WRITE_DMA, 0x04}, {ATA_C_IDLE, 0x01}, {ATA_C_WRITE_DMA_EXT, 0x04}
 };
 #define ATA_CMD_TABLE_SIZE	(sizeof ata_cmd_table/sizeof(ata_cmd_info_t))
 
-static ata_cmd_info_t smart_cmd_table[] = {
+static const ata_cmd_info_t smart_cmd_table[] = {
 	{ATA_C_SMART_ENABLE, 0x01}
 };
 #define SMART_CMD_TABLE_SIZE	(sizeof smart_cmd_table/sizeof(ata_cmd_info_t))

File modules/iopcore/cdvdman/cdvdman.c

 #define DPRINTF(args...)	do { } while(0)
 #endif
 
+#ifdef HDD_DRIVER
 #define MODNAME "dev9"
 IRX_ID(MODNAME, 2, 8);
-
+#else
+#define MODNAME "cdvdman"
+IRX_ID(MODNAME, 1, 1);
+#endif
 
 //------------------ Patch Zone ----------------------
 #ifdef SMB_DRIVER
 	u8 pad;
 } cd_read_mode_t;
 
+struct cdvdman_StreamingData{
+	unsigned int lsn;
+	unsigned int bufmax;
+	int stat;
+};
+
 typedef struct {
 	int err;
 	int status;
-	int Ststat;
-	int Stbufmax;
-	int Stlsn;
+	struct cdvdman_StreamingData StreamingData;
 	int intr_ef;
 	int disc_type_reg;
 #ifdef ALT_READ_CORE
 int sceCdLayerSearchFile(cdl_file_t *fp, const char *name, int layer);		// #84
 
 // internal functions prototypes
-void usbd_init(void);
-void ps2ip_init(void);
-void fs_init(void);
-void cdvdman_cdinit();
-int cdvdman_ReadSect(u32 lsn, u32 nsectors, void *buf);
-int cdvdman_readMechaconVersion(char *mname, u32 *stat);
-int cdvdman_readID(int mode, u8 *buf);
-FHANDLE *cdvdman_getfilefreeslot(void);
-void cdvdman_trimspaces(char* str);
-struct dirTocEntry *cdvdman_locatefile(char *name, u32 tocLBA, int tocLength, int layer);
-int cdvdman_findfile(cd_file_t *pcd_file, const char *name, int layer);
-int cdvdman_writeSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size);
-int cdvdman_sendSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size);
-int cdvdman_cb_event(int reason);
-unsigned int event_alarm_cb(void *args);
-void cdvdman_startThreads(void);
-void cdvdman_create_semaphores(void);
-void cdvdman_initdev(void);
-void cdvdman_get_part_specs(u32 lsn);
-
+#ifdef USB_DRIVER
+static void usbd_init(void);
+#endif
+#ifdef SMB_DRIVER
+static void ps2ip_init(void);
+#endif
+static void fs_init(void);
+#ifdef ALT_READ_CORE
+static void cdvdman_cdinit();
+static int cdvdman_ReadSect(u32 lsn, u32 nsectors, void *buf);
+#endif
+static int cdvdman_readMechaconVersion(char *mname, u32 *stat);
+static int cdvdman_readID(int mode, u8 *buf);
+static FHANDLE *cdvdman_getfilefreeslot(void);
+static void cdvdman_trimspaces(char* str);
+static struct dirTocEntry *cdvdman_locatefile(char *name, u32 tocLBA, int tocLength, int layer);
+static int cdvdman_findfile(cd_file_t *pcd_file, const char *name, int layer);
+static int cdvdman_writeSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size);
+static int cdvdman_sendSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size);
+static int cdvdman_cb_event(int reason);
+static unsigned int event_alarm_cb(void *args);
+static void cdvdman_startThreads(void);
+static void cdvdman_create_semaphores(void);
+static void cdvdman_initdev(void);
+#ifdef HDD_DRIVER
+static void cdvdman_get_part_specs(u32 lsn);
+#endif
+
+#ifdef USB_DRIVER
 // !!! usbd exports functions pointers !!!
 int (*pUsbRegisterDriver)(UsbDriver *driver); 								// #4
 void *(*pUsbGetDeviceStaticDescriptor)(int devId, void *data, u8 type); 				// #6
 int (*pUsbCloseEndpoint)(int id); 									// #10
 int (*pUsbTransfer)(int id, void *data, u32 len, void *option, UsbCallbackProc callback, void *cbArg); 	// #11
 int (*pUsbOpenEndpointAligned)(int devId, UsbEndpointDescriptor *desc); 				// #12
-
+#endif
+
+#ifdef SMB_DRIVER
 // !!! ps2ip exports functions pointers !!!
 // Note: recvfrom() used here is not a standard recvfrom() function.
 int (*plwip_close)(int s); 										// #6
 int (*plwip_send)(int s, void *dataptr, int size, unsigned int flags); 					// #11
 int (*plwip_socket)(int domain, int type, int protocol); 						// #13
 u32 (*pinet_addr)(const char *cp); 									// #24
+#endif
 
 // for "cdrom" devctl
 #define CDIOC_CMDBASE		0x430C
 int cdrom_ioctl2(iop_file_t *f, int cmd, void *args, u32 arglen, void *buf, u32 buflen);
 
 // driver ops func tab
-void *cdrom_ops[27] = {
+static void *cdrom_ops[27] = {
 	(void*)cdrom_init,
 	(void*)cdrom_deinit,
 	(void*)cdrom_dummy,
 int devctl_intref(void *args, void *buf);
 
 // devctl funcs array
-void *devctl_tab[134] = {
+static void *devctl_tab[134] = {
     (void *)devctl_cdreadclock,
 	(void *)devctl_dummy,
 	(void *)devctl_dummy,
 	u32 rootDirtocLength;
 } layer_info_t;
 
-layer_info_t layer_info[2];
+static layer_info_t layer_info[2];
 
 static int cdvdman_cdinited = 0;
 cdvdman_status_t cdvdman_stat;
 #define CDVDMAN_FS_BUFSIZE	CDVDMAN_FS_SECTORS * 2048
 static u8 cdvdman_fs_buf[CDVDMAN_FS_BUFSIZE + 2*2048] __attribute__((aligned(64))); 
 
-iop_sys_clock_t cdvdman_sysclock;
-
 static int fs_inited = 0;
 
 #ifdef HDD_DRIVER
 	u32 part_size; 		// in KB
 } cdvdman_partspecs_t;
 
-cdvdman_partspecs_t cdvdman_partspecs;
+static cdvdman_partspecs_t cdvdman_partspecs;
 #endif
 
 #define CDVDMAN_MODULE_VERSION 0x225
 #define NCMD_NUMBER		16
 static u8 cdvdman_Mbxbuf[NCMD_NUMBER*sizeof(NCmdMbx_t)];
 
-NCmdMbx_t *cdvdman_setNCmdMbx(void);
-void cdvdman_getNCmdMbx(NCmdMbx_t *mbxbuf);
-void cdvdman_sendNCmdMbx(int mbxid, cdvdman_NCmd_t *NCmdmsg, int size);
-cdvdman_NCmd_t *cdvdman_receiveNCmdMbx(int mbxid);
-void cdvdman_startNCmdthread(void);
-void cdvdman_NCmdthread(void *args);
-int cdvdman_sendNCmd(u8 ncmd, void *ndata, int ndlen);
-void cdvdman_waitNCmdsema(void);
-void cdvdman_signalNCmdsema(void);
-void cdvdman_waitsignalNCmdsema(void);
-int cdvdman_getNCmdstate(void);
-void cdvdman_NCmdCall(u8 ncmd, void *ndata);
-void (*NCmd_fn)(void *ndata);
-void NCmd_cdInit(void *ndata);
-void NCmd_cdRead(void *ndata);
-void NCmd_cdReadCDDA(void *ndata);
-void NCmd_cdSeek(void *ndata);
-void NCmd_cdStandby(void *ndata);
-void NCmd_cdStop(void *ndata);
-void NCmd_cdPause(void *ndata);
-int (*cdSync_fn)(void);
-int cdSync_blk(void);
-int cdSync_noblk(void);
-int cdSync_dummy(void);
+static NCmdMbx_t *cdvdman_setNCmdMbx(void);
+static void cdvdman_getNCmdMbx(NCmdMbx_t *mbxbuf);
+static void cdvdman_sendNCmdMbx(int mbxid, cdvdman_NCmd_t *NCmdmsg, int size);
+static cdvdman_NCmd_t *cdvdman_receiveNCmdMbx(int mbxid);
+static void cdvdman_startNCmdthread(void);
+static void cdvdman_NCmdthread(void *args);
+static int cdvdman_sendNCmd(u8 ncmd, void *ndata, int ndlen);
+static void cdvdman_waitNCmdsema(void);
+static void cdvdman_signalNCmdsema(void);
+static void cdvdman_waitsignalNCmdsema(void);
+static int cdvdman_getNCmdstate(void);
+static void cdvdman_NCmdCall(u8 ncmd, void *ndata);
+static void (*NCmd_fn)(void *ndata);
+static void NCmd_cdInit(void *ndata);
+static void NCmd_cdRead(void *ndata);
+static void NCmd_cdReadCDDA(void *ndata);
+static void NCmd_cdSeek(void *ndata);
+static void NCmd_cdStandby(void *ndata);
+static void NCmd_cdStop(void *ndata);
+static void NCmd_cdPause(void *ndata);
+static int (*cdSync_fn)(void);
+static int cdSync_blk(void);
+static int cdSync_noblk(void);
+static int cdSync_dummy(void);
 
 // NCmd funcs array
-void *NCmd_tab[7] = {
+static void *NCmd_tab[7] = {
     (void *)NCmd_cdInit,
     (void *)NCmd_cdRead,
     (void *)NCmd_cdReadCDDA,
 };
 
 // cdSync funcs array
-void *cdSync_tab[18] = {
+static void *cdSync_tab[18] = {
     (void *)cdSync_blk,
     (void *)cdSync_noblk,
     (void *)cdSync_dummy,
 };
 
 //-------------------------------------------------------------- 
-NCmdMbx_t *cdvdman_setNCmdMbx(void)
+static NCmdMbx_t *cdvdman_setNCmdMbx(void)
 {
 	int i, oldstate;
 	NCmdMbx_t *pmbx;
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_getNCmdMbx(NCmdMbx_t *pmbx)
+static void cdvdman_getNCmdMbx(NCmdMbx_t *pmbx)
 {	
 	cdvdman_pMbxcur = (void *)pmbx->next;
 	pmbx->next = (NCmdMbx_t *)cdvdman_pMbxnext;
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_sendNCmdMbx(int mbxid, cdvdman_NCmd_t *NCmdmsg, int size)
+static void cdvdman_sendNCmdMbx(int mbxid, cdvdman_NCmd_t *NCmdmsg, int size)
 {
 	NCmdMbx_t *pmbx;	
 
 }
 
 //-------------------------------------------------------------- 
-cdvdman_NCmd_t *cdvdman_receiveNCmdMbx(int mbxid)
+static cdvdman_NCmd_t *cdvdman_receiveNCmdMbx(int mbxid)
 {
 	NCmdMbx_t *pmbx;
 	int r;
 }
 
 //-------------------------------------------------------------- 
-int cdvdman_sendNCmd(u8 ncmd, void *ndata, int ndlen)
+static int cdvdman_sendNCmd(u8 ncmd, void *ndata, int ndlen)
 {
 	if (cdvdman_NCmdlocksema) {
 		if (cdvdman_stat.cdNCmd)
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_waitNCmdsema(void)
+static void cdvdman_waitNCmdsema(void)
 {
 	if (!cdvdman_NCmdsemacount) {
 		cdvdman_NCmdlocksema = 0;
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_signalNCmdsema(void)
+static void cdvdman_signalNCmdsema(void)
 {
 	if (!cdvdman_NCmdsemacount)
 		return;
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_waitsignalNCmdsema(void)
+static void cdvdman_waitsignalNCmdsema(void)
 {
 	WaitSema(cdvdman_NCmdsema);
 	SignalSema(cdvdman_NCmdsema);
 }
 
 //-------------------------------------------------------------- 
-int cdvdman_getNCmdstate(void)
+static int cdvdman_getNCmdstate(void)
 {
 	return cdvdman_stat.cdNCmd;
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_NCmdthread(void *args)
+static void cdvdman_NCmdthread(void *args)
 {
 	cdvdman_NCmd_t *NCmd;
 
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_startNCmdthread(void)
+static void cdvdman_startNCmdthread(void)
 {
 	int thid;
 	iop_mbx_t mbx;
 }
 
 //-------------------------------------------------------------- 
-void cdvdman_NCmdCall(u8 ncmd, void *ndata)
+static void cdvdman_NCmdCall(u8 ncmd, void *ndata)
 {
 	if ((u32)(ncmd >= 7))
 		return;
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdInit(void *ndata)
+static void NCmd_cdInit(void *ndata)
 {
 	cdvdman_cdinit();
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdRead(void *ndata)
+static void NCmd_cdRead(void *ndata)
 {
 	int r;
 	u32 lsn, sectors;
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdReadCDDA(void *ndata)
+static void NCmd_cdReadCDDA(void *ndata)
 {
 	int r;
 	u32 lsn, sectors;
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdSeek(void *ndata)
+static void NCmd_cdSeek(void *ndata)
 {
 	u32 lsn;
 	u8 *wdbuf = (u8 *)ndata;
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdStandby(void *ndata)
+static void NCmd_cdStandby(void *ndata)
 {
 	cdvdman_stat.status = CDVD_STAT_SPIN;
 
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdStop(void *ndata)
+static void NCmd_cdStop(void *ndata)
 {
 	cdvdman_stat.status = CDVD_STAT_STOP;
 
 }
 
 //-------------------------------------------------------------- 
-void NCmd_cdPause(void *ndata)
+static void NCmd_cdPause(void *ndata)
 {
 	cdvdman_stat.err = CDVD_ERR_NO;
 	cdvdman_stat.status = CDVD_STAT_PAUSE;
 }
 
 //-------------------------------------------------------------- 
-int cdSync_blk(void)
+static int cdSync_blk(void)
 {
 	cdvdman_waitsignalNCmdsema();
 
 }
 
 //-------------------------------------------------------------- 
-int cdSync_dummy(void)
+static int cdSync_dummy(void)
 {
 	return 0;
 }
 
 //-------------------------------------------------------------- 
-int cdSync_noblk(void)
+static int cdSync_noblk(void)
 {
 	return cdvdman_getNCmdstate();
 }
 
 #endif // ALT_READ_CORE
 
-
 //--------------------------------------------------------------
 #ifdef USB_DRIVER
-void usbd_init(void)
+static void usbd_init(void)
 {
 	modinfo_t info;
 	getModInfo("usbd\0\0\0\0", &info);
 }
 #endif
 #ifdef SMB_DRIVER
-void ps2ip_init(void)
+static void ps2ip_init(void)
 {
 	modinfo_t info;
 	getModInfo("ps2ip\0\0\0", &info);
 #endif
 
 //--------------------------------------------------------------
-void fs_init(void)
+static void fs_init(void)
 {
 	if (fs_inited)
 		return;
 }
 
 //-------------------------------------------------------------------------
-void cdvdman_initDiskType()
+static void cdvdman_initDiskType()
 {
         cdvdman_stat.err = CDVD_ERR_NO;
 
 int sceCdStInit(u32 bufmax, u32 bankmax, void *iop_bufaddr)
 {
 	cdvdman_stat.err = CDVD_ERR_NO;
-	cdvdman_stat.Ststat = 0;
-	cdvdman_stat.Stbufmax = bufmax;
+	cdvdman_stat.StreamingData.stat = 0;
+	cdvdman_stat.StreamingData.bufmax = bufmax;
 
 	return 1;
 }
 //-------------------------------------------------------------------------
 int sceCdStRead(u32 sectors, void *buf, u32 mode, u32 *err)
 {
-	sceCdRead0(cdvdman_stat.Stlsn, sectors, buf, NULL);
-	cdvdman_stat.Stlsn += sectors;
+	sceCdRead0(cdvdman_stat.StreamingData.lsn, sectors, buf, NULL);
+	cdvdman_stat.StreamingData.lsn += sectors;
 
 	if (err)
 		*err = sceCdGetError();
 
-	return sectors;	
+	return sectors;
 }
 
 //-------------------------------------------------------------------------
 int sceCdStSeek(u32 lsn)
 {
 	cdvdman_stat.err = CDVD_ERR_NO;
-	cdvdman_stat.Stlsn = lsn;
+	cdvdman_stat.StreamingData.lsn = lsn;
 
 	return 1;
 }
 		cdvdman_stat.err = CDVD_ERR_READ;
 	else {
 		cdvdman_stat.err = CDVD_ERR_NO;
-		cdvdman_stat.Stlsn = lsn;
-		cdvdman_stat.Ststat = 0;
+		cdvdman_stat.StreamingData.lsn = lsn;
+		cdvdman_stat.StreamingData.stat = 0;
 		cdvdman_stat.status = CDVD_STAT_PAUSE;
 	}
 
 //-------------------------------------------------------------------------
 int sceCdStStat(void)
 {
-	if (cdvdman_stat.Ststat == 1) 
+	if (cdvdman_stat.StreamingData.stat == 1) 
 		return 0;
 
-	return cdvdman_stat.Stbufmax;
+	return cdvdman_stat.StreamingData.bufmax;
 }
 
 //-------------------------------------------------------------------------
 int sceCdStStop(void)
 {
-	cdvdman_stat.Ststat = 1;
+	cdvdman_stat.StreamingData.stat = 1;
 	cdvdman_stat.err = CDVD_ERR_NO;
 	cdvdman_stat.status = CDVD_STAT_PAUSE;
 
 
 //-------------------------------------------------------------------------
 #ifndef HDD_DRIVER
-int cdvdman_ReadSect(u32 lsn, u32 nsectors, void *buf)
+static int cdvdman_ReadSect(u32 lsn, u32 nsectors, void *buf)
 {
 	register u32 r, sectors_to_read, lbound, ubound, nlsn, offslsn;
 	register int i, esc_flag = 0;
 }
 
 //-------------------------------------------------------------------------
-int cdvdman_readMechaconVersion(char *mname, u32 *stat)
+static int cdvdman_readMechaconVersion(char *mname, u32 *stat)
 {
 	u8 rdbuf[16];
 	u8 wrbuf[16];
 int sceCdStSeekF(u32 lsn)
 {	
 	cdvdman_stat.err = CDVD_ERR_NO;
-	cdvdman_stat.Stlsn = lsn;
+	cdvdman_stat.StreamingData.lsn = lsn;
 
 	return 1;
 }
 }
 
 //-------------------------------------------------------------- 
-FHANDLE *cdvdman_getfilefreeslot(void)
+static FHANDLE *cdvdman_getfilefreeslot(void)
 {
 	register int i;
 	FHANDLE *fh;
 }
 
 //-------------------------------------------------------------------------
-void cdvdman_trimspaces(char* str)
+static void cdvdman_trimspaces(char* str)
 {
 	int i, len;
 	char *p;
 }
 
 //-------------------------------------------------------------------------
-struct dirTocEntry *cdvdman_locatefile(char *name, u32 tocLBA, int tocLength, int layer)
+static struct dirTocEntry *cdvdman_locatefile(char *name, u32 tocLBA, int tocLength, int layer)
 {
 	char *p = (char *)name;
 	char *slash;
 }
 
 //-------------------------------------------------------------------------
-int cdvdman_findfile(cd_file_t *pcdfile, const char *name, int layer)
+static int cdvdman_findfile(cd_file_t *pcdfile, const char *name, int layer)
 {
 	register int len;
 	register u32 lsn;
 }
 
 //-------------------------------------------------------------------------
-int cdvdman_writeSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size)
+static int cdvdman_writeSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size)
 {
 	int i;
 	u8 dummy;
 }
 
 //-------------------------------------------------------------- 
-int cdvdman_sendSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size)
+static int cdvdman_sendSCmd(u8 cmd, void *in, u32 in_size, void *out, u32 out_size)
 {
 	int r, retryCount = 0;
 
 
 //--------------------------------------------------------------
 static u8 cb_args[8] __attribute__((aligned(16)));
-int cdvdman_cb_event(int reason)
+static int cdvdman_cb_event(int reason)
 {
 	iop_sys_clock_t sys_clock;	
 	int oldstate;
 }
 
 //-------------------------------------------------------------------------
-void (*cbfunc)(int reason);
-
-unsigned int event_alarm_cb(void *args)
+static void (*cbfunc)(int reason);
+
+static unsigned int event_alarm_cb(void *args)
 {
 	register int reason;
 	u8 *ptr = (u8 *)args;
 
 //-------------------------------------------------------------------------
 #ifndef ALT_READ_CORE
-void cdvdman_cdread_Thread(void *args)
+static void cdvdman_cdread_Thread(void *args)
 {
 	while (1) {
 		WaitSema(cdvdman_lockreadsema);
 
-		while (QueryIntrContext())
-			DelayThread(10000);
-
 		sceCdRead0(cdvdman_stat.cdread_lba, cdvdman_stat.cdread_sectors, cdvdman_stat.cdread_buf, &cdvdman_stat.cdread_mode);
 
 		sync_flag = 0;
 }
 
 //-------------------------------------------------------------------------
-void cdvdman_startThreads(void)
+static void cdvdman_startThreads(void)
 {
 	iop_thread_t thread_param;
 	register int thid;
 	cdvdman_stat.status = CDVD_STAT_PAUSE;
 	cdvdman_stat.err = CDVD_ERR_NO;
 
-	thread_param.thread = (void *)cdvdman_cdread_Thread;
+	thread_param.thread = &cdvdman_cdread_Thread;
 	thread_param.stacksize = 0x2000;
 	thread_param.priority = 0x0f;
 	thread_param.attr = TH_C;
 #endif
 
 //-------------------------------------------------------------------------
-void cdvdman_create_semaphores(void)
+static void cdvdman_create_semaphores(void)
 {
 	iop_sema_t smp;
 
 }
 
 //-------------------------------------------------------------------------
-void cdvdman_initdev(void)
+static void cdvdman_initdev(void)
 {
 	iop_event_t event;
 
 
 //-------------------------------------------------------------------------
 #ifdef HDD_DRIVER
-void cdvdman_get_part_specs(u32 lsn)
+static void cdvdman_get_part_specs(u32 lsn)
 {
 	register int i;
 	cdvdman_partspecs_t *ps = (cdvdman_partspecs_t *)&apaHeader.part_specs[0];

File src/system.c

 }
 
 void sysReset(int modload_mask) {
-
-	SifInitRpc(0);
-	cdInit(CDVD_INIT_NOCHECK);
-	cdInit(CDVD_INIT_EXIT);
-
-	while(!SifIopReset("rom0:UDNL rom0:EELOADCNF",0));
-	while(!SifIopSync());
-
 	fioExit();
 	SifExitIopHeap();
 	SifLoadFileExit();
 	SifExitRpc();
-	SifExitCmd();
 
 	SifInitRpc(0);
-	FlushCache(0);
-	FlushCache(2);
+
+	while(!SifIopReset("rom0:UDNL rom0:EELOADCNF", 0));
+	while(!SifIopSync());
+
+	SifInitRpc(0);
 
 	// init loadfile & iopheap services
 	SifLoadFileInit();
 }
 
 void sysPowerOff(void) {
-	u16 dev9_hw_type;
-
-	DIntr();
-	ee_kmode_enter();
-
-	// Get dev9 hardware type
-	dev9_hw_type = *DEV9_R_146E & 0xf0;
-
-	// Shutdown Pcmcia
-	if ( dev9_hw_type == 0x20 )
-	{
-		*DEV9_R_146C = 0;
-		*DEV9_R_1474 = 0;
-	}
-	// Shutdown Expansion Bay
-	else if ( dev9_hw_type == 0x30 )
-	{
-		*DEV9_R_1466 = 1;
-		*DEV9_R_1464 = 0;
-		*DEV9_R_1460 = *DEV9_R_1464;
-		*DEV9_R_146C = *DEV9_R_146C & ~4;
-		*DEV9_R_1460 = *DEV9_R_146C & ~1;
-	}
-
-	//Wait a sec
-	delay(5);
-
-	// PowerOff PS2
-	*CDVD_R_SDIN = 0;
-	*CDVD_R_SCMD = 0xF;
-
-	ee_kmode_exit();
-	EIntr();
+	poweroffShutdown();
 }
 
 void delay(int count) {
 }
 
 void sysExecExit() {
+	if(gExitPath[0]!='\0') sysExecElf(gExitPath, 0, NULL);
+
 	Exit(0);
 }
 
 static void restoreSyscallHandler(void)
 {
-	__asm__ __volatile__ (
-		"addiu 	$a0, $zero, 8\n\t"
-		"lui 	$a1, 0x8000\n\t"
-		"ori 	$a1, $a1, 0x0280\n\t"
-		"addiu 	$v1, $zero, 0x0e\n\t"
-		"syscall\n\t"
-		"nop\n\t"
-	);	
+	SetVCommonHandler(8, (void*)0x80000280);
 }
 
 #ifdef VMC
 	int i;
 	char *argv[3];
 	char config_str[255];
-//	char ipconfig[IPCONFIG_MAX_LEN] __attribute__((aligned(64)));
-
-//	sysSetIPConfig(ipconfig); // TODO only needed for ETH mode, and already done in ethsupport.ethLoadModules
 
 	if (gExitPath[0] == '\0')
 		strncpy(gExitPath, "Browser", 32);
 	fioExit();
 	SifInitRpc(0);
 	SifExitRpc();
-	FlushCache(0);
-	FlushCache(2);
 
 	sprintf(config_str, "%s %d %s %d %d %d.%d.%d.%d %d.%d.%d.%d %d.%d.%d.%d %d", mode_str, gDisableDebug, gExitPath, gUSBDelay, gHDDSpindown, \
 		ps2_ip[0], ps2_ip[1], ps2_ip[2], ps2_ip[3], \
 	argv[1] = filename;
 	argv[2] = cmask;
 
+	FlushCache(0);
+	FlushCache(2);
+
 	ExecPS2((void *)eh->entry, 0, 3, argv);
 }