- Fixed memory leaks in cellRtc module.

- Fixed CPUThread crash.
- Improved ARMv7 Interpreter.
This commit is contained in:
DH 2013-11-09 14:25:12 +02:00
parent 3b15f35432
commit 6ea2c7d6a8
6 changed files with 949 additions and 729 deletions

View File

@ -10,6 +10,229 @@ public:
{
}
enum SRType
{
SRType_None,
SRType_LSL,
SRType_LSR,
SRType_ASR,
SRType_ROR,
SRType_RRX,
};
template<typename T>
bool IsZero(T x)
{
return x == T(0);
}
template<typename T>
bool IsOnes(T x)
{
return x == ~T(0);
}
template<typename T>
u8 IsZeroBit(T x)
{
return IsZero(x) ? 1 : 0;
}
template<typename T>
bool IsOnesBit(T x, u8 len = sizeof(T) * 8)
{
return IsOnes(x) ? 1 : 0;
}
template<typename T>
u8 BitCount(T x, u8 len = sizeof(T) * 8)
{
u8 result = 0;
for(u8 mask=1 << (len - 1); mask; mask >>= 1)
{
if(x & mask) result++;
}
return result;
}
template<typename T>
s8 LowestSetBit(T x, u8 len = sizeof(T) * 8)
{
if(!x) return len;
u8 result = 0;
for(T mask=1, i=0; i<len && (x & mask) == 0; mask <<= 1, i++)
{
result++;
}
return result;
}
template<typename T>
s8 HighestSetBit(T x, u8 len = sizeof(T) * 8)
{
if(!x) return -1;
u8 result = len;
for(T mask=T(1) << (len - 1); (x & mask) == 0; mask >>= 1)
{
result--;
}
return result;
}
template<typename T>
s8 CountLeadingZeroBits(T x, u8 len = sizeof(T) * 8)
{
return len - 1 - HighestSetBit(x, len);
}
SRType DecodeImmShift(u8 type, u8 imm5, uint* shift_n)
{
SRType shift_t;
switch(type)
{
case 0: shift_t = SRType_LSL; if(shift_n) *shift_n = imm5; break;
case 1: shift_t = SRType_LSR; if(shift_n) *shift_n = imm5 == 0 ? 32 : imm5; break;
case 2: shift_t = SRType_ASR; if(shift_n) *shift_n = imm5 == 0 ? 32 : imm5; break;
case 3:
if(imm5 == 0)
{
shift_t = SRType_RRX; if(shift_n) *shift_n = 1;
}
else
{
shift_t = SRType_ROR; if(shift_n) *shift_n = imm5;
}
break;
}
return shift_t;
}
SRType DecodeRegShift(u8 type)
{
SRType shift_t;
switch(type)
{
case 0: shift_t = SRType_LSL; break;
case 1: shift_t = SRType_LSR; break;
case 2: shift_t = SRType_ASR; break;
case 3: shift_t = SRType_ROR; break;
}
return shift_t;
}
u32 LSL_C(u32 x, int shift, bool& carry_out)
{
u32 extended_x = x << shift;
carry_out = (extended_x >> 31) ? 1 : 0;
return extended_x & ~(1 << 31);
}
u32 LSL(u32 x, int shift)
{
if(!shift) return x;
bool carry_out;
return LSL_C(x, shift, carry_out);
}
u32 LSR_C(u32 x, int shift, bool& carry_out)
{
carry_out = (x >> (shift - 1)) & 0x1;
return x >> shift;
}
u32 LSR(u32 x, int shift)
{
if(!shift) return x;
bool carry_out;
return LSR_C(x, shift, carry_out);
}
s32 ASR_C(s32 x, int shift, bool& carry_out)
{
carry_out = (x >> (shift - 1)) & 0x1;
return x >> shift;
}
s32 ASR(s32 x, int shift)
{
if(!shift) return x;
bool carry_out;
return ASR_C(x, shift, carry_out);
}
u32 ROR_C(u32 x, int shift, bool& carry_out)
{
u32 result = LSR(x, shift) | LSL(x, 32 - shift);
carry_out = (result >> 30) & 0x1;
return result;
}
s32 ROR(s32 x, int shift)
{
if(!shift) return x;
bool carry_out;
return ROR_C(x, shift, carry_out);
}
template<typename T> T RRX_C(T x, bool carry_in, bool& carry_out)
{
carry_out = x & 0x1;
return ((u32)carry_in << 31) | (x & 0x7ffffffe);
}
s32 RRX(s32 x, int shift)
{
if(!shift) return x;
bool carry_out;
return RRX_C(x, shift, carry_out);
}
template<typename T> T Shift_C(T value, SRType type, uint amount, bool carry_in, bool& carry_out)
{
if(amount)
{
switch(type)
{
case SRType_LSL: return LSL_C(value, amount, carry_out);
case SRType_LSR: return LSR_C(value, amount, carry_out);
case SRType_ASR: return ASR_C(value, amount, carry_out);
case SRType_ROR: return ROR_C(value, amount, carry_out);
case SRType_RRX: return RRX_C(value, amount, carry_out);
}
}
carry_out = carry_in;
return value;
}
template<typename T> T Shift(T value, SRType type, uint amount, bool carry_in)
{
bool carry_out;
return Shift_C(value, type, amount, carry_in, carry_out);
}
template<typename T> T AddWithCarry(T x, T y, bool carry_in, bool& carry_out, bool& overflow)
{
uint unsigned_sum = (uint)x + (uint)y + (uint)carry_in;
int signed_sum = (int)x + (int)y + (int)carry_in;
T result = unsigned_sum & ~(T(1) << (sizeof(T) - 1));
carry_out = (uint)result != unsigned_sum;
overflow = (int)result != signed_sum;
return result;
}
bool ConditionPassed(u8 cond)
{
bool result;
@ -51,20 +274,20 @@ protected:
{
if(regs_list & mask)
{
CPU.SP -= 4;
Memory.Write32(CPU.SP, CPU.read_gpr(i));
CPU.SP += 4;
}
}
}
void POP(u16 regs_list)
{
for(u16 mask=(0x1 << 15), i=15; mask; mask >>= 1, i++)
for(u16 mask=(0x1 << 15), i=15; mask; mask >>= 1, i--)
{
if(regs_list & mask)
{
CPU.SP -= 4;
CPU.write_gpr(i, Memory.Read32(CPU.SP));
CPU.SP += 4;
}
}
}

View File

@ -24,12 +24,12 @@ void ARMv7Thread::InitStack()
m_stack_addr = Memory.Alloc(0x10000, 1);
}
m_stack_point = m_stack_addr;
m_stack_point = m_stack_addr + m_stack_size;
}
u64 ARMv7Thread::GetFreeStackSize() const
{
return GetStackSize() - (SP - GetStackAddr());
return SP - GetStackAddr();
}
void ARMv7Thread::SetArg(const uint pos, const u64 arg)

View File

@ -33,6 +33,11 @@ void CPUThread::Close()
{
m_free_data = true;
}
else
{
delete m_dec;
m_dec = nullptr;
}
Stop();
}
@ -242,7 +247,6 @@ void CPUThread::Stop()
Reset();
DoStop();
Emu.CheckStatus();
delete m_dec;
wxGetApp().SendDbgCommand(DID_STOPED_THREAD, this);
}
@ -326,5 +330,9 @@ void CPUThread::Task()
//ConLog.Write("%s leave", CPUThread::GetFName());
if(m_free_data)
{
delete m_dec;
m_dec = nullptr;
free(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -16,11 +16,11 @@ enum
};
const char *getModuleName(int id) {
struct Entry {
struct
{
const char *name;
int id;
};
static const Entry entries[] = {
} static const entries[] = {
{"CELL_SYSMODULE_INVALID", 0x0000ffff},
{"CELL_SYSMODULE_NET", 0x00000000},
{"CELL_SYSMODULE_HTTP", 0x00000001},
@ -28,109 +28,113 @@ const char *getModuleName(int id) {
{"CELL_SYSMODULE_SSL", 0x00000003},
{"CELL_SYSMODULE_HTTPS", 0x00000004},
{"CELL_SYSMODULE_VDEC", 0x00000005},
{"CELL_SYSMODULE_ADEC", 0x00000006},
{"CELL_SYSMODULE_DMUX", 0x00000007},
{"CELL_SYSMODULE_VPOST", 0x00000008},
{"CELL_SYSMODULE_RTC", 0x00000009},
{"CELL_SYSMODULE_SPURS", 0x0000000a},
{"CELL_SYSMODULE_OVIS", 0x0000000b},
{"CELL_SYSMODULE_SHEAP", 0x0000000c},
{"CELL_SYSMODULE_SYNC", 0x0000000d},
{"CELL_SYSMODULE_FS", 0x0000000e},
{"CELL_SYSMODULE_JPGDEC", 0x0000000f},
{"CELL_SYSMODULE_GCM_SYS", 0x00000010},
{"CELL_SYSMODULE_GCM", 0x00000010},
{"CELL_SYSMODULE_AUDIO", 0x00000011},
{"CELL_SYSMODULE_PAMF", 0x00000012},
{"CELL_SYSMODULE_ATRAC3PLUS", 0x00000013},
{"CELL_SYSMODULE_NETCTL", 0x00000014},
{"CELL_SYSMODULE_SYSUTIL", 0x00000015},
{"CELL_SYSMODULE_SYSUTIL_NP", 0x00000016},
{"CELL_SYSMODULE_IO", 0x00000017},
{"CELL_SYSMODULE_PNGDEC", 0x00000018},
{"CELL_SYSMODULE_FONT", 0x00000019},
{"CELL_SYSMODULE_FONTFT", 0x0000001a},
{"CELL_SYSMODULE_FREETYPE", 0x0000001b},
{"CELL_SYSMODULE_USBD", 0x0000001c},
{"CELL_SYSMODULE_SAIL", 0x0000001d},
{"CELL_SYSMODULE_L10N", 0x0000001e},
{"CELL_SYSMODULE_RESC", 0x0000001f},
{"CELL_SYSMODULE_DAISY", 0x00000020},
{"CELL_SYSMODULE_KEY2CHAR", 0x00000021},
{"CELL_SYSMODULE_MIC", 0x00000022},
{"CELL_SYSMODULE_CAMERA", 0x00000023},
{"CELL_SYSMODULE_VDEC_MPEG2", 0x00000024},
{"CELL_SYSMODULE_VDEC_AVC", 0x00000025},
{"CELL_SYSMODULE_ADEC_LPCM", 0x00000026},
{"CELL_SYSMODULE_ADEC_AC3", 0x00000027},
{"CELL_SYSMODULE_ADEC_ATX", 0x00000028},
{"CELL_SYSMODULE_ADEC_AT3", 0x00000029},
{"CELL_SYSMODULE_DMUX_PAMF", 0x0000002a},
{"CELL_SYSMODULE_VDEC_AL", 0x0000002b},
{"CELL_SYSMODULE_ADEC_AL", 0x0000002c},
{"CELL_SYSMODULE_DMUX_AL", 0x0000002d},
{"CELL_SYSMODULE_LV2DBG", 0x0000002e},
{"CELL_SYSMODULE_USBPSPCM", 0x00000030},
{"CELL_SYSMODULE_AVCONF_EXT", 0x00000031},
{"CELL_SYSMODULE_SYSUTIL_USERINFO", 0x00000032},
{"CELL_SYSMODULE_SYSUTIL_SAVEDATA", 0x00000033},
{"CELL_SYSMODULE_SUBDISPLAY", 0x00000034},
{"CELL_SYSMODULE_SYSUTIL_REC", 0x00000035},
{"CELL_SYSMODULE_VIDEO_EXPORT", 0x00000036},
{"CELL_SYSMODULE_SYSUTIL_GAME_EXEC", 0x00000037},
{"CELL_SYSMODULE_SYSUTIL_NP2", 0x00000038},
{"CELL_SYSMODULE_SYSUTIL_AP", 0x00000039},
{"CELL_SYSMODULE_SYSUTIL_NP_CLANS", 0x0000003a},
{"CELL_SYSMODULE_SYSUTIL_OSK_EXT", 0x0000003b},
{"CELL_SYSMODULE_VDEC_DIVX", 0x0000003c},
{"CELL_SYSMODULE_JPGENC", 0x0000003d},
{"CELL_SYSMODULE_SYSUTIL_GAME", 0x0000003e},
{"CELL_SYSMODULE_BGDL", 0x0000003f},
{"CELL_SYSMODULE_FREETYPE_TT", 0x00000040},
{"CELL_SYSMODULE_SYSUTIL_VIDEO_UPLOAD", 0x00000041},
{"CELL_SYSMODULE_SYSUTIL_SYSCONF_EXT", 0x00000042},
{"CELL_SYSMODULE_FIBER", 0x00000043},
{"CELL_SYSMODULE_SYSUTIL_NP_COMMERCE2", 0x00000044},
{"CELL_SYSMODULE_SYSUTIL_NP_TUS", 0x00000045},
{"CELL_SYSMODULE_VOICE", 0x00000046},
{"CELL_SYSMODULE_ADEC_CELP8", 0x00000047},
{"CELL_SYSMODULE_CELP8ENC", 0x00000048},
{"CELL_SYSMODULE_SYSUTIL_LICENSEAREA", 0x00000049},
{"CELL_SYSMODULE_SYSUTIL_MUSIC2", 0x0000004a},
{"CELL_SYSMODULE_SYSUTIL_SCREENSHOT", 0x0000004e},
{"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE", 0x0000004f},
{"CELL_SYSMODULE_SPURS_JQ", 0x00000050},
{"CELL_SYSMODULE_PNGENC", 0x00000052},
{"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE2", 0x00000053},
{"CELL_SYSMODULE_SYNC2", 0x00000055},
{"CELL_SYSMODULE_SYSUTIL_NP_UTIL", 0x00000056},
{"CELL_SYSMODULE_RUDP", 0x00000057},
{"CELL_SYSMODULE_SYSUTIL_NP_SNS", 0x00000059},
{"CELL_SYSMODULE_GEM", 0x0000005a},
{"CELL_SYSMODULE_CELPENC", 0x0000f00a},
{"CELL_SYSMODULE_GIFDEC", 0x0000f010},
{"CELL_SYSMODULE_ADEC_CELP", 0x0000f019},
{"CELL_SYSMODULE_ADEC_M2BC", 0x0000f01b},
{"CELL_SYSMODULE_ADEC_M4AAC", 0x0000f01d},
{"CELL_SYSMODULE_ADEC_MP3", 0x0000f01e},
{"CELL_SYSMODULE_IMEJP", 0x0000f023},
{"CELL_SYSMODULE_SYSUTIL_MUSIC", 0x0000f028},
{"CELL_SYSMODULE_PHOTO_EXPORT", 0x0000f029},
{"CELL_SYSMODULE_PRINT", 0x0000f02a},
{"CELL_SYSMODULE_PHOTO_IMPORT", 0x0000f02b},
{"CELL_SYSMODULE_MUSIC_EXPORT", 0x0000f02c},
{"CELL_SYSMODULE_PHOTO_DECODE", 0x0000f02e},
{"CELL_SYSMODULE_SYSUTIL_SEARCH", 0x0000f02f},
{"CELL_SYSMODULE_SYSUTIL_AVCHAT2", 0x0000f030},
{"CELL_SYSMODULE_SAIL_REC", 0x0000f034},
{"CELL_SYSMODULE_SYSUTIL_NP_TROPHY", 0x0000f035},
{"CELL_SYSMODULE_LIBATRAC3MULTI", 0x0000f054},
{"CELL_SYSMODULE_ADEC", 0x00000006},
{"CELL_SYSMODULE_DMUX", 0x00000007},
{"CELL_SYSMODULE_VPOST", 0x00000008},
{"CELL_SYSMODULE_RTC", 0x00000009},
{"CELL_SYSMODULE_SPURS", 0x0000000a},
{"CELL_SYSMODULE_OVIS", 0x0000000b},
{"CELL_SYSMODULE_SHEAP", 0x0000000c},
{"CELL_SYSMODULE_SYNC", 0x0000000d},
{"CELL_SYSMODULE_FS", 0x0000000e},
{"CELL_SYSMODULE_JPGDEC", 0x0000000f},
{"CELL_SYSMODULE_GCM_SYS", 0x00000010},
{"CELL_SYSMODULE_GCM", 0x00000010},
{"CELL_SYSMODULE_AUDIO", 0x00000011},
{"CELL_SYSMODULE_PAMF", 0x00000012},
{"CELL_SYSMODULE_ATRAC3PLUS", 0x00000013},
{"CELL_SYSMODULE_NETCTL", 0x00000014},
{"CELL_SYSMODULE_SYSUTIL", 0x00000015},
{"CELL_SYSMODULE_SYSUTIL_NP", 0x00000016},
{"CELL_SYSMODULE_IO", 0x00000017},
{"CELL_SYSMODULE_PNGDEC", 0x00000018},
{"CELL_SYSMODULE_FONT", 0x00000019},
{"CELL_SYSMODULE_FONTFT", 0x0000001a},
{"CELL_SYSMODULE_FREETYPE", 0x0000001b},
{"CELL_SYSMODULE_USBD", 0x0000001c},
{"CELL_SYSMODULE_SAIL", 0x0000001d},
{"CELL_SYSMODULE_L10N", 0x0000001e},
{"CELL_SYSMODULE_RESC", 0x0000001f},
{"CELL_SYSMODULE_DAISY", 0x00000020},
{"CELL_SYSMODULE_KEY2CHAR", 0x00000021},
{"CELL_SYSMODULE_MIC", 0x00000022},
{"CELL_SYSMODULE_CAMERA", 0x00000023},
{"CELL_SYSMODULE_VDEC_MPEG2", 0x00000024},
{"CELL_SYSMODULE_VDEC_AVC", 0x00000025},
{"CELL_SYSMODULE_ADEC_LPCM", 0x00000026},
{"CELL_SYSMODULE_ADEC_AC3", 0x00000027},
{"CELL_SYSMODULE_ADEC_ATX", 0x00000028},
{"CELL_SYSMODULE_ADEC_AT3", 0x00000029},
{"CELL_SYSMODULE_DMUX_PAMF", 0x0000002a},
{"CELL_SYSMODULE_VDEC_AL", 0x0000002b},
{"CELL_SYSMODULE_ADEC_AL", 0x0000002c},
{"CELL_SYSMODULE_DMUX_AL", 0x0000002d},
{"CELL_SYSMODULE_LV2DBG", 0x0000002e},
{"CELL_SYSMODULE_USBPSPCM", 0x00000030},
{"CELL_SYSMODULE_AVCONF_EXT", 0x00000031},
{"CELL_SYSMODULE_SYSUTIL_USERINFO", 0x00000032},
{"CELL_SYSMODULE_SYSUTIL_SAVEDATA", 0x00000033},
{"CELL_SYSMODULE_SUBDISPLAY", 0x00000034},
{"CELL_SYSMODULE_SYSUTIL_REC", 0x00000035},
{"CELL_SYSMODULE_VIDEO_EXPORT", 0x00000036},
{"CELL_SYSMODULE_SYSUTIL_GAME_EXEC", 0x00000037},
{"CELL_SYSMODULE_SYSUTIL_NP2", 0x00000038},
{"CELL_SYSMODULE_SYSUTIL_AP", 0x00000039},
{"CELL_SYSMODULE_SYSUTIL_NP_CLANS", 0x0000003a},
{"CELL_SYSMODULE_SYSUTIL_OSK_EXT", 0x0000003b},
{"CELL_SYSMODULE_VDEC_DIVX", 0x0000003c},
{"CELL_SYSMODULE_JPGENC", 0x0000003d},
{"CELL_SYSMODULE_SYSUTIL_GAME", 0x0000003e},
{"CELL_SYSMODULE_BGDL", 0x0000003f},
{"CELL_SYSMODULE_FREETYPE_TT", 0x00000040},
{"CELL_SYSMODULE_SYSUTIL_VIDEO_UPLOAD", 0x00000041},
{"CELL_SYSMODULE_SYSUTIL_SYSCONF_EXT", 0x00000042},
{"CELL_SYSMODULE_FIBER", 0x00000043},
{"CELL_SYSMODULE_SYSUTIL_NP_COMMERCE2", 0x00000044},
{"CELL_SYSMODULE_SYSUTIL_NP_TUS", 0x00000045},
{"CELL_SYSMODULE_VOICE", 0x00000046},
{"CELL_SYSMODULE_ADEC_CELP8", 0x00000047},
{"CELL_SYSMODULE_CELP8ENC", 0x00000048},
{"CELL_SYSMODULE_SYSUTIL_LICENSEAREA", 0x00000049},
{"CELL_SYSMODULE_SYSUTIL_MUSIC2", 0x0000004a},
{"CELL_SYSMODULE_SYSUTIL_SCREENSHOT", 0x0000004e},
{"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE", 0x0000004f},
{"CELL_SYSMODULE_SPURS_JQ", 0x00000050},
{"CELL_SYSMODULE_PNGENC", 0x00000052},
{"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE2", 0x00000053},
{"CELL_SYSMODULE_SYNC2", 0x00000055},
{"CELL_SYSMODULE_SYSUTIL_NP_UTIL", 0x00000056},
{"CELL_SYSMODULE_RUDP", 0x00000057},
{"CELL_SYSMODULE_SYSUTIL_NP_SNS", 0x00000059},
{"CELL_SYSMODULE_GEM", 0x0000005a},
{"CELL_SYSMODULE_CELPENC", 0x0000f00a},
{"CELL_SYSMODULE_GIFDEC", 0x0000f010},
{"CELL_SYSMODULE_ADEC_CELP", 0x0000f019},
{"CELL_SYSMODULE_ADEC_M2BC", 0x0000f01b},
{"CELL_SYSMODULE_ADEC_M4AAC", 0x0000f01d},
{"CELL_SYSMODULE_ADEC_MP3", 0x0000f01e},
{"CELL_SYSMODULE_IMEJP", 0x0000f023},
{"CELL_SYSMODULE_SYSUTIL_MUSIC", 0x0000f028},
{"CELL_SYSMODULE_PHOTO_EXPORT", 0x0000f029},
{"CELL_SYSMODULE_PRINT", 0x0000f02a},
{"CELL_SYSMODULE_PHOTO_IMPORT", 0x0000f02b},
{"CELL_SYSMODULE_MUSIC_EXPORT", 0x0000f02c},
{"CELL_SYSMODULE_PHOTO_DECODE", 0x0000f02e},
{"CELL_SYSMODULE_SYSUTIL_SEARCH", 0x0000f02f},
{"CELL_SYSMODULE_SYSUTIL_AVCHAT2", 0x0000f030},
{"CELL_SYSMODULE_SAIL_REC", 0x0000f034},
{"CELL_SYSMODULE_SYSUTIL_NP_TROPHY", 0x0000f035},
{"CELL_SYSMODULE_LIBATRAC3MULTI", 0x0000f054},
};
for (int i = 0; i < 103; ++i) {
if (entries[i].id == id) {
return entries[i].name;
}
}
for (int i = 0; i < sizeof(entries) / sizeof(entries[0]); ++i)
{
if (entries[i].id == id)
{
return entries[i].name;
}
}
return 0;
}

View File

@ -59,7 +59,7 @@ bool ELF32Loader::LoadEhdrInfo()
return false;
}
entry = ehdr.GetEntry() & ~0x3;
entry = ehdr.GetEntry();
if(entry == 0)
{
ConLog.Error("elf32 error: entry is null!");
@ -86,10 +86,12 @@ bool ELF32Loader::LoadPhdrInfo()
phdr_arr.Move(phdr);
}
if(!Memory.IsGoodAddr(entry))
if(/*!Memory.IsGoodAddr(entry)*/ entry & 0x1)
{
//entry is physical, convert to virtual
entry &= ~0x1;
for(size_t i=0; i<phdr_arr.GetCount(); ++i)
{
if(phdr_arr[i].p_paddr >= entry && entry < phdr_arr[i].p_paddr + phdr_arr[i].p_memsz)