Add a larger cache. Allocated when the dynamic core is selected.
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2461
This commit is contained in:
parent
e82452e6a9
commit
b33bfb80d9
3 changed files with 75 additions and 40 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if (C_HAVE_MPROTECT)
|
||||
#include <sys/mman.h>
|
||||
|
@ -46,14 +47,13 @@
|
|||
#include "inout.h"
|
||||
|
||||
#ifdef CHECKED_MEMORY_ACCESS
|
||||
#define CACHE_PAGES (128*2)
|
||||
#define CACHE_MAXSIZE (4096*2)
|
||||
#else
|
||||
#define CACHE_PAGES (128)
|
||||
#define CACHE_MAXSIZE (4096)
|
||||
#endif
|
||||
#define CACHE_PAGES (128*8)
|
||||
#define CACHE_TOTAL (CACHE_PAGES*4096)
|
||||
#define CACHE_BLOCKS (32*1024)
|
||||
#define CACHE_BLOCKS (64*1024)
|
||||
#define CACHE_ALIGN (16)
|
||||
#define DYN_HASH_SHIFT (4)
|
||||
#define DYN_PAGE_HASH (4096>>DYN_HASH_SHIFT)
|
||||
|
@ -346,11 +346,14 @@ void CPU_Core_Dyn_X86_Init(void) {
|
|||
DynRegs[G_SHIFT].flags=DYNFLG_HAS8|DYNFLG_HAS16;
|
||||
DynRegs[G_EXIT].data=0;
|
||||
DynRegs[G_EXIT].flags=DYNFLG_HAS16;
|
||||
/* Initialize code cache and dynamic blocks */
|
||||
cache_init();
|
||||
/* Init the generator */
|
||||
gen_init();
|
||||
return;
|
||||
}
|
||||
|
||||
void CPU_Core_Dyn_X86_Cache_Init(bool enable_cache) {
|
||||
/* Initialize code cache and dynamic blocks */
|
||||
cache_init(enable_cache);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,13 +44,10 @@ static struct {
|
|||
|
||||
#if (C_HAVE_MPROTECT)
|
||||
static Bit8u cache_code_link_blocks[2][16] GCC_ATTRIBUTE(aligned(PAGESIZE));
|
||||
static Bit8u cache_code[CACHE_TOTAL+CACHE_MAXSIZE] GCC_ATTRIBUTE(aligned(PAGESIZE));
|
||||
#else
|
||||
static Bit8u cache_code_link_blocks[2][16];
|
||||
static Bit8u cache_code[CACHE_TOTAL+CACHE_MAXSIZE];
|
||||
#endif
|
||||
|
||||
static CacheBlock cache_blocks[CACHE_BLOCKS];
|
||||
static CacheBlock link_blocks[2];
|
||||
|
||||
class CodePageHandler :public PageHandler {
|
||||
|
@ -393,38 +390,68 @@ static INLINE void cache_addd(Bit32u val) {
|
|||
|
||||
static void gen_return(BlockReturn retcode);
|
||||
|
||||
static void cache_init(void) {
|
||||
Bits i;
|
||||
memset(&cache_blocks,0,sizeof(cache_blocks));
|
||||
static Bit8u * cache_code=NULL;
|
||||
static CacheBlock * cache_blocks=NULL;
|
||||
|
||||
/* Define temporary pagesize so the MPROTECT case and the regular case share as much code as possible */
|
||||
#if (C_HAVE_MPROTECT)
|
||||
mprotect(cache_code,sizeof(cache_code),PROT_WRITE|PROT_READ|PROT_EXEC);
|
||||
mprotect(cache_code_link_blocks,sizeof(cache_code_link_blocks),PROT_WRITE|PROT_READ|PROT_EXEC);
|
||||
#define PAGESIZE_TEMP PAGESIZE
|
||||
#else
|
||||
#define PAGESIZE_TEMP 1
|
||||
#endif
|
||||
cache.block.free=&cache_blocks[0];
|
||||
for (i=0;i<CACHE_BLOCKS-1;i++) {
|
||||
cache_blocks[i].link[0].to=(CacheBlock *)1;
|
||||
cache_blocks[i].link[1].to=(CacheBlock *)1;
|
||||
cache_blocks[i].cache.next=&cache_blocks[i+1];
|
||||
}
|
||||
CacheBlock * block=cache_getblock();
|
||||
cache.block.first=block;
|
||||
cache.block.active=block;
|
||||
block->cache.start=&cache_code[0];
|
||||
block->cache.size=CACHE_TOTAL;
|
||||
block->cache.next=0; //Last block in the list
|
||||
cache.pos=&cache_code_link_blocks[0][0];
|
||||
link_blocks[0].cache.start=cache.pos;
|
||||
gen_return(BR_Link1);
|
||||
cache.pos=&cache_code_link_blocks[1][0];
|
||||
link_blocks[1].cache.start=cache.pos;
|
||||
gen_return(BR_Link2);
|
||||
cache.free_pages=0;
|
||||
cache.last_page=0;
|
||||
cache.used_pages=0;
|
||||
/* Setup the code pages */
|
||||
for (i=0;i<CACHE_PAGES-1;i++) {
|
||||
CodePageHandler * newpage=new CodePageHandler();
|
||||
newpage->next=cache.free_pages;
|
||||
cache.free_pages=newpage;
|
||||
|
||||
|
||||
static void cache_init(bool enable) {
|
||||
static bool cache_initialized = false;
|
||||
Bits i;
|
||||
if (enable) {
|
||||
if (cache_initialized) return;
|
||||
cache_initialized = true;
|
||||
if (cache_blocks == NULL) {
|
||||
cache_blocks=(CacheBlock*)malloc(CACHE_BLOCKS*sizeof(CacheBlock));
|
||||
if(!cache_blocks) E_Exit("Allocating cache_blocks has failed");
|
||||
memset(cache_blocks,0,sizeof(CacheBlock)*CACHE_BLOCKS);
|
||||
cache.block.free=&cache_blocks[0];
|
||||
for (i=0;i<CACHE_BLOCKS-1;i++) {
|
||||
cache_blocks[i].link[0].to=(CacheBlock *)1;
|
||||
cache_blocks[i].link[1].to=(CacheBlock *)1;
|
||||
cache_blocks[i].cache.next=&cache_blocks[i+1];
|
||||
}
|
||||
}
|
||||
#if (C_HAVE_MPROTECT)
|
||||
if(mprotect(cache_code_link_blocks,sizeof(cache_code_link_blocks),PROT_WRITE|PROT_READ|PROT_EXEC))
|
||||
LOG_MSG("Setting excute permission on cache code link blocks has failed");
|
||||
#endif
|
||||
if (cache_code==NULL) {
|
||||
cache_code=(Bit8u*)malloc(CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP-1);
|
||||
if(!cache_code) E_Exit("Allocating dynamic cache failed");
|
||||
#if (C_HAVE_MPROTECT)
|
||||
cache_code=(Bit8u*)(((int)cache_code + PAGESIZE-1) & ~(PAGESIZE-1)); //MEM LEAK. store old pointer if you want to free it.
|
||||
if(mprotect(cache_code,CACHE_TOTAL+CACHE_MAXSIZE,PROT_WRITE|PROT_READ|PROT_EXEC))
|
||||
LOG_MSG("Setting excute permission on the code cache has failed!");
|
||||
#endif
|
||||
CacheBlock * block=cache_getblock();
|
||||
cache.block.first=block;
|
||||
cache.block.active=block;
|
||||
block->cache.start=&cache_code[0];
|
||||
block->cache.size=CACHE_TOTAL;
|
||||
block->cache.next=0; //Last block in the list
|
||||
}
|
||||
/* Setup the default blocks for block linkage returns */
|
||||
cache.pos=&cache_code_link_blocks[0][0];
|
||||
link_blocks[0].cache.start=cache.pos;
|
||||
gen_return(BR_Link1);
|
||||
cache.pos=&cache_code_link_blocks[1][0];
|
||||
link_blocks[1].cache.start=cache.pos;
|
||||
gen_return(BR_Link2);
|
||||
cache.free_pages=0;
|
||||
cache.last_page=0;
|
||||
cache.used_pages=0;
|
||||
/* Setup the code pages */
|
||||
for (i=0;i<CACHE_PAGES-1;i++) {
|
||||
CodePageHandler * newpage=new CodePageHandler();
|
||||
newpage->next=cache.free_pages;
|
||||
cache.free_pages=newpage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: cpu.cpp,v 1.74 2005-08-15 14:17:20 c2woody Exp $ */
|
||||
/* $Id: cpu.cpp,v 1.75 2006-01-30 14:01:52 qbix79 Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include "dosbox.h"
|
||||
|
@ -50,6 +50,7 @@ void CPU_Core_Full_Init(void);
|
|||
void CPU_Core_Normal_Init(void);
|
||||
void CPU_Core_Simple_Init(void);
|
||||
void CPU_Core_Dyn_X86_Init(void);
|
||||
void CPU_Core_Dyn_X86_Cache_Init(bool enable_cache);
|
||||
|
||||
|
||||
/* In debug mode exceptions are tested and dosbox exits when
|
||||
|
@ -1977,6 +1978,10 @@ public:
|
|||
else {
|
||||
LOG_MSG("CPU:Unknown core type %s, switcing back to normal.",core);
|
||||
}
|
||||
|
||||
#if (C_DYNAMIC_X86)
|
||||
CPU_Core_Dyn_X86_Cache_Init(!strcasecmp(core,"dynamic"));
|
||||
#endif
|
||||
|
||||
if(CPU_CycleMax <= 0) CPU_CycleMax = 2500;
|
||||
if(CPU_CycleUp <= 0) CPU_CycleUp = 500;
|
||||
|
|
Loading…
Add table
Reference in a new issue