/[pcsx2_0.9.7]/trunk/pcsx2/vtlb.h
ViewVC logotype

Diff of /trunk/pcsx2/vtlb.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/pcsx2/vtlb.h	2010/09/07 03:24:11	31
+++ trunk/pcsx2/vtlb.h	2010/12/23 12:02:12	280
@@ -1,6 +1,26 @@
+/*  PCSX2 - PS2 Emulator for PCs
+ *  Copyright (C) 2002-2010  PCSX2 Dev Team
+ *
+ *  PCSX2 is free software: you can redistribute it and/or modify it under the terms
+ *  of the GNU Lesser General Public License as published by the Free Software Found-
+ *  ation, either version 3 of the License, or (at your option) any later version.
+ *
+ *  PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ *  PURPOSE.  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along with PCSX2.
+ *  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 #pragma once
 
+#include "MemoryTypes.h"
+
+#include "Utilities/PageFaultSource.h"
+
+static const uptr VTLB_AllocUpperBounds = _1gb * 2;
+
 // Specialized function pointers for each read type
 typedef  mem8_t __fastcall vtlbMemR8FP(u32 addr);
 typedef  mem16_t __fastcall vtlbMemR16FP(u32 addr);
@@ -18,12 +38,10 @@
 typedef u32 vtlbHandler;
 
 extern void vtlb_Core_Alloc();
-extern void vtlb_Core_Shutdown();
+extern void vtlb_Core_Free();
 extern void vtlb_Init();
 extern void vtlb_Reset();
 extern void vtlb_Term();
-extern u8* vtlb_malloc( uint size, uint align );
-extern void vtlb_free( void* pmem, uint size );
 
 
 extern vtlbHandler vtlb_NewHandler();
@@ -51,16 +69,15 @@
 
 //Memory functions
 
-extern mem8_t __fastcall vtlb_memRead8(u32 mem);
-extern mem16_t __fastcall vtlb_memRead16(u32 mem);
-extern u32 __fastcall vtlb_memRead32(u32 mem);
-extern void __fastcall vtlb_memRead64(u32 mem, u64 *out);
-extern void __fastcall vtlb_memRead128(u32 mem, u64 *out);
-extern void __fastcall vtlb_memWrite8 (u32 mem, mem8_t  value);
-extern void __fastcall vtlb_memWrite16(u32 mem, mem16_t value);
-extern void __fastcall vtlb_memWrite32(u32 mem, u32 value);
-extern void __fastcall vtlb_memWrite64(u32 mem, const u64* value);
-extern void __fastcall vtlb_memWrite128(u32 mem, const u64* value);
+template< typename DataType >
+extern DataType __fastcall vtlb_memRead(u32 mem);
+extern void __fastcall vtlb_memRead64(u32 mem, mem64_t *out);
+extern void __fastcall vtlb_memRead128(u32 mem, mem128_t *out);
+
+template< typename DataType >
+extern void __fastcall vtlb_memWrite(u32 mem, DataType value);
+extern void __fastcall vtlb_memWrite64(u32 mem, const mem64_t* value);
+extern void __fastcall vtlb_memWrite128(u32 mem, const mem128_t* value);
 
 extern void vtlb_DynGenWrite(u32 sz);
 extern void vtlb_DynGenRead32(u32 bits, bool sign);
@@ -70,30 +87,121 @@
 extern void vtlb_DynGenRead64_Const( u32 bits, u32 addr_const );
 extern void vtlb_DynGenRead32_Const( u32 bits, bool sign, u32 addr_const );
 
-namespace vtlb_private
+// --------------------------------------------------------------------------------------
+//  VtlbMemoryReserve
+// --------------------------------------------------------------------------------------
+class VtlbMemoryReserve
+{
+protected:
+	VirtualMemoryReserve	m_reserve;
+
+public:
+	VtlbMemoryReserve( const wxString& name, size_t size );
+	virtual ~VtlbMemoryReserve() throw()
+	{
+		m_reserve.Release();
+	}
+
+	virtual void Reserve( sptr hostptr );
+	virtual void Release();
+
+	virtual void Commit();
+	virtual void Reset();
+	virtual void Decommit();
+	virtual void SetBaseAddr( uptr newaddr );
+	
+	bool IsCommitted() const;
+};
+
+// --------------------------------------------------------------------------------------
+//  eeMemoryReserve
+// --------------------------------------------------------------------------------------
+class eeMemoryReserve : public VtlbMemoryReserve
+{
+	typedef VtlbMemoryReserve _parent;
+
+public:
+	eeMemoryReserve();
+	virtual ~eeMemoryReserve() throw()
+	{
+		Release();
+	}
+
+	void Reserve();
+	void Commit();
+	void Decommit();
+	void Reset();
+	void Release();
+};
+
+// --------------------------------------------------------------------------------------
+//  iopMemoryReserve
+// --------------------------------------------------------------------------------------
+class iopMemoryReserve : public VtlbMemoryReserve
 {
-	static const uint VTLB_ALLOC_SIZE = 0x2900000;	//this is a bit more than required
+	typedef VtlbMemoryReserve _parent;
+
+public:
+	iopMemoryReserve();
+	virtual ~iopMemoryReserve() throw()
+	{
+		Release();
+	}
 
+	void Reserve();
+	void Commit();
+	void Decommit();
+	void Release();
+	void Reset();
+};
+
+// --------------------------------------------------------------------------------------
+//  vuMemoryReserve
+// --------------------------------------------------------------------------------------
+class vuMemoryReserve : public VtlbMemoryReserve
+{
+	typedef VtlbMemoryReserve _parent;
+
+public:
+	vuMemoryReserve();
+	virtual ~vuMemoryReserve() throw()
+	{
+		Release();
+	}
+
+	virtual void Reserve();
+	virtual void Release();
+
+	void Reset();
+};
+
+namespace vtlb_private
+{
 	static const uint VTLB_PAGE_BITS = 12;
 	static const uint VTLB_PAGE_MASK = 4095;
 	static const uint VTLB_PAGE_SIZE = 4096;
 
-	static const uint VTLB_PMAP_ITEMS = 0x20000000 / VTLB_PAGE_SIZE;
-	static const uint VTLB_PMAP_SZ = 0x20000000;
-	static const uint VTLB_VMAP_ITEMS = 0x100000000ULL / VTLB_PAGE_SIZE;
+	static const uint VTLB_PMAP_SZ		= _1mb * 512;
+	static const uint VTLB_PMAP_ITEMS	= VTLB_PMAP_SZ / VTLB_PAGE_SIZE;
+	static const uint VTLB_VMAP_ITEMS	= _4gb / VTLB_PAGE_SIZE;
+
+	static const uint VTLB_HANDLER_ITEMS = 128;
 
 	struct MapData
 	{
-		u8* alloc_base;			//base of the memory array
-		int alloc_current;		//current base
-
-		s32 pmap[VTLB_PMAP_ITEMS];	//512KB
-		s32 vmap[VTLB_VMAP_ITEMS];   //4MB
-
 		// first indexer -- 8/16/32/64/128 bit tables [values 0-4]
 		// second indexer -- read/write  [0 or 1]
 		// third indexer -- 128 possible handlers!
-		void* RWFT[5][2][128];
+		void* RWFT[5][2][VTLB_HANDLER_ITEMS];
+
+		s32 pmap[VTLB_PMAP_ITEMS];	//512KB
+
+		s32* vmap;				//4MB (allocated by vtlb_init)
+
+		MapData()
+		{
+			vmap = NULL;
+		}
 	};
 
 	extern __aligned(64) MapData vtlbdata;

 

  ViewVC Help
Powered by ViewVC 1.1.22