Merge pull request #82 from yuriks/addr-types
Introduce VAddr and PAddr typedefs for ARM addresses.
This commit is contained in:
commit
038a51aac1
|
@ -9,6 +9,11 @@
|
||||||
|
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
|
|
||||||
|
// TODO: It would be nice to eventually replace these with strong types that prevent accidental
|
||||||
|
// conversion between each other.
|
||||||
|
typedef u32 VAddr; ///< Represents a pointer in the ARM11 virtual address space.
|
||||||
|
typedef u32 PAddr; ///< Represents a pointer in the physical address space.
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -127,25 +132,25 @@ void Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Read(T &var, const u32 addr);
|
inline void Read(T &var, VAddr addr);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Write(u32 addr, const T data);
|
inline void Write(VAddr addr, T data);
|
||||||
|
|
||||||
u8 Read8(const u32 addr);
|
u8 Read8(VAddr addr);
|
||||||
u16 Read16(const u32 addr);
|
u16 Read16(VAddr addr);
|
||||||
u32 Read32(const u32 addr);
|
u32 Read32(VAddr addr);
|
||||||
|
|
||||||
u32 Read8_ZX(const u32 addr);
|
u32 Read8_ZX(VAddr addr);
|
||||||
u32 Read16_ZX(const u32 addr);
|
u32 Read16_ZX(VAddr addr);
|
||||||
|
|
||||||
void Write8(const u32 addr, const u8 data);
|
void Write8(VAddr addr, u8 data);
|
||||||
void Write16(const u32 addr, const u16 data);
|
void Write16(VAddr addr, u16 data);
|
||||||
void Write32(const u32 addr, const u32 data);
|
void Write32(VAddr addr, u32 data);
|
||||||
|
|
||||||
void WriteBlock(const u32 addr, const u8* data, const int size);
|
void WriteBlock(VAddr addr, const u8* data, size_t size);
|
||||||
|
|
||||||
u8* GetPointer(const u32 virtual_address);
|
u8* GetPointer(VAddr virtual_address);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps a block of memory on the heap
|
* Maps a block of memory on the heap
|
||||||
|
@ -163,14 +168,18 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions);
|
||||||
*/
|
*/
|
||||||
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions);
|
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions);
|
||||||
|
|
||||||
inline const char* GetCharPointer(const u32 address) {
|
inline const char* GetCharPointer(const VAddr address) {
|
||||||
return (const char *)GetPointer(address);
|
return (const char *)GetPointer(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a physical address to virtual address
|
/// Converts a physical address to virtual address
|
||||||
u32 PhysicalToVirtualAddress(const u32 addr);
|
VAddr PhysicalToVirtualAddress(PAddr addr);
|
||||||
|
|
||||||
/// Converts a virtual address to physical address
|
/// Converts a virtual address to physical address
|
||||||
u32 VirtualToPhysicalAddress(const u32 addr);
|
PAddr VirtualToPhysicalAddress(VAddr addr);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
// These are used often, so re-export then on the root namespace
|
||||||
|
using Memory::VAddr;
|
||||||
|
using Memory::PAddr;
|
||||||
|
|
|
@ -18,7 +18,7 @@ std::map<u32, MemoryBlock> g_heap_gsp_map;
|
||||||
std::map<u32, MemoryBlock> g_shared_map;
|
std::map<u32, MemoryBlock> g_shared_map;
|
||||||
|
|
||||||
/// Convert a physical address to virtual address
|
/// Convert a physical address to virtual address
|
||||||
u32 PhysicalToVirtualAddress(const u32 addr) {
|
VAddr PhysicalToVirtualAddress(const PAddr addr) {
|
||||||
// Our memory interface read/write functions assume virtual addresses. Put any physical address
|
// Our memory interface read/write functions assume virtual addresses. Put any physical address
|
||||||
// to virtual address translations here. This is quite hacky, but necessary until we implement
|
// to virtual address translations here. This is quite hacky, but necessary until we implement
|
||||||
// proper MMU emulation.
|
// proper MMU emulation.
|
||||||
|
@ -34,7 +34,7 @@ u32 PhysicalToVirtualAddress(const u32 addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a physical address to virtual address
|
/// Convert a physical address to virtual address
|
||||||
u32 VirtualToPhysicalAddress(const u32 addr) {
|
PAddr VirtualToPhysicalAddress(const VAddr addr) {
|
||||||
// Our memory interface read/write functions assume virtual addresses. Put any physical address
|
// Our memory interface read/write functions assume virtual addresses. Put any physical address
|
||||||
// to virtual address translations here. This is quite hacky, but necessary until we implement
|
// to virtual address translations here. This is quite hacky, but necessary until we implement
|
||||||
// proper MMU emulation.
|
// proper MMU emulation.
|
||||||
|
@ -50,7 +50,7 @@ u32 VirtualToPhysicalAddress(const u32 addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Read(T &var, const u32 vaddr) {
|
inline void Read(T &var, const VAddr vaddr) {
|
||||||
// TODO: Figure out the fastest order of tests for both read and write (they are probably different).
|
// TODO: Figure out the fastest order of tests for both read and write (they are probably different).
|
||||||
// TODO: Make sure this represents the mirrors in a correct way.
|
// TODO: Make sure this represents the mirrors in a correct way.
|
||||||
// Could just do a base-relative read, too.... TODO
|
// Could just do a base-relative read, too.... TODO
|
||||||
|
@ -98,7 +98,7 @@ inline void Read(T &var, const u32 vaddr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Write(u32 vaddr, const T data) {
|
inline void Write(const VAddr vaddr, const T data) {
|
||||||
|
|
||||||
// Kernel memory command buffer
|
// Kernel memory command buffer
|
||||||
if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) {
|
if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) {
|
||||||
|
@ -146,7 +146,7 @@ inline void Write(u32 vaddr, const T data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 *GetPointer(const u32 vaddr) {
|
u8 *GetPointer(const VAddr vaddr) {
|
||||||
// Kernel memory command buffer
|
// Kernel memory command buffer
|
||||||
if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) {
|
if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) {
|
||||||
return g_kernel_mem + (vaddr & KERNEL_MEMORY_MASK);
|
return g_kernel_mem + (vaddr & KERNEL_MEMORY_MASK);
|
||||||
|
@ -227,13 +227,13 @@ u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
|
||||||
return block.GetVirtualAddress();
|
return block.GetVirtualAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 Read8(const u32 addr) {
|
u8 Read8(const VAddr addr) {
|
||||||
u8 data = 0;
|
u8 data = 0;
|
||||||
Read<u8>(data, addr);
|
Read<u8>(data, addr);
|
||||||
return (u8)data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 Read16(const u32 addr) {
|
u16 Read16(const VAddr addr) {
|
||||||
u16_le data = 0;
|
u16_le data = 0;
|
||||||
Read<u16_le>(data, addr);
|
Read<u16_le>(data, addr);
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ u16 Read16(const u32 addr) {
|
||||||
return (u16)data;
|
return (u16)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Read32(const u32 addr) {
|
u32 Read32(const VAddr addr) {
|
||||||
u32_le data = 0;
|
u32_le data = 0;
|
||||||
Read<u32_le>(data, addr);
|
Read<u32_le>(data, addr);
|
||||||
|
|
||||||
|
@ -263,31 +263,31 @@ u32 Read32(const u32 addr) {
|
||||||
return (u32)data;
|
return (u32)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Read8_ZX(const u32 addr) {
|
u32 Read8_ZX(const VAddr addr) {
|
||||||
return (u32)Read8(addr);
|
return (u32)Read8(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Read16_ZX(const u32 addr) {
|
u32 Read16_ZX(const VAddr addr) {
|
||||||
return (u32)Read16(addr);
|
return (u32)Read16(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write8(const u32 addr, const u8 data) {
|
void Write8(const VAddr addr, const u8 data) {
|
||||||
Write<u8>(addr, data);
|
Write<u8>(addr, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write16(const u32 addr, const u16 data) {
|
void Write16(const VAddr addr, const u16 data) {
|
||||||
Write<u16_le>(addr, data);
|
Write<u16_le>(addr, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write32(const u32 addr, const u32 data) {
|
void Write32(const VAddr addr, const u32 data) {
|
||||||
Write<u32_le>(addr, data);
|
Write<u32_le>(addr, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write64(const u32 addr, const u64 data) {
|
void Write64(const VAddr addr, const u64 data) {
|
||||||
Write<u64_le>(addr, data);
|
Write<u64_le>(addr, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteBlock(const u32 addr, const u8* data, const int size) {
|
void WriteBlock(const VAddr addr, const u8* data, const size_t size) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
while (offset < (size & ~3)) {
|
while (offset < (size & ~3)) {
|
||||||
Write32(addr + offset, *(u32*)&data[offset]);
|
Write32(addr + offset, *(u32*)&data[offset]);
|
||||||
|
|
Reference in New Issue