Memory fixes

This commit is contained in:
Nekotekina 2014-10-01 17:18:38 +04:00
parent ce97a7e7a6
commit 4a6779469c
7 changed files with 32 additions and 43 deletions

View file

@ -128,7 +128,6 @@ void MemoryBase::Init(MemoryType type)
MemoryBlocks.push_back(MainMem.SetRange(0x00010000, 0x2FFF0000)); MemoryBlocks.push_back(MainMem.SetRange(0x00010000, 0x2FFF0000));
MemoryBlocks.push_back(UserMemory = PRXMem.SetRange(0x30000000, 0x10000000)); MemoryBlocks.push_back(UserMemory = PRXMem.SetRange(0x30000000, 0x10000000));
MemoryBlocks.push_back(RSXCMDMem.SetRange(0x40000000, 0x10000000)); MemoryBlocks.push_back(RSXCMDMem.SetRange(0x40000000, 0x10000000));
MemoryBlocks.push_back(MmaperMem.SetRange(0xB0000000, 0x10000000));
MemoryBlocks.push_back(RSXFBMem.SetRange(0xC0000000, 0x10000000)); MemoryBlocks.push_back(RSXFBMem.SetRange(0xC0000000, 0x10000000));
MemoryBlocks.push_back(StackMem.SetRange(0xD0000000, 0x10000000)); MemoryBlocks.push_back(StackMem.SetRange(0xD0000000, 0x10000000));
break; break;
@ -218,7 +217,7 @@ bool MemoryBase::Map(const u64 addr, const u32 size)
} }
MemoryBlocks.push_back((new MemoryBlock())->SetRange(addr, size)); MemoryBlocks.push_back((new MemoryBlock())->SetRange(addr, size));
LOG_WARNING(MEMORY, "MemoryBase::Map(0x%llx, 0x%x)", addr, size); LOG_WARNING(MEMORY, "Memory mapped at 0x%llx: size=0x%x", addr, size);
return true; return true;
} }

View file

@ -35,7 +35,6 @@ public:
DynamicMemoryBlock MainMem; DynamicMemoryBlock MainMem;
DynamicMemoryBlock PRXMem; DynamicMemoryBlock PRXMem;
DynamicMemoryBlock RSXCMDMem; DynamicMemoryBlock RSXCMDMem;
DynamicMemoryBlock MmaperMem;
DynamicMemoryBlock RSXFBMem; DynamicMemoryBlock RSXFBMem;
DynamicMemoryBlock StackMem; DynamicMemoryBlock StackMem;
MemoryBlock* RawSPUMem[(0x100000000 - RAW_SPU_BASE_ADDR) / RAW_SPU_OFFSET]; MemoryBlock* RawSPUMem[(0x100000000 - RAW_SPU_BASE_ADDR) / RAW_SPU_OFFSET];

View file

@ -366,7 +366,7 @@ namespace vm
//BE pointer to LE data //BE pointer to LE data
template<typename T, int lvl = 1, typename AT = u32> struct bptrl : public _ptr_base<T, lvl, typename to_be_t<AT>::type> template<typename T, int lvl = 1, typename AT = u32> struct bptrl : public _ptr_base<T, lvl, typename to_be_t<AT>::type>
{ {
static bptrl make(AT addr) static bptrl make(typename to_be_t<AT>::type addr)
{ {
return (bptrl&)addr; return (bptrl&)addr;
} }
@ -378,7 +378,7 @@ namespace vm
//BE pointer to BE data //BE pointer to BE data
template<typename T, int lvl = 1, typename AT = u32> struct bptrb : public _ptr_base<typename to_be_t<T>::type, lvl, typename to_be_t<AT>::type> template<typename T, int lvl = 1, typename AT = u32> struct bptrb : public _ptr_base<typename to_be_t<T>::type, lvl, typename to_be_t<AT>::type>
{ {
static bptrb make(AT addr) static bptrb make(typename to_be_t<AT>::type addr)
{ {
return (bptrb&)addr; return (bptrb&)addr;
} }
@ -428,7 +428,7 @@ namespace vm
//default pointer for HLE structures (BE ptrerence to BE data) //default pointer for HLE structures (BE ptrerence to BE data)
template<typename T, int lvl = 1, typename AT = u32> struct bptr : public bptrb<T, lvl, AT> template<typename T, int lvl = 1, typename AT = u32> struct bptr : public bptrb<T, lvl, AT>
{ {
static bptr make(AT addr) static bptr make(typename to_be_t<AT>::type addr)
{ {
return (bptr&)addr; return (bptr&)addr;
} }

View file

@ -178,7 +178,7 @@ void getSaveDataStat(SaveDataEntry entry, vm::ptr<CellSaveDataStatGet> statGet)
strcpy_trunc(statGet->getParam.listParam, entry.listParam); strcpy_trunc(statGet->getParam.listParam, entry.listParam);
statGet->fileNum = 0; statGet->fileNum = 0;
statGet->fileList = vm::bptr<CellSaveDataFileStat>::make(0); statGet->fileList.set(be_t<u32>::make(0));
statGet->fileListNum = 0; statGet->fileListNum = 0;
std::string saveDir = "/dev_hdd0/home/00000001/savedata/" + entry.dirName; // TODO: Get the path of the current user std::string saveDir = "/dev_hdd0/home/00000001/savedata/" + entry.dirName; // TODO: Get the path of the current user
vfsDir dir(saveDir); vfsDir dir(saveDir);

View file

@ -1337,7 +1337,7 @@ s64 cellSpursGetWorkloadFlag(vm::ptr<CellSpurs> spurs, vm::ptr<vm::bptr<CellSpur
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN; return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
} }
*flag = vm::bptr<CellSpursWorkloadFlag>::make(Memory.RealToVirtualAddr(&spurs->m.wklFlag)); flag->set(be_t<u32>::make(Memory.RealToVirtualAddr(&spurs->m.wklFlag)));
return CELL_OK; return CELL_OK;
} }

View file

@ -271,20 +271,20 @@ struct CellSpurs
// real data // real data
struct struct
{ {
atomic_t<u8> wklReadyCount[0x20]; atomic_t<u8> wklReadyCount[0x20]; // 0x0 (index = wid)
u8 wklA[0x10]; // 0x20 u8 wklA[0x10]; // 0x20 (packed 4-bit data, index = wid % 16, internal index = wid / 16)
u8 wklB[0x10]; // 0x30 u8 wklB[0x10]; // 0x30 (packed 4-bit data, index = wid % 16, internal index = wid / 16)
u8 wklMinCnt[0x10]; // 0x40 u8 wklMinCnt[0x10]; // 0x40 (seems only for first 0..15 wids)
atomic_t<u8> wklMaxCnt[0x10]; // 0x50 atomic_t<u8> wklMaxCnt[0x10]; // 0x50 (packed 4-bit data, index = wid % 16, internal index = wid / 16)
CellSpursWorkloadFlag wklFlag; // 0x60 CellSpursWorkloadFlag wklFlag; // 0x60
atomic_t<u16> wklSet1; // 0x70 atomic_t<u16> wklSet1; // 0x70 (bitset for 0..15 wids)
atomic_t<u8> x72; // 0x72 atomic_t<u8> x72; // 0x72
u8 x73; // 0x73 u8 x73; // 0x73
u8 flags1; // 0x74 u8 flags1; // 0x74
u8 x75; // 0x75 u8 x75; // 0x75
u8 nSpus; // 0x76 u8 nSpus; // 0x76
atomic_t<u8> flagRecv; // 0x77 atomic_t<u8> flagRecv; // 0x77
atomic_t<u16> wklSet2; // 0x78 atomic_t<u16> wklSet2; // 0x78 (bitset for 16..32 wids)
u8 x7A[6]; // 0x7A u8 x7A[6]; // 0x7A
atomic_t<u8> wklStat1[0x10]; // 0x80 atomic_t<u8> wklStat1[0x10]; // 0x80
u8 wklD1[0x10]; // 0x90 u8 wklD1[0x10]; // 0x90

View file

@ -11,7 +11,7 @@ MemoryContainerInfo* current_ct;
s32 sys_vm_memory_map(u32 vsize, u32 psize, u32 cid, u64 flag, u64 policy, u32 addr) s32 sys_vm_memory_map(u32 vsize, u32 psize, u32 cid, u64 flag, u64 policy, u32 addr)
{ {
sys_vm.Todo("sys_vm_memory_map(vsize=0x%x,psize=0x%x,cidr=0x%x,flags=0x%llx,policy=0x%llx,addr=0x%x)", sys_vm.Error("sys_vm_memory_map(vsize=0x%x, psize=0x%x, cidr=0x%x, flags=0x%llx, policy=0x%llx, addr_addr=0x%x)",
vsize, psize, cid, flag, policy, addr); vsize, psize, cid, flag, policy, addr);
// Check virtual size. // Check virtual size.
@ -26,25 +26,12 @@ s32 sys_vm_memory_map(u32 vsize, u32 psize, u32 cid, u64 flag, u64 policy, u32 a
return CELL_ENOMEM; return CELL_ENOMEM;
} }
// Use fixed address (TODO: search and use some free address instead)
u32 new_addr = Memory.IsGoodAddr(0x60000000) ? 0x70000000 : 0x60000000;
// If container ID is SYS_MEMORY_CONTAINER_ID_INVALID, allocate directly. // If container ID is SYS_MEMORY_CONTAINER_ID_INVALID, allocate directly.
if(cid == SYS_MEMORY_CONTAINER_ID_INVALID) if(cid == SYS_MEMORY_CONTAINER_ID_INVALID)
{ {
u32 new_addr;
switch(flag)
{
case SYS_MEMORY_PAGE_SIZE_1M:
new_addr = (u32)Memory.Alloc(psize, 0x100000);
break;
case SYS_MEMORY_PAGE_SIZE_64K:
new_addr = (u32)Memory.Alloc(psize, 0x10000);
break;
default: return CELL_EINVAL;
}
if(!new_addr) return CELL_ENOMEM;
// Create a new MemoryContainerInfo to act as default container with vsize. // Create a new MemoryContainerInfo to act as default container with vsize.
current_ct = new MemoryContainerInfo(new_addr, vsize); current_ct = new MemoryContainerInfo(new_addr, vsize);
} }
@ -57,18 +44,22 @@ s32 sys_vm_memory_map(u32 vsize, u32 psize, u32 cid, u64 flag, u64 policy, u32 a
current_ct = ct; current_ct = ct;
} }
// Allocate actual memory using virtual size (physical size is ignored)
assert(Memory.Map(new_addr, vsize));
// Write a pointer for the allocated memory. // Write a pointer for the allocated memory.
vm::write32(addr, current_ct->addr); vm::write32(addr, new_addr);
return CELL_OK; return CELL_OK;
} }
s32 sys_vm_unmap(u32 addr) s32 sys_vm_unmap(u32 addr)
{ {
sys_vm.Todo("sys_vm_unmap(addr=0x%x)", addr); sys_vm.Error("sys_vm_unmap(addr=0x%x)", addr);
// Simply free the memory to unmap. // Unmap memory.
if(!Memory.Free(addr)) return CELL_EINVAL; assert(addr == 0x60000000 || addr == 0x70000000);
if(!Memory.Unmap(addr)) return CELL_EINVAL;
return CELL_OK; return CELL_OK;
} }