diff --git a/include/avcodec_audiocodec.h b/include/avcodec_audiocodec.h index e4fd8ea..afa7ba7 100644 --- a/include/avcodec_audiocodec.h +++ b/include/avcodec_audiocodec.h @@ -6,38 +6,48 @@ typedef struct { - int unk0; - int unk4; - int err; // 8 - int edramAddr; // 12 - int neededMem; // 16 - int unk20; + s32 unk0; + s32 unk4; + s32 err; // 8 + s32 edramAddr; // 12 + s32 neededMem; // 16 + s32 unk20; void *inBuf; // 24 - int unk28; + s32 unk28; void *outBuf; // 32 - int unk36; - char unk40; - char unk41; - char unk42; - char unk43; - char unk44; - char unk45; - char unk46; - char unk47; - int unk48; - int unk52; - int unk56; - int unk60; - int unk64; - int unk68; - int unk72; - int unk76; - int unk80; - int unk84; - int unk88; - int unk92; - int unk96; - int unk100; + s32 unk36; + s8 unk40; + s8 unk41; + s8 unk42; + s8 unk43; + s8 unk44; + s8 unk45; + s8 unk46; + s8 unk47; + s32 unk48; + s32 unk52; + s32 unk56; + s32 unk60; + s32 unk64; + s32 unk68; + s32 unk72; + s32 unk76; + s32 unk80; + s32 unk84; + s32 unk88; + s32 unk92; + s32 unk96; + s32 unk100; void *allocMem; // 104 } SceAudiocodecCodec; +s32 sceAudiocodecCheckNeedMem(SceAudiocodecCodec *info, s32 codec); +s32 sceAudiocodecInit(SceAudiocodecCodec *info, s32 codec); +s32 sceAudiocodec_3DD7EE1A(SceAudiocodecCodec *info, s32 codec); +s32 sceAudiocodecDecode(SceAudiocodecCodec *info, s32 codec); +s32 sceAudiocodecGetInfo(SceAudiocodecCodec *info, s32 codec); +s32 sceAudiocodecAlcExtendParameter(SceAudiocodecCodec *info, s32 codec, s32 *sizeOut); +s32 sceAudiocodecGetEDRAM(SceAudiocodecCodec *info, s32 codec); +s32 sceAudiocodecReleaseEDRAM(SceAudiocodecCodec *info); + + diff --git a/include/common/module.h b/include/common/module.h index 49b7482..dd3d36b 100644 --- a/include/common/module.h +++ b/include/common/module.h @@ -18,6 +18,13 @@ typedef struct { void *stub_end; } SceModuleInfo; +typedef struct { + u32 unk0; + u32 unk4; + u32 unk8; + u32 unk12; +} SceThreadParameter; + extern char _gp[]; /* Module attributes. */ @@ -72,3 +79,9 @@ enum SceModuleInfoAttr { __lib_stub_top, __lib_stub_bottom \ } +#define SCE_MODULE_START_THREAD_PARAMETER(unk1, unk2, unk3, unk4) \ + const SceThreadParameter module_start_thread_parameter = { unk1, unk2, unk3, unk4 }; + +#define SCE_MODULE_STOP_THREAD_PARAMETER(unk1, unk2, unk3, unk4) \ + const SceThreadParameter module_stop_thread_parameter = { unk1, unk2, unk3, unk4 }; + diff --git a/include/interruptman.h b/include/interruptman.h index 34eeb65..e1574c4 100644 --- a/include/interruptman.h +++ b/include/interruptman.h @@ -35,125 +35,131 @@ enum SceInterrupts { typedef struct { // Handler address - int handler; // 0 + s32 handler; // 0 // GP of the module - int gp; // 4 + s32 gp; // 4 // Argument given by sceKernelRegisterSubIntrHandler - int arg; // 8 - int u12, u16, u20; + s32 arg; // 8 + s32 u12, u16, u20; // See disableCb - int enableCb; // 24 + s32 enableCb; // 24 // Pointer to the callback called by sceKernelDisableSubIntr(), that takes the same arguments as it - int disableCb; // 28 + s32 disableCb; // 28 // See disableCb - int suspendCb; // 32 + s32 suspendCb; // 32 // See disableCb - int resumeCb; // 36 + s32 resumeCb; // 36 // See disableCb - int isOccuredCb; // 40 - int u44; + s32 isOccuredCb; // 40 + s32 u44; // Some options - int v48; // 48 - int u52, u56, u60; + s32 v48; // 48 + s32 u52, u56, u60; } SubInterrupt; // Size: 64 typedef struct { - int size; // 0 - int u4; + s32 size; // 0 + s32 u4; // Callback called before setting sub interrupt, when registering - int (*cbRegBefore)(int, int, void*, void*); // 8 + s32 (*cbRegBefore)(s32, s32, void*, void*); // 8 // Callback called after - int (*cbRegAfter)(int, int, void*, void*); // 12 + s32 (*cbRegAfter)(s32, s32, void*, void*); // 12 // Callback called before resetting handler to 0 - int (*cbRelBefore)(int, int); // 16 + s32 (*cbRelBefore)(s32, s32); // 16 // Callback called after - int (*cbRelAfter)(int, int); // 20 - int (*cbEnable)(int, int); // 24 - int (*cbDisable)(int, int); // 28 - int (*cbSuspend)(int, int, int*); // 32 - int (*cbResume)(int, int, int); // 36 - int (*cbIsOccured)(int, int); // 40 + s32 (*cbRelAfter)(s32, s32); // 20 + s32 (*cbEnable)(s32, s32); // 24 + s32 (*cbDisable)(s32, s32); // 28 + s32 (*cbSuspend)(s32, s32, s32*); // 32 + s32 (*cbResume)(s32, s32, s32); // 36 + s32 (*cbIsOccured)(s32, s32); // 40 } SceIntrCb; // Size: 44 // Arg4 in sceKernelRegisterIntrHandler() typedef struct { // Handler address, sometimes OR'ed with 2 ?!? - int handler; // 0 + s32 handler; // 0 // GP of the module - int gp; // 4 + s32 gp; // 4 // Argument given by sceKernelRegisterIntrHandler - int arg; // 8 - int u12, u16, u20, u24, u28, u32, u36; + void *arg; // 8 + s32 u12, u16, u20, u24, u28, u32, u36; // Pointer to sub interrupts SubInterrupt *subIntrs; // 40 // Some value set by sceKernelRegisterIntrHandler, using arg4 SubIntrInfo.callbacks, contains some handlers ran by sceKernelRegisterSubIntrHandler SceIntrCb *cb; // 44 // InterruptManagerForKernel_D01EAA3F changes a bit depending on arg1, sceKernelRegisterIntrHandler changes some also; lower byte is the max number of sub interrupts - int v48; // 48 - int u52, u56, u60; + s32 v48; // 48 + s32 u52, u56, u60; } Interrupt; // Size: 64 typedef struct { - int size; // must be 12 - int numSubIntrs; // 4 + s32 size; // must be 12 + s32 numSubIntrs; // 4 SceIntrCb *callbacks; // 8 } SubIntrInfo; // Size: 12 typedef struct { - int size; - int attr; + s32 size; + s32 attr; void *cb; } SceIntrHandler; -typedef struct CbMap { - struct CbMap *next; - int unk1, unk2, unk3; - void (*callbacks[64])(void); -} CbMap; +typedef struct SceSyscallTable { + struct SceSyscallTable *next; + s32 seed; + /** Size of the structure (including the syscalls array). */ + s32 tableSize; + /** Size of the syscalls array. */ + s32 funcTableSize; + /** Variable-size array containing a list of syscalls. */ + void (*syscalls[])(void); +} SceSyscallTable; -typedef int (*MonitorCb)(int intrNum, int subIntrNum, int, int, int, int, char); +typedef s32 (*MonitorCb)(s32 intrNum, s32 subIntrNum, s32, s32, s32, s32, s8); -int sceKernelRegisterIntrHandler(int intrNum, int arg1, void *func, void *arg3, SceIntrHandler *handler); -int sceKernelSetUserModeIntrHanlerAcceptable(int intrNum, int subIntrNum, int setBit); -int sceKernelReleaseIntrHandler(int intrNum); -int sceKernelSetIntrLevel(int intrNum, int num); -int sceKernelSetIntrLogging(int intrNum, int arg1); -int sceKernelEnableIntr(int intNum); -int sceKernelSuspendIntr(int arg0, int arg1); -int sceKernelResumeIntr(int intrNum, int arg1); +s32 sceKernelRegisterIntrHandler(s32 intrNum, s32 arg1, void *func, void *arg3, SceIntrHandler *handler); +s32 sceKernelSetUserModeIntrHanlerAcceptable(s32 intrNum, s32 subIntrNum, s32 setBit); +s32 sceKernelReleaseIntrHandler(s32 intrNum); +s32 sceKernelSetIntrLevel(s32 intrNum, s32 num); +s32 sceKernelSetIntrLogging(s32 intrNum, s32 arg1); +s32 sceKernelEnableIntr(s32 intNum); +s32 sceKernelSuspendIntr(s32 arg0, s32 *arg1); +s32 sceKernelResumeIntr(s32 intrNum, s32 arg1); void ReleaseContextHooks(); -void InterruptManagerForKernel_E790EAED(int (*arg0)(), int (*arg1)()); -int sceKernelCallSubIntrHandler(int intrNum, int subIntrNum, int arg2, int arg3); -int sceKernelGetUserIntrStack(); -int sceKernelRegisterSubIntrHandler(int intrNum, int subIntrNum, void *handler, void *arg); -int sceKernelReleaseSubIntrHandler(int intrNum, int subIntrNum); -int sceKernelEnableSubIntr(int intrNum, int subIntrNum); -int sceKernelDisableSubIntr(int intrNum, int subIntrNum); -int sceKernelSuspendSubIntr(int intrNum, int subIntrNum, int *arg2); -int sceKernelResumeSubIntr(int intrNum, int subIntrNum, int arg2); -int sceKernelIsSubInterruptOccured(int intrNum, int subIntrNum); -int sceKernelQueryIntrHandlerInfo(int intrNum, int subIntrNum, int out); -int sceKernelSetPrimarySyscallHandler(int arg0, void (*arg1)()); +void InterruptManagerForKernel_E790EAED(s32 (*arg0)(), s32 (*arg1)()); +s32 sceKernelCallSubIntrHandler(s32 intrNum, s32 subIntrNum, s32 arg2, s32 arg3); +s32 sceKernelGetUserIntrStack(); +s32 sceKernelRegisterSubIntrHandler(s32 intrNum, s32 subIntrNum, void *handler, void *arg); +s32 sceKernelReleaseSubIntrHandler(s32 intrNum, s32 subIntrNum); +s32 sceKernelEnableSubIntr(s32 intrNum, s32 subIntrNum); +s32 sceKernelDisableSubIntr(s32 intrNum, s32 subIntrNum); +s32 sceKernelSuspendSubIntr(s32 intrNum, s32 subIntrNum, s32 *arg2); +s32 sceKernelResumeSubIntr(s32 intrNum, s32 subIntrNum, s32 arg2); +s32 sceKernelIsSubInterruptOccured(s32 intrNum, s32 subIntrNum); +s32 sceKernelQueryIntrHandlerInfo(s32 intrNum, s32 subIntrNum, s32 out); +s32 sceKernelSetPrimarySyscallHandler(s32 arg0, void (*arg1)()); void sceKernelCpuEnableIntr(); -int InterruptManagerForKernel_6FCBA912(int set); -int sceKernelClearIntrLogging(int intrNum); -int sceKernelIsInterruptOccurred(int intrNum); -int sceKernelDisableIntr(int intrNum); +s32 InterruptManagerForKernel_6FCBA912(s32 set); +s32 sceKernelClearIntrLogging(s32 intrNum); +s32 sceKernelIsInterruptOccurred(s32 intrNum); +s32 sceKernelDisableIntr(s32 intrNum); void RegisterSubIntrruptMonitor(MonitorCb before, MonitorCb after); void ReleaseSubIntrruptMonitor(); -int UnSupportIntr(int intrNum); -int InterruptManagerForKernel_8DFBD787(); -int QueryIntrHandlerInfoForUser(); -int sceKernelRegisterUserSpaceIntrStack(int addr, int size, int arg2); -int sceKernelGetCpuClockCounter(); +s32 UnSupportIntr(s32 intrNum); +s32 InterruptManagerForKernel_8DFBD787(); +s32 QueryIntrHandlerInfoForUser(); +s32 sceKernelRegisterUserSpaceIntrStack(s32 addr, s32 size, s32 arg2); +s32 sceKernelGetCpuClockCounter(); u64 sceKernelGetCpuClockCounterWide(); u32 _sceKernelGetCpuClockCounterLow(); -int sceKernelRegisterSystemCallTable(CbMap *newMap); -int sceKernelQuerySystemCall(int (*arg)()); -void InterruptManagerForKernel_E526B767(int arg); -int sceKernelGetSyscallRA(void); -int sceKernelCpuSuspendIntr(void); -void sceKernelCpuResumeIntr(int intr); -void sceKernelCpuResumeIntrWithSync(int intr); -int sceKernelIsIntrContext(void); +s32 sceKernelRegisterSystemCallTable(SceSyscallTable *newMap); +s32 sceKernelQuerySystemCall(void (*sysc)()); +void InterruptManagerForKernel_E526B767(s32 arg); +s32 sceKernelGetSyscallRA(void); +s32 sceKernelCpuSuspendIntr(void); +void sceKernelCpuResumeIntr(s32 intr); +void sceKernelCpuResumeIntrWithSync(s32 intr); +s32 sceKernelIsIntrContext(void); +int sceKernelCallUserIntrHandler(int, int, int, int, int, int); diff --git a/include/loadcore.h b/include/loadcore.h new file mode 100644 index 0000000..ce37c0b --- /dev/null +++ b/include/loadcore.h @@ -0,0 +1,20 @@ +/* Copyright (C) 2011, 2012 The uOFW team + See the file COPYING for copying permission. +*/ + +typedef struct { + s8 *libName; //0 + u8 version[2]; //4 + u16 attribute; //6 + u8 len; //8 + u8 vstubcount; //9 + u8 stubcount; //10 + void *entryTable; //12 + u16 unk16; //16 + u8 unk18; //18 + u8 unk19; //19 +} SceLibraryEntryTable; + +int sceKernelRegisterLibrary(SceLibraryEntryTable *lib); +int sceKernelGetModuleGPByAddressForKernel(void *addr); + diff --git a/include/syscon.h b/include/syscon.h index 5aef972..523b140 100644 --- a/include/syscon.h +++ b/include/syscon.h @@ -1431,9 +1431,9 @@ s32 sceSysconBatteryGetChargeTime(s32 *time); s32 sceSysconCtrlTachyonVoltage(s32 voltage); /** - * Get the digital key (?). + * Get the pressed user keys. * - * @param key Pointer to a 2-byte buffer where the digital key will be stored. + * @param key Pointer to a 2-byte buffer where the pressed user keys will be stored. * * @return 0 on success. */ diff --git a/include/usersystemlib_kernel.h b/include/usersystemlib_kernel.h new file mode 100644 index 0000000..65ba775 --- /dev/null +++ b/include/usersystemlib_kernel.h @@ -0,0 +1,15 @@ +/* Copyright (C) 2011, 2012 The uOFW team + See the file COPYING for copying permission. +*/ + +#include "common.h" + +s32 sceKernelCpuSuspendIntr(void); +void sceKernelCpuResumeIntr(s32 intr); +void sceKernelCpuResumeIntrWithSync(s32 intr); +s32 sceKernelIsCpuIntrSuspended(s32 intr); +s32 sceKernelIsCpuIntrEnable(void); + +void *sceKernelMemcpy(void *dst, const void *src, u32 n); +void *sceKernelMemset(void *s, s32 c, u32 n); + diff --git a/lib/build.mak b/lib/build.mak index 34c9a16..08c6889 100644 --- a/lib/build.mak +++ b/lib/build.mak @@ -4,7 +4,7 @@ include ../../lib/common.mak PSPSDK = $(shell psp-config --pspsdk-path) -CFLAGS := -I../../include -O1 -fno-toplevel-reorder -G0 -Wall -Wextra -Werror -fno-builtin-bcopy -fno-builtin-bzero -fno-builtin-strchr -nostdlib -I$(PSPSDK)/include +CFLAGS := -I../../include -O1 -fno-toplevel-reorder -G0 -Wall -Wextra -Werror -fno-builtin-bcopy -fno-builtin-bzero -fno-builtin-strchr -fno-builtin-printf -fno-builtin-puts -fno-builtin-putchar -nostdlib -I$(PSPSDK)/include CFLAGS_S := -I../../include/common LDFLAGS := -L../../lib -specs=../../lib/prxspecs -Wl,-q,-T../../lib/linkfile.prx -L$(PSPSDK)/lib diff --git a/lib/libExceptionManagerForKernel.a b/lib/libExceptionManagerForKernel.a new file mode 100644 index 0000000..4209076 Binary files /dev/null and b/lib/libExceptionManagerForKernel.a differ diff --git a/lib/libKernel_Library.a b/lib/libKernel_Library.a new file mode 100644 index 0000000..2fe6fae Binary files /dev/null and b/lib/libKernel_Library.a differ diff --git a/lib/libLoadCoreForKernel.a b/lib/libLoadCoreForKernel.a new file mode 100644 index 0000000..d62fa70 Binary files /dev/null and b/lib/libLoadCoreForKernel.a differ diff --git a/lib/libdebug.a b/lib/libdebug.a index c3a9d2b..6f40e89 100644 Binary files a/lib/libdebug.a and b/lib/libdebug.a differ diff --git a/lib/libsceAudiocodec.a b/lib/libsceAudiocodec.a new file mode 100644 index 0000000..3420e10 Binary files /dev/null and b/lib/libsceAudiocodec.a differ diff --git a/lib/libsceAvcodec_driver.a b/lib/libsceAvcodec_driver.a new file mode 100644 index 0000000..c36c04d Binary files /dev/null and b/lib/libsceAvcodec_driver.a differ diff --git a/lib/libsceGe_lazy.a b/lib/libsceGe_lazy.a new file mode 100644 index 0000000..2e2f631 Binary files /dev/null and b/lib/libsceGe_lazy.a differ diff --git a/lib/libsceJpeg.a b/lib/libsceJpeg.a new file mode 100644 index 0000000..fac0ba1 Binary files /dev/null and b/lib/libsceJpeg.a differ diff --git a/lib/libsceMpegbase.a b/lib/libsceMpegbase.a new file mode 100644 index 0000000..45578e3 Binary files /dev/null and b/lib/libsceMpegbase.a differ diff --git a/lib/libsceMpegbase_driver.a b/lib/libsceMpegbase_driver.a new file mode 100644 index 0000000..d8eb11d Binary files /dev/null and b/lib/libsceMpegbase_driver.a differ diff --git a/lib/libsceVideocodec.a b/lib/libsceVideocodec.a new file mode 100644 index 0000000..c97a5d1 Binary files /dev/null and b/lib/libsceVideocodec.a differ diff --git a/src/audio/Makefile b/src/audio/Makefile index 43db91a..be6242c 100644 --- a/src/audio/Makefile +++ b/src/audio/Makefile @@ -4,6 +4,8 @@ TARGET = audio OBJS = audio.o +DEBUG = 1 + LIBS = -lsceCodec_driver -lInterruptManagerForKernel -lSysclibForKernel -lThreadManForKernel -lsceSysEventForKernel -lSysMemForKernel -lDmacManForKernel -lsceDdr_driver -lsceSysreg_driver -lsceClockgen_driver -lUtilsForKernel include ../../lib/build.mak diff --git a/src/audio/audio.c b/src/audio/audio.c index c729e44..7155f22 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -2,21 +2,21 @@ See the file COPYING for copying permission. */ -#include "common.h" +#include -#include "clockgen.h" -#include "codec.h" -#include "dmacman.h" -#include "interruptman.h" -#include "lowio_ddr.h" -#include "lowio_sysreg.h" -#include "sysmem_kernel.h" -#include "sysmem_sysclib.h" -#include "sysmem_sysevent.h" -#include "sysmem_utils_kernel.h" -#include "threadman_kernel.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "audio.h" +#include asm(".set noat"); // needed for AUDIO_SET_BUSY() @@ -94,7 +94,7 @@ void audioHwInit(); int audioOutputDmaCb(int unused, int arg1); int audioOutput(SceAudioChannel *channel, short leftVol, short rightVol, void *buf); int audioIntrHandler(); -int audioEventHandler(int ev_id, char* ev_name, void* param, int* result); +s32 audioEventHandler(s32 ev_id, s8* ev_name __attribute__((unused)), void* param, s32* result); int audioSRCOutput(int vol, void *buf); int audioSRCOutputDmaCb(int arg0, int arg1); int audioInputSetup(); @@ -104,8 +104,7 @@ int audioInputThread(); int audioInputDmaCb(int arg0, int arg1); SceAudio g_audio; -char g_audioEventName[] = "SceAudio"; -SceSysEventHandler g_audioEvent = {0x40, g_audioEventName, 0x00FFFF00, audioEventHandler, 0, 0, NULL, {0, 0, 0, 0, 0, 0, 0, 0, 0}}; +SceSysEventHandler g_audioEvent = {0x40, (s8*)"SceAudio", 0x00FFFF00, audioEventHandler, 0, 0, NULL, {0, 0, 0, 0, 0, 0, 0, 0, 0}}; // 0000 /* @@ -125,23 +124,23 @@ void updateAudioBuf(int arg) } // 0038 int v2 = v | g_audio.flags; - *(int*)(0xBE000004) = (int)(char)(v2 & 0xFF) ^ v; + HW(0xBE000004) = (int)(char)(v2 & 0xFF) ^ v; g_audio.flags = v2; // 0054 - while ((LW(0xBE00000C) & v) != 0) + while ((HW(0xBE00000C) & v) != 0) ; sceKernelDmaOpQuit(g_audio.dmaPtr[0]); - *(int*)(0xBE000008) = v ^ 7; - *(int*)(0xBE00002C) = v; - *(int*)(0xBE000020) = v; + HW(0xBE000008) = v ^ 7; + HW(0xBE00002C) = v; + HW(0xBE000020) = v; v <<= 4; // 00A0 int i; for (i = 0; i < 24; i++) { - while ((LW(0xBE000028) & v) == 0) + while ((HW(0xBE000028) & v) == 0) ; - *(int*)(0xBE000060 + (arg << 4)) = 0; + HW(0xBE000060 + (arg << 4)) = 0; } if (sceKernelDmaOpAssign(g_audio.dmaPtr[arg], 0xFF, 0xFF, (arg * 64 + 320) | 0x0100C801, 0) == 0) { @@ -161,10 +160,10 @@ void updateAudioBuf(int arg) } // 0180 // 0184 - *(int*)(0xBE000008) = 7; - *(int*)(0xBE000004) = (int)g_audio.flags; - *(int*)(0xBE000010) = g_audio.flags & 3; - *(int*)(0xBE000024) = (int)g_audio.flags; + HW(0xBE000008) = 7; + HW(0xBE000004) = (int)g_audio.flags; + HW(0xBE000010) = g_audio.flags & 3; + HW(0xBE000024) = (int)g_audio.flags; pspSync(); } @@ -177,7 +176,7 @@ int dmaUpdate(int arg) { dbg_printf("Running %s\n", __FUNCTION__); char v = g_audio.flags & ~(1 << (arg & 0x1F)); - *(int*)(0xBE000004) = v; + HW(0xBE000004) = v; g_audio.flags = v; sceKernelDmaOpQuit(g_audio.dmaPtr[arg]); sceKernelDmaOpDeQueue(g_audio.dmaPtr[arg]); @@ -186,7 +185,7 @@ int dmaUpdate(int arg) // 0298 g_audio.inputInited = 0; // 029C - while ((LW(0xBE00000C) & 4) != 0) + while ((HW(0xBE00000C) & 4) != 0) ; } // 025C @@ -835,14 +834,14 @@ int sceAudioSetFrequency(int freq) int oldIntr = sceKernelCpuSuspendIntr(); AUDIO_SET_BUSY(1); g_audio.freq = freq; - *(int*)(0xBE000004) = 0; + HW(0xBE000004) = 0; // 149C - while (LW(0xBE00000C) != 0) + while (HW(0xBE00000C) != 0) ; - *(int*)(0xBE000040) = 1; - *(int*)(0xBE000038) = hwFreq; - *(int*)(0xBE00003C) = hwFreq; - *(int*)(0xBE000004) = g_audio.flags; + HW(0xBE000040) = 1; + HW(0xBE000038) = hwFreq; + HW(0xBE00003C) = hwFreq; + HW(0xBE000004) = g_audio.flags; if (g_audio.flags == 0) AUDIO_SET_BUSY(0); // 14D0 @@ -854,9 +853,7 @@ int sceAudioSetFrequency(int freq) int sceAudioInit() { - //dbg_init(1, FB_AFTER_DISPLAY, FAT_AFTER_FATMS); - //dbg_init(1, FB_NONE, FAT_AFTER_FATMS); - dbg_init(1, FB_NONE, FAT_AFTER_FATMS); + dbg_init(1, FB_NONE, FAT_AFTER_SYSCON); dbg_printf("Running %s\n", __FUNCTION__); memset(&g_audio, 0, sizeof(g_audio)); // 1558 @@ -934,12 +931,12 @@ int sceAudioLoopbackTest(int arg0) g_audio.flags = 7; AUDIO_SET_BUSY(1); sceCodec_driver_376399B6(1); - *(int*)(0xBE000004) = 7; - *(int*)(0xBE00002C) = 7; - *(int*)(0xBE000010) = 4; - *(int*)(0xBE000008) = 0; - *(int*)(0xBE000020) = 7; - *(int*)(0xBE000024) = 0; + HW(0xBE000004) = 7; + HW(0xBE00002C) = 7; + HW(0xBE000010) = 4; + HW(0xBE000008) = 0; + HW(0xBE000020) = 7; + HW(0xBE000024) = 0; sceKernelCpuResumeIntrWithSync(oldIntr); } return 0; @@ -993,7 +990,7 @@ int audioIntrHandler() dbg_printf("Running %s\n", __FUNCTION__); int oldIntr = sceKernelCpuSuspendIntr(); char attr = g_audio.flags; - char hwAttr = LW(0xBE00001C) & attr; + char hwAttr = HW(0xBE00001C) & attr; if (hwAttr != 0) { // 1A00 @@ -1027,7 +1024,7 @@ int audioIntrHandler() g_audio.flags = attr; } // 19B4 - *(int*)(0xBE000024) = attr; + HW(0xBE000024) = attr; if (attr == 0) { // 19EC @@ -1053,45 +1050,45 @@ void audioHwInit() sceSysregAudioClkoutClkSelect(0); sceSysregAudioClkoutIoEnable(); AUDIO_SET_BUSY(1); - *(int*)(0xBE000004) = 0; + HW(0xBE000004) = 0; // 1B00 - while ((LW(0xBE00000C) & 7) != 0) + while ((HW(0xBE00000C) & 7) != 0) ; - *(int*)(0xBE00002C) = 7; + HW(0xBE00002C) = 7; // 1B20 - while ((LW(0xBE000028) & 0x30) != 0x30) + while ((HW(0xBE000028) & 0x30) != 0x30) ; - *(int*)(0xBE000024) = 0; - *(int*)(0xBE000020) = 7; - *(int*)(0xBE000008) = 7; - *(int*)(0xBE000014) = 0x1208; + HW(0xBE000024) = 0; + HW(0xBE000020) = 7; + HW(0xBE000008) = 7; + HW(0xBE000014) = 0x1208; // 1B50 - while ((LW(0xBE000050) & 0x30) != 0) + while ((HW(0xBE000050) & 0x30) != 0) ; - *(int*)(0xBE000050) = 0x8000; + HW(0xBE000050) = 0x8000; g_audio.srcVol = 0x0400; - *(int*)(0xBE000018) = 0; + HW(0xBE000018) = 0; if (g_audio.freq == 48000) { // 1BF0 - *(int*)(0xBE000038) = 0x100; + HW(0xBE000038) = 0x100; } else { g_audio.freq = 44100; - *(int*)(0xBE000038) = 0x80; + HW(0xBE000038) = 0x80; } // 1BA0 short v = g_audio.hwFreq; if (v == 0) { // 1BE0 - *(int*)(0xBE000040) = 5; + HW(0xBE000040) = 5; } else { - *(int*)(0xBE000040) = 4; - *(int*)(0xBE000044) = v; + HW(0xBE000040) = 4; + HW(0xBE000044) = v; // 1BBC - while ((LW(0xBE000040) & 2) != 0) + while ((HW(0xBE000040) & 2) != 0) ; } // 1BD0 @@ -1104,7 +1101,7 @@ void audioHwInit() * * Returns 0. */ -int audioEventHandler(int ev_id, char* ev_name __attribute__((unused)), void* param __attribute__((unused)), int* result __attribute__((unused))) +s32 audioEventHandler(s32 ev_id, s8* ev_name __attribute__((unused)), void* param __attribute__((unused)), s32* result __attribute__((unused))) { dbg_printf("Running %s\n", __FUNCTION__); switch (ev_id) @@ -1135,11 +1132,11 @@ int audioEventHandler(int ev_id, char* ev_name __attribute__((unused)), void* pa ptr[2] = 0; ptr[10] = 0; AUDIO_SET_BUSY(1); - *(int*)(0xBE000004) = 1; + HW(0xBE000004) = 1; sceKernelSetEventFlag(g_audio.evFlagId, (g_audio.inputCurSampleCnt != 0) ? 0x60000000 : 0xE0000000); g_audio.flags = 0; - *(int*)(0xBE000004) = 0; - *(int*)(0xBE000008) = 0; + HW(0xBE000004) = 0; + HW(0xBE000008) = 0; pspSync(); sceSysregAudioIoDisable(0); sceSysregAudioClkoutIoDisable(); @@ -1196,8 +1193,8 @@ int sceAudioSRCChReserve(int sampleCount, int freq, int numChans) if (g_audio.freq == 48000) { // 2030 - *(int*)(0xBE000038) = 128; - *(int*)(0xBE00003C) = 128; + HW(0xBE000038) = 128; + HW(0xBE00003C) = 128; } // 1E84 @@ -1246,31 +1243,31 @@ int sceAudioSRCChReserve(int sampleCount, int freq, int numChans) AUDIO_SET_BUSY(1); if ((g_audio.flags & 2) != 0) { - *(int*)(0xBE000004) = (int)(g_audio.flags ^ 2); + HW(0xBE000004) = (int)(g_audio.flags ^ 2); // 1F30 - while ((LW(0xBE00000C) & 2) != 0) + while ((HW(0xBE00000C) & 2) != 0) ; } // 1F44 g_audio.hwFreq = hwFreq; if (hwFreq == 0) { // 1FA8 - *(int*)(0xBE000040) = 5; + HW(0xBE000040) = 5; } else { - *(int*)(0xBE000040) = 4; - *(int*)(0xBE000044) = hwFreq; + HW(0xBE000040) = 4; + HW(0xBE000044) = hwFreq; // 1F5C - while ((LW(0xBE000040) & 2) != 0) + while ((HW(0xBE000040) & 2) != 0) ; } // 1F70 - *(int*)(0xBE00002C) = 2; + HW(0xBE00002C) = 2; if (g_audio.flags != 0) { // 1F9C - *(int*)(0xBE000004) = g_audio.flags; + HW(0xBE000004) = g_audio.flags; } else AUDIO_SET_BUSY(0); @@ -1407,13 +1404,13 @@ int audioSRCOutput(int vol, void *buf) while (sceKernelGetSystemTimeLow() - oldTime < 25) ; // 2414 - while ((LW(0xBE00000C) & 2) == 0) + while ((HW(0xBE00000C) & 2) == 0) ; } // 23D8 - while ((LW(0xBE000050) & 0x10000) != 0) + while ((HW(0xBE000050) & 0x10000) != 0) ; - *(int*)(0xBE000050) = volHi; + HW(0xBE000050) = volHi; } // 239C return g_audio.srcChSampleCnt; @@ -1450,13 +1447,13 @@ int audioInputThread() if (g_audio.inputIsWaiting == 0 && g_audio.unkCodecArgSet == 0) { int oldIntr = sceKernelCpuSuspendIntr(); - *(int*)(0xBE000004) = (int)(char)(g_audio.flags & 0xFB); + HW(0xBE000004) = (int)(char)(g_audio.flags & 0xFB); g_audio.flags &= 0xFB; // 268C - while ((LW(0xBE00000C) & 4) != 0) + while ((HW(0xBE00000C) & 4) != 0) ; sceKernelDmaOpQuit(g_audio.dmaPtr[2]); - *(int*)(0xBE000008) = g_audio.flags; + HW(0xBE000008) = g_audio.flags; sceKernelCpuResumeIntr(oldIntr); sceCodec_driver_277DFFB6(); } @@ -1505,11 +1502,11 @@ int audioInputThread() *uncached2 = (int)UCACHED(&g_audio.hwBuf[36 + shift]); if (DmacManForKernel_E18A93A5(ptr1, UCACHED(&g_audio.hwBuf[32 + shift])) < 0) { - *(int*)(0xBE000004) = (int)(char)(g_audio.flags & 0xFB); + HW(0xBE000004) = (int)(char)(g_audio.flags & 0xFB); g_audio.flags &= 0xFB; pspSync(); // 2600 - while ((LW(0xBE00000C) & 4) != 0) + while ((HW(0xBE00000C) & 4) != 0) ; sceKernelDmaOpQuit(g_audio.dmaPtr[2]); ptr1[2] = g_audio.flags; @@ -1647,15 +1644,15 @@ int audioInputSetup() sceCodec_driver_376399B6(1); } // 2A10 - *(int*)(0xBE000024) = (char)((flags | 4) & 0xFF) - 4; + HW(0xBE000024) = (char)((flags | 4) & 0xFF) - 4; g_audio.flags = flags | 4; - *(int*)(0xBE00002C) = 4; - *(int*)(0xBE000020) = 4; + HW(0xBE00002C) = 4; + HW(0xBE000020) = 4; pspSync(); ret = sceKernelDmaOpEnQueue(g_audio.dmaPtr[2]); - *(int*)(0xBE000008) = g_audio.flags; - *(int*)(0xBE000004) = g_audio.flags | 1; - *(int*)(0xBE000024) = g_audio.flags; + HW(0xBE000008) = g_audio.flags; + HW(0xBE000004) = g_audio.flags | 1; + HW(0xBE000024) = g_audio.flags; pspSync(); return ret; } @@ -1752,7 +1749,7 @@ int audioInput(int sampleCount, int freq, void *buf) { g_audio.unkCodecRet = ret & 1; if ((ret & 4) != 0) - *(int*)(0xBE0000D0) = (ret >> 1) & 1; + HW(0xBE0000D0) = (ret >> 1) & 1; } // 2BD8 ret = sceCodec_driver_A88FD064(g_audio.unkInput0, g_audio.inputGain, g_audio.unkInput2, g_audio.unkInput3, g_audio.unkInput4, g_audio.unkInput5); diff --git a/src/interruptman/Makefile b/src/interruptman/Makefile index 9eeafc7..afee1b0 100644 --- a/src/interruptman/Makefile +++ b/src/interruptman/Makefile @@ -4,5 +4,9 @@ TARGET = interruptman OBJS = start.o interruptman.o end.o +DEBUG = 1 + +LIBS = -lExceptionManagerForKernel -lLoadCoreForKernel -lSysMemForKernel -lsceSuspendForKernel + include ../../lib/build.mak diff --git a/src/interruptman/end.S b/src/interruptman/end.S index 7436b67..8a6edd0 100644 --- a/src/interruptman/end.S +++ b/src/interruptman/end.S @@ -1,10 +1,9 @@ # Copyright (C) 2011, 2012 The uOFW team # See the file COPYING for copying permission. - .text - .set noat - .set noreorder +#include "common.S" + .text .globl sceKernelCpuSuspendIntr sceKernelCpuSuspendIntr: mfic $v0, $0 diff --git a/src/interruptman/exports.exp b/src/interruptman/exports.exp index 85b1ab5..bac0ceb 100644 --- a/src/interruptman/exports.exp +++ b/src/interruptman/exports.exp @@ -59,7 +59,7 @@ PSP_EXPORT_FUNC_NID(sceKernelEnableSubIntr, 0xFB8E22EC) PSP_EXPORT_FUNC_NID(sceKernelIsIntrContext, 0xFE28C6D9) PSP_EXPORT_FUNC_NID(sceKernelRegisterSubIntrHandler, 0xFFA8B183) PSP_EXPORT_VAR_NID(intInfo, 0x201A1A19) -PSP_EXPORT_VAR_NID(intInfo.intrStackArg, 0xFD6B9CAB) +PSP_EXPORT_VAR_NID(intInfo + 116, 0xFD6B9CAB) PSP_EXPORT_END PSP_EXPORT_START(InterruptManager, 0x0011, 0x4000) diff --git a/src/interruptman/interruptman.c b/src/interruptman/interruptman.c index f2822a6..075bbe4 100644 --- a/src/interruptman/interruptman.c +++ b/src/interruptman/interruptman.c @@ -2,103 +2,145 @@ See the file COPYING for copying permission. */ -#include "common.h" +#include -#include "exceptionman.h" +#include +#include +#include +#include + +#include -#include "interruptman.h" #include "end.h" +#include "interruptman.h" #include "start.h" -char intrMgrStr[] = "InterruptManager"; // 0x36F4 -char **intrMgrStrPtr = (char**)&intrMgrStr; // 0x33E8 +SceLibraryEntryTable intrEntry = { + .libName = (s8*)"InterruptManager", + .version = { + 0x11, + 0 + }, + .attribute = 0x4000, + .len = 4, + .vstubcount = 9, + .stubcount = 0, + .entryTable = (void*)(s32[]) { + 0x5CB5A78B, + 0x7860E0DC, + 0x8A389411, + 0xCA04A2B9, + 0xD2E8363F, + 0xD61E6961, + 0xEEE43F47, + 0xFB8E22EC, + 0xFC4374B8, + (s32)sceKernelSuspendSubIntr, + (s32)sceKernelResumeSubIntr, + (s32)sceKernelDisableSubIntr, + (s32)sceKernelRegisterSubIntrHandler, + (s32)QueryIntrHandlerInfoForUser, + (s32)sceKernelReleaseSubIntrHandler, + (s32)sceKernelRegisterUserSpaceIntrStack, + (s32)sceKernelEnableSubIntr, + (s32)sceKernelIsSubInterruptOccured + }, + .unk16 = 0, + .unk18 = 0, + .unk19 = 0 +}; // 0x3458 SCE_MODULE_INFO("sceInterruptManager", SCE_MODULE_KERNEL | SCE_MODULE_NO_STOP | SCE_MODULE_SINGLE_LOAD | SCE_MODULE_SINGLE_START, 1, 9); -SCE_MODULE_BOOTSTART(IntrManInit); -SCE_MODULE_REBOOT_BEFORE(IntrManTerminate); +SCE_MODULE_BOOTSTART("IntrManInit"); +SCE_MODULE_REBOOT_BEFORE("IntrManTerminate"); SCE_SDK_VERSION(SDK_VERSION); -char heapName[] = "SceInterruptManager"; // 0x3778 +SceSyscallTable g_emptyTable = { // 0x3810 + .next = NULL, + .seed = 0, + .tableSize = 0, + .funcTableSize = 0, +}; -CbMap emptyMap = {NULL, 0, 0, 0, {}}; // 0x38D0 - -CbMap cbMap = // 0x37C0 -{ - &emptyMap, 0, 0x00000100, 0x00000110, - { - sub_0CC0, sub_0CC0, sub_0864, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0ECC, sub_0EF8, sub_0F20, sub_0F58, - sub_0FE4, sub_0FF0, sub_0F64, sub_0FA4, - sub_0FF8, sub_1000, sub_1008, sub_0EC0, - sub_1010, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, - sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0 +SceSyscallTable g_syscallTable = { // 0x3700 + .next = &g_emptyTable, + .seed = 0, + .tableSize = 0x00000100, + .funcTableSize = 0x00000110, + .syscalls = { + sub_0CC0, sub_0CC0, sub_0864, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0ECC, sub_0EF8, sub_0F20, sub_0F58, + sub_0FE4, sub_0FF0, sub_0F64, sub_0FA4, + sub_0FF8, sub_1000, sub_1008, sub_0EC0, + sub_1010, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0, + sub_0CC0, sub_0CC0, sub_0CC0, sub_0CC0 } }; -/* TODO: find what lays here [0x3818 - 0x3ABC] */ +s8 g_stackBottom[672]; // 0x3820? -int wut; // 0x3AC0 +s8 g_stackMiddle[7232]; // 0x3AC0 -/* TODO: find what lays here [0x3AC4 - 0x56FC] */ +s8 g_stackTop[304]; // 0x5700 -int g_sp; // 0x5700 - -/* TODO: find what lays here [0x5704 - 0x5840] */ +s8 g_syscCtx[16]; // 0x5830 typedef struct { - int grpsOpt[24]; // 0 - char unused2; // 96 - char opt2; // 97 - char opt; // 98 - char unused3; // 99 + s32 grpsOpt[24]; // 0 + s8 unused2; // 96 + s8 opt2; // 97 + s8 opt; // 98 + s8 unused3; // 99 MonitorCb monitorCbBefore; // 100 MonitorCb monitorCbAfter; // 104 - int unused; // 108 - int intrStack; // 112 - int intrStackArg; // 116 + s32 unused; // 108 + s32 intrStack; // 112 + s32 intrStackArg; // 116 u32 clockCounterLo; // 120 u32 clockCounterHi; // 124 Interrupt intr[68]; // 128 - int subIntrMemoryPoolId; // 4088 - int intcState[2]; // 4092 - int count; - int compare; + s32 subIntrMemoryPoolId; // 4088 + s32 intcState[2]; // 4092 + s32 count; + s32 compare; } InterruptInfo; InterruptInfo intInfo; // 0x5840 -int IntrManInit() +s32 IntrManInit() { - int oldIc = sceKernelCpuSuspendIntr(); + dbg_init(1, FB_NONE, FAT_HARDWARE); + dbg_printf("Called %s\n", __FUNCTION__); + s32 oldIc = sceKernelCpuSuspendIntr(); pspCop0CtrlSet(COP0_CTRL_IS_INTERRUPT, 0); - pspCop0CtrlSet(COP0_CTRL_SP_KERNEL, (int)globUnk); + pspCop0CtrlSet(COP0_CTRL_SP_KERNEL, (s32)g_stackTop); pspCop0CtrlSet(COP0_CTRL_SP_USER, 0); mymemset(&intInfo, 0, sizeof(InterruptInfo)); intInfo.opt = 1; sub_1030(); ReleaseContextHooks(); // 1150 - int i; + s32 i; for (i = 67; i >= 0; i--) { intInfo.intr[i].u16 = -1; intInfo.intr[i].u20 = -1; } - sceKernelRegisterExceptionHandler(EXCEP_INT, (void*)sub_0038); - sceKernelRegisterPriorityExceptionHandler(EXCEP_INT, 3, (void*)sub_0924); - sceKernelRegisterExceptionHandler(EXCEP_SYS, (void*)sub_0CF8); + sceKernelRegisterExceptionHandler(EXCEP_INT, (void*)intrExcepHandler); + sceKernelRegisterPriorityExceptionHandler(EXCEP_INT, 3, (void*)intrExcepHandler2); + sceKernelRegisterExceptionHandler(EXCEP_SYS, (void*)syscallExcepHandler); sceKernelRegisterIntrHandler(67, 0, sub_0000, 0, 0); sceKernelRegisterSuspendHandler(29, SuspendIntc, 0); sceKernelRegisterResumeHandler(29, ResumeIntc, 0); @@ -108,15 +150,17 @@ int IntrManInit() pspCop0StateSet(COP0_STATE_COUNT, 0); pspCop0StateSet(COP0_STATE_COMPARE, 0x80000000); sceKernelCpuResumeIntr(oldIc); - int ret = sceKernelRegisterLibrary(intrMgrStrPtr); // This address contains a pointer to "InterruptManager" + s32 ret = sceKernelRegisterLibrary(&intrEntry); + dbg_printf("init ok\n"); if (ret < 0) return ret; return 0; } // 58DD8978 -int sceKernelRegisterIntrHandler(int intrNum, int arg1, void *func, int arg3, SceIntrHandler *handler) +s32 sceKernelRegisterIntrHandler(s32 intrNum, s32 arg1, void *func, void *arg3, SceIntrHandler *handler) { + dbg_printf("sceKernelRegisterIntrHandler(%d, %d, %08x, %08x, %08x)\n", intrNum, arg1, func, arg3, handler); if (sceKernelIsIntrContext() != 0) return 0x80020064; if (intrNum >= 68) @@ -124,11 +168,10 @@ int sceKernelRegisterIntrHandler(int intrNum, int arg1, void *func, int arg3, Sc if (handler != NULL && handler->size != 12) return 0x8002006B; // 12B8 - int oldIc = sceKernelCpuSuspendIntr(); - if (handler != NULL && handler->size > 0 && intInfo.subIntrMemoryPoolId == 0) - { + s32 oldIc = sceKernelCpuSuspendIntr(); + if (handler != NULL && handler->size > 0 && intInfo.subIntrMemoryPoolId == 0) { // 1468 - int ret = sceKernelCreateHeap(1, 1, 0x800, heapName); // "SceInterruptManager" + s32 ret = sceKernelCreateHeap(1, 1, 0x800, "SceInterruptManager"); if (ret > 0) intInfo.subIntrMemoryPoolId = ret; if (ret < 0) { @@ -143,31 +186,27 @@ int sceKernelRegisterIntrHandler(int intrNum, int arg1, void *func, int arg3, Sc return 0x80020067; } // 1354 - if ((int)func >= 0) { + if ((s32)func >= 0) { sceKernelCpuResumeIntr(oldIc); return 0x80020065; } intr->subIntrs = NULL; // 1368 intr->cb = NULL; - int size; - if (handler == NULL || (size = handler->attr) <= 0) - { + s32 size; + if (handler == NULL || (size = handler->attr) <= 0) { // 144C if (intr->subIntrs != NULL) { sceKernelFreeHeapMemory(intInfo.subIntrMemoryPoolId, intr->subIntrs); // Free memory space intr->subIntrs = NULL; } - } - else - { + } else { SubInterrupt *subIntrs = sceKernelAllocHeapMemory(intInfo.subIntrMemoryPoolId, size); // Allocate space to store the subIntrs if (subIntrs != NULL) mymemset(subIntrs, 0, sizeof(*subIntrs)); // 13A4 intr->subIntrs = subIntrs; - if (subIntrs == NULL) - { + if (subIntrs == NULL) { // 1440 sceKernelCpuResumeIntr(oldIc); return 0x80020190; @@ -176,7 +215,7 @@ int sceKernelRegisterIntrHandler(int intrNum, int arg1, void *func, int arg3, Sc } // 13B4 sceKernelSuspendIntr(intrNum, 0); - int unk2; + s32 unk2; if (intr->handler != 1 && intrNum < 64) unk2 = 3; else @@ -185,36 +224,35 @@ int sceKernelRegisterIntrHandler(int intrNum, int arg1, void *func, int arg3, Sc if (arg1 != 0) arg1 = 2; intr->v48 = (intr->v48 & 0xFFFFFCFF) | ((unk2 << 8) & 0x300); - intr->handler = arg1 | (int)func; + intr->handler = arg1 | (s32)func; intr->gp = sceKernelGetModuleGPByAddressForKernel(func); intr->arg = arg3; - *(char*)&intr->v48 = 0; + *(s8*)&intr->v48 = 0; if (handler != NULL) - *(char*)&intr->v48 = *(char*)&handler->attr; + *(s8*)&intr->v48 = *(s8*)&handler->attr; // 1420 intr->v48 = ((intr->v48 & 0x7FFF7FFF) | ((intInfo.opt << 15) & 0x8000)) & 0x7FFFFFFF; - *(char*)(&intr->v48 + 2) = intrNum; + *(s8*)(&intr->v48 + 2) = intrNum; sceKernelCpuResumeIntr(oldIc); return 0; } // A1B88367 -int sceKernelSetUserModeIntrHanlerAcceptable(int intrNum, int subIntrNum, int setBit) +s32 sceKernelSetUserModeIntrHanlerAcceptable(s32 intrNum, s32 subIntrNum, s32 setBit) { + dbg_printf("Called %s\n", __FUNCTION__); if (sceKernelIsIntrContext() != 0) return 0x80020064; if (intrNum >= 68) return 0x80020065; - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; - if (intr->handler == 0 || (intr->handler & 3) == 1) - { + if (intr->handler == 0 || (intr->handler & 3) == 1) { // 15F4 sceKernelCpuResumeIntr(oldIntr); return 0x80020068; } - if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF)) - { + if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF)) { // 1538 sceKernelCpuResumeIntr(oldIntr); return 0x80020065; @@ -223,14 +261,12 @@ int sceKernelSetUserModeIntrHanlerAcceptable(int intrNum, int subIntrNum, int se SubInterrupt *subIntr = &intr->subIntrs[subIntrNum]; subIntr->v48 = (subIntr->v48 & 0xFFFFFBFF) | (((setBit != 0) << 10) & 0x00000400); intr->v48 &= 0xFFFFF7FF; - char num = intr->v48 & 0xFF; - char v = (subIntr->v48 >> 10) & 1; + s8 num = intr->v48 & 0xFF; + s8 v = (subIntr->v48 >> 10) & 1; // 15B4 - int i; - for (i = 0; i < num; i++) - { - if (v != 0) - { + s32 i; + for (i = 0; i < num; i++) { + if (v != 0) { // 15E4 intr->v48 |= 0x800; break; @@ -244,26 +280,25 @@ int sceKernelSetUserModeIntrHanlerAcceptable(int intrNum, int subIntrNum, int se } // F987B1F0 -int sceKernelReleaseIntrHandler(int intrNum) +s32 sceKernelReleaseIntrHandler(s32 intrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (sceKernelIsIntrContext() != 0) return 0x80020064; if (intrNum >= 68) return 0x80020065; - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (intr->handler == 0) { sceKernelCpuResumeIntr(oldIntr); return 0x80020068; } // 1698 - if (((intr->v48 >> 8) & 3) != 0) - { + if (((intr->v48 >> 8) & 3) != 0) { // 16CC intr->handler = 0; sceKernelSuspendIntr(intrNum, 0); - } - else + } else intr->handler = 1; // 16B0 intr->cb = NULL; @@ -276,35 +311,30 @@ int sceKernelReleaseIntrHandler(int intrNum) } // B941600E -int sceKernelSetIntrLevel(int intrNum, int num) +s32 sceKernelSetIntrLevel(s32 intrNum, s32 num) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 64) return 0x80020065; if (num < 1 || num >= 4) return 0x80020069; Interrupt *intr = &intInfo.intr[intrNum]; - int oldIntr = sceKernelCpuSuspendIntr(); - if (intr->handler == 0 || (intr->handler & 3) == 1) - { + s32 oldIntr = sceKernelCpuSuspendIntr(); + if (intr->handler == 0 || (intr->handler & 3) == 1) { // 1814 sceKernelCpuResumeIntr(oldIntr); return 0x80020068; } - if (((intr->v48 >> 11) & 1) != 0 && ((num ^ 2) != 0)) - { + if (((intr->v48 >> 11) & 1) != 0 && ((num ^ 2) != 0)) { // 1800 sceKernelCpuResumeIntr(oldIntr); return 0x80020069; } - if (((intInfo.grpsOpt[(intrNum >> 5) + 24] >> (intrNum & 0x1F)) & 1) == 0) - { + if (((intInfo.grpsOpt[(intrNum >> 5) + 24] >> (intrNum & 0x1F)) & 1) == 0) { // 17F4 intr->v48 = (intr->v48 & 0xFFFFFCFF) | ((num << 8) & 0x00000300); - } - else - { - if (((intr->v48 >> 8) & 3) < num) - { + } else { + if (((intr->v48 >> 8) & 3) < num) { // 17E4 InterruptDisableInTable(intrNum); } @@ -318,17 +348,17 @@ int sceKernelSetIntrLevel(int intrNum, int num) } // AB1FC793 -int sceKernelSetIntrLogging(int intrNum, int arg1) +s32 sceKernelSetIntrLogging(s32 intrNum, s32 arg1) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldIc = sceKernelCpuSuspendIntr(); + s32 oldIc = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (arg1 == 0) { // 189C intr->v48 |= 0x00008000; - } - else + } else intr->v48 &= 0xFFFF7FFF; // 1878 sceKernelCpuResumeIntr(oldIc); @@ -336,19 +366,19 @@ int sceKernelSetIntrLogging(int intrNum, int arg1) } // 4D6E7305 -int sceKernelEnableIntr(int intNum) +s32 sceKernelEnableIntr(s32 intNum) { - int v; + dbg_printf("sceKernelEnableIntr(%d)\n", intNum); + s32 v; if (intNum >= 68) return 0x80020065; - int oldIc = sceKernelCpuSuspendIntr(); + s32 oldIc = sceKernelCpuSuspendIntr(); if (intInfo.intr[intNum].handler == 0) { sceKernelCpuResumeIntr(oldIc); return 0x80020068; } // 1928 - if (intNum < 64) - { + if (intNum < 64) { // 1978 sub_29B0(intNum); sceKernelCpuResumeIntr(oldIc); @@ -371,13 +401,14 @@ int sceKernelEnableIntr(int intNum) } // 2412F096 -int sceKernelSuspendIntr(int arg0, int arg1) +s32 sceKernelSuspendIntr(s32 arg0, s32 *arg1) { - int ret = 0; - int mask; + dbg_printf("sceKernelSuspendIntr(%d, %08x)\n", arg0, arg1); + s32 ret = 0; + s32 mask; if (arg0 >= 68) return 0x80020065; - int oldIc = sceKernelCpuSuspendIntr(); + s32 oldIc = sceKernelCpuSuspendIntr(); if (arg0 == 64) mask = 0x100; else if (arg0 == 65) @@ -389,32 +420,25 @@ int sceKernelSuspendIntr(int arg0, int arg1) else mask = 0; // 19F8 - if (intInfo.intr[arg0].handler != 0) - { + if (intInfo.intr[arg0].handler != 0) { // 1A78 - if (arg1 != 0) - { + if (arg1 != NULL) { if (arg0 >= 64) { // 1AA8 - *(int*)arg1 = (pspCop0StateGet(COP0_STATE_STATUS) & 0xFF00) | mask; - } - else - *(int*)arg1 = (intInfo.grpsOpt[(arg0 >> 5) + 24] >> (arg0 & 0x1F)) & 1; + *arg1 = (pspCop0StateGet(COP0_STATE_STATUS) & 0xFF00) | mask; + } else + *arg1 = (intInfo.grpsOpt[(arg0 >> 5) + 24] >> (arg0 & 0x1F)) & 1; } - } - else - { + } else { ret = 0x80020068; - if (arg1 != 0) - *(int*)arg1 = 0; + if (arg1 != NULL) + *arg1 = 0; } // 1A24 - if (arg0 < 64) - { + if (arg0 < 64) { // 1A68 AllLevelInterruptDisable(arg0); - } - else + } else pspCop0StateSet(COP0_STATE_STATUS, pspCop0StateGet(COP0_STATE_STATUS) & ~(mask & 0xFF00)); // 1A3C sceKernelCpuResumeIntr(oldIc); @@ -422,12 +446,13 @@ int sceKernelSuspendIntr(int arg0, int arg1) } // DB14CBE0 -int sceKernelResumeIntr(int intrNum, int arg1) +s32 sceKernelResumeIntr(s32 intrNum, s32 arg1) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldIntr = sceKernelCpuSuspendIntr(); - int mask; + s32 oldIntr = sceKernelCpuSuspendIntr(); + s32 mask; if (intrNum == 64) mask = 0x100; else if (intrNum == 65) @@ -439,41 +464,30 @@ int sceKernelResumeIntr(int intrNum, int arg1) else mask = 0; // 1B2C - if (intInfo.intr[intrNum].handler != 0) - { + if (intInfo.intr[intrNum].handler != 0) { // 1BA8 - if (intrNum >= 64) - { + if (intrNum >= 64) { // 1BC8 - if (arg1 != 0) - { + if (arg1 != 0) { pspCop0StateSet(COP0_STATE_STATUS, pspCop0StateGet(COP0_STATE_STATUS) | (mask & 0xFF00)); sceKernelCpuResumeIntr(oldIntr); return 0; } - } - else - { - if (arg1 == 0) - { + } else { + if (arg1 == 0) { // 1B98 AllLevelInterruptDisable(intrNum); - } - else + } else sub_29B0(intrNum); sceKernelCpuResumeIntr(oldIntr); return 0; } - } - else if (intrNum < 64) - { + } else if (intrNum < 64) { // 1B98 AllLevelInterruptDisable(intrNum); sceKernelCpuResumeIntr(oldIntr); return 0x80020068; - } - else - { + } else { pspCop0StateSet(COP0_STATE_STATUS, pspCop0StateGet(COP0_STATE_STATUS) | ~(mask & 0xFF00)); sceKernelCpuResumeIntr(oldIntr); return 0x80020068; @@ -487,44 +501,45 @@ int sceKernelResumeIntr(int intrNum, int arg1) // DB9A5496 void ReleaseContextHooks() { + dbg_printf("Called %s\n", __FUNCTION__); InterruptManagerForKernel_E790EAED(sub_091C, sub_091C); } -void InterruptManagerForKernel_E790EAED(int (*arg0)(), int (*arg1)()) +void InterruptManagerForKernel_E790EAED(s32 (*arg0)(), s32 (*arg1)()) { - int oldIc = sceKernelCpuSuspendIntr(); - *(int*)(mod_0468) = 0x0C000000 + (((int)arg1 >> 2) & 0x3FFFFFF); - pspCache(0x1A, mod_0468); - pspCache(0x08, mod_0468); - *(int*)(mod_0400) = 0x0C000000 + (((int)arg0 >> 2) & 0x3FFFFFF); - pspCache(0x1A, mod_0400); - pspCache(0x08, mod_0400); + dbg_printf("Called %s\n", __FUNCTION__); + s32 oldIc = sceKernelCpuSuspendIntr(); + *(s32*)(&mod_0468) = 0x0C000000 + (((s32)arg1 >> 2) & 0x3FFFFFF); + pspCache(0x1A, &mod_0468); + pspCache(0x08, &mod_0468); + *(s32*)(&mod_0400) = 0x0C000000 + (((s32)arg0 >> 2) & 0x3FFFFFF); + pspCache(0x1A, &mod_0400); + pspCache(0x08, &mod_0400); sceKernelCpuResumeIntr(oldIc); } // 0C5F7AE3 -int sceKernelCallSubIntrHandler(int intrNum, int subIntrNum, int arg2, int arg3) +s32 sceKernelCallSubIntrHandler(s32 intrNum, s32 subIntrNum, s32 arg2, s32 arg3) { + dbg_printf("Called %s\n", __FUNCTION__); SubInterrupt *subIntr = &intInfo.intr[intrNum].subIntrs[subIntrNum]; if (subIntr->handler < 2) return 0x80020068; - if (intInfo.monitorCbBefore != NULL) - { + if (intInfo.monitorCbBefore != NULL) { if (((subIntr->v48 >> 15) & 1) == 0) subIntr->u12++; // 1D18 intInfo.monitorCbBefore(intrNum, subIntrNum, arg2, subIntr->arg, arg3, subIntr->handler, intInfo.opt2); } // 1D28 - int oldGp = pspGetGp(); + s32 oldGp = pspGetGp(); pspSetGp(subIntr->gp); - int ret; + s32 ret; if (subIntr->handler >= 0) { // 1DB8 ret = sceKernelCallUserIntrHandler(arg2, subIntr->arg, arg3, 0, subIntr->handler, sceKernelGetUserIntrStack()); - } - else { - int (*func)(int, int, int) = (void*)subIntr->handler; + } else { + s32 (*func)(s32, s32, s32) = (void*)subIntr->handler; ret = func(arg2, subIntr->arg, arg3); } // 1D4C @@ -537,20 +552,22 @@ int sceKernelCallSubIntrHandler(int intrNum, int subIntrNum, int arg2, int arg3) } // CD36EB65 -int sceKernelGetUserIntrStack() +s32 sceKernelGetUserIntrStack() { + dbg_printf("Called %s\n", __FUNCTION__); if (intInfo.opt2 == 0) return intInfo.intrStack; - return *(int*)(pspCop0CtrlGet(COP0_CTRL_SP_KERNEL) + 180); + return *(s32*)(pspCop0CtrlGet(COP0_CTRL_SP_KERNEL) + 180); } // FFA8B183 (kernel) / CA04A2B9 -int sceKernelRegisterSubIntrHandler(int intrNum, int subIntrNum, void *handler, void *arg) +s32 sceKernelRegisterSubIntrHandler(s32 intrNum, s32 subIntrNum, void *handler, void *arg) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldK1 = pspShiftK1(); - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldK1 = pspShiftK1(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (intr->handler == 0) { sceKernelCpuResumeIntr(oldIntr); @@ -558,18 +575,14 @@ int sceKernelRegisterSubIntrHandler(int intrNum, int subIntrNum, void *handler, return 0x80020068; } // 1ED4 - if (((int)handler >> 31) == 0 && pspK1IsUserMode()) // 200C - { + if (((s32)handler >> 31) == 0 && pspK1IsUserMode()) { // 200C sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; - } - else - { + } else { if (intInfo.intrStack == 0) return 0x80020065; - if (((intr->v48 >> 11) & 1) == 0) - { + if (((intr->v48 >> 11) & 1) == 0) { sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; @@ -582,43 +595,37 @@ int sceKernelRegisterSubIntrHandler(int intrNum, int subIntrNum, void *handler, return 0x80020065; } SubInterrupt *subIntr = &intr->subIntrs[subIntrNum]; - if (subIntr->handler != 0) - { + if (subIntr->handler != 0) { sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020067; } // 1F3C - if (((int)handler >> 31) == 0 && (((subIntr->v48 & 0xFF) >> 10) & 1) == 0) - { + if (((s32)handler >> 31) == 0 && (((subIntr->v48 & 0xFF) >> 10) & 1) == 0) { sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; } // 1F60 - if (intr->cb != NULL && intr->cb->cbRegBefore != NULL) - { + if (intr->cb != NULL && intr->cb->cbRegBefore != NULL) { // 1FEC - int ret = intr->cb->cbRegBefore(intrNum, subIntrNum, handler, arg); - if (ret != 0) - { + s32 ret = intr->cb->cbRegBefore(intrNum, subIntrNum, handler, arg); + if (ret != 0) { sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } } - subIntr->handler = (int)handler; + subIntr->handler = (s32)handler; // 1F78 subIntr->gp = sceKernelGetModuleGPByAddressForKernel(handler); - *(char*)&subIntr->v48 = 0; - subIntr->arg = (int)arg; + *(s8*)&subIntr->v48 = 0; + subIntr->arg = (s32)arg; subIntr->v48 = (subIntr->v48 & 0xFFFF7FFF) | (intr->v48 & 0x00008000) | 0x80000300; - if (intr->cb != NULL && intr->cb->cbRegAfter != NULL) - { + if (intr->cb != NULL && intr->cb->cbRegAfter != NULL) { // 1FD4 - int ret = intr->cb->cbRegAfter(intrNum, subIntrNum, handler, arg); - if (ret != 0) - { + s32 ret = intr->cb->cbRegAfter(intrNum, subIntrNum, handler, arg); + if (ret != 0) { // (moved 1FC4) subIntr->handler = 0; sceKernelCpuResumeIntr(oldIntr); @@ -632,22 +639,21 @@ int sceKernelRegisterSubIntrHandler(int intrNum, int subIntrNum, void *handler, } // D61E6961 (both kernel and user) -int sceKernelReleaseSubIntrHandler(int intrNum, int subIntrNum) +s32 sceKernelReleaseSubIntrHandler(s32 intrNum, s32 subIntrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldK1 = pspShiftK1(); - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldK1 = pspShiftK1(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; - if (intr->handler == 0) - { + if (intr->handler == 0) { // 2108 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020068; } - if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF)) - { + if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF)) { // 20A0 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); @@ -655,35 +661,30 @@ int sceKernelReleaseSubIntrHandler(int intrNum, int subIntrNum) } // 20E0 SubInterrupt *subIntr = &intr->subIntrs[subIntrNum]; - if (subIntr->handler == 0 || (subIntr->handler < 0 && pspK1IsUserMode())) - { + if (subIntr->handler == 0 || (subIntr->handler < 0 && pspK1IsUserMode())) { // 2108 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020068; } // 2110 - if (intr->cb != NULL && intr->cb->cbRelBefore != NULL) - { + if (intr->cb != NULL && intr->cb->cbRelBefore != NULL) { // 2160 - int ret = intr->cb->cbRelBefore(intrNum, subIntrNum); - if (ret != 0) - { + s32 ret = intr->cb->cbRelBefore(intrNum, subIntrNum); + if (ret != 0) { sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } } // 2128 - int oldHandler = subIntr->handler; + s32 oldHandler = subIntr->handler; subIntr->handler = 0; - if (intr->cb != NULL && intr->cb->cbRelAfter != NULL) - { + if (intr->cb != NULL && intr->cb->cbRelAfter != NULL) { // 2150 - int ret = intr->cb->cbRelAfter(intrNum, subIntrNum); + s32 ret = intr->cb->cbRelAfter(intrNum, subIntrNum); // (moved 2140) - if (ret != 0) - { + if (ret != 0) { subIntr->handler = oldHandler; sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); @@ -696,94 +697,90 @@ int sceKernelReleaseSubIntrHandler(int intrNum, int subIntrNum) } // FB8E22EC (both user and kernel) -int sceKernelEnableSubIntr(int intrNum, int subIntrNum) +s32 sceKernelEnableSubIntr(s32 intrNum, s32 subIntrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldK1 = pspShiftK1(); - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldK1 = pspShiftK1(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF) || (pspK1IsUserMode() && (((intr->v48 >> 11) & 1) == 0 - || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) - { + || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) { // 2210 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; } // 2248 - if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbEnable == NULL) - { + if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbEnable == NULL) { // 226C sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020068; } // 2274 - int ret = intr->cb->cbEnable(intrNum, subIntrNum); + s32 ret = intr->cb->cbEnable(intrNum, subIntrNum); sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } // 4023E1A7 (kernel) / 8A389411 (user) -int sceKernelDisableSubIntr(int intrNum, int subIntrNum) +s32 sceKernelDisableSubIntr(s32 intrNum, s32 subIntrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldK1 = pspShiftK1(); - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldK1 = pspShiftK1(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF) || (pspK1IsUserMode() && (((intr->v48 >> 11) & 1) == 0 - || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) - { + || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) { // 231C sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; } // 2354 - if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbDisable == NULL) - { + if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbDisable == NULL) { // 2378 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020068; } - int ret = intr->cb->cbDisable(intrNum, subIntrNum); + s32 ret = intr->cb->cbDisable(intrNum, subIntrNum); sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } // C495F536 (kernel) / 5CB5A78B (user) -int sceKernelSuspendSubIntr(int intrNum, int subIntrNum, int *arg2) +s32 sceKernelSuspendSubIntr(s32 intrNum, s32 subIntrNum, s32 *arg2) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldK1 = pspShiftK1(); - if (!pspK1PtrOk(arg2)) - { + s32 oldK1 = pspShiftK1(); + if (!pspK1PtrOk(arg2)) { // 24C4 pspSetK1(oldK1); return 0x800200D3; } - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF) || (pspK1IsUserMode() && (((intr->v48 >> 11) & 1) == 0 - || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) - { + || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) { // 2440 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; } // 247C - if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbSuspend == NULL) - { + if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbSuspend == NULL) { // 24A0 if (arg2 != NULL) *arg2 = 0; @@ -792,98 +789,93 @@ int sceKernelSuspendSubIntr(int intrNum, int subIntrNum, int *arg2) return 0x80020068; } - int ret = intr->cb->cbSuspend(intrNum, subIntrNum, arg2); + s32 ret = intr->cb->cbSuspend(intrNum, subIntrNum, arg2); sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } // 2980AE03 (kernel) / 7860E0DC (user) -int sceKernelResumeSubIntr(int intrNum, int subIntrNum, int arg2) +s32 sceKernelResumeSubIntr(s32 intrNum, s32 subIntrNum, s32 arg2) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 0) return 0x80020065; - int oldK1 = pspShiftK1(); - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldK1 = pspShiftK1(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF) || (pspK1IsUserMode() && (((intr->v48 >> 11) & 1) == 0 - || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) - { + || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) { // 2574 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; } // 25B0 - if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbResume == NULL) - { + if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbResume == NULL) { // 25D4 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020068; } - int ret = intr->cb->cbResume(intrNum, subIntrNum, arg2); + s32 ret = intr->cb->cbResume(intrNum, subIntrNum, arg2); sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } // 4351DD4E (kernel) / FC4374B8 (user) -int sceKernelIsSubInterruptOccured(int intrNum, int subIntrNum) +s32 sceKernelIsSubInterruptOccured(s32 intrNum, s32 subIntrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldK1 = pspShiftK1(); - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldK1 = pspShiftK1(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; if (subIntrNum < 0 || subIntrNum >= (intr->v48 & 0xFF) || (pspK1IsUserMode() && (((intr->v48 >> 11) & 1) == 0 - || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) - { + || ((intr->subIntrs[subIntrNum].v48 >> 10) & 1) == 0))) { // 2688 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020065; } // 26C0 - if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbIsOccured == NULL) - { + if (intr->handler == 0 || intr->cb == NULL || intr->cb->cbIsOccured == NULL) { // 26E4 sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return 0x80020068; } // 26EC - int ret = intr->cb->cbIsOccured(intrNum, subIntrNum); + s32 ret = intr->cb->cbIsOccured(intrNum, subIntrNum); sceKernelCpuResumeIntr(oldIntr); pspSetK1(oldK1); return ret; } // 68B5CA51 -int sceKernelQueryIntrHandlerInfo(int intrNum, int subIntrNum, int out) +s32 sceKernelQueryIntrHandlerInfo(s32 intrNum, s32 subIntrNum, s32 out) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - if (*(int*)(out + 0) != 56) + if (*(s32*)(out + 0) != 56) return 0x8002006B; - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; - char numSubIntr = intr->v48 & 0xFF; - if (numSubIntr != 0) - { - if (subIntrNum < 0 || subIntrNum >= numSubIntr) - { + s8 numSubIntr = intr->v48 & 0xFF; + if (numSubIntr != 0) { + if (subIntrNum < 0 || subIntrNum >= numSubIntr) { // (2918) // 291C if (subIntrNum != -1) { sceKernelCpuResumeIntr(oldIntr); return 0x80020065; } - } - else - { + } else { if (intr->subIntrs == NULL) subIntrNum = 0; else @@ -892,16 +884,15 @@ int sceKernelQueryIntrHandlerInfo(int intrNum, int subIntrNum, int out) } // (2794) // 2798 - *(int*)(out + 8) = intr->arg; - *(int*)(out + 4) = intr->handler; - *(int*)(out + 12) = intr->gp; - *(short*)(out + 16) = intrNum; - *(short*)(out + 20) = (intr->v48 >> 8) & 3; - if (intrNum >= 64) - { + *(void**)(out + 8) = intr->arg; + *(s32*)(out + 4) = intr->handler; + *(s32*)(out + 12) = intr->gp; + *(s16*)(out + 16) = intrNum; + *(s16*)(out + 20) = (intr->v48 >> 8) & 3; + if (intrNum >= 64) { // 28D0 - int st = pspCop0StateGet(COP0_STATE_STATUS) & 0xFF00;; - int mask; + s32 st = pspCop0StateGet(COP0_STATE_STATUS) & 0xFF00;; + s32 mask; if (intrNum == 64) mask = 0x0100; else if (intrNum == 65) @@ -913,50 +904,45 @@ int sceKernelQueryIntrHandlerInfo(int intrNum, int subIntrNum, int out) else mask = 0; // 2908 - *(short*)(out + 22) = (st & mask) != 0; - } - else - { - char bit = (intInfo.grpsOpt[(intrNum >> 5) + 24] >> (intrNum & 0x1F)) & 1; - *(short*)(out + 22) = bit; - if ((bit & (~subIntrNum >> 31)) != 0) - { - if (intr->handler != 0) - { + *(s16*)(out + 22) = (st & mask) != 0; + } else { + s8 bit = (intInfo.grpsOpt[(intrNum >> 5) + 24] >> (intrNum & 0x1F)) & 1; + *(s16*)(out + 22) = bit; + if ((bit & (~subIntrNum >> 31)) != 0) { + if (intr->handler != 0) { // 287C - if (intr->cb != NULL && intr->cb->cbSuspend != NULL && intr->cb->cbResume != NULL) - { - int sp; + if (intr->cb != NULL && intr->cb->cbSuspend != NULL && intr->cb->cbResume != NULL) { + s32 sp; intr->cb->cbSuspend(intrNum, subIntrNum, &sp); intr->cb->cbResume(intrNum, subIntrNum, sp); - *(short*)(out + 22) = (sp != 0); + *(s16*)(out + 22) = (sp != 0); } } else - *(short*)(out + 22) = 0; + *(s16*)(out + 22) = 0; } } // 280C - *(int*)(out + 32) = intr->u32; - *(int*)(out + 36) = intr->u36; - *(short*)(out + 18) = intr->v48 & 0xFF; - *(int*)(out + 40) = intr->u16; - *(int*)(out + 44) = intr->u20; - *(int*)(out + 24) = intr->u12; - *(int*)(out + 48) = intr->u24; - *(int*)(out + 52) = intr->u28; + *(s32*)(out + 32) = intr->u32; + *(s32*)(out + 36) = intr->u36; + *(s16*)(out + 18) = intr->v48 & 0xFF; + *(s32*)(out + 40) = intr->u16; + *(s32*)(out + 44) = intr->u20; + *(s32*)(out + 24) = intr->u12; + *(s32*)(out + 48) = intr->u24; + *(s32*)(out + 52) = intr->u28; sceKernelCpuResumeIntr(oldIntr); return 0; } // 2938 -void *mymemset(void *dstVoid, char c, int n) +void *mymemset(void *dstVoid, s8 c, s32 n) { - char *dst = (char*)dstVoid; - if (dst != NULL) - { + dbg_printf("Called %s\n", __FUNCTION__); + s8 *dst = (s8*)dstVoid; + if (dst != NULL) { // 2950 - char *actDst = dst; + s8 *actDst = dst; while ((n--) > 0) *(actDst++) = c; } @@ -964,11 +950,12 @@ void *mymemset(void *dstVoid, char c, int n) } // 2968 -void InterruptDisableInTable(int intrNum) +void InterruptDisableInTable(s32 intrNum) { - int mask = ~(1 << (intrNum & 0x1F)); - int *ptr = &intInfo.grpsOpt[intrNum >> 5]; - int i = 4; + dbg_printf("Called %s\n", __FUNCTION__); + s32 mask = ~(1 << (intrNum & 0x1F)); + s32 *ptr = &intInfo.grpsOpt[intrNum >> 5]; + s32 i = 4; // 2990 while ((i--) >= 0) { *ptr &= mask; @@ -976,11 +963,12 @@ void InterruptDisableInTable(int intrNum) } } -void sub_29B0(int intrNum) +void sub_29B0(s32 intrNum) { - int val = (intInfo.intr[intrNum].v48 >> 8) & 3; - int mask = 1 << (intrNum & 0x1F); - int *ptr = &intInfo.grpsOpt[(intrNum >> 5) + (val << 1)]; + dbg_printf("Called %s\n", __FUNCTION__); + s32 val = (intInfo.intr[intrNum].v48 >> 8) & 3; + s32 mask = 1 << (intrNum & 0x1F); + s32 *ptr = &intInfo.grpsOpt[(intrNum >> 5) + (val << 1)]; // 29F8 while ((val++) < 4) { *ptr |= mask; @@ -991,79 +979,84 @@ void sub_29B0(int intrNum) // 2A30 sub_10A8(&intInfo.grpsOpt[6]); } + dbg_printf(" sub_29B0 ok\n"); } // 2A40 -void AllLevelInterruptDisable(int intrNum) +void AllLevelInterruptDisable(s32 intrNum) { - int *ptr = &intInfo.grpsOpt[intrNum >> 5]; - int mask = ~(1 << (intrNum & 0x1F)); - int i = 11; + dbg_printf("Called %s\n", __FUNCTION__); + s32 *ptr = &intInfo.grpsOpt[intrNum >> 5]; + s32 mask = ~(1 << (intrNum & 0x1F)); + s32 i = 11; // 2A78 while ((--i) >= 0) { *ptr &= mask; ptr += 2; } - int sp[2]; + s32 sp[2]; sub_1080(sp); sp[intrNum >> 5] &= mask; sub_10A8(sp); } // 55D18836 -int sceKernelSetPrimarySyscallHandler(int arg0, void (*arg1)()) +s32 sceKernelSetPrimarySyscallHandler(s32 syscallId, void (*syscall)()) { - int oldIntr = sceKernelCpuSuspendIntr(); - int shift = arg0 * 4; - if (arg0 <= 0 || cbMap.unk2 + cbMap.unk3 < shift) { + dbg_printf("Called %s\n", __FUNCTION__); + s32 oldIntr = sceKernelCpuSuspendIntr(); + if (syscallId <= 0 || g_syscallTable.tableSize + g_syscallTable.funcTableSize < syscallId * 4) { sceKernelCpuResumeIntr(oldIntr); return 0x80020038; } - if (cbMap.callbacks[arg0] != cbMap.callbacks[0]) { + if (g_syscallTable.syscalls[syscallId] != g_syscallTable.syscalls[0]) { sceKernelCpuResumeIntr(oldIntr); return 0x80020039; } // 2B68 - if ((int)arg1 >= 0) - { + if ((s32)syscall >= 0) { // 2B8C sceKernelCpuResumeIntr(oldIntr); return 0x800200D3; } - cbMap.callbacks[arg0] = arg1; - pspCache(0x1A, &cbMap.callbacks[arg0]); + g_syscallTable.syscalls[syscallId] = syscall; + pspCache(0x1A, &g_syscallTable.syscalls[syscallId]); sceKernelCpuResumeIntr(oldIntr); return 0; } -int IntrManTerminate() +s32 IntrManTerminate() { + dbg_printf("Called %s\n", __FUNCTION__); pspCop0StateSet(COP0_STATE_STATUS, pspCop0StateGet(COP0_STATE_STATUS) & 0xFFFF7BFF); sceKernelReleaseIntrHandler(67); - sceKernelReleaseExceptionHandler(EXCEP_INT, (void*)sub_0038); - sceKernelReleaseExceptionHandler(EXCEP_INT, (void*)sub_0924); - sceKernelReleaseExceptionHandler(EXCEP_SYS, (void*)sub_0CF8); + sceKernelReleaseExceptionHandler(EXCEP_INT, (void*)intrExcepHandler); + sceKernelReleaseExceptionHandler(EXCEP_INT, (void*)intrExcepHandler2); + sceKernelReleaseExceptionHandler(EXCEP_SYS, (void*)syscallExcepHandler); return 0; } // 02314986 void sceKernelCpuEnableIntr() { + dbg_printf("Called %s\n", __FUNCTION__); asm("mtic %0, $0" : : "r" (1)); } -int InterruptManagerForKernel_6FCBA912(int set) +s32 InterruptManagerForKernel_6FCBA912(s32 set) { + dbg_printf("Called %s\n", __FUNCTION__); intInfo.opt = (set == 0); return 0; } // A4C1C627 -int sceKernelClearIntrLogging(int intrNum) +s32 sceKernelClearIntrLogging(s32 intrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 68) return 0x80020065; - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); Interrupt *intr = &intInfo.intr[intrNum]; intr->u16 = -1; intr->u20 = -1; @@ -1077,9 +1070,10 @@ int sceKernelClearIntrLogging(int intrNum) } // F2F1E983 -int sceKernelIsInterruptOccurred(int intrNum) +s32 sceKernelIsInterruptOccurred(s32 intrNum) { - int sp[2]; + dbg_printf("Called %s\n", __FUNCTION__); + s32 sp[2]; if (intrNum >= 64) return 0x80020065; sub_1050(sp); @@ -1087,14 +1081,16 @@ int sceKernelIsInterruptOccurred(int intrNum) } // D774BA45 -int sceKernelDisableIntr(int intrNum) +s32 sceKernelDisableIntr(s32 intrNum) { + dbg_printf("Called %s\n", __FUNCTION__); return sceKernelSuspendIntr(intrNum, 0); } // DBD52A5D void RegisterSubIntrruptMonitor(MonitorCb before, MonitorCb after) { + dbg_printf("Called %s\n", __FUNCTION__); intInfo.monitorCbAfter = after; intInfo.monitorCbBefore = before; } @@ -1102,16 +1098,18 @@ void RegisterSubIntrruptMonitor(MonitorCb before, MonitorCb after) // 19596CD3 void ReleaseSubIntrruptMonitor() { + dbg_printf("Called %s\n", __FUNCTION__); intInfo.monitorCbAfter = 0; intInfo.monitorCbBefore = 0; } // 8357E7FA -int UnSupportIntr(int intrNum) +s32 UnSupportIntr(s32 intrNum) { + dbg_printf("Called %s\n", __FUNCTION__); if (intrNum >= 64) return 0x80020065; - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); sceKernelSuspendIntr(intrNum, 0); Interrupt *intr = &intInfo.intr[intrNum]; intr->handler = 1; @@ -1120,29 +1118,31 @@ int UnSupportIntr(int intrNum) return 0; } -int InterruptManagerForKernel_8DFBD787() +s32 InterruptManagerForKernel_8DFBD787() { - if (intInfo.opt2 != 0) - { - int addr = pspCop0CtrlGet(COP0_CTRL_TCB); + dbg_printf("Called %s\n", __FUNCTION__); + if (intInfo.opt2 != 0) { + s32 addr = pspCop0CtrlGet(COP0_CTRL_TCB); if (addr != 0) - return *(int*)addr; + return *(s32*)addr; } return 0; } // D2E8363F -int QueryIntrHandlerInfoForUser() +s32 QueryIntrHandlerInfoForUser() { + dbg_printf("Called %s\n", __FUNCTION__); return 0x80020001; } // EEE43F47 -int sceKernelRegisterUserSpaceIntrStack(int addr, int size, int arg2) +s32 sceKernelRegisterUserSpaceIntrStack(s32 addr, s32 size, s32 arg2) { + dbg_printf("Called %s\n", __FUNCTION__); if (size != 0x2000) return 0x80000104; - int oldIntr = sceKernelCpuSuspendIntr(); + s32 oldIntr = sceKernelCpuSuspendIntr(); if (intInfo.intrStack != 0) { sceKernelCpuResumeIntr(oldIntr); return 0x8002006D; @@ -1159,15 +1159,17 @@ int sceKernelRegisterUserSpaceIntrStack(int addr, int size, int arg2) } // 30C08374 -int sceKernelGetCpuClockCounter() +s32 sceKernelGetCpuClockCounter() { + dbg_printf("Called %s\n", __FUNCTION__); return pspCop0StateGet(COP0_STATE_COUNT); } // F9E06DF1 u64 sceKernelGetCpuClockCounterWide() { - int oldIntr = sceKernelCpuSuspendIntr(); + dbg_printf("Called %s\n", __FUNCTION__); + s32 oldIntr = sceKernelCpuSuspendIntr(); u32 hi = intInfo.clockCounterHi; u32 count = pspCop0StateGet(COP0_STATE_COUNT); if (count >= intInfo.clockCounterLo) @@ -1180,63 +1182,59 @@ u64 sceKernelGetCpuClockCounterWide() } // 6DDA4D7B -int *QueryInterruptManCB() +s32 *QueryInterruptManCB() { + dbg_printf("Called %s\n", __FUNCTION__); return intInfo.grpsOpt; } // E6FB16E3 u32 _sceKernelGetCpuClockCounterLow() { + dbg_printf("Called %s\n", __FUNCTION__); return intInfo.clockCounterLo; } // 14D4C61A -int sceKernelRegisterSystemCallTable(CbMap *newMap) +s32 sceKernelRegisterSystemCallTable(SceSyscallTable *newMap) { + dbg_printf("Called %s\n", __FUNCTION__); if (newMap->next != NULL) return 0x80020036; - int limit = newMap->unk2; - if (limit < 0 || newMap->unk3 - 16 < limit) { - // 2FF0 + if (newMap->tableSize < 0 || newMap->funcTableSize - 16 < newMap->tableSize) return 0x80020037; + // 2F7C + s32 oldIntr = sceKernelCpuSuspendIntr(); + SceSyscallTable *cur = g_syscallTable.next; + SceSyscallTable *prev = &g_syscallTable; + // 2FA0 + while (cur->seed != 0) { + prev = cur; + cur = cur->next; } - // 3008 - int oldIntr = sceKernelCpuSuspendIntr(); - CbMap *map = cbMap.next; - CbMap *oldMap = &cbMap; - // 302C - while (map->unk1 != 0) { - oldMap = map; - map = map->next; - } - // 305C is useless? - // 303C - newMap->next = map; - oldMap->next = newMap; - pspCop0CtrlSet(COP0_CTRL_SC_TABLE, (int)cbMap.next); + // 2FB0 + newMap->next = cur; + prev->next = newMap; + pspCop0CtrlSet(COP0_CTRL_SC_TABLE, (s32)g_syscallTable.next); sceKernelCpuResumeIntr(oldIntr); return 0; } // F153B371 -int sceKernelQuerySystemCall(int (*arg)()) -{ - CbMap *cur = &cbMap; +s32 sceKernelQuerySystemCall(void (*sysc)()) +{ + SceSyscallTable *cur = &g_syscallTable; // 2FE4 - do - { - int count = (cur->unk3 < 16) ? cur->unk3 - 13 : cur->unk3; - count /= 4; + do { + s32 count = (cur->funcTableSize < 16 ? cur->funcTableSize - 13 : cur->funcTableSize - 16) / 4; // 3008 - int i; - for (i = 0; i < count; i++) - { - if ((void*)((int)cur->callbacks[i] | 0x80000000) == arg) - { - cur->callbacks[i] = (void*)((int)cur->callbacks[i] | 0x80000000); + s32 i; + for (i = 0; i < count; i++) { + void (*curSys)(void) = (void*)((s32)cur->syscalls[i] | 0x80000000); + if (curSys == sysc) { + cur->syscalls[i] = curSys; // 303C - return (cur->unk1 < 0 ? cur->unk1 + 3 : cur->unk1) * 4 + i; + return (cur->seed < 0 ? cur->seed + 3 : cur->seed) / 4 + i; } } // 3028 @@ -1245,22 +1243,23 @@ int sceKernelQuerySystemCall(int (*arg)()) return -1; } -void InterruptManagerForKernel_E526B767(int arg) +void InterruptManagerForKernel_E526B767(s32 arg) { + dbg_printf("Called %s\n", __FUNCTION__); if (arg == 0) - *(int*)(mod_0E48) = 0x42000018; // eret + *(s32*)(&mod_0E48) = 0x42000018; // eret // 30F0 - if (arg == 1) - { + if (arg == 1) { // 3104 - *(int*)(mod_0E50) = 0x00005821; // t3 = 0 + *(s32*)(&mod_0E50) = 0x00005821; // t3 = 0 } } // 3110 -int SuspendIntc() +s32 SuspendIntc(s32 unk __attribute__((unused)), void *param __attribute__((unused))) { - int sp[2]; + dbg_printf("Called %s\n", __FUNCTION__); + s32 sp[2]; intInfo.compare = pspCop0StateGet(COP0_STATE_COMPARE); intInfo.count = pspCop0StateGet(COP0_STATE_COUNT); sub_1080(intInfo.intcState); @@ -1270,8 +1269,9 @@ int SuspendIntc() } // 3160 -int ResumeIntc() +s32 ResumeIntc(s32 unk __attribute__((unused)), void *param __attribute__((unused))) { + dbg_printf("Called %s\n", __FUNCTION__); sub_10A8(intInfo.intcState); pspCop0StateSet(COP0_STATE_COMPARE, intInfo.compare); pspCop0StateSet(COP0_STATE_COUNT, intInfo.count); diff --git a/src/interruptman/interruptman.h b/src/interruptman/interruptman.h new file mode 100644 index 0000000..ffe3837 --- /dev/null +++ b/src/interruptman/interruptman.h @@ -0,0 +1,11 @@ +/* Copyright (C) 2011, 2012 The uOFW team + See the file COPYING for copying permission. +*/ + +void *mymemset(void *dstVoid, s8 c, s32 n); +s32 SuspendIntc(s32 unk, void *param); +s32 ResumeIntc(s32 unk, void *param); +void InterruptDisableInTable(s32 intrNum); +void sub_29B0(s32 intrNum); +void AllLevelInterruptDisable(s32 intrNum); + diff --git a/src/interruptman/start.S b/src/interruptman/start.S index 190a461..34e8bea 100644 --- a/src/interruptman/start.S +++ b/src/interruptman/start.S @@ -30,10 +30,10 @@ loc_0024: nop # ? ## -# sub_0038 +# intrExcepHandler ## - .globl sub_0038 -sub_0038: + .globl intrExcepHandler +intrExcepHandler: nop nop cfc0 $v0, $13 @@ -91,8 +91,8 @@ loc_00F8: move $k1, $sp bnez $gp, loc_0138 sw $a3, 92($sp) - lui $sp, %hi(unkTab) - addiu $sp, $sp, %lo(unkTab) + lui $sp, %hi(g_syscCtx) + addiu $sp, $sp, %lo(g_syscCtx) cache 0x18, 0($sp) lui $a3, %hi(intInfo) addiu $a2, $a3, 32 @@ -146,7 +146,7 @@ loc_019C: sh $0, 36($k1) or $ra, $ra, $v1 - beqz $ra, InterruptManagerForKernel_551097F2 + beqz $ra, _InterruptManagerForKernel_551097F2 move $a0, $k1 j loc_00000978 sw $k1, 12($sp) @@ -178,8 +178,8 @@ loc_0218: addiu $sp, $sp, -320 loc_022C: - lui $v0, %hi(wut) - addiu $v0, $v0, %lo(wut) + lui $v0, %hi(g_stackMiddle) + addiu $v0, $v0, %lo(g_stackMiddle) sltu $v0, $sp, $v0 beqz $v0, loc_0050 ins $sp, $0, 0, 6 @@ -319,7 +319,7 @@ loc_03A4: mod_0400: jal sub_091C li $k1, 3 - beqz $v0, InterruptManagerForKernel_551097F2 + beqz $v0, _InterruptManagerForKernel_551097F2 lw $a0, 12($sp) lb $v0, 36($a0) bnez $v0, loc_0444 @@ -351,12 +351,12 @@ mod_0468: jal sub_091C move $a1, $0 - j InterruptManagerForKernel_551097F2 + j _InterruptManagerForKernel_551097F2 move $a0, $v0 loc_0478: lb $a2, 37($a0) - beqz $a2, InterruptManagerForKernel_551097F2 + beqz $a2, _InterruptManagerForKernel_551097F2 mfc0 $k0, $12 ins $k0, $a2, 29, 1 mtc0 $k0, $12 @@ -394,6 +394,7 @@ loc_0478: lwc1 $30, 312($a0) lwc1 $31, 316($a0) +_InterruptManagerForKernel_551097F2: .globl InterruptManagerForKernel_551097F2 InterruptManagerForKernel_551097F2: lw $sp, 180($a0) @@ -691,8 +692,8 @@ sub_091C: jr $ra move $v0, $0 - .globl sub_0924 -sub_0924: + .globl intrExcepHandler2 +intrExcepHandler2: nop nop cfc0 $v1, $25 @@ -719,8 +720,8 @@ loc_0000095C: loc_00000978: move $sp, $k1 - lui $v1, %hi(sub_0038) - lw $v1, %lo(sub_0038)($v1) + lui $v1, %hi(intrExcepHandler) + lw $v1, %lo(intrExcepHandler)($v1) lui $at, %hi(intInfo+108) sw $v1, %lo(intInfo+108)($at) sll $v0, $gp, 3 @@ -964,12 +965,13 @@ InterruptManagerForKernel_1373F20E: nop nop +_sub_0CC0: .globl sub_0CC0 sub_0CC0: cfc0 $v0, $0 mtc0 $v0, $14 - lui $v0, %hi(sub_0CF8) - lw $v0, %lo(sub_0CF8) + lui $v0, %hi(syscallExcepHandler) + lw $v0, %lo(syscallExcepHandler) jr $v0 nop @@ -986,12 +988,8 @@ loc_00000CF0: jr $ra nop -## -# sub_0CF8 -## - - .globl sub_0CF8 -sub_0CF8: + .globl syscallExcepHandler +syscallExcepHandler: nop nop cfc0 $v0, $0 @@ -1002,9 +1000,9 @@ sub_0CF8: beqz $at, loc_00000D34 ctc0 $t7, $23 bltz $v1, loc_00000E98 - lui $t4, %hi(cbMap + 0x20000010) + lui $t4, %hi(g_syscallTable + 0x20000010) addu $t4, $t4, $t7 - lw $t7, %lo(cbMap+16)($t4) + lw $t7, %lo(g_syscallTable + 0x10)($t4) jr $t7 mtc0 $v0, $14 @@ -1017,7 +1015,7 @@ loc_00000D40: lw $t5, 4($t4) mtc0 $v0, $14 lw $t6, 8($t4) - beqz $t5, sub_0CC0 + beqz $t5, _sub_0CC0 subu $t5, $t7, $t5 sltu $at, $t5, $t6 beqzl $at, loc_00000D40 diff --git a/src/interruptman/start.h b/src/interruptman/start.h index 0ae2279..c12cd45 100644 --- a/src/interruptman/start.h +++ b/src/interruptman/start.h @@ -3,19 +3,13 @@ */ void sub_0000(); -void sub_0038(); -void InterruptManagerForKernel_551097F2(); -int sceKernelIsIntrContext(); +void intrExcepHandler(void); void SaveThreadContext(); -int sceKernelCallUserIntrHandler(int, int, int, int, int, int); void sub_0864(); int sub_091C(); -void sub_0924(); -void InterruptManagerForKernel_A6978B70(); -void InterruptManagerForKernel_1373F20E(); +void intrExcepHandler2(void); void sub_0CC0(); -int sceKernelGetSyscallRA(); -void sub_0CF8(); +void syscallExcepHandler(void); void loc_00000DDC(); void sub_0EC0(); void sub_0ECC(); @@ -36,9 +30,9 @@ void sub_1050(int*); void sub_1080(int*); void sub_10A8(int*); -int mod_0400; -int mod_0468; -int mod_0DC4; -int mod_0E48; -int mod_0E50; +s32 mod_0400; +s32 mod_0468; +s32 mod_0DC4; +s32 mod_0E48; +s32 mod_0E50; diff --git a/src/iofilemgr/iofilemgr.c b/src/iofilemgr/iofilemgr.c index baf4dde..0e295af 100644 --- a/src/iofilemgr/iofilemgr.c +++ b/src/iofilemgr/iofilemgr.c @@ -2228,13 +2228,13 @@ int sceIoReadAsync(SceUID fd, void *data, SceSize size) return do_read(fd, data, size, 1); } -int sceIoWrite(SceUID fd, void *data, SceSize size) +int sceIoWrite(SceUID fd, const void *data, SceSize size) { dbg_printf("Calling %s\n", __FUNCTION__); return do_write(fd, data, size, 0); } -int sceIoWriteAsync(SceUID fd, void *data, SceSize size) +int sceIoWriteAsync(SceUID fd, const void *data, SceSize size) { dbg_printf("Calling %s\n", __FUNCTION__); return do_write(fd, data, size, 1); diff --git a/src/libatrac3plus/libatrac3plus.c b/src/libatrac3plus/libatrac3plus.c index 36f8d95..7e84a4f 100644 --- a/src/libatrac3plus/libatrac3plus.c +++ b/src/libatrac3plus/libatrac3plus.c @@ -1,6 +1,16 @@ -#include "common.h" +#include -#include "libatrac3plus_int.h" +#include +#include + +#include "libatrac3plus.h" + +SCE_MODULE_INFO("sceATRAC3plus_Library", SCE_MODULE_SINGLE_LOAD | SCE_MODULE_SINGLE_START, 1, 5); +SCE_MODULE_BOOTSTART("sceAtracStartEntry"); +SCE_MODULE_STOP("sceAtracEndEntry"); +SCE_SDK_VERSION(0x06060010); +SCE_MODULE_START_THREAD_PARAMETER(3, 0x20, 0x0400, 0); +SCE_MODULE_STOP_THREAD_PARAMETER(3, 0x20, 0x0400, 0); // 3F80 int g_edramAddr = -1; @@ -78,7 +88,7 @@ int sceAtracReinit(int numAT3Id, int numAT3plusId) return 0; } g_edramAddr = -1; - return sceAudiocodecReleaseEDRAM(&g_atracIds[0]); + return sceAudiocodecReleaseEDRAM(&g_atracIds[0].codec); } int sceAtracGetAtracID(u32 codecType) @@ -453,6 +463,7 @@ int sceAtracSetLoopNum(int atracID, int loopNum) return 0; } +int __attribute__((alias("sceAtracGetBufferInfoForResetting"))) sceAtracGetBufferInfoForReseting(int atracID, u32 sample, SceBufferInfo *bufferInfo); int sceAtracGetBufferInfoForResetting(int atracID, u32 sample, SceBufferInfo *bufferInfo) { if (atracID < 0 || atracID >= 6 || g_atracIds[atracID].info.state <= 0) @@ -710,12 +721,12 @@ int allocEdram(void) if (ret < 0) return ret; g_needMemAT3plus = (g_atracIds[0].codec.neededMem + 0x3F) & 0xFFFFFFC0; - ret = sceAudiocodecCheckNeedMem(&g_atracIds[0].info, 0x1001); + ret = sceAudiocodecCheckNeedMem(&g_atracIds[0].codec, 0x1001); if (ret < 0) return ret; g_needMemAT3 = (g_atracIds[0].codec.neededMem + 0x3F) & 0xFFFFFFC0; g_atracIds[0].codec.neededMem = 0x19000; - ret = sceAudiocodecGetEDRAM(&g_atracIds[0].info, 0x1001); + ret = sceAudiocodecGetEDRAM(&g_atracIds[0].codec, 0x1001); if (ret < 0) return ret; g_edramAddr = g_atracIds[0].codec.edramAddr; @@ -905,9 +916,9 @@ int loadWaveFile(u32 size, SceAtracFile *info, u8 *in) int inc = cksize + (cksize & 1); if (readWaveData(in, &curOff, 4) == WAVE_MAGIC) break; - if (size < curOff + cksize) + if (size < curOff + inc) return 0x80630011; - curOff += cksize; + curOff += inc; } // 1EAC if (curOff + 8 >= size) { @@ -994,7 +1005,7 @@ int loadWaveFile(u32 size, SceAtracFile *info, u8 *in) case WAVE_CHUNK_ID_FMT: // 1F64 - if (fmt != 0x80630006) + if (fmt != (s32)0x80630006) return 0x80630006; if (cksize < 32) return 0x80630006; @@ -1029,7 +1040,7 @@ int loadWaveFile(u32 size, SceAtracFile *info, u8 *in) } else { - if (fmtCode != 0xFFFE) { + if (fmtCode != (s16)0xFFFE) { // 20B8 return 0x80630006; } @@ -1315,7 +1326,7 @@ int initAT3Decoder(SceAudiocodecCodec *codec, void *arg1) return 0; } // 2784 - unk; + unk--; } return 0x80630001; } @@ -1364,7 +1375,7 @@ int initAT3plusDecoder(SceAudiocodecCodec *codec, void *arg1) int *cur = (int*)&g_3E88[0]; int *curSp = sp; int *end = (int*)&g_3E88[28]; - if ((int)g_3E88 & 3 == 0) + if (((int)g_3E88 & 3) == 0) { // 2918 do @@ -1634,7 +1645,7 @@ int sub_2DF8(SceAtracIdInfo *info) return ret; u32 ret2 = getSecondBufPos(info, info->loopEnd); u32 sum = info->curOff + info->streamDataByte; - if (sum >= ret2 + 1 && (sum - (ret2 + 1)) / (ret2 - getOffFromSample(info, info->loopStart) + 1) >= info->loopNum) // 2E78 + if (sum >= ret2 + 1 && (s32)(sum - (ret2 + 1)) / (s32)(ret2 - getOffFromSample(info, info->loopStart) + 1) >= info->loopNum) // 2E78 ret = -3; // 2E58 return ret; @@ -1642,7 +1653,7 @@ int sub_2DF8(SceAtracIdInfo *info) int sub_2EA4(SceAtracIdInfo *info) { - int ret = getSecondBufPos(info, info->loopEnd); + u32 ret = getSecondBufPos(info, info->loopEnd); u32 sum = info->curOff + info->streamDataByte; u32 sum2 = sum - ret - 1; int count; @@ -2006,7 +2017,7 @@ int parseAA3(u32 readByte, SceAA3File *aa3, int arg2, u8 *buffer) aa3->unk44 = sub_3AA0(buffer, &curOff, readByte); if (aa3->unk44 == -1) return 0x80631003; - if (sub_3AA0(buffer, &curOff, readByte) != 0xFFFF) + if (sub_3AA0(buffer, &curOff, readByte) != -1) return 0x80631003; curOff += 24; aa3->unk6 = *(u8*)(buffer + curOff); diff --git a/src/libatrac3plus/libatrac3plus_int.h b/src/libatrac3plus/libatrac3plus.h similarity index 98% rename from src/libatrac3plus/libatrac3plus_int.h rename to src/libatrac3plus/libatrac3plus.h index 3158ded..3e87220 100644 --- a/src/libatrac3plus/libatrac3plus_int.h +++ b/src/libatrac3plus/libatrac3plus.h @@ -26,7 +26,7 @@ typedef struct char unk22; char numChan; // 23 u16 sampleSize; // 24 - short codec; // 26 + u16 codec; // 26 u32 dataOff; // 28 u32 curOff; // 32 u32 dataEnd; // 36 @@ -69,7 +69,9 @@ typedef struct u32 dataSize; // 16 u32 unk20, unk24, unk28; u32 unk32; - u32 unk36, unk40, unk44; + u32 unk36; + s32 unk40; + s32 unk44; } SceAA3File; int setHalfwayBuffer(SceAtracId *id, u8 *buffer, u32 readByte, u32 bufferByte, SceAtracFile *info); diff --git a/src/loadcore/exports.exp b/src/loadcore/exports.exp new file mode 100644 index 0000000..7da6eaa --- /dev/null +++ b/src/loadcore/exports.exp @@ -0,0 +1,48 @@ +# Export file automatically generated with prxtool +PSP_BEGIN_EXPORTS + +PSP_EXPORT_START(syslib, 0x0000, 0x8000) +PSP_EXPORT_FUNC_HASH(module_bootstart) +PSP_EXPORT_VAR_HASH(module_info) +PSP_EXPORT_VAR_HASH(module_sdk_version) +PSP_EXPORT_END + +PSP_EXPORT_START(LoadCoreForKernel, 0x0011, 0x0001) +PSP_EXPORT_FUNC_NID(sceKernelDeleteModule, 0x001B57BB) +PSP_EXPORT_FUNC_NID(sceKernelUnlinkLibraryEntries, 0x0295CFCE) +PSP_EXPORT_FUNC_NID(sceKernelMaskLibraryEntries, 0x1915737F) +PSP_EXPORT_FUNC_NID(sceKernelLoadCoreLock, 0x1999032F) +PSP_EXPORT_FUNC_NID(sceKernelLoadExecutableObject, 0x1C394885) +PSP_EXPORT_FUNC_NID(sceKernelCreateModule, 0x2C44F793) +PSP_EXPORT_FUNC_NID(sceKernelRegisterLibraryForUser, 0x2C60CCB8) +PSP_EXPORT_FUNC_NID(sceKernelGetModuleIdListForKernel, 0x37E6F41B) +PSP_EXPORT_FUNC_NID(sceKernelGetModuleListWithAlloc, 0x3FE631F0) +PSP_EXPORT_FUNC_NID(sceKernelFindModuleByUID, 0x40972E6E) +PSP_EXPORT_FUNC_NID(sceKernelGetModuleGPByAddressForKernel, 0x410084F9) +PSP_EXPORT_FUNC_NID(sceKernelProbeExecutableObject, 0x41D10899) +PSP_EXPORT_FUNC_NID(sceKernelRegisterLibrary, 0x48AF96A9) +PSP_EXPORT_FUNC_NID(sceKernelLoadModuleBootLoadCore, 0x493EE781) +PSP_EXPORT_FUNC_NID(sceKernelCanReleaseLibrary, 0x538129F8) +PSP_EXPORT_FUNC_NID(sceKernelSegmentChecksum, 0x5FDDB07A) +PSP_EXPORT_FUNC_NID(sceKernelQueryLoadCoreCB, 0x696594C8) +PSP_EXPORT_FUNC_NID(sceKernelLinkLibraryEntriesForUser, 0x6ECFFFBA) +PSP_EXPORT_FUNC_NID(sceKernelCreateAssignModule, 0x84D5C971) +PSP_EXPORT_FUNC_NID(sceKernelLinkLibraryEntries, 0x8EAE9534) +PSP_EXPORT_FUNC_NID(sceKernelLinkLibraryEntriesWithModule, 0xA481E30E) +PSP_EXPORT_FUNC_NID(sceKernelReleaseModule, 0xB17F5075) +PSP_EXPORT_FUNC_NID(sceKernelLoadRebootBin, 0xB27CC244) +PSP_EXPORT_FUNC_NID(sceKernelLoadCoreUnlock, 0xB6C037EA) +PSP_EXPORT_FUNC_NID(sceKernelFindModuleByAddress, 0xBC99C625) +PSP_EXPORT_FUNC_NID(sceKernelRegisterModule, 0xBF2E388C) +PSP_EXPORT_FUNC_NID(sceKernelLoadCoreMode, 0xC8FF5EE5) +PSP_EXPORT_FUNC_NID(sceKernelReleaseLibrary, 0xCB636A90) +PSP_EXPORT_FUNC_NID(sceKernelGetModuleFromUID, 0xCD26E0CA) +PSP_EXPORT_FUNC_NID(sceKernelCheckExecFile, 0xD3353EC4) +PSP_EXPORT_FUNC_NID(sceKernelAssignModule, 0xF3DD4808) +PSP_EXPORT_FUNC_NID(sceKernelFindModuleByName, 0xF6B1BF0F) +PSP_EXPORT_FUNC_NID(sceKernelSetBootCallbackLevel, 0xF976EF41) +PSP_EXPORT_FUNC_NID(sceKernelCheckPspConfig, 0xFC47F93A) +PSP_EXPORT_END + +PSP_END_EXPORTS + diff --git a/src/usersystemlib/exports.exp b/src/usersystemlib/exports.exp new file mode 100644 index 0000000..8269fd0 --- /dev/null +++ b/src/usersystemlib/exports.exp @@ -0,0 +1,35 @@ +# Export file automatically generated with prxtool +PSP_BEGIN_EXPORTS + +PSP_EXPORT_START(syslib, 0x0000, 0x8000) +PSP_EXPORT_FUNC_HASH(module_start) +PSP_EXPORT_VAR_HASH(module_info) +PSP_EXPORT_VAR_HASH(module_sdk_version) +PSP_EXPORT_VAR_HASH(module_start_thread_parameter) +PSP_EXPORT_END + +PSP_EXPORT_START(Kernel_Library, 0x0011, 0x0001) +PSP_EXPORT_FUNC_HASH(sceKernelCpuSuspendIntr) +PSP_EXPORT_FUNC_HASH(sceKernelUnlockLwMutex) +PSP_EXPORT_FUNC_HASH(sceKernelMemcpy) +PSP_EXPORT_FUNC_HASH(sceKernelLockLwMutexCB) +PSP_EXPORT_FUNC_HASH(sceKernelGetThreadId) +PSP_EXPORT_FUNC_HASH(sceKernelTryLockLwMutex_600) +PSP_EXPORT_FUNC_NID(Kernel_Library_3AD10D4D, 0x3AD10D4D) +PSP_EXPORT_FUNC_HASH(sceKernelCpuResumeIntrWithSync) +PSP_EXPORT_FUNC_HASH(sceKernelIsCpuIntrSuspended) +PSP_EXPORT_FUNC_HASH(sceKernelCpuResumeIntr) +PSP_EXPORT_FUNC_HASH(sceKernelMemset) +PSP_EXPORT_FUNC_HASH(sceKernelIsCpuIntrEnable) +PSP_EXPORT_FUNC_HASH(sceKernelLockLwMutex) +PSP_EXPORT_FUNC_HASH(sceKernelReferLwMutexStatus) +PSP_EXPORT_FUNC_HASH(sceKernelCheckThreadStack) +PSP_EXPORT_FUNC_HASH(sceKernelTryLockLwMutex) +PSP_EXPORT_FUNC_NID(Kernel_Library_FA835CDE, 0xFA835CDE) +PSP_EXPORT_END + +PSP_EXPORT_START(sceGe_lazy, 0x0011, 0x0001) +PSP_EXPORT_FUNC_NID(sceGe_lazy_31129B95, 0x31129B95) +PSP_EXPORT_END + +PSP_END_EXPORTS diff --git a/utils/build-exports/psp-build-exports.c b/utils/build-exports/psp-build-exports.c index 9ca4827..0f7c480 100644 --- a/utils/build-exports/psp-build-exports.c +++ b/utils/build-exports/psp-build-exports.c @@ -276,7 +276,7 @@ int parse_string(char *line, char **params, int max_params) param_start = pos; /* Scan parameters */ - while((isalnum(line[pos])) || (line[pos] == '_') || (line[pos] == ',') || (line[pos] == '.')) + while((isalnum(line[pos])) || (line[pos] == '_') || (line[pos] == ',') || (line[pos] == '.') || (line[pos] == '+')) { pos++; } @@ -325,7 +325,8 @@ void build_exports_output_extern(struct psp_export *pHead) pExp = pHead; while(pExp != NULL) { - fprintf(stdout, "extern int %s;\n", pExp->name); + if (strchr(pExp->name, '+') == NULL) + fprintf(stdout, "extern char %s;\n", pExp->name); pExp = pExp->pNext; } } diff --git a/utils/build-exports/psp-build-exports.exe b/utils/build-exports/psp-build-exports.exe index 2b3d368..5ba06c5 100755 Binary files a/utils/build-exports/psp-build-exports.exe and b/utils/build-exports/psp-build-exports.exe differ