00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __EMULATORUTILITY_MEMORY_SYSTEM_H__
00033 #define __EMULATORUTILITY_MEMORY_SYSTEM_H__
00034
00035 #include "Emu/Utility/System/Memory/HeapAllocator.h"
00036 #include "Emu/Utility/System/Memory/VirtualMemory.h"
00037
00038 namespace Onikiri {
00039 namespace EmulatorUtility {
00040
00041
00042
00043 class MemorySystem
00044 {
00045 static const int RESERVED_PAGES = 256;
00046 static const int RESERVED_PAGE_NULL = 0;
00047 static const int RESERVED_PAGE_ZERO_FILLED = 1;
00048 public:
00049 MemorySystem( int pid, bool bigEndian, SystemIF* simSystem );
00050 ~MemorySystem();
00051
00052
00053
00054 u64 GetPageSize();
00055
00056
00057 u64 GetReservedAddressRange(){ return GetPageSize() * RESERVED_PAGES - 1; };
00058
00059
00060 void AddHeapBlock(u64 addr, u64 size);
00061
00062
00063 void SetInitialBrk(u64 initialBrk);
00064 u64 Brk(u64 addr);
00065 u64 MMap(u64 addr, u64 length);
00066 u64 MRemap(u64 old_addr, u64 old_size, u64 new_size, bool mayMove = false);
00067 int MUnmap(u64 addr, u64 length);
00068
00069
00070 bool IsBigEndian() const
00071 {
00072 return m_bigEndian;
00073 }
00074
00075 u64 GetPageSize() const
00076 {
00077 return m_virtualMemory.GetPageSize();
00078 }
00079
00080
00081 void AssignPhysicalMemory(u64 addr, u64 size, VIRTUAL_MEMORY_ATTR_TYPE attr )
00082 {
00083 m_virtualMemory.AssignPhysicalMemory( addr, size, attr );
00084 }
00085
00086
00087 void ReadMemory( MemAccess* access )
00088 {
00089 m_virtualMemory.ReadMemory( access );
00090 }
00091
00092 void WriteMemory( MemAccess* access )
00093 {
00094 m_virtualMemory.WriteMemory( access );
00095 }
00096
00097
00098
00099
00100 void TargetMemset(u64 targetAddr, int value, u64 size )
00101 {
00102 m_virtualMemory.TargetMemset( targetAddr, value, size );
00103 }
00104
00105 void MemCopyToHost(void* dst, u64 src, u64 size)
00106 {
00107 m_virtualMemory.MemCopyToHost( dst, src, size );
00108 }
00109
00110 void MemCopyToTarget(u64 dst, const void* src, u64 size)
00111 {
00112 m_virtualMemory.MemCopyToTarget( dst, src, size );
00113 }
00114
00115 private:
00116
00117
00118 void CheckValueOnPageBoundary( u64 addr, const char* signature );
00119
00120 VirtualMemory m_virtualMemory;
00121 HeapAllocator m_heapAlloc;
00122
00123
00124 u64 m_currentBrk;
00125
00126
00127 SystemIF* m_simSystem;
00128
00129
00130 int m_pid;
00131
00132
00133 bool m_bigEndian;
00134 };
00135
00136 }
00137 }
00138
00139 #endif