Some fixes

This commit is contained in:
Nekotekina 2014-07-11 13:18:23 +04:00
parent 259b57c64a
commit 125359e30e
15 changed files with 94 additions and 90 deletions

View file

@ -310,7 +310,7 @@ class SPUThread : public PPCThread
public: public:
SPU_GPR_hdr GPR[128]; //General-Purpose Register SPU_GPR_hdr GPR[128]; //General-Purpose Register
SPU_SPR_hdr SPR[128]; //Special-Purpose Registers SPU_SPR_hdr SPR[128]; //Special-Purpose Registers
// FPSCR fpscr; //Unused FPSCR FPSCR;
SPU_SNRConfig_hdr cfg; //Signal Notification Registers Configuration (OR-mode enabled: 0x1 for SNR1, 0x2 for SNR2) SPU_SNRConfig_hdr cfg; //Signal Notification Registers Configuration (OR-mode enabled: 0x1 for SNR1, 0x2 for SNR2)
EventPort SPUPs[64]; // SPU Thread Event Ports EventPort SPUPs[64]; // SPU Thread Event Ports

View file

@ -32,12 +32,15 @@ u64 vfsStreamMemory::Write(const void* src, u64 size)
size = GetSize() - Tell(); size = GetSize() - Tell();
} }
if(!size || !Memory.IsGoodAddr(m_addr + Tell(), size)) return 0; if (!Memory.CopyFromReal(m_addr + Tell(), (void*)src, size))
{
Memory.CopyFromReal(m_addr + Tell(), (void*)src, size); return 0;
}
else
{
return vfsStream::Write(src, size); return vfsStream::Write(src, size);
} }
}
u64 vfsStreamMemory::Read(void* dst, u64 size) u64 vfsStreamMemory::Read(void* dst, u64 size)
{ {
@ -46,9 +49,12 @@ u64 vfsStreamMemory::Read(void* dst, u64 size)
size = GetSize() - Tell(); size = GetSize() - Tell();
} }
if(!size || !Memory.IsGoodAddr(m_addr + Tell(), size)) return 0; if (!Memory.CopyToReal(dst, m_addr + Tell(), size))
{
Memory.CopyToReal(dst, m_addr + Tell(), size); return 0;
}
else
{
return vfsStream::Read(dst, size); return vfsStream::Read(dst, size);
} }
}

View file

@ -104,14 +104,14 @@ bool MemoryBlock::GetMemFromAddr(void* dst, const u64 addr, const u32 size)
{ {
if(!IsMyAddress(addr) || FixAddr(addr) + size > GetSize()) return false; if(!IsMyAddress(addr) || FixAddr(addr) + size > GetSize()) return false;
return Memory.CopyToReal(dst, (u32)addr, size); return Memory.CopyToReal(dst, addr, size);
} }
bool MemoryBlock::SetMemFromAddr(void* src, const u64 addr, const u32 size) bool MemoryBlock::SetMemFromAddr(void* src, const u64 addr, const u32 size)
{ {
if(!IsMyAddress(addr) || FixAddr(addr) + size > GetSize()) return false; if(!IsMyAddress(addr) || FixAddr(addr) + size > GetSize()) return false;
return Memory.CopyFromReal((u32)addr, src, size); return Memory.CopyFromReal(addr, src, size);
} }
bool MemoryBlock::GetMemFFromAddr(void* dst, const u64 addr) bool MemoryBlock::GetMemFFromAddr(void* dst, const u64 addr)

View file

@ -318,52 +318,32 @@ public:
u64 Read64(const u64 addr); u64 Read64(const u64 addr);
u128 Read128(const u64 addr); u128 Read128(const u64 addr);
bool CopyToReal(void* real, u32 from, u32 count) bool CopyToReal(void* real, u64 from, u32 count)
{ {
if (!count) return true; if (!IsGoodAddr(from, count)) return false;
memcpy(real, GetMemFromAddr(from), count); memcpy(real, GetMemFromAddr(from), count);
return true; return true;
} }
bool CopyFromReal(u32 to, const void* real, u32 count) bool CopyFromReal(u64 to, const void* real, u32 count)
{ {
if (!count) return true; if (!IsGoodAddr(to, count)) return false;
memcpy(GetMemFromAddr(to), real, count); memcpy(GetMemFromAddr(to), real, count);
return true; return true;
} }
bool Copy(u32 to, u32 from, u32 count) bool Copy(u64 to, u64 from, u32 count)
{ {
if (u8* buf = (u8*)malloc(count)) if (!IsGoodAddr(to, count) || !IsGoodAddr(from, count)) return false;
{
if (CopyToReal(buf, from, count)) memmove(GetMemFromAddr(to), GetMemFromAddr(from), count);
{
if (CopyFromReal(to, buf, count))
{
free(buf);
return true; return true;
} }
else
{
free(buf);
return false;
}
}
else
{
free(buf);
return false;
}
}
else
{
return false;
}
}
void ReadLeft(u8* dst, const u64 addr, const u32 size) void ReadLeft(u8* dst, const u64 addr, const u32 size)
{ {
@ -797,7 +777,7 @@ public:
u32 AppendRawBytes(const u8 *bytes, size_t count) u32 AppendRawBytes(const u8 *bytes, size_t count)
{ {
Memory.CopyFromReal(this->m_addr, bytes, count); memmove(Memory + this->m_addr, bytes, count);
this->m_addr += count; this->m_addr += count;
return this->m_addr; return this->m_addr;
} }

View file

@ -724,33 +724,11 @@ int cellAdecGetPcm(u32 handle, u32 outBuffer_addr)
if (!af.data) // fake: empty data if (!af.data) // fake: empty data
{ {
/*u8* buf = (u8*)malloc(4096);
memset(buf, 0, 4096);
Memory.CopyFromReal(outBuffer_addr, buf, 4096);
free(buf);*/
return result; return result;
} }
// copy data // copy data
SwrContext* swr = nullptr;
/*swr = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_FLT, 48000,
frame->channel_layout, (AVSampleFormat)frame->format, frame->sample_rate, 0, NULL);
if (!swr)
{
LOG_ERROR(HLE, "cellAdecGetPcm(%d): swr_alloc_set_opts() failed", handle);
Emu.Pause();
free(out);
if (af.data)
{
av_frame_unref(af.data);
av_frame_free(&af.data);
}
return result;
}*/
u8* out = (u8*)malloc(af.size); u8* out = (u8*)malloc(af.size);
// something is wrong
//swr_convert(swr, &out, frame->nb_samples, (const u8**)frame->extended_data, frame->nb_samples);
// reverse byte order, extract data: // reverse byte order, extract data:
float* in_f[2]; float* in_f[2];
@ -770,7 +748,6 @@ int cellAdecGetPcm(u32 handle, u32 outBuffer_addr)
} }
free(out); free(out);
if (swr) swr_free(&swr);
if (af.data) if (af.data)
{ {

View file

@ -494,7 +494,12 @@ int cellGcmSetPrepareFlip(mem_ptr_t<CellGcmContextData> ctxt, u32 id)
const s32 res = ctxt->current - ctxt->begin - ctrl.put; const s32 res = ctxt->current - ctxt->begin - ctrl.put;
if(res > 0) Memory.Copy(ctxt->begin, ctxt->current - res, res); if (res > 0 && !Memory.Copy(ctxt->begin, ctxt->current - res, res))
{
cellGcmSys->Error("cellGcmSetPrepareFlip(): Memory.Copy(0x%x, 0x%x, 0x%x) failed", (u32)ctxt->begin, (u32)ctxt->current - res, res);
Emu.Pause();
return CELL_EFAULT;
}
ctxt->current = ctxt->begin + res; ctxt->current = ctxt->begin + res;
//InterlockedExchange64((volatile long long*)((u8*)&ctrl + offsetof(CellGcmControl, put)), (u64)(u32)re(res)); //InterlockedExchange64((volatile long long*)((u8*)&ctrl + offsetof(CellGcmControl, put)), (u64)(u32)re(res));
@ -1160,7 +1165,12 @@ int cellGcmCallback(u32 context_addr, u32 count)
const s32 res = ctx.current - ctx.begin - ctrl.put; const s32 res = ctx.current - ctx.begin - ctrl.put;
if(res > 0) Memory.Copy(ctx.begin, ctx.current - res, res); if (res > 0 && !Memory.Copy(ctx.begin, ctx.current - res, res))
{
cellGcmSys->Error("cellGcmCallback(): Memory.Copy(0x%x, 0x%x, 0x%x) failed", (u32)ctx.begin, (u32)ctx.current - res, res);
Emu.Pause();
return CELL_EFAULT;
}
ctx.current = ctx.begin + res; ctx.current = ctx.begin + res;

View file

@ -182,7 +182,11 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, const m
switch((u32)current_outParam.outputColorSpace) switch((u32)current_outParam.outputColorSpace)
{ {
case CELL_GIFDEC_RGBA: case CELL_GIFDEC_RGBA:
Memory.CopyFromReal(data.GetAddr(), image.get(), image_size); if (!Memory.CopyFromReal(data.GetAddr(), image.get(), image_size))
{
cellGifDec->Error("cellGifDecDecodeData() failed (dataa_addr=0x%x)", data.GetAddr());
return CELL_EFAULT;
}
break; break;
case CELL_GIFDEC_ARGB: case CELL_GIFDEC_ARGB:

View file

@ -164,7 +164,11 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, const m
case CELL_JPG_RGBA: case CELL_JPG_RGBA:
case CELL_JPG_RGB: case CELL_JPG_RGB:
image_size *= current_outParam.outputColorSpace == CELL_JPG_RGBA ? 4 : 3; image_size *= current_outParam.outputColorSpace == CELL_JPG_RGBA ? 4 : 3;
Memory.CopyFromReal(data.GetAddr(), image.get(), image_size); if (!Memory.CopyFromReal(data.GetAddr(), image.get(), image_size))
{
cellJpgDec->Error("cellJpgDecDecodeData() failed (data_addr=0x%x)", data.GetAddr());
return CELL_EFAULT;
}
break; break;
case CELL_JPG_ARGB: case CELL_JPG_ARGB:

View file

@ -148,7 +148,11 @@ int cellPngDecReadHeader(u32 mainHandle, u32 subHandle, mem_ptr_t<CellPngDecInfo
switch(subHandle_data->src.srcSelect.ToBE()) switch(subHandle_data->src.srcSelect.ToBE())
{ {
case se32(CELL_PNGDEC_BUFFER): case se32(CELL_PNGDEC_BUFFER):
Memory.Copy(buffer.GetAddr(), subHandle_data->src.streamPtr.ToLE(), buffer.GetSize()); if (!Memory.Copy(buffer.GetAddr(), subHandle_data->src.streamPtr.ToLE(), buffer.GetSize()))
{
cellPngDec->Error("cellPngDecReadHeader() failed ()");
return CELL_EFAULT;
}
break; break;
case se32(CELL_PNGDEC_FILE): case se32(CELL_PNGDEC_FILE):
cellFsLseek(fd, 0, CELL_SEEK_SET, pos.GetAddr()); cellFsLseek(fd, 0, CELL_SEEK_SET, pos.GetAddr());
@ -213,7 +217,11 @@ int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, const m
switch(subHandle_data->src.srcSelect.ToLE()) switch(subHandle_data->src.srcSelect.ToLE())
{ {
case CELL_PNGDEC_BUFFER: case CELL_PNGDEC_BUFFER:
Memory.Copy(png.GetAddr(), subHandle_data->src.streamPtr.ToLE(), png.GetSize()); if (!Memory.Copy(png.GetAddr(), subHandle_data->src.streamPtr.ToLE(), png.GetSize()))
{
cellPngDec->Error("cellPngDecDecodeData() failed (I)");
return CELL_EFAULT;
}
break; break;
case CELL_PNGDEC_FILE: case CELL_PNGDEC_FILE:
cellFsLseek(fd, 0, CELL_SEEK_SET, pos.GetAddr()); cellFsLseek(fd, 0, CELL_SEEK_SET, pos.GetAddr());
@ -249,12 +257,20 @@ int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, const m
{ {
const int dstOffset = i * bytesPerLine; const int dstOffset = i * bytesPerLine;
const int srcOffset = width * nComponents * (flip ? height - i - 1 : i); const int srcOffset = width * nComponents * (flip ? height - i - 1 : i);
Memory.CopyFromReal(data.GetAddr() + dstOffset, &image.get()[srcOffset], linesize); if (!Memory.CopyFromReal(data.GetAddr() + dstOffset, &image.get()[srcOffset], linesize))
{
cellPngDec->Error("cellPngDecDecodeData() failed (II)");
return CELL_EFAULT;
}
} }
} }
else else
{ {
Memory.CopyFromReal(data.GetAddr(), image.get(), image_size); if (!Memory.CopyFromReal(data.GetAddr(), image.get(), image_size))
{
cellPngDec->Error("cellPngDecDecodeData() failed (III)");
return CELL_EFAULT;
}
} }
} }
break; break;
@ -279,7 +295,11 @@ int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, const m
output[j + 2] = image.get()[srcOffset + j + 1]; output[j + 2] = image.get()[srcOffset + j + 1];
output[j + 3] = image.get()[srcOffset + j + 2]; output[j + 3] = image.get()[srcOffset + j + 2];
} }
Memory.CopyFromReal(data.GetAddr() + dstOffset, output, linesize); if (!Memory.CopyFromReal(data.GetAddr() + dstOffset, output, linesize))
{
cellPngDec->Error("cellPngDecDecodeData() failed (IV)");
return CELL_EFAULT;
}
} }
free(output); free(output);
} }

View file

@ -168,9 +168,12 @@ int sys_raw_spu_image_load(int id, mem_ptr_t<sys_spu_image> img)
{ {
sysPrxForUser->Warning("sys_raw_spu_image_load(id=0x%x, img_addr=0x%x)", id, img.GetAddr()); sysPrxForUser->Warning("sys_raw_spu_image_load(id=0x%x, img_addr=0x%x)", id, img.GetAddr());
Memory.Copy(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id, (u32)img->segs_addr, 256 * 1024); if (!Memory.Copy(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id, (u32)img->segs_addr, 256 * 1024))
Memory.Write32(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id + RAW_SPU_PROB_OFFSET + SPU_NPC_offs, {
(u32)img->entry_point); sysPrxForUser->Error("sys_raw_spu_image_load() failed");
return CELL_EFAULT;
}
Memory.Write32(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id + RAW_SPU_PROB_OFFSET + SPU_NPC_offs, (u32)img->entry_point);
return CELL_OK; return CELL_OK;
} }

View file

@ -71,7 +71,7 @@ enum cellFsStStatus
}; };
#pragma pack(4) #pragma pack(push, 4)
struct CellFsStat struct CellFsStat
{ {
@ -98,7 +98,7 @@ struct CellFsDirent
char d_name[CELL_MAX_FS_FILE_NAME_LENGTH + 1]; char d_name[CELL_MAX_FS_FILE_NAME_LENGTH + 1];
}; };
#pragma pack() #pragma pack(pop)
struct CellFsAio struct CellFsAio
{ {

View file

@ -14,8 +14,6 @@ struct sys_rwlock_attribute_t
}; };
}; };
#pragma pack()
struct RWLock struct RWLock
{ {
std::mutex m_lock; // internal lock std::mutex m_lock; // internal lock

View file

@ -136,10 +136,14 @@ s32 sys_spu_thread_initialize(mem32_t thread, u32 group, u32 spu_num, mem_ptr_t<
u64 a3 = arg->arg3; u64 a3 = arg->arg3;
u64 a4 = arg->arg4; u64 a4 = arg->arg4;
CPUThread& new_thread = Emu.GetCPU().AddThread(CPU_THREAD_SPU);
//copy SPU image: //copy SPU image:
u32 spu_offset = Memory.MainMem.AllocAlign(256 * 1024); auto spu_offset = Memory.MainMem.AllocAlign(256 * 1024);
Memory.CopyToReal(Memory + spu_offset, (u32)img->segs_addr, 256 * 1024); if (!Memory.Copy(spu_offset, (u32)img->segs_addr, 256 * 1024))
{
return CELL_EFAULT;
}
CPUThread& new_thread = Emu.GetCPU().AddThread(CPU_THREAD_SPU);
//initialize from new place: //initialize from new place:
new_thread.SetOffset(spu_offset); new_thread.SetOffset(spu_offset);
new_thread.SetEntry(spu_ep); new_thread.SetEntry(spu_ep);

View file

@ -20,8 +20,6 @@ struct timer
sys_timer_information_t timer_information_t; sys_timer_information_t timer_information_t;
}; };
#pragma pack()
s32 sys_timer_create(mem32_t timer_id); s32 sys_timer_create(mem32_t timer_id);
s32 sys_timer_destroy(u32 timer_id); s32 sys_timer_destroy(u32 timer_id);
s32 sys_timer_get_information(u32 timer_id, mem_ptr_t<sys_timer_information_t> info); s32 sys_timer_get_information(u32 timer_id, mem_ptr_t<sys_timer_information_t> info);

View file

@ -1,4 +1,4 @@
#pragma pack #pragma once
#define SYS_VM_TEST_INVALID 0x0000ULL #define SYS_VM_TEST_INVALID 0x0000ULL
#define SYS_VM_TEST_UNUSED 0x0001ULL #define SYS_VM_TEST_UNUSED 0x0001ULL