/** ****************************************************************************** * 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_CPU_XENON_MEMORY_H_ #define XENIA_CPU_XENON_MEMORY_H_ #include #include typedef struct xe_ppc_state xe_ppc_state_t; namespace xe { namespace cpu { class XenonMemoryHeap; typedef uint64_t (*MMIOReadCallback)(void* context, uint64_t addr); typedef void (*MMIOWriteCallback)(void* context, uint64_t addr, uint64_t value); class XenonMemory : public alloy::Memory { public: XenonMemory(); virtual ~XenonMemory(); int Initialize() override; uint64_t page_table() const override { return page_table_; } bool AddMappedRange(uint64_t address, uint64_t mask, uint64_t size, void* context, MMIOReadCallback read_callback = nullptr, MMIOWriteCallback write_callback = nullptr); uint8_t LoadI8(uint64_t address) override; uint16_t LoadI16(uint64_t address) override; uint32_t LoadI32(uint64_t address) override; uint64_t LoadI64(uint64_t address) override; void StoreI8(uint64_t address, uint8_t value) override; void StoreI16(uint64_t address, uint16_t value) override; void StoreI32(uint64_t address, uint32_t value) override; void StoreI64(uint64_t address, uint64_t value) override; uint64_t HeapAlloc( uint64_t base_address, size_t size, uint32_t flags, uint32_t alignment = 0x20) override; int HeapFree(uint64_t address, size_t size) override; size_t QuerySize(uint64_t base_address) override; int Protect(uint64_t address, size_t size, uint32_t access) override; uint32_t QueryProtect(uint64_t address) override; private: int MapViews(uint8_t* mapping_base); void UnmapViews(); bool CheckMMIOLoad(uint64_t address, uint64_t* out_value); bool CheckMMIOStore(uint64_t address, uint64_t value); private: HANDLE mapping_; uint8_t* mapping_base_; union { struct { uint8_t* v00000000; uint8_t* v40000000; uint8_t* v80000000; uint8_t* vA0000000; uint8_t* vC0000000; uint8_t* vE0000000; }; uint8_t* all_views[6]; } views_; XenonMemoryHeap* virtual_heap_; XenonMemoryHeap* physical_heap_; uint64_t page_table_; friend class XenonMemoryHeap; }; } // namespace cpu } // namespace xe #endif // XENIA_CPU_XENON_MEMORY_H_