diff --git a/Utilities/BEType.h b/Utilities/BEType.h index 1994f7a28d..79f09e2495 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -443,34 +443,16 @@ static force_inline u128 sync_fetch_and_xor(volatile u128* dest, u128 value) } } -#define re16(val) _byteswap_ushort(val) -#define re32(val) _byteswap_ulong(val) -#define re64(val) _byteswap_uint64(val) -#define re128(val) u128::byteswap(val) - template struct se_t; -template struct se_t -{ - static force_inline u8 to_be(const T& src) - { - return (u8&)src; - } - - static force_inline T from_be(const u8 src) - { - return (T&)src; - } -}; - template struct se_t { - static force_inline u16 to_be(const T& src) + static force_inline u16 to(const T& src) { return _byteswap_ushort((u16&)src); } - static force_inline T from_be(const u16 src) + static force_inline T from(const u16 src) { const u16 res = _byteswap_ushort(src); return (T&)res; @@ -479,12 +461,12 @@ template struct se_t template struct se_t { - static force_inline u32 to_be(const T& src) + static force_inline u32 to(const T& src) { return _byteswap_ulong((u32&)src); } - static force_inline T from_be(const u32 src) + static force_inline T from(const u32 src) { const u32 res = _byteswap_ulong(src); return (T&)res; @@ -493,12 +475,12 @@ template struct se_t template struct se_t { - static force_inline u64 to_be(const T& src) + static force_inline u64 to(const T& src) { return _byteswap_uint64((u64&)src); } - static force_inline T from_be(const u64 src) + static force_inline T from(const u64 src) { const u64 res = _byteswap_uint64(src); return (T&)res; @@ -507,12 +489,12 @@ template struct se_t template struct se_t { - static force_inline u128 to_be(const T& src) + static force_inline u128 to(const T& src) { return u128::byteswap((u128&)src); } - static force_inline T from_be(const u128& src) + static force_inline T from(const u128& src) { const u128 res = u128::byteswap(src); return (T&)res; @@ -582,6 +564,7 @@ template using be_storage_t = typename be_storage::type; template class be_t { + // TODO (complicated cases like int-float conversions are not handled correctly) template struct _convert { @@ -634,9 +617,9 @@ public: be_t(const be_t&) = default; - template::value>> be_t(const CT& value) + template::value>> be_t(const type& value) #ifdef IS_LE_MACHINE - : m_data(se_t::to_be(value)) + : m_data(se_t::to(value)) #else : m_data(value) #endif @@ -647,7 +630,7 @@ public: force_inline type value() const { #ifdef IS_LE_MACHINE - return se_t::from_be(m_data); + return se_t::from(m_data); #else return m_data; #endif @@ -667,7 +650,11 @@ public: template std::enable_if_t::value, be_t&> operator =(const CT& value) { - m_data = se_t::to_be(value); +#ifdef IS_LE_MACHINE + m_data = se_t::to(value); +#else + m_data = value; +#endif return *this; } @@ -683,13 +670,11 @@ public: } // conversion to another be_t type - template operator be_t() const - { - return value(); - - // TODO (complicated cases like int-float conversions are not handled correctly) - //return _convert sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data); - } + //template operator be_t() const + //{ + // return value(); + // //return _convert sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data); + //} template be_t& operator +=(const T1& right) { return *this = value() + right; } template be_t& operator -=(const T1& right) { return *this = value() - right; } @@ -791,11 +776,6 @@ template<> struct to_be { using type = char; }; template<> struct to_be { using type = u8; }; template<> struct to_be { using type = s8; }; -template struct _se : public const_se_t {}; -template struct _se, T1, value> : public const_se_t {}; - -#define se32(x) _se::value - template class le_t { public: @@ -816,7 +796,7 @@ public: le_t(const le_t&) = default; - template::value>> le_t(const CT& value) + template::value>> le_t(const type& value) : m_data(value) { } @@ -845,10 +825,10 @@ public: } // conversion to another le_t type - template operator le_t() const - { - return value(); - } + //template operator le_t() const + //{ + // return value(); + //} template le_t& operator +=(const T1& right) { return *this = value() + right; } template le_t& operator -=(const T1& right) { return *this = value() - right; } diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 3595a3461f..d160a46198 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -827,7 +827,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) case X64OP_LOAD: { u32 value; - if (is_writing || !spu.ReadReg(addr, value) || !put_x64_reg_value(context, reg, d_size, re32(value))) + if (is_writing || !spu.ReadReg(addr, value) || !put_x64_reg_value(context, reg, d_size, _byteswap_ulong(value))) { return false; } @@ -837,7 +837,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) case X64OP_STORE: { u64 reg_value; - if (!is_writing || !get_x64_reg_value(context, reg, d_size, i_size, reg_value) || !spu.WriteReg(addr, re32((u32)reg_value))) + if (!is_writing || !get_x64_reg_value(context, reg, d_size, i_size, reg_value) || !spu.WriteReg(addr, _byteswap_ulong((u32)reg_value))) { return false; } diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index fdc99b2e99..b76f75fecf 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -179,7 +179,7 @@ bool UnpackEntry(const fs::file& dec_pkg_f, const PKGEntry& entry, std::string d dec_pkg_f.read(buf, entry.name_size); buf[entry.name_size] = 0; - switch (entry.type.data() >> 24) + switch (entry.type & 0xff) { case PKG_FILE_ENTRY_NPDRM: case PKG_FILE_ENTRY_NPDRMEDAT: diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index 57f084e30b..56cd59e994 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -102,34 +102,34 @@ force_inline void Write64LE(const fs::file& f, const u64 data) f.write(&data, sizeof(data)); } -force_inline void Write16(vfsStream& f, const u16 data) +force_inline void Write16(vfsStream& f, const be_t data) { - Write16LE(f, re16(data)); + f.Write(&data, sizeof(data)); } -force_inline void Write16(const fs::file& f, const u16 data) +force_inline void Write16(const fs::file& f, const be_t data) { - Write16LE(f, re16(data)); + f.write(&data, sizeof(data)); } -force_inline void Write32(vfsStream& f, const u32 data) +force_inline void Write32(vfsStream& f, const be_t data) { - Write32LE(f, re32(data)); + f.Write(&data, sizeof(data)); } -force_inline void Write32(const fs::file& f, const u32 data) +force_inline void Write32(const fs::file& f, const be_t data) { - Write32LE(f, re32(data)); + f.write(&data, sizeof(data)); } -force_inline void Write64(vfsStream& f, const u64 data) +force_inline void Write64(vfsStream& f, const be_t data) { - Write64LE(f, re64(data)); + f.Write(&data, sizeof(data)); } -force_inline void Write64(const fs::file& f, const u64 data) +force_inline void Write64(const fs::file& f, const be_t data) { - Write64LE(f, re64(data)); + f.write(&data, sizeof(data)); } void WriteEhdr(const fs::file& f, Elf64_Ehdr& ehdr) diff --git a/rpcs3/Emu/ARMv7/ARMv7Interpreter.cpp b/rpcs3/Emu/ARMv7/ARMv7Interpreter.cpp index 1c51b2de71..20136a5fc4 100644 --- a/rpcs3/Emu/ARMv7/ARMv7Interpreter.cpp +++ b/rpcs3/Emu/ARMv7/ARMv7Interpreter.cpp @@ -3699,7 +3699,7 @@ void ARMv7_instrs::REV(ARMv7Context& context, const ARMv7Code code, const ARMv7_ if (ConditionPassed(context, cond)) { - context.write_gpr(d, re32(context.read_gpr(m))); + context.write_gpr(d, _byteswap_ulong(context.read_gpr(m))); } } diff --git a/rpcs3/Emu/Cell/PPULLVMRecompiler.cpp b/rpcs3/Emu/Cell/PPULLVMRecompiler.cpp index 5ae0548f65..f3e161c054 100644 --- a/rpcs3/Emu/Cell/PPULLVMRecompiler.cpp +++ b/rpcs3/Emu/Cell/PPULLVMRecompiler.cpp @@ -148,7 +148,7 @@ Executable Compiler::Compile(const std::string & name, const ControlFlowGraph & } if (instr_bb->empty()) { - u32 instr = re32(vm::get_ref(m_state.current_instruction_address)); + u32 instr = vm::ps3::read32(m_state.current_instruction_address); Decode(instr); if (!m_state.hit_branch_instruction) { m_ir_builder->CreateBr(GetBasicBlockFromAddress(m_state.current_instruction_address + 4)); @@ -6025,7 +6025,7 @@ u32 ppu_recompiler_llvm::ExecutionEngine::ExecuteTillReturn(PPUThread * ppu_stat } } else { execution_engine->m_tracer.Trace(Tracer::TraceType::Instruction, ppu_state->PC, 0); - auto instruction = re32(vm::get_ref(ppu_state->PC)); + u32 instruction = vm::ps3::read32(ppu_state->PC); execution_engine->m_decoder.Decode(instruction); branch_type = ppu_state->m_is_branch ? GetBranchTypeFromInstruction(instruction) : BranchType::NonBranch; ppu_state->NextPc(4); diff --git a/rpcs3/Emu/Cell/SPURecompiler.h b/rpcs3/Emu/Cell/SPURecompiler.h index 893e8d8f63..57b79757f5 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.h +++ b/rpcs3/Emu/Cell/SPURecompiler.h @@ -28,7 +28,7 @@ public: struct SPURecEntry { u32 count; // count of instructions compiled from current point (and to be checked) - u32 valid; // copy of valid opcode for validation + be_t _valid; // copy of valid opcode for validation void* pointer; // pointer to executable memory object }; diff --git a/rpcs3/Emu/Cell/SPURecompilerCore.cpp b/rpcs3/Emu/Cell/SPURecompilerCore.cpp index 0caf41d906..a880ac031d 100644 --- a/rpcs3/Emu/Cell/SPURecompilerCore.cpp +++ b/rpcs3/Emu/Cell/SPURecompilerCore.cpp @@ -95,9 +95,9 @@ void SPURecompilerCore::Compile(u16 pos) while (true) { - const u32 opcode = vm::ps3::read32(CPU.offset + pos * 4); + const be_t opcode = vm::ps3::read32(CPU.offset + pos * 4); m_enc->do_finalize = false; - if (opcode) + if (opcode.data()) { //const u64 stamp1 = get_system_time(); // disasm for logging: @@ -120,11 +120,11 @@ void SPURecompilerCore::Compile(u16 pos) m_enc->do_finalize = true; } bool fin = m_enc->do_finalize; - //if (entry[pos].valid == re32(opcode)) + //if (entry[pos]._valid == opcode) //{ // excess++; //} - entry[pos].valid = re32(opcode); + entry[pos]._valid = opcode; if (fin) break; CPU.PC += 4; @@ -169,7 +169,7 @@ void SPURecompilerCore::Compile(u16 pos) u32 SPURecompilerCore::DecodeMemory(const u32 address) { const u32 pos = CPU.PC >> 2; // 0x0..0xffff - const auto ls = vm::get_ptr(CPU.offset); + const auto _ls = vm::get_ptr>(CPU.offset); assert(CPU.offset == address - CPU.PC && pos < 0x10000); @@ -182,7 +182,7 @@ u32 SPURecompilerCore::DecodeMemory(const u32 address) { for (u32 i = 0; i < 0x10000; i++) { - if (entry[i].valid && entry[i].valid != ls[i]) + if (entry[i]._valid.data() && entry[i]._valid != _ls[i]) { is_valid = false; break; @@ -199,14 +199,14 @@ u32 SPURecompilerCore::DecodeMemory(const u32 address) { if (!entry[i].pointer) continue; - if (!entry[i].valid || entry[i].valid != ls[i] || (i + entry[i].count > pos && i < pos + entry[pos].count)) + if (!entry[i]._valid.data() || entry[i]._valid != _ls[i] || (i + entry[i].count > pos && i < pos + entry[pos].count)) { m_jit->release(entry[i].pointer); entry[i].pointer = nullptr; for (u32 j = i; j < i + entry[i].count; j++) { - entry[j].valid = 0; + entry[j]._valid = 0; } //need_check = true; @@ -225,9 +225,9 @@ u32 SPURecompilerCore::DecodeMemory(const u32 address) return 0; } - const auto func = asmjit_cast(entry[pos].pointer); + const auto func = asmjit_cast* _ls, const void* _imm, const void* _g_imm)>(entry[pos].pointer); - u32 res = func(CPU, ls, imm_table.data(), &g_spu_imm); + u32 res = func(CPU, _ls, imm_table.data(), &g_spu_imm); if (res & 0x1000000) { diff --git a/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp b/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp index c7c82a42e8..0725d69783 100644 --- a/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp @@ -227,7 +227,7 @@ void CgBinaryDisasm::TaskFP() assert((m_buffer_size - m_offset) % sizeof(u32) == 0); for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++) { - data[i] = re32(data[i]); + data[i] = _byteswap_ulong(data[i]); // WTF, cannot use be_t<> there? } enum diff --git a/rpcs3/Emu/RSX/CgBinaryProgram.h b/rpcs3/Emu/RSX/CgBinaryProgram.h index 89959d0300..9f40dd61e1 100644 --- a/rpcs3/Emu/RSX/CgBinaryProgram.h +++ b/rpcs3/Emu/RSX/CgBinaryProgram.h @@ -365,7 +365,7 @@ public: assert((m_buffer_size - m_offset) % sizeof(u32) == 0); for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++) { - vdata[i] = re32(vdata[i]); + vdata[i] = _byteswap_ulong(vdata[i]); // WTF, cannot use be_t<> there? } for (u32 i = 0; i < prog.ucodeSize / sizeof(u32); i++) diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 09d51c55a5..07da68791d 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -101,17 +101,17 @@ void RSXVertexData::Load(u32 start, u32 count, u32 baseOffset, u32 baseIndex = 0 case 2: { - const u16* c_src = (const u16*)src; - u16* c_dst = (u16*)dst; - for (u32 j = 0; j < size; ++j) *c_dst++ = re16(*c_src++); + auto c_src = (const be_t*)src; + auto c_dst = (u16*)dst; + for (u32 j = 0; j < size; ++j) *c_dst++ = *c_src++; break; } case 4: { - const u32* c_src = (const u32*)src; - u32* c_dst = (u32*)dst; - for (u32 j = 0; j < size; ++j) *c_dst++ = re32(*c_src++); + auto c_src = (const be_t*)src; + auto c_dst = (u32*)dst; + for (u32 j = 0; j < size; ++j) *c_dst++ = *c_src++; break; } } diff --git a/rpcs3/Emu/SysCalls/Modules.cpp b/rpcs3/Emu/SysCalls/Modules.cpp index 3cfe404d2a..a72371bcbe 100644 --- a/rpcs3/Emu/SysCalls/Modules.cpp +++ b/rpcs3/Emu/SysCalls/Modules.cpp @@ -59,8 +59,8 @@ u32 add_ppu_func_sub(const char group[8], const SearchPatternEntry ops[], const { SearchPatternEntry op; op.type = ops[i].type; - op.data = re32(ops[i].data); - op.mask = re32(ops[i].mask); + op.data = _byteswap_ulong(ops[i].data); // TODO: use be_t<> + op.mask = _byteswap_ulong(ops[i].mask); op.num = ops[i].num; assert(!op.mask || (op.data & ~op.mask) == 0); sf.ops.push_back(op); @@ -250,7 +250,7 @@ void hook_ppu_func(vm::ptr base, u32 pos, u32 size) } // skip NOP - if (base[k].data() == se32(0x60000000)) + if (base[k] == 0x60000000) { x--; continue; @@ -308,7 +308,7 @@ void hook_ppu_func(vm::ptr base, u32 pos, u32 size) break; } - const auto addr = (base[k].data() & se32(2) ? 0 : (base + k).addr()) + ((s32)base[k] << cntlz32(mask) >> (cntlz32(mask) + 2)); + const auto addr = (base[k] & 2 ? 0 : (base + k).addr()) + ((s32)base[k] << cntlz32(mask) >> (cntlz32(mask) + 2)); const auto lnum = sub.ops[x].num; const auto label = sub.labels.find(lnum); @@ -331,7 +331,7 @@ void hook_ppu_func(vm::ptr base, u32 pos, u32 size) // break; // } - // const auto addr = (base[k].data() & se32(2) ? 0 : (base + k).addr()) + ((s32)base[k] << cntlz32(mask) >> (cntlz32(mask) + 2)); + // const auto addr = (base[k] & 2 ? 0 : (base + k).addr()) + ((s32)base[k] << cntlz32(mask) >> (cntlz32(mask) + 2)); // const auto nid = sub.ops[x].num; // // TODO: recursive call //} @@ -376,7 +376,7 @@ void hook_ppu_funcs(vm::ptr base, u32 size) for (u32 i = 0; i < size; i++) { // skip NOP - if (base[i].data() == se32(0x60000000)) + if (base[i] == 0x60000000) { continue; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellFs.cpp b/rpcs3/Emu/SysCalls/Modules/cellFs.cpp index db7c587a7e..c0703e216c 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellFs.cpp @@ -315,7 +315,7 @@ s32 cellFsStReadInit(u32 fd, vm::cptr ringbuf) { cellFs.Warning("cellFsStReadInit(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf); - if (ringbuf->copy.data() & ~se32(CELL_FS_ST_COPYLESS)) + if (ringbuf->copy & ~CELL_FS_ST_COPYLESS) { return CELL_FS_EINVAL; } @@ -352,7 +352,7 @@ s32 cellFsStReadInit(u32 fd, vm::cptr ringbuf) file->st_ringbuf_size = ringbuf->ringbuf_size; file->st_block_size = ringbuf->ringbuf_size; file->st_trans_rate = ringbuf->transfer_rate; - file->st_copyless = ringbuf->copy.data() == se32(CELL_FS_ST_COPYLESS); + file->st_copyless = ringbuf->copy == CELL_FS_ST_COPYLESS; const u64 alloc_size = align(file->st_ringbuf_size, file->st_ringbuf_size < 1024 * 1024 ? 64 * 1024 : 1024 * 1024); @@ -776,17 +776,17 @@ int sdata_unpack(const std::string& packed_file, const std::string& unpacked_fil char buffer[10200]; packed_stream->Read(buffer, 256); - u32 format = re32(*(u32*)&buffer[0]); + u32 format = *(be_t*)&buffer[0]; if (format != 0x4E504400) // "NPD\x00" { cellFs.Error("Illegal format. Expected 0x4E504400, but got 0x%08x", format); return CELL_EFSSPECIFIC; } - u32 version = re32(*(u32*)&buffer[0x04]); - u32 flags = re32(*(u32*)&buffer[0x80]); - u32 blockSize = re32(*(u32*)&buffer[0x84]); - u64 filesizeOutput = re64(*(u64*)&buffer[0x88]); + u32 version = *(be_t*)&buffer[0x04]; + u32 flags = *(be_t*)&buffer[0x80]; + u32 blockSize = *(be_t*)&buffer[0x84]; + u64 filesizeOutput = *(be_t*)&buffer[0x88]; u64 filesizeInput = packed_stream->GetSize(); u32 blockCount = (u32)((filesizeOutput + blockSize - 1) / blockSize); diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp index 3803069015..704af81681 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp @@ -50,13 +50,13 @@ s32 cellGifDecOpen( current_subHandle->fd = 0; current_subHandle->src = *src; - switch(src->srcSelect.data()) + switch (src->srcSelect.value()) { - case se32(CELL_GIFDEC_BUFFER): + case CELL_GIFDEC_BUFFER: current_subHandle->fileSize = src->streamSize; break; - case se32(CELL_GIFDEC_FILE): + case CELL_GIFDEC_FILE: { // Get file descriptor and size std::shared_ptr file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead)); @@ -95,13 +95,13 @@ s32 cellGifDecReadHeader( //Write the header to buffer vm::var buffer; // Alloc buffer for GIF header - switch(subHandle_data->src.srcSelect.data()) + switch(subHandle_data->src.srcSelect.value()) { - case se32(CELL_GIFDEC_BUFFER): + case CELL_GIFDEC_BUFFER: memmove(buffer.begin(), subHandle_data->src.streamPtr.get_ptr(), buffer.size()); break; - case se32(CELL_GIFDEC_FILE): + case CELL_GIFDEC_FILE: { auto file = Emu.GetIdManager().get(fd); file->file->Seek(0); @@ -192,13 +192,13 @@ s32 cellGifDecDecodeData( //Copy the GIF file to a buffer vm::var gif((u32)fileSize); - switch(subHandle_data->src.srcSelect.data()) + switch(subHandle_data->src.srcSelect.value()) { - case se32(CELL_GIFDEC_BUFFER): + case CELL_GIFDEC_BUFFER: memmove(gif.begin(), subHandle_data->src.streamPtr.get_ptr(), gif.size()); break; - case se32(CELL_GIFDEC_FILE): + case CELL_GIFDEC_FILE: { auto file = Emu.GetIdManager().get(fd); file->file->Seek(0); diff --git a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp index 244cc9d483..c3a7aa162c 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp @@ -44,13 +44,13 @@ s32 cellJpgDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptrfd = 0; current_subHandle->src = *src; - switch(src->srcSelect.data()) + switch(src->srcSelect.value()) { - case se32(CELL_JPGDEC_BUFFER): + case CELL_JPGDEC_BUFFER: current_subHandle->fileSize = src->streamSize; break; - case se32(CELL_JPGDEC_FILE): + case CELL_JPGDEC_FILE: { // Get file descriptor and size std::shared_ptr file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead)); @@ -103,13 +103,13 @@ s32 cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr //Write the header to buffer vm::var buffer((u32)fileSize); - switch(subHandle_data->src.srcSelect.data()) + switch(subHandle_data->src.srcSelect.value()) { - case se32(CELL_JPGDEC_BUFFER): + case CELL_JPGDEC_BUFFER: memmove(buffer.begin(), vm::get_ptr(subHandle_data->src.streamPtr), buffer.size()); break; - case se32(CELL_JPGDEC_FILE): + case CELL_JPGDEC_FILE: { auto file = Emu.GetIdManager().get(fd); file->file->Seek(0); @@ -177,13 +177,13 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp //Copy the JPG file to a buffer vm::var jpg((u32)fileSize); - switch(subHandle_data->src.srcSelect.data()) + switch(subHandle_data->src.srcSelect.value()) { - case se32(CELL_JPGDEC_BUFFER): + case CELL_JPGDEC_BUFFER: memmove(jpg.begin(), vm::get_ptr(subHandle_data->src.streamPtr), jpg.size()); break; - case se32(CELL_JPGDEC_FILE): + case CELL_JPGDEC_FILE: { auto file = Emu.GetIdManager().get(fd); file->file->Seek(0); diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 7fa8544d73..1cd823d757 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -76,13 +76,13 @@ s32 pngDecOpen( stream->fd = 0; stream->src = *src; - switch (src->srcSelect.data()) + switch (src->srcSelect.value()) { - case se32(CELL_PNGDEC_BUFFER): + case CELL_PNGDEC_BUFFER: stream->fileSize = src->streamSize; break; - case se32(CELL_PNGDEC_FILE): + case CELL_PNGDEC_FILE: { // Get file descriptor and size std::shared_ptr file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead)); @@ -141,12 +141,12 @@ s32 pngReadHeader( vm::var buffer; // Alloc buffer for PNG header auto buffer_32 = buffer.To>(); - switch (stream->src.srcSelect.data()) + switch (stream->src.srcSelect.value()) { - case se32(CELL_PNGDEC_BUFFER): + case CELL_PNGDEC_BUFFER: memmove(buffer.begin(), stream->src.streamPtr.get_ptr(), buffer.size()); break; - case se32(CELL_PNGDEC_FILE): + case CELL_PNGDEC_FILE: { auto file = Emu.GetIdManager().get(stream->fd); file->file->Seek(0); @@ -155,9 +155,9 @@ s32 pngReadHeader( } } - if (buffer_32[0].data() != se32(0x89504E47) || - buffer_32[1].data() != se32(0x0D0A1A0A) || // Error: The first 8 bytes are not a valid PNG signature - buffer_32[3].data() != se32(0x49484452)) // Error: The PNG file does not start with an IHDR chunk + if (buffer_32[0] != 0x89504E47 || + buffer_32[1] != 0x0D0A1A0A || // Error: The first 8 bytes are not a valid PNG signature + buffer_32[3] != 0x49484452) // Error: The PNG file does not start with an IHDR chunk { return CELL_PNGDEC_ERROR_HEADER; } @@ -205,20 +205,20 @@ s32 pngDecSetParameter( current_outParam.outputHeight = current_info.imageHeight; current_outParam.outputColorSpace = inParam->outputColorSpace; - switch (current_outParam.outputColorSpace.data()) + switch (current_outParam.outputColorSpace.value()) { - case se32(CELL_PNGDEC_PALETTE): - case se32(CELL_PNGDEC_GRAYSCALE): + case CELL_PNGDEC_PALETTE: + case CELL_PNGDEC_GRAYSCALE: current_outParam.outputComponents = 1; break; - case se32(CELL_PNGDEC_GRAYSCALE_ALPHA): + case CELL_PNGDEC_GRAYSCALE_ALPHA: current_outParam.outputComponents = 2; break; - case se32(CELL_PNGDEC_RGB): + case CELL_PNGDEC_RGB: current_outParam.outputComponents = 3; break; - case se32(CELL_PNGDEC_RGBA): - case se32(CELL_PNGDEC_ARGB): + case CELL_PNGDEC_RGBA: + case CELL_PNGDEC_ARGB: current_outParam.outputComponents = 4; break; default: @@ -252,13 +252,13 @@ s32 pngDecodeData( //Copy the PNG file to a buffer vm::var png((u32)fileSize); - switch (stream->src.srcSelect.data()) + switch (stream->src.srcSelect.value()) { - case se32(CELL_PNGDEC_BUFFER): + case CELL_PNGDEC_BUFFER: memmove(png.begin(), stream->src.streamPtr.get_ptr(), png.size()); break; - case se32(CELL_PNGDEC_FILE): + case CELL_PNGDEC_FILE: { auto file = Emu.GetIdManager().get(stream->fd); file->file->Seek(0); @@ -284,10 +284,10 @@ s32 pngDecodeData( const int bytesPerLine = (u32)dataCtrlParam->outputBytesPerLine; uint image_size = width * height; - switch (current_outParam.outputColorSpace.data()) + switch (current_outParam.outputColorSpace.value()) { - case se32(CELL_PNGDEC_RGB): - case se32(CELL_PNGDEC_RGBA): + case CELL_PNGDEC_RGB: + case CELL_PNGDEC_RGBA: { const char nComponents = current_outParam.outputColorSpace == CELL_PNGDEC_RGBA ? 4 : 3; image_size *= nComponents; @@ -308,7 +308,7 @@ s32 pngDecodeData( break; } - case se32(CELL_PNGDEC_ARGB): + case CELL_PNGDEC_ARGB: { const int nComponents = 4; image_size *= nComponents; @@ -350,9 +350,9 @@ s32 pngDecodeData( break; } - case se32(CELL_PNGDEC_GRAYSCALE): - case se32(CELL_PNGDEC_PALETTE): - case se32(CELL_PNGDEC_GRAYSCALE_ALPHA): + case CELL_PNGDEC_GRAYSCALE: + case CELL_PNGDEC_PALETTE: + case CELL_PNGDEC_GRAYSCALE_ALPHA: cellPngDec.Error("pngDecodeData: Unsupported color space (%d)", current_outParam.outputColorSpace); break; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp b/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp index 7d492cf87c..6d03aa6f08 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp @@ -555,7 +555,7 @@ never_inline s32 savedata_op( } } - psf.SetInteger("*" + file_path, fileSet->fileType.data() == se32(CELL_SAVEDATA_FILETYPE_SECUREFILE)); + psf.SetInteger("*" + file_path, fileSet->fileType == CELL_SAVEDATA_FILETYPE_SECUREFILE); std::string local_path; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index de61f9f5d0..791c1de37f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -2311,7 +2311,7 @@ s32 spursAddWorkload( v &= ~0xf; v |= (maxContention > 8 ? 8 : maxContention); }); - spurs->wklSignal1._and_not({ 0x8000 >> index }); // clear bit in wklFlag1 + spurs->wklSignal1._and_not(0x8000 >> index); // clear bit in wklFlag1 } else { @@ -2320,7 +2320,7 @@ s32 spursAddWorkload( v &= ~0xf0; v |= (maxContention > 8 ? 8 : maxContention) << 4; }); - spurs->wklSignal2._and_not({ 0x8000 >> index }); // clear bit in wklFlag2 + spurs->wklSignal2._and_not(0x8000 >> index); // clear bit in wklFlag2 } spurs->wklFlagReceiver.compare_and_swap(wnum, 0xff); @@ -2386,7 +2386,7 @@ s32 cellSpursAddWorkloadWithAttribute(vm::ptr spurs, vm::ptr wid return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN; } - if (attr->revision.data() != se32(1)) + if (attr->revision != 1) { return CELL_SPURS_POLICY_MODULE_ERROR_INVAL; } diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index 2878101c64..091dcf4e60 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -94,9 +94,9 @@ s32 sys_lwmutex_create(vm::ptr lwmutex, vm::ptrrecursive.data() == se32(SYS_SYNC_RECURSIVE); + const bool recursive = attr->recursive == SYS_SYNC_RECURSIVE; - if (!recursive && attr->recursive.data() != se32(SYS_SYNC_NOT_RECURSIVE)) + if (!recursive && attr->recursive != SYS_SYNC_NOT_RECURSIVE) { sysPrxForUser.Error("sys_lwmutex_create(): invalid recursive attribute (0x%x)", attr->recursive); return CELL_EINVAL; @@ -160,7 +160,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout // try to lock lightweight mutex const be_t old_owner = lwmutex->vars.owner.compare_and_swap(lwmutex_free, tid); - if (old_owner.data() == se32(lwmutex_free)) + if (old_owner == lwmutex_free) { // locking succeeded return CELL_OK; @@ -170,7 +170,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout { // recursive locking - if ((lwmutex->attribute.data() & se32(SYS_SYNC_RECURSIVE)) == 0) + if ((lwmutex->attribute & SYS_SYNC_RECURSIVE) == 0) { // if not recursive return CELL_EDEADLK; @@ -189,7 +189,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout return CELL_OK; } - if (old_owner.data() == se32(lwmutex_dead)) + if (old_owner == lwmutex_dead) { // invalid or deleted mutex return CELL_EINVAL; @@ -197,7 +197,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout for (u32 i = 0; i < 300; i++) { - if (lwmutex->vars.owner.read_relaxed().data() == se32(lwmutex_free)) + if (lwmutex->vars.owner.read_relaxed() == lwmutex_free) { if (lwmutex->vars.owner.compare_and_swap_test(lwmutex_free, tid)) { @@ -228,7 +228,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout // locking succeeded auto old = lwmutex->vars.owner.exchange(tid); - if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) + if (old != lwmutex_reserved && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwmutex_lock(lwmutex=*0x%x): locking failed (owner=0x%x)", lwmutex, old); } @@ -236,7 +236,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout return CELL_OK; } - if (res == CELL_EBUSY && lwmutex->attribute.data() & se32(SYS_SYNC_RETRY)) + if (res == CELL_EBUSY && lwmutex->attribute & SYS_SYNC_RETRY) { // TODO (protocol is ignored in current implementation) throw __FUNCTION__; @@ -254,7 +254,7 @@ s32 sys_lwmutex_trylock(PPUThread& CPU, vm::ptr lwmutex) // try to lock lightweight mutex const be_t old_owner = lwmutex->vars.owner.compare_and_swap(lwmutex_free, tid); - if (old_owner.data() == se32(lwmutex_free)) + if (old_owner == lwmutex_free) { // locking succeeded return CELL_OK; @@ -264,7 +264,7 @@ s32 sys_lwmutex_trylock(PPUThread& CPU, vm::ptr lwmutex) { // recursive locking - if ((lwmutex->attribute.data() & se32(SYS_SYNC_RECURSIVE)) == 0) + if ((lwmutex->attribute & SYS_SYNC_RECURSIVE) == 0) { // if not recursive return CELL_EDEADLK; @@ -283,13 +283,13 @@ s32 sys_lwmutex_trylock(PPUThread& CPU, vm::ptr lwmutex) return CELL_OK; } - if (old_owner.data() == se32(lwmutex_dead)) + if (old_owner == lwmutex_dead) { // invalid or deleted mutex return CELL_EINVAL; } - if (old_owner.data() == se32(lwmutex_reserved)) + if (old_owner == lwmutex_reserved) { // should be locked by the syscall const s32 res = _sys_lwmutex_trylock(lwmutex->sleep_queue); @@ -299,7 +299,7 @@ s32 sys_lwmutex_trylock(PPUThread& CPU, vm::ptr lwmutex) // locking succeeded auto old = lwmutex->vars.owner.exchange(tid); - if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) + if (old != lwmutex_reserved && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwmutex_trylock(lwmutex=*0x%x): locking failed (owner=0x%x)", lwmutex, old); } @@ -339,7 +339,7 @@ s32 sys_lwmutex_unlock(PPUThread& CPU, vm::ptr lwmutex) return CELL_OK; } - if (lwmutex->attribute.data() & se32(SYS_SYNC_RETRY)) + if (lwmutex->attribute & SYS_SYNC_RETRY) { // TODO (protocol is ignored in current implementation) } @@ -386,7 +386,7 @@ s32 sys_lwcond_signal(PPUThread& CPU, vm::ptr lwcond) const vm::ptr lwmutex = lwcond->lwmutex; - if ((lwmutex->attribute.data() & se32(SYS_SYNC_ATTR_PROTOCOL_MASK)) == se32(SYS_SYNC_RETRY)) + if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY) { // TODO (protocol ignored) //return _sys_lwcond_signal(lwcond->lwcond_queue, 0, -1, 2); @@ -444,7 +444,7 @@ s32 sys_lwcond_signal_all(PPUThread& CPU, vm::ptr lwcond) const vm::ptr lwmutex = lwcond->lwmutex; - if ((lwmutex->attribute.data() & se32(SYS_SYNC_ATTR_PROTOCOL_MASK)) == se32(SYS_SYNC_RETRY)) + if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY) { // TODO (protocol ignored) //return _sys_lwcond_signal_all(lwcond->lwcond_queue, lwmutex->sleep_queue, 2); @@ -501,7 +501,7 @@ s32 sys_lwcond_signal_to(PPUThread& CPU, vm::ptr lwcond, u32 ppu_t const vm::ptr lwmutex = lwcond->lwmutex; - if ((lwmutex->attribute.data() & se32(SYS_SYNC_ATTR_PROTOCOL_MASK)) == se32(SYS_SYNC_RETRY)) + if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY) { // TODO (protocol ignored) //return _sys_lwcond_signal(lwcond->lwcond_queue, 0, ppu_thread_id, 2); @@ -588,7 +588,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) const auto old = lwmutex->vars.owner.exchange(tid); lwmutex->recursive_count = recursive_value; - if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) + if (old != lwmutex_reserved && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwcond_wait(lwcond=*0x%x): locking failed (lwmutex->owner=0x%x)", lwcond, old); } @@ -617,7 +617,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) const auto old = lwmutex->vars.owner.exchange(tid); lwmutex->recursive_count = recursive_value; - if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) + if (old != lwmutex_reserved && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwcond_wait(lwcond=*0x%x): locking failed after timeout (lwmutex->owner=0x%x)", lwcond, old); } diff --git a/rpcs3/Emu/SysCalls/lv2/sleep_queue.h b/rpcs3/Emu/SysCalls/lv2/sleep_queue.h index b4c9768144..aeb554db66 100644 --- a/rpcs3/Emu/SysCalls/lv2/sleep_queue.h +++ b/rpcs3/Emu/SysCalls/lv2/sleep_queue.h @@ -31,7 +31,14 @@ enum // attr_pshared enum { - SYS_SYNC_NOT_PROCESS_SHARED = 0x200 + SYS_SYNC_NOT_PROCESS_SHARED = 0x200, +}; + +// attr_adaptive +enum +{ + SYS_SYNC_ADAPTIVE = 0x1000, + SYS_SYNC_NOT_ADAPTIVE = 0x2000, }; class sleep_queue_t diff --git a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp index a0d5d227e4..2aa1cd929a 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp @@ -26,7 +26,7 @@ s32 sys_cond_create(vm::ptr cond_id, u32 mutex_id, vm::ptrpshared.data() != se32(0x200) || attr->ipc_key.data() || attr->flags.data()) + if (attr->pshared != SYS_SYNC_NOT_PROCESS_SHARED || attr->ipc_key.data() || attr->flags.data()) { sys_cond.Error("sys_cond_create(): unknown attributes (pshared=0x%x, ipc_key=0x%llx, flags=0x%x)", attr->pshared, attr->ipc_key, attr->flags); return CELL_EINVAL; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp b/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp index 14e512ca94..0179e1fa00 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp @@ -32,7 +32,7 @@ s32 sys_event_flag_create(vm::ptr id, vm::ptr attr, u6 default: sys_event_flag.Error("sys_event_flag_create(): unknown protocol (0x%x)", attr->protocol); return CELL_EINVAL; } - if (attr->pshared.data() != se32(0x200) || attr->ipc_key.data() || attr->flags.data()) + if (attr->pshared != SYS_SYNC_NOT_PROCESS_SHARED || attr->ipc_key.data() || attr->flags.data()) { sys_event_flag.Error("sys_event_flag_create(): unknown attributes (pshared=0x%x, ipc_key=0x%llx, flags=0x%x)", attr->pshared, attr->ipc_key, attr->flags); return CELL_EINVAL; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp index 96333a6920..6616f0dd71 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp @@ -31,9 +31,9 @@ s32 sys_mutex_create(vm::ptr mutex_id, vm::ptr attr) default: sys_mutex.Error("sys_mutex_create(): unknown protocol (0x%x)", protocol); return CELL_EINVAL; } - const bool recursive = attr->recursive.data() == se32(SYS_SYNC_RECURSIVE); + const bool recursive = attr->recursive == SYS_SYNC_RECURSIVE; - if ((!recursive && attr->recursive.data() != se32(SYS_SYNC_NOT_RECURSIVE)) || attr->pshared.data() != se32(0x200) || attr->adaptive.data() != se32(0x2000) || attr->ipc_key.data() || attr->flags.data()) + if ((!recursive && attr->recursive != SYS_SYNC_NOT_RECURSIVE) || attr->pshared.data() != SYS_SYNC_NOT_PROCESS_SHARED || attr->adaptive != SYS_SYNC_NOT_ADAPTIVE || attr->ipc_key.data() || attr->flags.data()) { sys_mutex.Error("sys_mutex_create(): unknown attributes (recursive=0x%x, pshared=0x%x, adaptive=0x%x, ipc_key=0x%llx, flags=0x%x)", attr->recursive, attr->pshared, attr->adaptive, attr->ipc_key, attr->flags); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp index d23d5270dc..cac0d33348 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp @@ -30,7 +30,7 @@ s32 sys_rwlock_create(vm::ptr rw_lock_id, vm::ptr a default: sys_rwlock.Error("sys_rwlock_create(): unknown protocol (0x%x)", protocol); return CELL_EINVAL; } - if (attr->pshared.data() != se32(0x200) || attr->ipc_key.data() || attr->flags.data()) + if (attr->pshared != SYS_SYNC_NOT_PROCESS_SHARED || attr->ipc_key.data() || attr->flags.data()) { sys_rwlock.Error("sys_rwlock_create(): unknown attributes (pshared=0x%x, ipc_key=0x%llx, flags=0x%x)", attr->pshared, attr->ipc_key, attr->flags); return CELL_EINVAL; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp index 26528daa6b..b0f6aa72ee 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp @@ -37,7 +37,7 @@ s32 sys_semaphore_create(vm::ptr sem, vm::ptr at default: sys_semaphore.Error("sys_semaphore_create(): unknown protocol (0x%x)", protocol); return CELL_EINVAL; } - if (attr->pshared.data() != se32(0x200) || attr->ipc_key.data() || attr->flags.data()) + if (attr->pshared != SYS_SYNC_NOT_PROCESS_SHARED || attr->ipc_key.data() || attr->flags.data()) { sys_semaphore.Error("sys_semaphore_create(): unknown attributes (pshared=0x%x, ipc_key=0x%x, flags=0x%x)", attr->pshared, attr->ipc_key, attr->flags); return CELL_EINVAL; diff --git a/rpcs3/Loader/ELF64.h b/rpcs3/Loader/ELF64.h index ab2c455b98..bb0120ecd5 100644 --- a/rpcs3/Loader/ELF64.h +++ b/rpcs3/Loader/ELF64.h @@ -32,7 +32,7 @@ namespace loader be_t e_shnum; be_t e_shstrndx; - bool check() const { return e_magic.data() == se32(0x7F454C46); } + bool check() const { return e_magic == 0x7F454C46; } } m_ehdr; struct phdr