Moving byte order/memory access to poly.

This commit is contained in:
Ben Vanik 2014-07-17 19:20:17 -07:00
parent ce70978ef6
commit ec4f41fec4
42 changed files with 608 additions and 486 deletions

View File

@ -1405,7 +1405,7 @@ uint32_t IntCode_LOAD_I16(IntCodeState& ics, const IntCode* i) {
uint32_t address = ics.rf[i->src1_reg].u32;
if (DYNAMIC_REGISTER_ACCESS_CHECK(address)) {
ics.rf[i->dest_reg].i16 =
XESWAP16(ics.thread_state->memory()->LoadI16(address));
poly::byte_swap(ics.thread_state->memory()->LoadI16(address));
return IA_NEXT;
}
DPRINT("%d (%X) = load.i16 %.8X\n", *((int16_t*)(ics.membase + address)),
@ -1418,7 +1418,7 @@ uint32_t IntCode_LOAD_I32(IntCodeState& ics, const IntCode* i) {
uint32_t address = ics.rf[i->src1_reg].u32;
if (DYNAMIC_REGISTER_ACCESS_CHECK(address)) {
ics.rf[i->dest_reg].i32 =
XESWAP32(ics.thread_state->memory()->LoadI32(address));
poly::byte_swap(ics.thread_state->memory()->LoadI32(address));
return IA_NEXT;
}
DFLUSH();
@ -1432,7 +1432,7 @@ uint32_t IntCode_LOAD_I64(IntCodeState& ics, const IntCode* i) {
uint32_t address = ics.rf[i->src1_reg].u32;
if (DYNAMIC_REGISTER_ACCESS_CHECK(address)) {
ics.rf[i->dest_reg].i64 =
XESWAP64(ics.thread_state->memory()->LoadI64(address));
poly::byte_swap(ics.thread_state->memory()->LoadI64(address));
return IA_NEXT;
}
DPRINT("%lld (%llX) = load.i64 %.8X\n", *((int64_t*)(ics.membase + address)),
@ -1498,8 +1498,8 @@ uint32_t IntCode_STORE_I8(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_STORE_I16(IntCodeState& ics, const IntCode* i) {
uint32_t address = ics.rf[i->src1_reg].u32;
if (DYNAMIC_REGISTER_ACCESS_CHECK(address)) {
ics.thread_state->memory()->StoreI16(address,
XESWAP16(ics.rf[i->src2_reg].i16));
ics.thread_state->memory()->StoreI16(
address, poly::byte_swap(ics.rf[i->src2_reg].i16));
return IA_NEXT;
}
DPRINT("store.i16 %.8X = %d (%X)\n", address, ics.rf[i->src2_reg].i16,
@ -1512,8 +1512,8 @@ uint32_t IntCode_STORE_I16(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_STORE_I32(IntCodeState& ics, const IntCode* i) {
uint32_t address = ics.rf[i->src1_reg].u32;
if (DYNAMIC_REGISTER_ACCESS_CHECK(address)) {
ics.thread_state->memory()->StoreI32(address,
XESWAP32(ics.rf[i->src2_reg].i32));
ics.thread_state->memory()->StoreI32(
address, poly::byte_swap(ics.rf[i->src2_reg].i32));
return IA_NEXT;
}
DPRINT("store.i32 %.8X = %d (%X)\n", address, ics.rf[i->src2_reg].i32,
@ -1526,8 +1526,8 @@ uint32_t IntCode_STORE_I32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_STORE_I64(IntCodeState& ics, const IntCode* i) {
uint32_t address = ics.rf[i->src1_reg].u32;
if (DYNAMIC_REGISTER_ACCESS_CHECK(address)) {
ics.thread_state->memory()->StoreI64(address,
XESWAP64(ics.rf[i->src2_reg].i64));
ics.thread_state->memory()->StoreI64(
address, poly::byte_swap(ics.rf[i->src2_reg].i64));
return IA_NEXT;
}
DPRINT("store.i64 %.8X = %lld (%llX)\n", address, ics.rf[i->src2_reg].i64,
@ -2210,13 +2210,13 @@ int Translate_VECTOR_COMPARE_SGT(TranslationContext& ctx, Instr* i) {
return DispatchToC(ctx, i, fns[i->flags]);
}
uint32_t IntCode_VECTOR_COMPARE_SGE_I8(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_SGE_I8(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(int8_t, b16, b16, 16, >= )};
uint32_t IntCode_VECTOR_COMPARE_SGE_I16(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_SGE_I16(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(int16_t, s8, s8, 8, >= )};
uint32_t IntCode_VECTOR_COMPARE_SGE_I32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_SGE_I32(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(int32_t, i4, i4, 4, >= )};
uint32_t IntCode_VECTOR_COMPARE_SGE_F32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_SGE_F32(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(float, f4, i4, 4, >= )};
int Translate_VECTOR_COMPARE_SGE(TranslationContext& ctx, Instr* i) {
static IntCodeFn fns[] = {
@ -2228,13 +2228,13 @@ int Translate_VECTOR_COMPARE_SGE(TranslationContext& ctx, Instr* i) {
return DispatchToC(ctx, i, fns[i->flags]);
}
uint32_t IntCode_VECTOR_COMPARE_UGT_I8(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGT_I8(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(uint8_t, b16, b16, 16, > )};
uint32_t IntCode_VECTOR_COMPARE_UGT_I16(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGT_I16(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(uint16_t, s8, s8, 8, > )};
uint32_t IntCode_VECTOR_COMPARE_UGT_I32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGT_I32(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(uint32_t, i4, i4, 4, > )};
uint32_t IntCode_VECTOR_COMPARE_UGT_F32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGT_F32(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(float, f4, i4, 4, > )};
int Translate_VECTOR_COMPARE_UGT(TranslationContext& ctx, Instr* i) {
static IntCodeFn fns[] = {
@ -2246,13 +2246,13 @@ int Translate_VECTOR_COMPARE_UGT(TranslationContext& ctx, Instr* i) {
return DispatchToC(ctx, i, fns[i->flags]);
}
uint32_t IntCode_VECTOR_COMPARE_UGE_I8(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGE_I8(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(uint8_t, b16, b16, 16, >= )};
uint32_t IntCode_VECTOR_COMPARE_UGE_I16(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGE_I16(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(uint16_t, s8, s8, 8, >= )};
uint32_t IntCode_VECTOR_COMPARE_UGE_I32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGE_I32(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(uint32_t, i4, i4, 4, >= )};
uint32_t IntCode_VECTOR_COMPARE_UGE_F32(IntCodeState& ics, const IntCode* i) {
uint32_t IntCode_VECTOR_COMPARE_UGE_F32(IntCodeState& ics, const IntCode* i){
VECTOR_COMPARER(float, f4, i4, 4, >= )};
int Translate_VECTOR_COMPARE_UGE(TranslationContext& ctx, Instr* i) {
static IntCodeFn fns[] = {
@ -3526,22 +3526,22 @@ int Translate_ROTATE_LEFT(TranslationContext& ctx, Instr* i) {
}
uint32_t IntCode_BYTE_SWAP_I16(IntCodeState& ics, const IntCode* i) {
ics.rf[i->dest_reg].i16 = XESWAP16(ics.rf[i->src1_reg].i16);
ics.rf[i->dest_reg].i16 = poly::byte_swap(ics.rf[i->src1_reg].i16);
return IA_NEXT;
}
uint32_t IntCode_BYTE_SWAP_I32(IntCodeState& ics, const IntCode* i) {
ics.rf[i->dest_reg].i32 = XESWAP32(ics.rf[i->src1_reg].i32);
ics.rf[i->dest_reg].i32 = poly::byte_swap(ics.rf[i->src1_reg].i32);
return IA_NEXT;
}
uint32_t IntCode_BYTE_SWAP_I64(IntCodeState& ics, const IntCode* i) {
ics.rf[i->dest_reg].i64 = XESWAP64(ics.rf[i->src1_reg].i64);
ics.rf[i->dest_reg].i64 = poly::byte_swap(ics.rf[i->src1_reg].i64);
return IA_NEXT;
}
uint32_t IntCode_BYTE_SWAP_V128(IntCodeState& ics, const IntCode* i) {
const vec128_t& src1 = ics.rf[i->src1_reg].v128;
vec128_t& dest = ics.rf[i->dest_reg].v128;
for (int n = 0; n < 4; n++) {
VECI4(dest, n) = XESWAP32(VECI4(src1, n));
VECI4(dest, n) = poly::byte_swap(VECI4(src1, n));
}
return IA_NEXT;
}

View File

@ -11,7 +11,6 @@
#define ALLOY_CORE_H_
// TODO(benvanik): move the common stuff into here?
#include <xenia/byte_order.h>
#include <xenia/config.h>
#include <xenia/logging.h>
#include <xenia/malloc.h>

View File

@ -1343,7 +1343,9 @@ int InstrEmit_vsldoi_(PPCHIRBuilder& f, uint32_t vd, uint32_t va, uint32_t vb,
// (ABCD ABCD) << 4b = (BCDA)
// (VA << SH) OR (VB >> (16 - SH))
vec128_t shift = *((vec128_t*)(__vsldoi_table[sh]));
for (int i = 0; i < 4; ++i) shift.i4[i] = XESWAP32BE(shift.i4[i]);
for (int i = 0; i < 4; ++i) {
shift.i4[i] = poly::byte_swap(shift.i4[i]);
}
Value* control = f.LoadConstant(shift);
Value* v = f.Permute(control, f.LoadVR(va), f.LoadVR(vb), INT8_TYPE);
f.StoreVR(vd, v);

View File

@ -81,7 +81,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) {
for (uint64_t address = start_address, offset = 0; address <= end_address;
address += 4, offset++) {
i.address = address;
i.code = XEGETUINT32BE(p + address);
i.code = poly::load_and_swap<uint32_t>(p + address);
// TODO(benvanik): find a way to avoid using the opcode tables.
i.type = GetInstrType(i.code);

View File

@ -14,6 +14,7 @@
#include <alloy/frontend/ppc/ppc_frontend.h>
#include <alloy/frontend/ppc/ppc_instr.h>
#include <alloy/runtime/runtime.h>
#include <poly/memory.h>
namespace alloy {
namespace frontend {
@ -58,7 +59,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
InstrData i;
while (true) {
i.address = address;
i.code = XEGETUINT32BE(p + address);
i.code = poly::load_and_swap<uint32_t>(p + address);
// If we fetched 0 assume that we somehow hit one of the awesome
// 'no really we meant to end after that bl' functions.
@ -291,7 +292,7 @@ std::vector<BlockInfo> PPCScanner::FindBlocks(FunctionInfo* symbol_info) {
InstrData i;
for (uint64_t address = start_address; address <= end_address; address += 4) {
i.address = address;
i.code = XEGETUINT32BE(p + address);
i.code = poly::load_and_swap<uint32_t>(p + address);
if (!i.code) {
continue;
}

View File

@ -174,7 +174,7 @@ void PPCTranslator::DumpSource(runtime::FunctionInfo* symbol_info,
for (uint64_t address = start_address, offset = 0; address <= end_address;
address += 4, offset++) {
i.address = address;
i.code = XEGETUINT32BE(p + address);
i.code = poly::load_and_swap<uint32_t>(p + address);
// TODO(benvanik): find a way to avoid using the opcode tables.
i.type = GetInstrType(i.code);

View File

@ -572,17 +572,17 @@ void Value::ByteSwap() {
constant.i8 = constant.i8;
break;
case INT16_TYPE:
constant.i16 = XESWAP16(constant.i16);
constant.i16 = poly::byte_swap(constant.i16);
break;
case INT32_TYPE:
constant.i32 = XESWAP32(constant.i32);
constant.i32 = poly::byte_swap(constant.i32);
break;
case INT64_TYPE:
constant.i64 = XESWAP64(constant.i64);
constant.i64 = poly::byte_swap(constant.i64);
break;
case VEC128_TYPE:
for (int n = 0; n < 4; n++) {
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
constant.v128.i4[n] = poly::byte_swap(constant.v128.i4[n]);
}
break;
default:

61
src/poly/byte_order.h Normal file
View File

@ -0,0 +1,61 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef POLY_BYTE_ORDER_H_
#define POLY_BYTE_ORDER_H_
#include <cstdint>
#include <poly/config.h>
#include <poly/platform.h>
#if XE_LIKE_OSX
#include <libkern/OSByteOrder.h>
#endif // XE_LIKE_OSX
namespace poly {
#if XE_COMPILER_MSVC
#define POLY_BYTE_SWAP_16 _byteswap_ushort
#define POLY_BYTE_SWAP_32 _byteswap_ulong
#define POLY_BYTE_SWAP_64 _byteswap_uint64
#elif XE_LIKE_OSX
#define POLY_BYTE_SWAP_16 OSSwapInt16
#define POLY_BYTE_SWAP_32 OSSwapInt32
#define POLY_BYTE_SWAP_64 OSSwapInt64
#else
#define POLY_BYTE_SWAP_16 __bswap_16
#define POLY_BYTE_SWAP_32 __bswap_32
#define POLY_BYTE_SWAP_64 __bswap_64
#endif // XE_COMPILER_MSVC
inline int16_t byte_swap(int16_t value) {
return static_cast<int16_t>(POLY_BYTE_SWAP_16(static_cast<int16_t>(value)));
}
inline uint16_t byte_swap(uint16_t value) { return POLY_BYTE_SWAP_16(value); }
inline int32_t byte_swap(int32_t value) {
return static_cast<int32_t>(POLY_BYTE_SWAP_32(static_cast<int32_t>(value)));
}
inline uint32_t byte_swap(uint32_t value) { return POLY_BYTE_SWAP_32(value); }
inline int64_t byte_swap(int64_t value) {
return static_cast<int64_t>(POLY_BYTE_SWAP_64(static_cast<int64_t>(value)));
}
inline uint64_t byte_swap(uint64_t value) { return POLY_BYTE_SWAP_64(value); }
inline float byte_swap(float value) {
uint32_t temp = byte_swap(*reinterpret_cast<uint32_t *>(&value));
return *reinterpret_cast<float *>(&temp);
}
inline double byte_swap(double value) {
uint64_t temp = byte_swap(*reinterpret_cast<uint64_t *>(&value));
return *reinterpret_cast<double *>(&temp);
}
} // namespace poly
#endif // POLY_BYTE_ORDER_H_

View File

@ -10,13 +10,184 @@
#ifndef POLY_MEMORY_H_
#define POLY_MEMORY_H_
#include <poly/config.h>
#include <poly/platform.h>
#include <poly/byte_order.h>
namespace poly {
size_t page_size();
template <typename T>
T load(const void* mem);
template <>
inline int8_t load<int8_t>(const void* mem) {
return *reinterpret_cast<const int8_t*>(mem);
}
template <>
inline uint8_t load<uint8_t>(const void* mem) {
return *reinterpret_cast<const uint8_t*>(mem);
}
template <>
inline int16_t load<int16_t>(const void* mem) {
return *reinterpret_cast<const int16_t*>(mem);
}
template <>
inline uint16_t load<uint16_t>(const void* mem) {
return *reinterpret_cast<const uint16_t*>(mem);
}
template <>
inline int32_t load<int32_t>(const void* mem) {
return *reinterpret_cast<const int32_t*>(mem);
}
template <>
inline uint32_t load<uint32_t>(const void* mem) {
return *reinterpret_cast<const uint32_t*>(mem);
}
template <>
inline int64_t load<int64_t>(const void* mem) {
return *reinterpret_cast<const int64_t*>(mem);
}
template <>
inline uint64_t load<uint64_t>(const void* mem) {
return *reinterpret_cast<const uint64_t*>(mem);
}
template <>
inline float load<float>(const void* mem) {
return *reinterpret_cast<const float*>(mem);
}
template <>
inline double load<double>(const void* mem) {
return *reinterpret_cast<const double*>(mem);
}
template <typename T>
T load_and_swap(const void* mem);
template <>
inline int8_t load_and_swap<int8_t>(const void* mem) {
return *reinterpret_cast<const int8_t*>(mem);
}
template <>
inline uint8_t load_and_swap<uint8_t>(const void* mem) {
return *reinterpret_cast<const uint8_t*>(mem);
}
template <>
inline int16_t load_and_swap<int16_t>(const void* mem) {
return byte_swap(*reinterpret_cast<const int16_t*>(mem));
}
template <>
inline uint16_t load_and_swap<uint16_t>(const void* mem) {
return byte_swap(*reinterpret_cast<const uint16_t*>(mem));
}
template <>
inline int32_t load_and_swap<int32_t>(const void* mem) {
return byte_swap(*reinterpret_cast<const int32_t*>(mem));
}
template <>
inline uint32_t load_and_swap<uint32_t>(const void* mem) {
return byte_swap(*reinterpret_cast<const uint32_t*>(mem));
}
template <>
inline int64_t load_and_swap<int64_t>(const void* mem) {
return byte_swap(*reinterpret_cast<const int64_t*>(mem));
}
template <>
inline uint64_t load_and_swap<uint64_t>(const void* mem) {
return byte_swap(*reinterpret_cast<const uint64_t*>(mem));
}
template <>
inline float load_and_swap<float>(const void* mem) {
return byte_swap(*reinterpret_cast<const float*>(mem));
}
template <>
inline double load_and_swap<double>(const void* mem) {
return byte_swap(*reinterpret_cast<const double*>(mem));
}
template <typename T>
void store(void* mem, T value);
template <>
inline void store<int8_t>(void* mem, int8_t value) {
*reinterpret_cast<int8_t*>(mem) = value;
}
template <>
inline void store<uint8_t>(void* mem, uint8_t value) {
*reinterpret_cast<uint8_t*>(mem) = value;
}
template <>
inline void store<int16_t>(void* mem, int16_t value) {
*reinterpret_cast<int16_t*>(mem) = value;
}
template <>
inline void store<uint16_t>(void* mem, uint16_t value) {
*reinterpret_cast<uint16_t*>(mem) = value;
}
template <>
inline void store<int32_t>(void* mem, int32_t value) {
*reinterpret_cast<int32_t*>(mem) = value;
}
template <>
inline void store<uint32_t>(void* mem, uint32_t value) {
*reinterpret_cast<uint32_t*>(mem) = value;
}
template <>
inline void store<int64_t>(void* mem, int64_t value) {
*reinterpret_cast<int64_t*>(mem) = value;
}
template <>
inline void store<uint64_t>(void* mem, uint64_t value) {
*reinterpret_cast<uint64_t*>(mem) = value;
}
template <>
inline void store<float>(void* mem, float value) {
*reinterpret_cast<float*>(mem) = value;
}
template <>
inline void store<double>(void* mem, double value) {
*reinterpret_cast<double*>(mem) = value;
}
template <typename T>
void store_and_swap(void* mem, T value);
template <>
inline void store_and_swap<int8_t>(void* mem, int8_t value) {
*reinterpret_cast<int8_t*>(mem) = value;
}
template <>
inline void store_and_swap<uint8_t>(void* mem, uint8_t value) {
*reinterpret_cast<uint8_t*>(mem) = value;
}
template <>
inline void store_and_swap<int16_t>(void* mem, int16_t value) {
*reinterpret_cast<int16_t*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<uint16_t>(void* mem, uint16_t value) {
*reinterpret_cast<uint16_t*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<int32_t>(void* mem, int32_t value) {
*reinterpret_cast<int32_t*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<uint32_t>(void* mem, uint32_t value) {
*reinterpret_cast<uint32_t*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<int64_t>(void* mem, int64_t value) {
*reinterpret_cast<int64_t*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<uint64_t>(void* mem, uint64_t value) {
*reinterpret_cast<uint64_t*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<float>(void* mem, float value) {
*reinterpret_cast<float*>(mem) = byte_swap(value);
}
template <>
inline void store_and_swap<double>(void* mem, double value) {
*reinterpret_cast<double*>(mem) = byte_swap(value);
}
} // namespace poly
#endif // POLY_MEMORY_H_

View File

@ -12,6 +12,7 @@
#include <poly/assert.h>
#include <poly/atomic.h>
#include <poly/byte_order.h>
#include <poly/config.h>
#include <poly/cxx_compat.h>
#include <poly/math.h>

View File

@ -3,6 +3,7 @@
'sources': [
'assert.h',
'atomic.h',
'byte_order.h',
'config.h',
'cxx_compat.h',
'math.cc',

View File

@ -149,7 +149,7 @@ X_STATUS AudioSystem::RegisterClient(
uint32_t ptr = (uint32_t)memory()->HeapAlloc(0, 0x4, 0);
auto mem = memory()->membase();
XESETUINT32BE(mem + ptr, callback_arg);
poly::store_and_swap<uint32_t>(mem + ptr, callback_arg);
clients_[index] = { driver, callback, callback_arg, ptr };

View File

@ -131,7 +131,7 @@ void XAudio2AudioDriver::SubmitFrame(uint32_t frame_ptr) {
// interleave the data
for (int index = 0, o = 0; index < channel_samples_; ++index) {
for (int channel = 0, table = 0; channel < interleave_channels; ++channel, table += channel_samples_) {
output_frame[o++] = XESWAPF32BE(input_frame[table + index]);
output_frame[o++] = poly::byte_swap(input_frame[table + index]);
}
}

View File

@ -1,120 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_BYTE_ORDER_H_
#define XENIA_BYTE_ORDER_H_
#include <cstdint>
#include <xenia/platform.h>
#include <xenia/types.h>
#if XE_COMPILER_MSVC
#define XESWAP16 _byteswap_ushort
#define XESWAP32 _byteswap_ulong
#define XESWAP64 _byteswap_uint64
#elif XE_LIKE_OSX
#include <libkern/OSByteOrder.h>
#define XESWAP16 OSSwapInt16
#define XESWAP32 OSSwapInt32
#define XESWAP64 OSSwapInt64
#else
#define XESWAP16 __bswap_16
#define XESWAP32 __bswap_32
#define XESWAP64 __bswap_64
#endif
#if XE_CPU_BIGENDIAN
#define XESWAP16BE(p) (p)
#define XESWAP32BE(p) (p)
#define XESWAP64BE(p) (p)
#define XESWAP16LE(p) XESWAP16(p)
#define XESWAP32LE(p) XESWAP32(p)
#define XESWAP64LE(p) XESWAP64(p)
#else
#define XESWAP16BE(p) XESWAP16(p)
#define XESWAP32BE(p) XESWAP32(p)
#define XESWAP64BE(p) XESWAP64(p)
#define XESWAP16LE(p) (p)
#define XESWAP32LE(p) (p)
#define XESWAP64LE(p) (p)
#endif
#if XE_CPU_BIGENDIAN
#define XESWAPF32BE(p) (p)
#define XESWAPF64BE(p) (p)
XEFORCEINLINE float XESWAPF32LE(float value) {
uint32_t dummy = XESWAP32LE(*reinterpret_cast<uint32_t *>(&value));
return *reinterpret_cast<float *>(&dummy);
}
XEFORCEINLINE double XESWAPF64LE(double value) {
uint64_t dummy = XESWAP64LE(*reinterpret_cast<uint64_t *>(&value));
return *reinterpret_cast<double *>(&dummy);
}
#else
XEFORCEINLINE float XESWAPF32BE(float value) {
uint32_t dummy = XESWAP32BE(*reinterpret_cast<uint32_t *>(&value));
return *reinterpret_cast<float *>(&dummy);
}
XEFORCEINLINE double XESWAPF64BE(double value) {
uint64_t dummy = XESWAP64BE(*reinterpret_cast<uint64_t *>(&value));
return *reinterpret_cast<double *>(&dummy);
}
#define XESWAPF32LE(p) (p)
#define XESWAPF64LE(p) (p)
#endif
#define XEGETINT8BE(p) ( (int8_t)(*(p)))
#define XEGETUINT8BE(p) ( (uint8_t)(*(p)))
#define XEGETINT16BE(p) ( (int16_t)XESWAP16BE(*(uint16_t*)(p)))
#define XEGETUINT16BE(p) ((uint16_t)XESWAP16BE(*(uint16_t*)(p)))
#define XEGETUINT24BE(p) \
(((uint32_t)XEGETUINT8BE((p) + 0) << 16) | \
((uint32_t)XEGETUINT8BE((p) + 1) << 8) | \
(uint32_t)XEGETUINT8BE((p) + 2))
#define XEGETINT32BE(p) ( (int32_t)XESWAP32BE(*(uint32_t*)(p)))
#define XEGETUINT32BE(p) ((uint32_t)XESWAP32BE(*(uint32_t*)(p)))
#define XEGETINT64BE(p) ( (int64_t)XESWAP64BE(*(uint64_t*)(p)))
#define XEGETUINT64BE(p) ((uint64_t)XESWAP64BE(*(uint64_t*)(p)))
#define XEGETINT8LE(p) ( (int8_t)(*(p)))
#define XEGETUINT8LE(p) ( (uint8_t)(*(p)))
#define XEGETINT16LE(p) ( (int16_t)XESWAP16LE(*(uint16_t*)(p)))
#define XEGETUINT16LE(p) ((uint16_t)XESWAP16LE(*(uint16_t*)(p)))
#define XEGETUINT24LE(p) \
(((uint32_t)XEGETUINT8LE((p) + 2) << 16) | \
((uint32_t)XEGETUINT8LE((p) + 1) << 8) | \
(uint32_t)XEGETUINT8LE((p) + 0))
#define XEGETINT32LE(p) ( (int32_t)XESWAP32LE(*(uint32_t*)(p)))
#define XEGETUINT32LE(p) ((uint32_t)XESWAP32LE(*(uint32_t*)(p)))
#define XEGETINT64LE(p) ( (int64_t)XESWAP64LE(*(uint64_t*)(p)))
#define XEGETUINT64LE(p) ((uint64_t)XESWAP64LE(*(uint64_t*)(p)))
#define XESETINT8BE(p, v) (*( (int8_t*)(p)) = (int8_t)v)
#define XESETUINT8BE(p, v) (*( (uint8_t*)(p)) = (uint8_t)v)
#define XESETINT16BE(p, v) (*( (int16_t*)(p)) = XESWAP16BE( (int16_t)v))
#define XESETUINT16BE(p, v) (*((uint16_t*)(p)) = XESWAP16BE((uint16_t)v))
#define XESETINT32BE(p, v) (*( (int32_t*)(p)) = XESWAP32BE( (int32_t)v))
#define XESETUINT32BE(p, v) (*((uint32_t*)(p)) = XESWAP32BE((uint32_t)v))
#define XESETINT64BE(p, v) (*( (int64_t*)(p)) = XESWAP64BE( (int64_t)v))
#define XESETUINT64BE(p, v) (*((uint64_t*)(p)) = XESWAP64BE((uint64_t)v))
#define XESETINT8LE(p, v) (*( (int8_t*)(p)) = (int8_t)v)
#define XESETUINT8LE(p, v) (*( (uint8_t*)(p)) = (uint8_t)v)
#define XESETINT16LE(p, v) (*( (int16_t*)(p)) = (int16_t)v)
#define XESETUINT16LE(p, v) (*((uint16_t*)(p)) = (uint16_t)v)
#define XESETINT32LE(p, v) (*( (int32_t*)(p)) = (int32_t)v)
#define XESETUINT32LE(p, v) (*((uint32_t*)(p)) = (uint32_t)v)
#define XESETINT64LE(p, v) (*( (int64_t*)(p)) = (int64_t)v)
#define XESETUINT64LE(p, v) (*((uint64_t*)(p)) = (uint64_t)v)
#endif // XENIA_BYTE_ORDER_H_

View File

@ -12,8 +12,9 @@
#include <poly/assert.h>
#include <poly/atomic.h>
#include <poly/byte_order.h>
#include <poly/memory.h>
#include <xenia/byte_order.h>
#include <xenia/config.h>
#include <xenia/logging.h>
#include <xenia/malloc.h>

View File

@ -300,7 +300,7 @@ uint32_t xe_crc32(const void* data, size_t length, uint32_t previous_crc) {
const uint32_t* current = (const uint32_t*)data;
while (length >= 8) {
#if XE_CPU_BIGENDIAN
uint32_t one = *current++ ^ XESWAP32(crc);
uint32_t one = *current++ ^ poly::byte_swap(crc);
uint32_t two = *current++;
crc = xe_crc32_lookup_[0][ two & 0xFF] ^
xe_crc32_lookup_[1][(two>> 8) & 0xFF] ^

View File

@ -86,8 +86,8 @@ XEFORCEINLINE uint32_t UNALIGNED_LOAD32(const char *p) {
#endif
#if XE_CPU_BIGENDIAN
#define uint32_t_in_expected_order(x) (XESWAP32(x))
#define uint64_in_expected_order(x) (XESWAP64(x))
#define uint32_t_in_expected_order(x) (poly::byte_swap(x))
#define uint64_in_expected_order(x) (poly::byte_swap(x))
#else
#define uint32_t_in_expected_order(x) (x)
#define uint64_in_expected_order(x) (x)
@ -227,9 +227,9 @@ uint32_t CityHash32(const char *s, size_t len) {
h = Rotate32(h, 19);
h = h * 5 + 0xe6546b64;
g ^= a4;
g = XESWAP32(g) * 5;
g = poly::byte_swap(g) * 5;
h += a4 * 5;
h = XESWAP32(h);
h = poly::byte_swap(h);
f += a0;
PERMUTE3(f, h, g);
s += 20;
@ -346,11 +346,11 @@ static uint64_t HashLen33to64(const char *s, size_t len) {
uint64_t h = Fetch64(s + len - 16) * mul;
uint64_t u = Rotate(a + g, 43) + (Rotate(b, 30) + c) * 9;
uint64_t v = ((a + g) ^ d) + f + 1;
uint64_t w = XESWAP64((u + v) * mul) + h;
uint64_t w = poly::byte_swap((u + v) * mul) + h;
uint64_t x = Rotate(e + f, 42) + c;
uint64_t y = (XESWAP64((v + w) * mul) + g) * mul;
uint64_t y = (poly::byte_swap((v + w) * mul) + g) * mul;
uint64_t z = e + f + c;
a = XESWAP64((x + z) * mul + y) + b;
a = poly::byte_swap((x + z) * mul + y) + b;
b = ShiftMix((z + a) * mul + d + h) * mul;
return b + x;
}

View File

@ -144,7 +144,7 @@ uint64_t Processor::ExecuteInterrupt(
// Set 0x10C(r13) to the current CPU ID.
uint8_t* p = memory_->membase();
XESETUINT8BE(p + interrupt_thread_block_ + 0x10C, cpu);
poly::store_and_swap<uint8_t>(p + interrupt_thread_block_ + 0x10C, cpu);
// Execute interrupt.
uint64_t result = Execute(interrupt_thread_state_, address, args, arg_count);

View File

@ -180,13 +180,13 @@ LONG CALLBACK CheckMMIOHandler(PEXCEPTION_POINTERS ex_info) {
*reg_ptr = static_cast<uint8_t>(value);
break;
case 16:
*reg_ptr = XESWAP16(static_cast<uint16_t>(value));
*reg_ptr = poly::byte_swap(static_cast<uint16_t>(value));
break;
case 32:
*reg_ptr = XESWAP32(static_cast<uint32_t>(value));
*reg_ptr = poly::byte_swap(static_cast<uint32_t>(value));
break;
case 64:
*reg_ptr = XESWAP64(static_cast<uint64_t>(value));
*reg_ptr = poly::byte_swap(static_cast<uint64_t>(value));
break;
}
ex_info->ContextRecord->Rip += len;
@ -207,13 +207,13 @@ LONG CALLBACK CheckMMIOHandler(PEXCEPTION_POINTERS ex_info) {
value = static_cast<uint8_t>(value);
break;
case 16:
value = XESWAP16(static_cast<uint16_t>(value));
value = poly::byte_swap(static_cast<uint16_t>(value));
break;
case 32:
value = XESWAP32(static_cast<uint32_t>(value));
value = poly::byte_swap(static_cast<uint32_t>(value));
break;
case 64:
value = XESWAP64(static_cast<uint64_t>(value));
value = poly::byte_swap(static_cast<uint64_t>(value));
break;
}
range.write(range.context, address & 0xFFFFFFFF, value);

View File

@ -132,20 +132,20 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
if (kernel_export->type == KernelExport::Function) {
// Not exactly sure what this should be...
if (info->thunk_address) {
*slot = XESWAP32BE(info->thunk_address);
*slot = poly::byte_swap(info->thunk_address);
} else {
// TODO(benvanik): find out what import variables are.
XELOGW("kernel import variable not defined %.8X %s",
info->value_address, kernel_export->name);
*slot = XESWAP32BE(0xF00DF00D);
*slot = poly::byte_swap(0xF00DF00D);
}
} else {
if (kernel_export->is_implemented) {
// Implemented - replace with pointer.
XESETUINT32BE(slot, kernel_export->variable_ptr);
poly::store_and_swap<uint32_t>(slot, kernel_export->variable_ptr);
} else {
// Not implemented - write with a dummy value.
XESETUINT32BE(slot, 0xD000BEEF | (kernel_export->ordinal & 0xFFF) << 16);
poly::store_and_swap<uint32_t>(slot, 0xD000BEEF | (kernel_export->ordinal & 0xFFF) << 16);
XELOGCPU("WARNING: imported a variable with no value: %s",
kernel_export->name);
}
@ -175,10 +175,10 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
// nop
// nop
uint8_t* p = memory()->Translate(info->thunk_address);
XESETUINT32BE(p + 0x0, 0x44000002);
XESETUINT32BE(p + 0x4, 0x4E800020);
XESETUINT32BE(p + 0x8, 0x60000000);
XESETUINT32BE(p + 0xC, 0x60000000);
poly::store_and_swap<uint32_t>(p + 0x0, 0x44000002);
poly::store_and_swap<uint32_t>(p + 0x4, 0x4E800020);
poly::store_and_swap<uint32_t>(p + 0x8, 0x60000000);
poly::store_and_swap<uint32_t>(p + 0xC, 0x60000000);
FunctionInfo::ExternHandler handler = 0;
void* handler_data = 0;

View File

@ -118,7 +118,7 @@ void CommandProcessor::Pump() {
// TODO(benvanik): use read_ptr_update_freq_ and only issue after moving
// that many indices.
if (read_ptr_writeback_ptr_) {
XESETUINT32BE(p + read_ptr_writeback_ptr_, read_ptr_index_);
poly::store_and_swap<uint32_t>(p + read_ptr_writeback_ptr_, read_ptr_index_);
}
}
@ -174,7 +174,7 @@ void CommandProcessor::ExecuteIndirectBuffer(uint32_t ptr, uint32_t length) {
for (uint32_t __m = 0; __m < count; __m++) { \
XETRACECP("[%.8X] %.8X", \
packet_ptr + (1 + __m) * 4, \
XEGETUINT32BE(packet_base + 1 * 4 + __m * 4)); \
poly::load_and_swap<uint32_t>(packet_base + 1 * 4 + __m * 4)); \
}
void CommandProcessor::AdvancePtr(PacketArgs& args, uint32_t n) {
@ -186,9 +186,9 @@ void CommandProcessor::AdvancePtr(PacketArgs& args, uint32_t n) {
}
#define ADVANCE_PTR(n) AdvancePtr(args, n)
#define PEEK_PTR() \
XEGETUINT32BE(p + args.ptr)
poly::load_and_swap<uint32_t>(p + args.ptr)
#define READ_PTR() \
XEGETUINT32BE(p + args.ptr); ADVANCE_PTR(1);
poly::load_and_swap<uint32_t>(p + args.ptr); ADVANCE_PTR(1);
uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) {
uint8_t* p = memory_->membase();
@ -339,7 +339,7 @@ uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) {
// Memory.
XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(poll_reg_addr & 0x3);
poll_reg_addr &= ~0x3;
value = XEGETUINT32LE(p + GpuToCpu(packet_ptr, poll_reg_addr));
value = poly::load<uint32_t>(p + GpuToCpu(packet_ptr, poll_reg_addr));
value = GpuSwap(value, endianness);
} else {
// Register.
@ -434,7 +434,7 @@ uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) {
// Memory.
XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(poll_reg_addr & 0x3);
poll_reg_addr &= ~0x3;
value = XEGETUINT32LE(p + GpuToCpu(packet_ptr, poll_reg_addr));
value = poly::load<uint32_t>(p + GpuToCpu(packet_ptr, poll_reg_addr));
value = GpuSwap(value, endianness);
} else {
// Register.
@ -475,8 +475,8 @@ uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) {
XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(write_reg_addr & 0x3);
write_reg_addr &= ~0x3;
write_data = GpuSwap(write_data, endianness);
XESETUINT32LE(p + GpuToCpu(packet_ptr, write_reg_addr),
write_data);
poly::store(p + GpuToCpu(packet_ptr, write_reg_addr),
write_data);
} else {
// Register.
WriteRegister(packet_ptr, write_reg_addr, write_data);
@ -524,7 +524,7 @@ uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) {
XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(address & 0x3);
address &= ~0x3;
data_value = GpuSwap(data_value, endianness);
XESETUINT32LE(p + GpuToCpu(address), data_value);
poly::store(p + GpuToCpu(address), data_value);
}
break;
@ -637,7 +637,7 @@ uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) {
size &= 0xFFF;
index += 0x4000; // alu constants
for (uint32_t n = 0; n < size; n++, index++) {
uint32_t data = XEGETUINT32BE(
uint32_t data = poly::load_and_swap<uint32_t>(
p + GpuToCpu(packet_ptr, address + n * 4));
const char* reg_name = regs->GetRegisterName(index);
XETRACECP("[%.8X] %.8X -> %.4X %s",
@ -769,7 +769,7 @@ void CommandProcessor::WriteRegister(
uint8_t* p = memory_->membase();
uint32_t scratch_addr = regs->values[XE_GPU_REG_SCRATCH_ADDR].u32;
uint32_t mem_addr = scratch_addr + (scratch_reg * 4);
XESETUINT32BE(p + GpuToCpu(primary_buffer_ptr_, mem_addr), value);
poly::store_and_swap<uint32_t>(p + GpuToCpu(primary_buffer_ptr_, mem_addr), value);
}
}
}

View File

@ -69,7 +69,7 @@ int D3D11IndexBufferResource::InvalidateRegion(
memory_range_.host_base);
uint32_t* dest = reinterpret_cast<uint32_t*>(res.pData);
for (uint32_t n = 0; n < index_count; n++) {
dest[n] = XESWAP32(src[n]);
dest[n] = poly::byte_swap(src[n]);
}
} else {
uint32_t index_count = memory_range_.length / 2;
@ -77,7 +77,7 @@ int D3D11IndexBufferResource::InvalidateRegion(
memory_range_.host_base);
uint16_t* dest = reinterpret_cast<uint16_t*>(res.pData);
for (uint32_t n = 0; n < index_count; n++) {
dest[n] = XESWAP16(src[n]);
dest[n] = poly::byte_swap(src[n]);
}
}
resource_cache_->context()->Unmap(handle_, 0);
@ -138,7 +138,7 @@ int D3D11VertexBufferResource::InvalidateRegion(
uint32_t o = 0;
for (uint32_t i = 0; i < count; i++) {
for (uint32_t j = 0; j < el.size_words; j++) {
dest_ptr[o + j] = XESWAP32(src_ptr[o + j]);
dest_ptr[o + j] = poly::byte_swap(src_ptr[o + j]);
}
o += stride;
}

View File

@ -35,7 +35,7 @@ ShaderResource::ShaderResource(const MemoryRange& memory_range,
size_t byte_size = dword_count_ * sizeof(uint32_t);
dwords_ = (uint32_t*)xe_malloc(byte_size);
for (uint32_t n = 0; n < dword_count_; n++) {
dwords_[n] = XEGETUINT32BE(memory_range.host_base + n * 4);
dwords_[n] = poly::load_and_swap<uint32_t>(memory_range.host_base + n * 4);
}
// Disassemble, for debugging.

View File

@ -307,12 +307,12 @@ void TextureResource::TextureSwap(uint8_t* dest, const uint8_t* src,
switch (info_.endianness) {
case XE_GPU_ENDIAN_8IN16:
for (uint32_t i = 0; i < pitch; i += 2, src += 2, dest += 2) {
*(uint16_t*)dest = XESWAP16(*(uint16_t*)src);
*(uint16_t*)dest = poly::byte_swap(*(uint16_t*)src);
}
break;
case XE_GPU_ENDIAN_8IN32: // Swap bytes.
for (uint32_t i = 0; i < pitch; i += 4, src += 4, dest += 4) {
*(uint32_t*)dest = XESWAP32(*(uint32_t*)src);
*(uint32_t*)dest = poly::byte_swap(*(uint32_t*)src);
}
break;
case XE_GPU_ENDIAN_16IN32: // Swap half words.

View File

@ -83,7 +83,7 @@ XEFORCEINLINE uint32_t GpuSwap(uint32_t value, XE_GPU_ENDIAN endianness) {
((value >> 8) & 0x00FF00FF);
case XE_GPU_ENDIAN_8IN32: // Swap bytes.
// NOTE: we are likely doing two swaps here. Wasteful. Oh well.
return XESWAP32(value);
return poly::byte_swap(value);
case XE_GPU_ENDIAN_16IN32: // Swap half words.
return ((value >> 16) & 0xFFFF) | (value << 16);
}

View File

@ -122,8 +122,8 @@ GDFX::Error GDFX::Verify(ParseState& state) {
return kErrorReadError;
}
uint8_t* fs_ptr = state.ptr + state.game_offset + (32 * kXESectorSize);
state.root_sector = XEGETUINT32LE(fs_ptr + 20);
state.root_size = XEGETUINT32LE(fs_ptr + 24);
state.root_sector = poly::load<uint32_t>(fs_ptr + 20);
state.root_size = poly::load<uint32_t>(fs_ptr + 24);
state.root_offset = state.game_offset + (state.root_sector * kXESectorSize);
if (state.root_size < 13 ||
state.root_size > 32 * 1024 * 1024) {
@ -157,12 +157,12 @@ bool GDFX::ReadEntry(ParseState& state, const uint8_t* buffer,
uint16_t entry_ordinal, GDFXEntry* parent) {
const uint8_t* p = buffer + (entry_ordinal * 4);
uint16_t node_l = XEGETUINT16LE(p + 0);
uint16_t node_r = XEGETUINT16LE(p + 2);
size_t sector = XEGETUINT32LE(p + 4);
size_t length = XEGETUINT32LE(p + 8);
uint8_t attributes = XEGETUINT8LE(p + 12);
uint8_t name_length = XEGETUINT8LE(p + 13);
uint16_t node_l = poly::load<uint16_t>(p + 0);
uint16_t node_r = poly::load<uint16_t>(p + 2);
size_t sector = poly::load<uint32_t>(p + 4);
size_t length = poly::load<uint32_t>(p + 8);
uint8_t attributes = poly::load<uint8_t>(p + 12);
uint8_t name_length = poly::load<uint8_t>(p + 13);
char* name = (char*)(p + 14);
if (node_l && !ReadEntry(state, buffer, node_l, parent)) {

View File

@ -16,21 +16,29 @@ using namespace xe;
using namespace xe::kernel;
using namespace xe::kernel::fs;
#define XEGETUINT24BE(p) \
(((uint32_t)poly::load_and_swap<uint8_t>((p) + 0) << 16) | \
((uint32_t)poly::load_and_swap<uint8_t>((p) + 1) << 8) | \
(uint32_t)poly::load_and_swap<uint8_t>((p) + 2))
#define XEGETUINT24LE(p) \
(((uint32_t)poly::load<uint8_t>((p) + 2) << 16) | \
((uint32_t)poly::load<uint8_t>((p) + 1) << 8) | \
(uint32_t)poly::load<uint8_t>((p) + 0))
bool STFSVolumeDescriptor::Read(const uint8_t* p) {
descriptor_size = XEGETUINT8BE(p + 0x00);
descriptor_size = poly::load_and_swap<uint8_t>(p + 0x00);
if (descriptor_size != 0x24) {
XELOGE("STFS volume descriptor size mismatch, expected 0x24 but got 0x%X",
descriptor_size);
return false;
}
reserved = XEGETUINT8BE(p + 0x01);
block_separation = XEGETUINT8BE(p + 0x02);
file_table_block_count = XEGETUINT16BE(p + 0x03);
reserved = poly::load_and_swap<uint8_t>(p + 0x01);
block_separation = poly::load_and_swap<uint8_t>(p + 0x02);
file_table_block_count = poly::load_and_swap<uint16_t>(p + 0x03);
file_table_block_number = XEGETUINT24BE(p + 0x05);
xe_copy_struct(top_hash_table_hash, p + 0x08, 0x14);
total_allocated_block_count = XEGETUINT32BE(p + 0x1C);
total_unallocated_block_count = XEGETUINT32BE(p + 0x20);
total_allocated_block_count = poly::load_and_swap<uint32_t>(p + 0x1C);
total_unallocated_block_count = poly::load_and_swap<uint32_t>(p + 0x20);
return true;
};
@ -38,29 +46,29 @@ bool STFSVolumeDescriptor::Read(const uint8_t* p) {
bool STFSHeader::Read(const uint8_t* p) {
xe_copy_struct(license_entries, p + 0x22C, 0x100);
xe_copy_struct(header_hash, p + 0x32C, 0x14);
header_size = XEGETUINT32BE(p + 0x340);
content_type = (STFSContentType)XEGETUINT32BE(p + 0x344);
metadata_version = XEGETUINT32BE(p + 0x348);
header_size = poly::load_and_swap<uint32_t>(p + 0x340);
content_type = (STFSContentType)poly::load_and_swap<uint32_t>(p + 0x344);
metadata_version = poly::load_and_swap<uint32_t>(p + 0x348);
if (metadata_version > 1) {
// This is a variant of thumbnail data/etc.
// Can just ignore it for now (until we parse thumbnails).
XELOGW("STFSContainer doesn't support version %d yet", metadata_version);
}
content_size = XEGETUINT32BE(p + 0x34C);
media_id = XEGETUINT32BE(p + 0x354);
version = XEGETUINT32BE(p + 0x358);
base_version = XEGETUINT32BE(p + 0x35C);
title_id = XEGETUINT32BE(p + 0x360);
platform = (STFSPlatform)XEGETUINT8BE(p + 0x364);
executable_type = XEGETUINT8BE(p + 0x365);
disc_number = XEGETUINT8BE(p + 0x366);
disc_in_set = XEGETUINT8BE(p + 0x367);
save_game_id = XEGETUINT32BE(p + 0x368);
content_size = poly::load_and_swap<uint32_t>(p + 0x34C);
media_id = poly::load_and_swap<uint32_t>(p + 0x354);
version = poly::load_and_swap<uint32_t>(p + 0x358);
base_version = poly::load_and_swap<uint32_t>(p + 0x35C);
title_id = poly::load_and_swap<uint32_t>(p + 0x360);
platform = (STFSPlatform)poly::load_and_swap<uint8_t>(p + 0x364);
executable_type = poly::load_and_swap<uint8_t>(p + 0x365);
disc_number = poly::load_and_swap<uint8_t>(p + 0x366);
disc_in_set = poly::load_and_swap<uint8_t>(p + 0x367);
save_game_id = poly::load_and_swap<uint32_t>(p + 0x368);
xe_copy_struct(console_id, p + 0x36C, 0x5);
xe_copy_struct(profile_id, p + 0x371, 0x8);
data_file_count = XEGETUINT32BE(p + 0x39D);
data_file_combined_size = XEGETUINT64BE(p + 0x3A1);
descriptor_type = (STFSDescriptorType)XEGETUINT8BE(p + 0x3A9);
data_file_count = poly::load_and_swap<uint32_t>(p + 0x39D);
data_file_combined_size = poly::load_and_swap<uint64_t>(p + 0x3A1);
descriptor_type = (STFSDescriptorType)poly::load_and_swap<uint8_t>(p + 0x3A9);
if (descriptor_type != STFS_DESCRIPTOR_STFS) {
XELOGE("STFS descriptor format not supported: %d", descriptor_type);
return false;
@ -70,16 +78,16 @@ bool STFSHeader::Read(const uint8_t* p) {
}
xe_copy_struct(device_id, p + 0x3FD, 0x14);
for (size_t n = 0; n < 0x900 / 2; n++) {
display_names[n] = XEGETUINT16BE(p + 0x411 + n * 2);
display_descs[n] = XEGETUINT16BE(p + 0xD11 + n * 2);
display_names[n] = poly::load_and_swap<uint16_t>(p + 0x411 + n * 2);
display_descs[n] = poly::load_and_swap<uint16_t>(p + 0xD11 + n * 2);
}
for (size_t n = 0; n < 0x80 / 2; n++) {
publisher_name[n] = XEGETUINT16BE(p + 0x1611 + n * 2);
title_name[n] = XEGETUINT16BE(p + 0x1691 + n * 2);
publisher_name[n] = poly::load_and_swap<uint16_t>(p + 0x1611 + n * 2);
title_name[n] = poly::load_and_swap<uint16_t>(p + 0x1691 + n * 2);
}
transfer_flags = XEGETUINT8BE(p + 0x1711);
thumbnail_image_size = XEGETUINT32BE(p + 0x1712);
title_thumbnail_image_size = XEGETUINT32BE(p + 0x1716);
transfer_flags = poly::load_and_swap<uint8_t>(p + 0x1711);
thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1712);
title_thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1716);
xe_copy_struct(thumbnail_image, p + 0x171A, 0x4000);
xe_copy_struct(title_thumbnail_image, p + 0x571A, 0x4000);
return true;
@ -203,13 +211,13 @@ STFS::Error STFS::ReadAllEntries(const uint8_t* map_ptr) {
// Done.
break;
}
uint8_t filename_length_flags = XEGETUINT8BE(p + 0x28);
uint8_t filename_length_flags = poly::load_and_swap<uint8_t>(p + 0x28);
uint32_t allocated_block_count = XEGETUINT24LE(p + 0x29);
uint32_t start_block_index = XEGETUINT24LE(p + 0x2F);
uint16_t path_indicator = XEGETUINT16BE(p + 0x32);
uint32_t file_size = XEGETUINT32BE(p + 0x34);
uint32_t update_timestamp = XEGETUINT32BE(p + 0x38);
uint32_t access_timestamp = XEGETUINT32BE(p + 0x3C);
uint16_t path_indicator = poly::load_and_swap<uint16_t>(p + 0x32);
uint32_t file_size = poly::load_and_swap<uint32_t>(p + 0x34);
uint32_t update_timestamp = poly::load_and_swap<uint32_t>(p + 0x38);
uint32_t access_timestamp = poly::load_and_swap<uint32_t>(p + 0x3C);
p += 0x40;
STFSEntry* entry = new STFSEntry();
@ -337,7 +345,7 @@ STFS::BlockHash_t STFS::GetBlockHash(
//table_index += table_offset - (1 << table_size_shift_);
const uint8_t* hash_data = map_ptr + BlockToOffset(table_index);
const uint8_t* record_data = hash_data + record * 0x18;
uint32_t info = XEGETUINT8BE(record_data + 0x14);
uint32_t info = poly::load_and_swap<uint8_t>(record_data + 0x14);
uint32_t next_block_index = XEGETUINT24BE(record_data + 0x15);
return{ next_block_index, info };
}

View File

@ -21,40 +21,40 @@ NativeList::NativeList(Memory* memory) :
void NativeList::Insert(uint32_t ptr) {
uint8_t* mem = memory_->membase();
XESETUINT32BE(mem + ptr + 0, head_);
XESETUINT32BE(mem + ptr + 4, 0);
poly::store_and_swap<uint32_t>(mem + ptr + 0, head_);
poly::store_and_swap<uint32_t>(mem + ptr + 4, 0);
if (head_) {
XESETUINT32BE(mem + head_ + 4, ptr);
poly::store_and_swap<uint32_t>(mem + head_ + 4, ptr);
}
head_ = ptr;
}
bool NativeList::IsQueued(uint32_t ptr) {
uint8_t* mem = memory_->membase();
uint32_t flink = XEGETUINT32BE(mem + ptr + 0);
uint32_t blink = XEGETUINT32BE(mem + ptr + 4);
uint32_t flink = poly::load_and_swap<uint32_t>(mem + ptr + 0);
uint32_t blink = poly::load_and_swap<uint32_t>(mem + ptr + 4);
return head_ == ptr || flink || blink;
}
void NativeList::Remove(uint32_t ptr) {
uint8_t* mem = memory_->membase();
uint32_t flink = XEGETUINT32BE(mem + ptr + 0);
uint32_t blink = XEGETUINT32BE(mem + ptr + 4);
uint32_t flink = poly::load_and_swap<uint32_t>(mem + ptr + 0);
uint32_t blink = poly::load_and_swap<uint32_t>(mem + ptr + 4);
if (ptr == head_) {
head_ = flink;
if (flink) {
XESETUINT32BE(mem + flink + 4, 0);
poly::store_and_swap<uint32_t>(mem + flink + 4, 0);
}
} else {
if (blink) {
XESETUINT32BE(mem + blink + 0, flink);
poly::store_and_swap<uint32_t>(mem + blink + 0, flink);
}
if (flink) {
XESETUINT32BE(mem + flink + 4, blink);
poly::store_and_swap<uint32_t>(mem + flink + 4, blink);
}
}
XESETUINT32BE(mem + ptr + 0, 0);
XESETUINT32BE(mem + ptr + 4, 0);
poly::store_and_swap<uint32_t>(mem + ptr + 0, 0);
poly::store_and_swap<uint32_t>(mem + ptr + 4, 0);
}
uint32_t NativeList::Shift() {

View File

@ -33,14 +33,14 @@ public:
X_FILE_ATTRIBUTES attributes;
void Write(uint8_t* base, uint32_t p) {
XESETUINT64BE(base + p, creation_time);
XESETUINT64BE(base + p + 8, last_access_time);
XESETUINT64BE(base + p + 16, last_write_time);
XESETUINT64BE(base + p + 24, change_time);
XESETUINT64BE(base + p + 32, allocation_size);
XESETUINT64BE(base + p + 40, file_length);
XESETUINT32BE(base + p + 48, attributes);
XESETUINT32BE(base + p + 52, 0); // pad
poly::store_and_swap<uint64_t>(base + p, creation_time);
poly::store_and_swap<uint64_t>(base + p + 8, last_access_time);
poly::store_and_swap<uint64_t>(base + p + 16, last_write_time);
poly::store_and_swap<uint64_t>(base + p + 24, change_time);
poly::store_and_swap<uint64_t>(base + p + 32, allocation_size);
poly::store_and_swap<uint64_t>(base + p + 40, file_length);
poly::store_and_swap<uint32_t>(base + p + 48, attributes);
poly::store_and_swap<uint32_t>(base + p + 52, 0); // pad
}
};
@ -65,16 +65,16 @@ public:
XDirectoryInfo* info;
do {
info = (XDirectoryInfo*)src;
XESETUINT32BE(dst, info->next_entry_offset);
XESETUINT32BE(dst + 4, info->file_index);
XESETUINT64BE(dst + 8, info->creation_time);
XESETUINT64BE(dst + 16, info->last_access_time);
XESETUINT64BE(dst + 24, info->last_write_time);
XESETUINT64BE(dst + 32, info->change_time);
XESETUINT64BE(dst + 40, info->end_of_file);
XESETUINT64BE(dst + 48, info->allocation_size);
XESETUINT32BE(dst + 56, info->attributes);
XESETUINT32BE(dst + 60, info->file_name_length);
poly::store_and_swap<uint32_t>(dst, info->next_entry_offset);
poly::store_and_swap<uint32_t>(dst + 4, info->file_index);
poly::store_and_swap<uint64_t>(dst + 8, info->creation_time);
poly::store_and_swap<uint64_t>(dst + 16, info->last_access_time);
poly::store_and_swap<uint64_t>(dst + 24, info->last_write_time);
poly::store_and_swap<uint64_t>(dst + 32, info->change_time);
poly::store_and_swap<uint64_t>(dst + 40, info->end_of_file);
poly::store_and_swap<uint64_t>(dst + 48, info->allocation_size);
poly::store_and_swap<uint32_t>(dst + 56, info->attributes);
poly::store_and_swap<uint32_t>(dst + 60, info->file_name_length);
xe_copy_memory(dst + 64, info->file_name_length, info->file_name, info->file_name_length);
dst += info->next_entry_offset;
src += info->next_entry_offset;
@ -95,10 +95,10 @@ public:
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
XESETUINT64BE(dst + 0, this->creation_time);
XESETUINT32BE(dst + 8, this->serial_number);
XESETUINT32BE(dst + 12, this->label_length);
XESETUINT32BE(dst + 16, this->supports_objects);
poly::store_and_swap<uint64_t>(dst + 0, this->creation_time);
poly::store_and_swap<uint32_t>(dst + 8, this->serial_number);
poly::store_and_swap<uint32_t>(dst + 12, this->label_length);
poly::store_and_swap<uint32_t>(dst + 16, this->supports_objects);
xe_copy_memory(dst + 20, this->label_length, this->label, this->label_length);
}
};
@ -115,9 +115,9 @@ public:
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
XESETUINT32BE(dst + 0, this->attributes);
XESETUINT32BE(dst + 4, this->maximum_component_name_length);
XESETUINT32BE(dst + 8, this->fs_name_length);
poly::store_and_swap<uint32_t>(dst + 0, this->attributes);
poly::store_and_swap<uint32_t>(dst + 4, this->maximum_component_name_length);
poly::store_and_swap<uint32_t>(dst + 8, this->fs_name_length);
xe_copy_memory(dst + 12, this->fs_name_length, this->fs_name, this->fs_name_length);
}
};

View File

@ -120,7 +120,7 @@ uint32_t XThread::GetCurrentThreadHandle() {
}
uint32_t XThread::GetCurrentThreadId(const uint8_t* thread_state_block) {
return XEGETUINT32BE(thread_state_block + 0x14C);
return poly::load_and_swap<uint32_t>(thread_state_block + 0x14C);
}
uint32_t XThread::thread_state() {
@ -133,12 +133,12 @@ uint32_t XThread::thread_id() {
uint32_t XThread::last_error() {
uint8_t *p = memory()->Translate(thread_state_address_);
return XEGETUINT32BE(p + 0x160);
return poly::load_and_swap<uint32_t>(p + 0x160);
}
void XThread::set_last_error(uint32_t error_code) {
uint8_t *p = memory()->Translate(thread_state_address_);
XESETUINT32BE(p + 0x160, error_code);
poly::store_and_swap<uint32_t>(p + 0x160, error_code);
}
void XThread::set_name(const char* name) {
@ -221,11 +221,11 @@ X_STATUS XThread::Create() {
// Setup the thread state block (last error/etc).
uint8_t *p = memory()->Translate(thread_state_address_);
XESETUINT32BE(p + 0x000, tls_address_);
XESETUINT32BE(p + 0x100, thread_state_address_);
XESETUINT32BE(p + 0x14C, thread_id_);
XESETUINT32BE(p + 0x150, 0); // ?
XESETUINT32BE(p + 0x160, 0); // last error
poly::store_and_swap<uint32_t>(p + 0x000, tls_address_);
poly::store_and_swap<uint32_t>(p + 0x100, thread_state_address_);
poly::store_and_swap<uint32_t>(p + 0x14C, thread_id_);
poly::store_and_swap<uint32_t>(p + 0x150, 0); // ?
poly::store_and_swap<uint32_t>(p + 0x160, 0); // last error
// Allocate processor thread state.
// This is thread safe.
@ -440,25 +440,25 @@ void XThread::DeliverAPCs(void* data) {
// Calling the routine may delete the memory/overwrite it.
uint32_t apc_address = apc_list->Shift() - 8;
uint8_t* apc_ptr = membase + apc_address;
uint32_t kernel_routine = XEGETUINT32BE(apc_ptr + 16);
uint32_t normal_routine = XEGETUINT32BE(apc_ptr + 24);
uint32_t normal_context = XEGETUINT32BE(apc_ptr + 28);
uint32_t system_arg1 = XEGETUINT32BE(apc_ptr + 32);
uint32_t system_arg2 = XEGETUINT32BE(apc_ptr + 36);
uint32_t kernel_routine = poly::load_and_swap<uint32_t>(apc_ptr + 16);
uint32_t normal_routine = poly::load_and_swap<uint32_t>(apc_ptr + 24);
uint32_t normal_context = poly::load_and_swap<uint32_t>(apc_ptr + 28);
uint32_t system_arg1 = poly::load_and_swap<uint32_t>(apc_ptr + 32);
uint32_t system_arg2 = poly::load_and_swap<uint32_t>(apc_ptr + 36);
// Mark as uninserted so that it can be reinserted again by the routine.
uint32_t old_flags = XEGETUINT32BE(apc_ptr + 40);
XESETUINT32BE(apc_ptr + 40, old_flags & ~0xFF00);
uint32_t old_flags = poly::load_and_swap<uint32_t>(apc_ptr + 40);
poly::store_and_swap<uint32_t>(apc_ptr + 40, old_flags & ~0xFF00);
// Call kernel routine.
// The routine can modify all of its arguments before passing it on.
// Since we need to give guest accessible pointers over, we copy things
// into and out of scratch.
uint8_t* scratch_ptr = membase + thread->scratch_address_;
XESETUINT32BE(scratch_ptr + 0, normal_routine);
XESETUINT32BE(scratch_ptr + 4, normal_context);
XESETUINT32BE(scratch_ptr + 8, system_arg1);
XESETUINT32BE(scratch_ptr + 12, system_arg2);
poly::store_and_swap<uint32_t>(scratch_ptr + 0, normal_routine);
poly::store_and_swap<uint32_t>(scratch_ptr + 4, normal_context);
poly::store_and_swap<uint32_t>(scratch_ptr + 8, system_arg1);
poly::store_and_swap<uint32_t>(scratch_ptr + 12, system_arg2);
// kernel_routine(apc_address, &normal_routine, &normal_context, &system_arg1, &system_arg2)
uint64_t kernel_args[] = {
apc_address,
@ -469,10 +469,10 @@ void XThread::DeliverAPCs(void* data) {
};
processor->ExecuteInterrupt(
0, kernel_routine, kernel_args, XECOUNT(kernel_args));
normal_routine = XEGETUINT32BE(scratch_ptr + 0);
normal_context = XEGETUINT32BE(scratch_ptr + 4);
system_arg1 = XEGETUINT32BE(scratch_ptr + 8);
system_arg2 = XEGETUINT32BE(scratch_ptr + 12);
normal_routine = poly::load_and_swap<uint32_t>(scratch_ptr + 0);
normal_context = poly::load_and_swap<uint32_t>(scratch_ptr + 4);
system_arg1 = poly::load_and_swap<uint32_t>(scratch_ptr + 8);
system_arg2 = poly::load_and_swap<uint32_t>(scratch_ptr + 12);
// Call the normal routine. Note that it may have been killed by the kernel
// routine.
@ -496,11 +496,11 @@ void XThread::RundownAPCs() {
// Calling the routine may delete the memory/overwrite it.
uint32_t apc_address = apc_list_->Shift() - 8;
uint8_t* apc_ptr = membase + apc_address;
uint32_t rundown_routine = XEGETUINT32BE(apc_ptr + 20);
uint32_t rundown_routine = poly::load_and_swap<uint32_t>(apc_ptr + 20);
// Mark as uninserted so that it can be reinserted again by the routine.
uint32_t old_flags = XEGETUINT32BE(apc_ptr + 40);
XESETUINT32BE(apc_ptr + 40, old_flags & ~0xFF00);
uint32_t old_flags = poly::load_and_swap<uint32_t>(apc_ptr + 40);
poly::store_and_swap<uint32_t>(apc_ptr + 40, old_flags & ~0xFF00);
// Call the rundown routine.
if (rundown_routine) {

View File

@ -35,15 +35,15 @@ using PPCContext = alloy::frontend::ppc::PPCContext;
#define SHIM_MEM_ADDR(a) (a ? (ppc_state->membase + a) : NULL)
#define SHIM_MEM_8(a) (*(uint8_t*)SHIM_MEM_ADDR(a))
#define SHIM_MEM_16(a) (uint16_t)XEGETUINT16BE(SHIM_MEM_ADDR(a))
#define SHIM_MEM_32(a) (uint32_t)XEGETUINT32BE(SHIM_MEM_ADDR(a))
#define SHIM_MEM_64(a) (uint64_t)XEGETUINT64BE(SHIM_MEM_ADDR(a))
#define SHIM_MEM_16(a) (uint16_t)poly::load_and_swap<uint16_t>(SHIM_MEM_ADDR(a))
#define SHIM_MEM_32(a) (uint32_t)poly::load_and_swap<uint32_t>(SHIM_MEM_ADDR(a))
#define SHIM_MEM_64(a) (uint64_t)poly::load_and_swap<uint64_t>(SHIM_MEM_ADDR(a))
#define SHIM_SET_MEM_8(a, v) (*(uint8_t*)SHIM_MEM_ADDR(a)) = v
#define SHIM_SET_MEM_16(a, v) (*(uint16_t*)SHIM_MEM_ADDR(a)) = XESWAP16(v)
#define SHIM_SET_MEM_32(a, v) (*(uint32_t*)SHIM_MEM_ADDR(a)) = XESWAP32(v)
#define SHIM_SET_MEM_64(a, v) (*(uint64_t*)SHIM_MEM_ADDR(a)) = XESWAP64(v)
#define SHIM_SET_MEM_F32(a, v) (*(float*)SHIM_MEM_ADDR(a)) = XESWAPF32BE(v)
#define SHIM_SET_MEM_F64(a, v) (*(double*)SHIM_MEM_ADDR(a)) = XESWAPF64BE(v)
#define SHIM_SET_MEM_16(a, v) (*(uint16_t*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_32(a, v) (*(uint32_t*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_64(a, v) (*(uint64_t*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_F32(a, v) (*(float*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_F64(a, v) (*(double*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_GPR_8(n) (uint8_t)(ppc_state->r[n])
#define SHIM_GPR_16(n) (uint16_t)(ppc_state->r[n])
@ -63,11 +63,11 @@ using PPCContext = alloy::frontend::ppc::PPCContext;
#define IMPL_MEM_ADDR(a) (a ? state->memory()->Translate(a) : NULL)
#define IMPL_MEM_8(a) (*(uint8_t*)(IMPL_MEM_ADDR(a)))
#define IMPL_MEM_16(a) (uint16_t)XEGETUINT16BE(IMPL_MEM_ADDR(a))
#define IMPL_MEM_32(a) (uint32_t)XEGETUINT32BE(IMPL_MEM_ADDR(a))
#define IMPL_MEM_16(a) (uint16_t)poly::load_and_swap<uint16_t>(IMPL_MEM_ADDR(a))
#define IMPL_MEM_32(a) (uint32_t)poly::load_and_swap<uint32_t>(IMPL_MEM_ADDR(a))
#define IMPL_SET_MEM_8(a, v) (*(uint8_t*)IMPL_MEM_ADDR(a)) = v
#define IMPL_SET_MEM_16(a, v) (*(uint16_t*)IMPL_MEM_ADDR(a)) = XESWAP16(v)
#define IMPL_SET_MEM_32(a, v) (*(uint32_t*)IMPL_MEM_ADDR(a)) = XESWAP32(v)
#define IMPL_SET_MEM_16(a, v) (*(uint16_t*)IMPL_MEM_ADDR(a)) = poly::byte_swap(v)
#define IMPL_SET_MEM_32(a, v) (*(uint32_t*)IMPL_MEM_ADDR(a)) = poly::byte_swap(v)
} // namespace kernel

View File

@ -125,21 +125,21 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
const uint8_t *ps;
xe_xex2_loader_info_t *ldr;
header->xex2 = XEGETUINT32BE(p + 0x00);
header->xex2 = poly::load_and_swap<uint32_t>(p + 0x00);
if (header->xex2 != 0x58455832) {
return 1;
}
header->module_flags = (xe_xex2_module_flags)XEGETUINT32BE(p + 0x04);
header->exe_offset = XEGETUINT32BE(p + 0x08);
header->unknown0 = XEGETUINT32BE(p + 0x0C);
header->certificate_offset = XEGETUINT32BE(p + 0x10);
header->header_count = XEGETUINT32BE(p + 0x14);
header->module_flags = (xe_xex2_module_flags)poly::load_and_swap<uint32_t>(p + 0x04);
header->exe_offset = poly::load_and_swap<uint32_t>(p + 0x08);
header->unknown0 = poly::load_and_swap<uint32_t>(p + 0x0C);
header->certificate_offset = poly::load_and_swap<uint32_t>(p + 0x10);
header->header_count = poly::load_and_swap<uint32_t>(p + 0x14);
for (size_t n = 0; n < header->header_count; n++) {
const uint8_t *ph = p + 0x18 + (n * 8);
const uint32_t key = XEGETUINT32BE(ph + 0x00);
const uint32_t data_offset = XEGETUINT32BE(ph + 0x04);
const uint32_t key = poly::load_and_swap<uint32_t>(ph + 0x00);
const uint32_t data_offset = poly::load_and_swap<uint32_t>(ph + 0x04);
xe_xex2_opt_header_t *opt_header = &header->headers[n];
opt_header->key = key;
@ -151,7 +151,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
break;
case 0xFF:
// dataOffset = offset (first dword in data is size)
opt_header->length = XEGETUINT32BE(p + data_offset);
opt_header->length = poly::load_and_swap<uint32_t>(p + data_offset);
opt_header->offset = data_offset;
break;
default:
@ -176,8 +176,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
auto& res = header->resource_infos[n];
XEEXPECTZERO(xe_copy_memory(res.name,
sizeof(res.name), ph + 0x00, 8));
res.address = XEGETUINT32BE(ph + 0x08);
res.size = XEGETUINT32BE(ph + 0x0C);
res.address = poly::load_and_swap<uint32_t>(ph + 0x08);
res.size = poly::load_and_swap<uint32_t>(ph + 0x0C);
ph += 16;
}
}
@ -185,41 +185,41 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
case XEX_HEADER_EXECUTION_INFO:
{
xe_xex2_execution_info_t *ex = &header->execution_info;
ex->media_id = XEGETUINT32BE(pp + 0x00);
ex->version.value = XEGETUINT32BE(pp + 0x04);
ex->base_version.value = XEGETUINT32BE(pp + 0x08);
ex->title_id = XEGETUINT32BE(pp + 0x0C);
ex->platform = XEGETUINT8BE(pp + 0x10);
ex->executable_table = XEGETUINT8BE(pp + 0x11);
ex->disc_number = XEGETUINT8BE(pp + 0x12);
ex->disc_count = XEGETUINT8BE(pp + 0x13);
ex->savegame_id = XEGETUINT32BE(pp + 0x14);
ex->media_id = poly::load_and_swap<uint32_t>(pp + 0x00);
ex->version.value = poly::load_and_swap<uint32_t>(pp + 0x04);
ex->base_version.value = poly::load_and_swap<uint32_t>(pp + 0x08);
ex->title_id = poly::load_and_swap<uint32_t>(pp + 0x0C);
ex->platform = poly::load_and_swap<uint8_t>(pp + 0x10);
ex->executable_table = poly::load_and_swap<uint8_t>(pp + 0x11);
ex->disc_number = poly::load_and_swap<uint8_t>(pp + 0x12);
ex->disc_count = poly::load_and_swap<uint8_t>(pp + 0x13);
ex->savegame_id = poly::load_and_swap<uint32_t>(pp + 0x14);
}
break;
case XEX_HEADER_GAME_RATINGS:
{
xe_xex2_game_ratings_t *ratings = &header->game_ratings;
ratings->esrb = (xe_xex2_rating_esrb_value)XEGETUINT8BE(pp + 0x00);
ratings->pegi = (xe_xex2_rating_pegi_value)XEGETUINT8BE(pp + 0x01);
ratings->pegifi = (xe_xex2_rating_pegi_fi_value)XEGETUINT8BE(pp + 0x02);
ratings->pegipt = (xe_xex2_rating_pegi_pt_value)XEGETUINT8BE(pp + 0x03);
ratings->bbfc = (xe_xex2_rating_bbfc_value)XEGETUINT8BE(pp + 0x04);
ratings->cero = (xe_xex2_rating_cero_value)XEGETUINT8BE(pp + 0x05);
ratings->usk = (xe_xex2_rating_usk_value)XEGETUINT8BE(pp + 0x06);
ratings->oflcau = (xe_xex2_rating_oflc_au_value)XEGETUINT8BE(pp + 0x07);
ratings->oflcnz = (xe_xex2_rating_oflc_nz_value)XEGETUINT8BE(pp + 0x08);
ratings->kmrb = (xe_xex2_rating_kmrb_value)XEGETUINT8BE(pp + 0x09);
ratings->brazil = (xe_xex2_rating_brazil_value)XEGETUINT8BE(pp + 0x0A);
ratings->fpb = (xe_xex2_rating_fpb_value)XEGETUINT8BE(pp + 0x0B);
ratings->esrb = (xe_xex2_rating_esrb_value)poly::load_and_swap<uint8_t>(pp + 0x00);
ratings->pegi = (xe_xex2_rating_pegi_value)poly::load_and_swap<uint8_t>(pp + 0x01);
ratings->pegifi = (xe_xex2_rating_pegi_fi_value)poly::load_and_swap<uint8_t>(pp + 0x02);
ratings->pegipt = (xe_xex2_rating_pegi_pt_value)poly::load_and_swap<uint8_t>(pp + 0x03);
ratings->bbfc = (xe_xex2_rating_bbfc_value)poly::load_and_swap<uint8_t>(pp + 0x04);
ratings->cero = (xe_xex2_rating_cero_value)poly::load_and_swap<uint8_t>(pp + 0x05);
ratings->usk = (xe_xex2_rating_usk_value)poly::load_and_swap<uint8_t>(pp + 0x06);
ratings->oflcau = (xe_xex2_rating_oflc_au_value)poly::load_and_swap<uint8_t>(pp + 0x07);
ratings->oflcnz = (xe_xex2_rating_oflc_nz_value)poly::load_and_swap<uint8_t>(pp + 0x08);
ratings->kmrb = (xe_xex2_rating_kmrb_value)poly::load_and_swap<uint8_t>(pp + 0x09);
ratings->brazil = (xe_xex2_rating_brazil_value)poly::load_and_swap<uint8_t>(pp + 0x0A);
ratings->fpb = (xe_xex2_rating_fpb_value)poly::load_and_swap<uint8_t>(pp + 0x0B);
}
break;
case XEX_HEADER_TLS_INFO:
{
xe_xex2_tls_info_t *tls = &header->tls_info;
tls->slot_count = XEGETUINT32BE(pp + 0x00);
tls->raw_data_address = XEGETUINT32BE(pp + 0x04);
tls->data_size = XEGETUINT32BE(pp + 0x08);
tls->raw_data_size = XEGETUINT32BE(pp + 0x0C);
tls->slot_count = poly::load_and_swap<uint32_t>(pp + 0x00);
tls->raw_data_address = poly::load_and_swap<uint32_t>(pp + 0x04);
tls->data_size = poly::load_and_swap<uint32_t>(pp + 0x08);
tls->raw_data_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
}
break;
case XEX_HEADER_IMAGE_BASE_ADDRESS:
@ -237,7 +237,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
case XEX_HEADER_IMPORT_LIBRARIES:
{
const size_t max_count = XECOUNT(header->import_libraries);
size_t count = XEGETUINT32BE(pp + 0x08);
size_t count = poly::load_and_swap<uint32_t>(pp + 0x08);
assert_true(count <= max_count);
if (count > max_count) {
XELOGW("ignoring %zu extra entries in XEX_HEADER_IMPORT_LIBRARIES",
@ -246,7 +246,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
}
header->import_library_count = count;
uint32_t string_table_size = XEGETUINT32BE(pp + 0x04);
uint32_t string_table_size = poly::load_and_swap<uint32_t>(pp + 0x04);
const char *string_table = (const char*)(pp + 0x0C);
pp += 12 + string_table_size;
@ -254,11 +254,11 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
xe_xex2_import_library_t *library = &header->import_libraries[m];
XEEXPECTZERO(xe_copy_memory(library->digest, sizeof(library->digest),
pp + 0x04, 20));
library->import_id = XEGETUINT32BE(pp + 0x18);
library->version.value = XEGETUINT32BE(pp + 0x1C);
library->min_version.value = XEGETUINT32BE(pp + 0x20);
library->import_id = poly::load_and_swap<uint32_t>(pp + 0x18);
library->version.value = poly::load_and_swap<uint32_t>(pp + 0x1C);
library->min_version.value = poly::load_and_swap<uint32_t>(pp + 0x20);
const uint16_t name_index = XEGETUINT16BE(pp + 0x24) & 0xFF;
const uint16_t name_index = poly::load_and_swap<uint16_t>(pp + 0x24) & 0xFF;
for (size_t i = 0, j = 0; i < string_table_size;) {
assert_true(j <= 0xFF);
if (j == name_index) {
@ -277,13 +277,13 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
}
}
library->record_count = XEGETUINT16BE(pp + 0x26);
library->record_count = poly::load_and_swap<uint16_t>(pp + 0x26);
library->records = (uint32_t*)xe_calloc(
library->record_count * sizeof(uint32_t));
XEEXPECTNOTNULL(library->records);
pp += 0x28;
for (size_t i = 0; i < library->record_count; i++) {
library->records[i] = XEGETUINT32BE(pp);
library->records[i] = poly::load_and_swap<uint32_t>(pp);
pp += 4;
}
}
@ -306,10 +306,10 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
XEEXPECTZERO(xe_copy_memory(library->name, sizeof(library->name),
pp + 0x00, 8));
library->name[8] = 0;
library->major = XEGETUINT16BE(pp + 0x08);
library->minor = XEGETUINT16BE(pp + 0x0A);
library->build = XEGETUINT16BE(pp + 0x0C);
uint16_t qfeapproval = XEGETUINT16BE(pp + 0x0E);
library->major = poly::load_and_swap<uint16_t>(pp + 0x08);
library->minor = poly::load_and_swap<uint16_t>(pp + 0x0A);
library->build = poly::load_and_swap<uint16_t>(pp + 0x0C);
uint16_t qfeapproval = poly::load_and_swap<uint16_t>(pp + 0x0E);
library->approval = (xe_xex2_approval_type)(qfeapproval & 0x8000);
library->qfe = qfeapproval & ~0x8000;
pp += 16;
@ -320,9 +320,9 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
{
xe_xex2_file_format_info_t *fmt = &header->file_format_info;
fmt->encryption_type =
(xe_xex2_encryption_type)XEGETUINT16BE(pp + 0x04);
(xe_xex2_encryption_type)poly::load_and_swap<uint16_t>(pp + 0x04);
fmt->compression_type =
(xe_xex2_compression_type)XEGETUINT16BE(pp + 0x06);
(xe_xex2_compression_type)poly::load_and_swap<uint16_t>(pp + 0x06);
switch (fmt->compression_type) {
case XEX_COMPRESSION_NONE:
// TODO: XEX_COMPRESSION_NONE
@ -332,7 +332,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
{
xe_xex2_file_basic_compression_info_t *comp_info =
&fmt->compression_info.basic;
uint32_t info_size = XEGETUINT32BE(pp + 0x00);
uint32_t info_size = poly::load_and_swap<uint32_t>(pp + 0x00);
comp_info->block_count = (info_size - 8) / 8;
comp_info->blocks = (xe_xex2_file_basic_compression_block_t*)
xe_calloc(comp_info->block_count *
@ -341,8 +341,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
for (size_t m = 0; m < comp_info->block_count; m++) {
xe_xex2_file_basic_compression_block_t *block =
&comp_info->blocks[m];
block->data_size = XEGETUINT32BE(pp + 0x08 + (m * 8));
block->zero_size = XEGETUINT32BE(pp + 0x0C + (m * 8));
block->data_size = poly::load_and_swap<uint32_t>(pp + 0x08 + (m * 8));
block->zero_size = poly::load_and_swap<uint32_t>(pp + 0x0C + (m * 8));
}
}
break;
@ -350,7 +350,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
{
xe_xex2_file_normal_compression_info_t *comp_info =
&fmt->compression_info.normal;
uint32_t window_size = XEGETUINT32BE(pp + 0x08);
uint32_t window_size = poly::load_and_swap<uint32_t>(pp + 0x08);
uint32_t window_bits = 0;
for (size_t m = 0; m < 32; m++, window_bits++) {
window_size <<= 1;
@ -358,9 +358,9 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
break;
}
}
comp_info->window_size = XEGETUINT32BE(pp + 0x08);
comp_info->window_size = poly::load_and_swap<uint32_t>(pp + 0x08);
comp_info->window_bits = window_bits;
comp_info->block_size = XEGETUINT32BE(pp + 0x0C);
comp_info->block_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
XEEXPECTZERO(xe_copy_memory(comp_info->block_hash,
sizeof(comp_info->block_hash),
pp + 0x10, 20));
@ -379,16 +379,16 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
// Loader info.
pc = p + header->certificate_offset;
ldr = &header->loader_info;
ldr->header_size = XEGETUINT32BE(pc + 0x000);
ldr->image_size = XEGETUINT32BE(pc + 0x004);
ldr->header_size = poly::load_and_swap<uint32_t>(pc + 0x000);
ldr->image_size = poly::load_and_swap<uint32_t>(pc + 0x004);
XEEXPECTZERO(xe_copy_memory(ldr->rsa_signature, sizeof(ldr->rsa_signature),
pc + 0x008, 256));
ldr->unklength = XEGETUINT32BE(pc + 0x108);
ldr->image_flags = (xe_xex2_image_flags)XEGETUINT32BE(pc + 0x10C);
ldr->load_address = XEGETUINT32BE(pc + 0x110);
ldr->unklength = poly::load_and_swap<uint32_t>(pc + 0x108);
ldr->image_flags = (xe_xex2_image_flags)poly::load_and_swap<uint32_t>(pc + 0x10C);
ldr->load_address = poly::load_and_swap<uint32_t>(pc + 0x110);
XEEXPECTZERO(xe_copy_memory(ldr->section_digest, sizeof(ldr->section_digest),
pc + 0x114, 20));
ldr->import_table_count = XEGETUINT32BE(pc + 0x128);
ldr->import_table_count = poly::load_and_swap<uint32_t>(pc + 0x128);
XEEXPECTZERO(xe_copy_memory(ldr->import_table_digest,
sizeof(ldr->import_table_digest),
pc + 0x12C, 20));
@ -396,22 +396,22 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
pc + 0x140, 16));
XEEXPECTZERO(xe_copy_memory(ldr->file_key, sizeof(ldr->file_key),
pc + 0x150, 16));
ldr->export_table = XEGETUINT32BE(pc + 0x160);
ldr->export_table = poly::load_and_swap<uint32_t>(pc + 0x160);
XEEXPECTZERO(xe_copy_memory(ldr->header_digest, sizeof(ldr->header_digest),
pc + 0x164, 20));
ldr->game_regions = (xe_xex2_region_flags)XEGETUINT32BE(pc + 0x178);
ldr->media_flags = (xe_xex2_media_flags)XEGETUINT32BE(pc + 0x17C);
ldr->game_regions = (xe_xex2_region_flags)poly::load_and_swap<uint32_t>(pc + 0x178);
ldr->media_flags = (xe_xex2_media_flags)poly::load_and_swap<uint32_t>(pc + 0x17C);
// Section info follows loader info.
ps = p + header->certificate_offset + 0x180;
header->section_count = XEGETUINT32BE(ps + 0x000);
header->section_count = poly::load_and_swap<uint32_t>(ps + 0x000);
ps += 4;
header->sections = (xe_xex2_section_t*)xe_calloc(
header->section_count * sizeof(xe_xex2_section_t));
XEEXPECTNOTNULL(header->sections);
for (size_t n = 0; n < header->section_count; n++) {
xe_xex2_section_t *section = &header->sections[n];
section->info.value = XEGETUINT32BE(ps);
section->info.value = poly::load_and_swap<uint32_t>(ps);
ps += 4;
XEEXPECTZERO(xe_copy_memory(section->digest, sizeof(section->digest), ps,
sizeof(section->digest)));
@ -717,7 +717,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
block_size = header->file_format_info.compression_info.normal.block_size;
while (block_size) {
const uint8_t *pnext = p + block_size;
const size_t next_size = XEGETINT32BE(p);
const size_t next_size = poly::load_and_swap<int32_t>(p);
p += 4;
p += 20; // skip 20b hash
@ -935,7 +935,7 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
size_t info_count = 0;
for (size_t n = 0; n < library->record_count; n++) {
const uint32_t record = library->records[n];
const uint32_t value = XEGETUINT32BE(mem + record);
const uint32_t value = poly::load_and_swap<uint32_t>(mem + record);
if (value & 0xFF000000) {
// Thunk for previous record - ignore.
} else {
@ -954,7 +954,7 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
// Construct infos.
for (size_t n = 0, i = 0; n < library->record_count; n++) {
const uint32_t record = library->records[n];
const uint32_t value = XEGETUINT32BE(mem + record);
const uint32_t value = poly::load_and_swap<uint32_t>(mem + record);
const uint32_t type = (value & 0xFF000000) >> 24;
// Verify library index matches given library.

View File

@ -125,7 +125,7 @@ SHIM_CALL XAudioRegisterRenderDriverClient_shim(
}
assert_true(!(index & ~0x0000FFFF));
SHIM_SET_MEM_32(driver_ptr, 0x41550000 | (index & 0x0000FFFF));
SHIM_SET_MEM_32(driver_ptr, 0x41550000 | (static_cast<uint32_t>(index) & 0x0000FFFF));
SHIM_SET_RETURN_32(X_ERROR_SUCCESS);
}

View File

@ -435,7 +435,7 @@ SHIM_CALL NtQueryInformationFile_shim(
if (XSUCCEEDED(result)) {
if (bytes_read == sizeof(magic)) {
info = 4;
SHIM_SET_MEM_32(file_info_ptr, magic == XESWAP32BE(0x0FF512ED));
SHIM_SET_MEM_32(file_info_ptr, magic == poly::byte_swap(0x0FF512ED));
}
else {
result = X_STATUS_UNSUCCESSFUL;

View File

@ -63,7 +63,7 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::KeDebugMonitorData,
pKeDebugMonitorData);
XESETUINT32BE(mem + pKeDebugMonitorData, 0);
poly::store_and_swap<uint32_t>(mem + pKeDebugMonitorData, 0);
// KeCertMonitorData (?*)
// Always set to zero, ignored.
@ -71,7 +71,7 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::KeCertMonitorData,
pKeCertMonitorData);
XESETUINT32BE(mem + pKeCertMonitorData, 0);
poly::store_and_swap<uint32_t>(mem + pKeCertMonitorData, 0);
// XboxHardwareInfo (XboxHardwareInfo_t, 16b)
// flags cpu# ? ? ? ? ? ?
@ -82,8 +82,8 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::XboxHardwareInfo,
pXboxHardwareInfo);
XESETUINT32BE(mem + pXboxHardwareInfo + 0, 0x00000000); // flags
XESETUINT8BE (mem + pXboxHardwareInfo + 4, 0x06); // cpu count
poly::store_and_swap<uint32_t>(mem + pXboxHardwareInfo + 0, 0x00000000); // flags
poly::store_and_swap<uint8_t> (mem + pXboxHardwareInfo + 4, 0x06); // cpu count
// Remaining 11b are zeroes?
// XexExecutableModuleHandle (?**)
@ -101,8 +101,8 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
ppXexExecutableModuleHandle);
uint32_t pXexExecutableModuleHandle =
(uint32_t)memory_->HeapAlloc(0, 256, 0);
XESETUINT32BE(mem + ppXexExecutableModuleHandle, pXexExecutableModuleHandle);
XESETUINT32BE(mem + pXexExecutableModuleHandle + 0x58, 0x80101100);
poly::store_and_swap<uint32_t>(mem + ppXexExecutableModuleHandle, pXexExecutableModuleHandle);
poly::store_and_swap<uint32_t>(mem + pXexExecutableModuleHandle + 0x58, 0x80101100);
// ExLoadedCommandLine (char*)
// The name of the xex. Not sure this is ever really used on real devices.
@ -123,19 +123,19 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::XboxKrnlVersion,
pXboxKrnlVersion);
XESETUINT16BE(mem + pXboxKrnlVersion + 0, 2);
XESETUINT16BE(mem + pXboxKrnlVersion + 2, 0xFFFF);
XESETUINT16BE(mem + pXboxKrnlVersion + 4, 0xFFFF);
XESETUINT16BE(mem + pXboxKrnlVersion + 6, 0xFFFF);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 0, 2);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 2, 0xFFFF);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 4, 0xFFFF);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 6, 0xFFFF);
// KeTimeStampBundle (ad)
uint32_t pKeTimeStampBundle = (uint32_t)memory_->HeapAlloc(0, 24, 0);
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::KeTimeStampBundle,
pKeTimeStampBundle);
XESETUINT64BE(mem + pKeTimeStampBundle + 0, 0);
XESETUINT64BE(mem + pKeTimeStampBundle + 8, 0);
XESETUINT32BE(mem + pKeTimeStampBundle + 12, 0);
poly::store_and_swap<uint64_t>(mem + pKeTimeStampBundle + 0, 0);
poly::store_and_swap<uint64_t>(mem + pKeTimeStampBundle + 8, 0);
poly::store_and_swap<uint32_t>(mem + pKeTimeStampBundle + 12, 0);
}
XboxkrnlModule::~XboxkrnlModule() {

View File

@ -97,7 +97,7 @@ X_STATUS xeExGetXConfigSetting(
}
if (buffer) {
XESETUINT32BE(buffer, value);
poly::store_and_swap<uint32_t>(buffer, value);
}
if (required_size) {
*required_size = setting_size;

View File

@ -91,7 +91,7 @@ uint32_t xeRtlCompareMemoryUlong(uint32_t source_ptr, uint32_t length,
// TODO(benvanik): ensure byte order of pattern is correct.
// Since we are doing byte-by-byte comparison we may not want to swap.
// GET_ARG swaps, so this is a swap back. Ugly.
const uint32_t pb32 = XESWAP32BE(pattern);
const uint32_t pb32 = poly::byte_swap(pattern);
const uint8_t* pb = (uint8_t*)&pb32;
uint32_t c = 0;
@ -138,7 +138,7 @@ void xeRtlFillMemoryUlong(uint32_t destination_ptr, uint32_t length,
// swapped arg value.
uint32_t count = length >> 2;
uint32_t native_pattern = XESWAP32BE(pattern);
uint32_t native_pattern = poly::byte_swap(pattern);
// TODO: unroll loop?
@ -364,7 +364,7 @@ SHIM_CALL RtlMultiByteToUnicodeN_shim(
auto destination = (uint16_t*)SHIM_MEM_ADDR(destination_ptr);
for (uint32_t i = 0; i < copy_len; i++)
{
*destination++ = XESWAP16(*source++);
*destination++ = poly::byte_swap(*source++);
}
if (written_ptr != 0)
@ -393,7 +393,7 @@ SHIM_CALL RtlUnicodeToMultiByteN_shim(
auto destination = (uint8_t*)SHIM_MEM_ADDR(destination_ptr);
for (uint32_t i = 0; i < copy_len; i++)
{
uint16_t c = XESWAP16(*source++);
uint16_t c = poly::byte_swap(*source++);
*destination++ = c < 256 ? (uint8_t)c : '?';
}

View File

@ -472,9 +472,8 @@ SHIM_CALL _vswprintf_shim(
// swap the format buffer
wchar_t* swapped_format = (wchar_t*)xe_malloc((format_length + 1) * sizeof(wchar_t));
for (size_t i = 0; i < format_length; ++i)
{
swapped_format[i] = XESWAP16(format[i]);
for (size_t i = 0; i < format_length; ++i) {
swapped_format[i] = poly::byte_swap(format[i]);
}
swapped_format[format_length] = '\0';
@ -676,9 +675,8 @@ SHIM_CALL _vswprintf_shim(
const wchar_t* data = (const wchar_t*)SHIM_MEM_ADDR(value);
size_t data_length = wcslen(data);
wchar_t* swapped_data = (wchar_t*)xe_malloc((data_length + 1) * sizeof(wchar_t));
for (size_t i = 0; i < data_length; ++i)
{
swapped_data[i] = XESWAP16(data[i]);
for (size_t i = 0; i < data_length; ++i) {
swapped_data[i] = poly::byte_swap(data[i]);
}
swapped_data[data_length] = '\0';
int result = wsprintf(b, local, swapped_data);
@ -703,7 +701,7 @@ SHIM_CALL _vswprintf_shim(
// swap the result buffer
for (wchar_t* swap = buffer; swap != b; ++swap)
{
*swap = XESWAP16(*swap);
*swap = poly::byte_swap(*swap);
}
SHIM_SET_RETURN_32((uint32_t)((b - buffer) / sizeof(wchar_t)));

View File

@ -117,15 +117,15 @@ void xeVdQueryVideoMode(X_VIDEO_MODE *video_mode, bool swap) {
video_mode->unknown_0x01 = 0x01;
if (swap) {
video_mode->display_width = XESWAP32BE(video_mode->display_width);
video_mode->display_height = XESWAP32BE(video_mode->display_height);
video_mode->is_interlaced = XESWAP32BE(video_mode->is_interlaced);
video_mode->is_widescreen = XESWAP32BE(video_mode->is_widescreen);
video_mode->is_hi_def = XESWAP32BE(video_mode->is_hi_def);
video_mode->refresh_rate = XESWAPF32BE(video_mode->refresh_rate);
video_mode->video_standard = XESWAP32BE(video_mode->video_standard);
video_mode->unknown_0x8a = XESWAP32BE(video_mode->unknown_0x8a);
video_mode->unknown_0x01 = XESWAP32BE(video_mode->unknown_0x01);
video_mode->display_width = poly::byte_swap(video_mode->display_width);
video_mode->display_height = poly::byte_swap(video_mode->display_height);
video_mode->is_interlaced = poly::byte_swap(video_mode->is_interlaced);
video_mode->is_widescreen = poly::byte_swap(video_mode->is_widescreen);
video_mode->is_hi_def = poly::byte_swap(video_mode->is_hi_def);
video_mode->refresh_rate = poly::byte_swap(video_mode->refresh_rate);
video_mode->video_standard = poly::byte_swap(video_mode->video_standard);
video_mode->unknown_0x8a = poly::byte_swap(video_mode->unknown_0x8a);
video_mode->unknown_0x01 = poly::byte_swap(video_mode->unknown_0x01);
}
}
@ -430,9 +430,9 @@ SHIM_CALL VdSwap_shim(
// use this method.
xe_zero_struct(SHIM_MEM_ADDR(unk0), 64 * 4);
auto dwords = reinterpret_cast<uint32_t*>(SHIM_MEM_ADDR(unk0));
dwords[0] = XESWAP32((0x03 << 30) |
((1 - 1) << 16) |
(xenos::PM4_XE_SWAP << 8));
dwords[0] = poly::byte_swap((0x03 << 30) |
((1 - 1) << 16) |
(xenos::PM4_XE_SWAP << 8));
SHIM_SET_RETURN_64(0);
}
@ -472,7 +472,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports(
export_resolver->SetVariableMapping(
"xboxkrnl.exe", ordinals::VdGlobalDevice,
pVdGlobalDevice);
XESETUINT32BE(mem + pVdGlobalDevice, 0);
poly::store_and_swap<uint32_t>(mem + pVdGlobalDevice, 0);
// VdGlobalXamDevice (4b)
// Pointer to the XAM D3D device, which we don't have.
@ -480,7 +480,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports(
export_resolver->SetVariableMapping(
"xboxkrnl.exe", ordinals::VdGlobalXamDevice,
pVdGlobalXamDevice);
XESETUINT32BE(mem + pVdGlobalXamDevice, 0);
poly::store_and_swap<uint32_t>(mem + pVdGlobalXamDevice, 0);
// VdGpuClockInMHz (4b)
// GPU clock. Xenos is 500MHz. Hope nothing is relying on this timing...
@ -488,7 +488,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports(
export_resolver->SetVariableMapping(
"xboxkrnl.exe", ordinals::VdGpuClockInMHz,
pVdGpuClockInMHz);
XESETUINT32BE(mem + pVdGpuClockInMHz, 500);
poly::store_and_swap<uint32_t>(mem + pVdGpuClockInMHz, 500);
// VdHSIOCalibrationLock (28b)
// CriticalSection.

View File

@ -162,18 +162,18 @@ void XObject::SetNativePointer(uint32_t native_ptr) {
DISPATCH_HEADER* header_be =
(DISPATCH_HEADER*)kernel_state_->memory()->Translate(native_ptr);
DISPATCH_HEADER header;
header.type_flags = XESWAP32(header_be->type_flags);
header.signal_state = XESWAP32(header_be->signal_state);
header.wait_list_flink = XESWAP32(header_be->wait_list_flink);
header.wait_list_blink = XESWAP32(header_be->wait_list_blink);
header.type_flags = poly::byte_swap(header_be->type_flags);
header.signal_state = poly::byte_swap(header_be->signal_state);
header.wait_list_flink = poly::byte_swap(header_be->wait_list_flink);
header.wait_list_blink = poly::byte_swap(header_be->wait_list_blink);
assert_true(!(header.wait_list_blink & 0x1));
// Stash pointer in struct.
uint64_t object_ptr = reinterpret_cast<uint64_t>(this);
object_ptr |= 0x1;
header_be->wait_list_flink = XESWAP32((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = XESWAP32((uint32_t)(object_ptr & 0xFFFFFFFF));
header_be->wait_list_flink = poly::byte_swap((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = poly::byte_swap((uint32_t)(object_ptr & 0xFFFFFFFF));
XObject::UnlockType();
}
@ -193,10 +193,10 @@ XObject* XObject::GetObject(KernelState* kernel_state, void* native_ptr,
DISPATCH_HEADER* header_be = (DISPATCH_HEADER*)native_ptr;
DISPATCH_HEADER header;
header.type_flags = XESWAP32(header_be->type_flags);
header.signal_state = XESWAP32(header_be->signal_state);
header.wait_list_flink = XESWAP32(header_be->wait_list_flink);
header.wait_list_blink = XESWAP32(header_be->wait_list_blink);
header.type_flags = poly::byte_swap(header_be->type_flags);
header.signal_state = poly::byte_swap(header_be->signal_state);
header.wait_list_flink = poly::byte_swap(header_be->wait_list_flink);
header.wait_list_blink = poly::byte_swap(header_be->wait_list_blink);
if (as_type == -1) {
as_type = header.type_flags & 0xFF;
@ -260,8 +260,8 @@ XObject* XObject::GetObject(KernelState* kernel_state, void* native_ptr,
// Stash pointer in struct.
uint64_t object_ptr = reinterpret_cast<uint64_t>(object);
object_ptr |= 0x1;
header_be->wait_list_flink = XESWAP32((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = XESWAP32((uint32_t)(object_ptr & 0xFFFFFFFF));
header_be->wait_list_flink = poly::byte_swap((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = poly::byte_swap((uint32_t)(object_ptr & 0xFFFFFFFF));
XObject::UnlockType();
return object;

View File

@ -1,7 +1,6 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'byte_order.h',
'common.h',
'config.h',
'core.h',

View File

@ -205,10 +205,10 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
length = XEGETUINT16BE(base + p);
maximum_length = XEGETUINT16BE(base + p + 2);
length = poly::load_and_swap<uint16_t>(base + p);
maximum_length = poly::load_and_swap<uint16_t>(base + p + 2);
if (maximum_length) {
buffer = (const char*)(base + XEGETUINT32BE(base + p + 4));
buffer = (const char*)(base + poly::load_and_swap<uint32_t>(base + p + 4));
} else {
buffer = 0;
}
@ -242,14 +242,14 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
root_directory = XEGETUINT32BE(base + p);
object_name_ptr = XEGETUINT32BE(base + p + 4);
root_directory = poly::load_and_swap<uint32_t>(base + p);
object_name_ptr = poly::load_and_swap<uint32_t>(base + p + 4);
if (object_name_ptr) {
object_name.Read(base, object_name_ptr);
} else {
object_name.Zero();
}
attributes = XEGETUINT32BE(base + p + 8);
attributes = poly::load_and_swap<uint32_t>(base + p + 8);
}
void Zero() {
root_directory = 0;
@ -302,22 +302,22 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
buttons = XEGETUINT16BE(base + p);
left_trigger = XEGETUINT8BE(base + p + 2);
right_trigger = XEGETUINT8BE(base + p + 3);
thumb_lx = XEGETINT16BE(base + p + 4);
thumb_ly = XEGETINT16BE(base + p + 6);
thumb_rx = XEGETINT16BE(base + p + 8);
thumb_ry = XEGETINT16BE(base + p + 10);
buttons = poly::load_and_swap<uint16_t>(base + p);
left_trigger = poly::load_and_swap<uint8_t>(base + p + 2);
right_trigger = poly::load_and_swap<uint8_t>(base + p + 3);
thumb_lx = poly::load_and_swap<int16_t>(base + p + 4);
thumb_ly = poly::load_and_swap<int16_t>(base + p + 6);
thumb_rx = poly::load_and_swap<int16_t>(base + p + 8);
thumb_ry = poly::load_and_swap<int16_t>(base + p + 10);
}
void Write(uint8_t* base, uint32_t p) {
XESETUINT16BE(base + p, buttons);
XESETUINT8BE(base + p + 2, left_trigger);
XESETUINT8BE(base + p + 3, right_trigger);
XESETINT16BE(base + p + 4, thumb_lx);
XESETINT16BE(base + p + 6, thumb_ly);
XESETINT16BE(base + p + 8, thumb_rx);
XESETINT16BE(base + p + 10, thumb_ry);
poly::store_and_swap<uint16_t>(base + p, buttons);
poly::store_and_swap<uint8_t>(base + p + 2, left_trigger);
poly::store_and_swap<uint8_t>(base + p + 3, right_trigger);
poly::store_and_swap<int16_t>(base + p + 4, thumb_lx);
poly::store_and_swap<int16_t>(base + p + 6, thumb_ly);
poly::store_and_swap<int16_t>(base + p + 8, thumb_rx);
poly::store_and_swap<int16_t>(base + p + 10, thumb_ry);
}
void Zero() {
buttons = 0;
@ -337,11 +337,11 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
packet_number = XEGETUINT32BE(base + p);
packet_number = poly::load_and_swap<uint32_t>(base + p);
gamepad.Read(base, p + 4);
}
void Write(uint8_t* base, uint32_t p) {
XESETUINT32BE(base + p, packet_number);
poly::store_and_swap<uint32_t>(base + p, packet_number);
gamepad.Write(base, p + 4);
}
void Zero() {
@ -361,12 +361,12 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
left_motor_speed = XEGETUINT16BE(base + p);
right_motor_speed = XEGETUINT16BE(base + p + 2);
left_motor_speed = poly::load_and_swap<uint16_t>(base + p);
right_motor_speed = poly::load_and_swap<uint16_t>(base + p + 2);
}
void Write(uint8_t* base, uint32_t p) {
XESETUINT16BE(base + p, left_motor_speed);
XESETUINT16BE(base + p + 2, right_motor_speed);
poly::store_and_swap<uint16_t>(base + p, left_motor_speed);
poly::store_and_swap<uint16_t>(base + p + 2, right_motor_speed);
}
void Zero() {
left_motor_speed = right_motor_speed = 0;
@ -387,16 +387,16 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
type = XEGETUINT8BE(base + p);
sub_type = XEGETUINT8BE(base + p + 1);
flags = XEGETUINT16BE(base + p + 2);
type = poly::load_and_swap<uint8_t>(base + p);
sub_type = poly::load_and_swap<uint8_t>(base + p + 1);
flags = poly::load_and_swap<uint16_t>(base + p + 2);
gamepad.Read(base, p + 4);
vibration.Read(base, p + 4 + 12);
}
void Write(uint8_t* base, uint32_t p) {
XESETUINT8BE(base + p, type);
XESETUINT8BE(base + p + 1, sub_type);
XESETUINT16BE(base + p + 2, flags);
poly::store_and_swap<uint8_t>(base + p, type);
poly::store_and_swap<uint8_t>(base + p + 1, sub_type);
poly::store_and_swap<uint16_t>(base + p + 2, flags);
gamepad.Write(base, p + 4);
vibration.Write(base, p + 4 + 12);
}
@ -424,18 +424,18 @@ public:
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
virtual_key = XEGETUINT16BE(base + p + 0);
unicode = XEGETUINT16BE(base + p + 2);
flags = XEGETUINT16BE(base + p + 4);
user_index = XEGETUINT8BE(base + p + 6);
hid_code = XEGETUINT8BE(base + p + 7);
virtual_key = poly::load_and_swap<uint16_t>(base + p + 0);
unicode = poly::load_and_swap<uint16_t>(base + p + 2);
flags = poly::load_and_swap<uint16_t>(base + p + 4);
user_index = poly::load_and_swap<uint8_t>(base + p + 6);
hid_code = poly::load_and_swap<uint8_t>(base + p + 7);
}
void Write(uint8_t* base, uint32_t p) {
XESETUINT16BE(base + p + 0, virtual_key);
XESETUINT16BE(base + p + 2, unicode);
XESETUINT16BE(base + p + 4, flags);
XESETUINT8BE(base + p + 6, user_index);
XESETUINT8BE(base + p + 7, hid_code);
poly::store_and_swap<uint16_t>(base + p + 0, virtual_key);
poly::store_and_swap<uint16_t>(base + p + 2, unicode);
poly::store_and_swap<uint16_t>(base + p + 4, flags);
poly::store_and_swap<uint8_t>(base + p + 6, user_index);
poly::store_and_swap<uint8_t>(base + p + 7, hid_code);
}
void Zero() {
virtual_key = 0;