libpcsxcore/new_dynarec/emu_if.o: CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -DDRC_DBG
endif
-ifeq "$(DRC_CACHE_BASE)" "1"
-libpcsxcore/new_dynarec/%.o: CFLAGS += -DBASE_ADDR_FIXED=1
+ifeq "$(BASE_ADDR_DYNAMIC)" "1"
+libpcsxcore/new_dynarec/%.o: CFLAGS += -DBASE_ADDR_DYNAMIC=1
endif
# spu
echo "USE_DYNAREC = 1" >> $config_mak
fi
if [ "$drc_cache_base" = "yes" ]; then
- echo "DRC_CACHE_BASE = 1" >> $config_mak
+ echo "BASE_ADDR_DYNAMIC = 1" >> $config_mak
fi
if [ "$have_c64x_dsp" = "yes" ]; then
echo "HAVE_C64_TOOLS = 1" >> $config_mak
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus/PCSX - assem_arm.c *
* Copyright (C) 2009-2011 Ari64 *
- * Copyright (C) 2010-2011 Gražvydas "notaz" Ignotas *
+ * Copyright (C) 2010-2021 Gražvydas "notaz" Ignotas *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
#include "pcnt.h"
#include "arm_features.h"
-#if defined(BASE_ADDR_FIXED)
-#elif defined(BASE_ADDR_DYNAMIC)
-u_char *translation_cache;
-#else
-u_char translation_cache[1 << TARGET_SIZE_2] __attribute__((aligned(4096)));
-#endif
-
#ifndef __MACH__
#define CALLER_SAVE_REGS 0x100f
#else
emit_cmovb_imm(1,rt);
}
+static int can_jump_or_call(const void *a)
+{
+ intptr_t offset = (u_char *)a - out - 8;
+ return (-33554432 <= offset && offset < 33554432);
+}
+
static void emit_call(const void *a_)
{
int a = (int)a_;
emit_writeword(ECX,&last_count);
#endif
//DEBUG <
- emit_jmp(linker);
+ emit_far_jump(linker);
}
static void check_extjump2(void *src)
if(cc<0)
emit_loadreg(CCREG,2);
emit_addimm(cc<0?2:cc,CLOCK_ADJUST((int)stubs[n].d+1),2);
- emit_call(handler);
+ emit_far_call(handler);
if(itype[i]==C1LS||itype[i]==C2LS||(rt>=0&&rt1[i]!=0)) {
mov_loadtype_adj(type,0,rt);
}
int rt=get_reg(regmap,target);
if(rs<0) rs=get_reg(regmap,-1);
assert(rs>=0);
- u_int is_dynamic,far_call=0;
+ u_int is_dynamic;
uintptr_t host_addr = 0;
void *handler;
int cc=get_reg(regmap,CCREG);
emit_movimm(addr,0);
else if(rs!=0)
emit_mov(rs,0);
- int offset=(u_char *)handler-out-8;
- if(offset<-33554432||offset>=33554432) {
- // unreachable memhandler, a plugin func perhaps
- emit_movimm((u_int)handler,12);
- far_call=1;
- }
if(cc<0)
emit_loadreg(CCREG,2);
if(is_dynamic) {
emit_writeword(2,&Count);
}
- if(far_call)
- emit_callreg(12);
- else
- emit_call(handler);
+ emit_far_call(handler);
if(rt>=0&&rt1[i]!=0) {
switch(type) {
emit_loadreg(CCREG,2);
emit_addimm(cc<0?2:cc,CLOCK_ADJUST((int)stubs[n].d+1),2);
// returns new cycle_count
- emit_call(handler);
+ emit_far_call(handler);
emit_addimm(0,-CLOCK_ADJUST((int)stubs[n].d+1),cc<0?2:cc);
if(cc<0)
emit_storereg(CCREG,2);
emit_addimm(cc<0?2:cc,CLOCK_ADJUST(adj+1),2);
emit_movimm((u_int)handler,3);
// returns new cycle_count
- emit_call(jump_handler_write_h);
+ emit_far_call(jump_handler_write_h);
emit_addimm(0,-CLOCK_ADJUST(adj+1),cc<0?2:cc);
if(cc<0)
emit_storereg(CCREG,2);
{
assem_debug("do_dirty_stub %x\n",start+i*4);
do_dirty_stub_emit_args(start + i*4);
- emit_call(verify_code);
+ emit_far_call(verify_code);
void *entry = out;
load_regs_entry(i);
if (entry == out)
static void do_dirty_stub_ds()
{
do_dirty_stub_emit_args(start + 1);
- emit_call(verify_code_ds);
+ emit_far_call(verify_code_ds);
}
/* Special assem */
save_regs_all(reglist);
#ifdef PCNT
emit_movimm(op,0);
- emit_call(pcnt_gte_start);
+ emit_far_call(pcnt_gte_start);
#endif
emit_addimm(FP,(int)&psxRegs.CP2D.r[0]-(int)&dynarec_local,0); // cop2 regs
}
{
#ifdef PCNT
emit_movimm(op,0);
- emit_call(pcnt_gte_end);
+ emit_far_call(pcnt_gte_end);
#endif
restore_regs_all(reglist);
}
static void c2op_call_MACtoIR(int lm,int need_flags)
{
if(need_flags)
- emit_call(lm?gteMACtoIR_lm1:gteMACtoIR_lm0);
+ emit_far_call(lm?gteMACtoIR_lm1:gteMACtoIR_lm0);
else
- emit_call(lm?gteMACtoIR_lm1_nf:gteMACtoIR_lm0_nf);
+ emit_far_call(lm?gteMACtoIR_lm1_nf:gteMACtoIR_lm0_nf);
}
static void c2op_call_rgb_func(void *func,int lm,int need_ir,int need_flags)
{
- emit_call(func);
+ emit_far_call(func);
// func is C code and trashes r0
emit_addimm(FP,(int)&psxRegs.CP2D.r[0]-(int)&dynarec_local,0);
if(need_flags||need_ir)
c2op_call_MACtoIR(lm,need_flags);
- emit_call(need_flags?gteMACtoRGB:gteMACtoRGB_nf);
+ emit_far_call(need_flags?gteMACtoRGB:gteMACtoRGB_nf);
}
static void c2op_assemble(int i,struct regstat *i_regs)
emit_readword(&zeromem_ptr,7);
#ifdef __ARM_NEON__
emit_movimm(source[i],1); // opcode
- emit_call(gteMVMVA_part_neon);
+ emit_far_call(gteMVMVA_part_neon);
if(need_flags) {
emit_movimm(lm,1);
- emit_call(gteMACtoIR_flags_neon);
+ emit_far_call(gteMACtoIR_flags_neon);
}
#else
if(cv==3&&shift)
- emit_call((int)gteMVMVA_part_cv3sh12_arm);
+ emit_far_call((int)gteMVMVA_part_cv3sh12_arm);
else {
emit_movimm(shift,1);
- emit_call((int)(need_flags?gteMVMVA_part_arm:gteMVMVA_part_nf_arm));
+ emit_far_call((int)(need_flags?gteMVMVA_part_arm:gteMVMVA_part_nf_arm));
}
if(need_flags||need_ir)
c2op_call_MACtoIR(lm,need_flags);
c2op_prologue(c2op,reglist);
emit_movimm(source[i],1); // opcode
emit_writeword(1,&psxRegs.code);
- emit_call((int)(need_flags?gte_handlers[c2op]:gte_handlers_nf[c2op]));
+ emit_far_call(need_flags?gte_handlers[c2op]:gte_handlers_nf[c2op]);
#endif
break;
}
case GTE_OP:
c2op_prologue(c2op,reglist);
- emit_call(shift?gteOP_part_shift:gteOP_part_noshift);
+ emit_far_call(shift?gteOP_part_shift:gteOP_part_noshift);
if(need_flags||need_ir) {
emit_addimm(FP,(int)&psxRegs.CP2D.r[0]-(int)&dynarec_local,0);
c2op_call_MACtoIR(lm,need_flags);
break;
case GTE_SQR:
c2op_prologue(c2op,reglist);
- emit_call(shift?gteSQR_part_shift:gteSQR_part_noshift);
+ emit_far_call(shift?gteSQR_part_shift:gteSQR_part_noshift);
if(need_flags||need_ir) {
emit_addimm(FP,(int)&psxRegs.CP2D.r[0]-(int)&dynarec_local,0);
c2op_call_MACtoIR(lm,need_flags);
emit_movimm(source[i],1); // opcode
emit_writeword(1,&psxRegs.code);
#endif
- emit_call(need_flags?gte_handlers[c2op]:gte_handlers_nf[c2op]);
+ emit_far_call(need_flags?gte_handlers[c2op]:gte_handlers_nf[c2op]);
break;
}
c2op_epilogue(c2op,reglist);
static void do_jump_vaddr(int rs)
{
- emit_jmp(jump_vaddr_reg[rs]);
+ emit_far_jump(jump_vaddr_reg[rs]);
}
static void do_preload_rhash(int r) {
}
// CPU-architecture-specific initialization
-static void arch_init() {
+static void arch_init(void)
+{
+ uintptr_t diff = (u_char *)&ndrc->tramp.f - (u_char *)&ndrc->tramp.ops - 8;
+ struct tramp_insns *ops = ndrc->tramp.ops;
+ size_t i;
+ assert(!(diff & 3));
+ assert(diff < 0x1000);
+ start_tcache_write(ops, (u_char *)ops + sizeof(ndrc->tramp.ops));
+ for (i = 0; i < ARRAY_SIZE(ndrc->tramp.ops); i++)
+ ops[i].ldrpc = 0xe5900000 | rd_rn_rm(15,15,0) | diff; // ldr pc, [=val]
+ end_tcache_write(ops, (u_char *)ops + sizeof(ndrc->tramp.ops));
}
// vim:shiftwidth=2:expandtab
#define TARGET_SIZE_2 24 // 2^24 = 16 megabytes
-// Code generator target address
-#if defined(BASE_ADDR_FIXED)
- // "round" address helpful for debug
- // this produces best code, but not many platforms allow it,
- // only use if you are sure this range is always free
- #define BASE_ADDR_ 0x1000000
- #define translation_cache (u_char *)BASE_ADDR_
-#elif defined(BASE_ADDR_DYNAMIC)
- // for platforms that can't just use .bss buffer, like vita
- // otherwise better to use the next option for closer branches
- extern u_char *translation_cache;
-#else
- // using a static buffer in .bss
- extern u_char translation_cache[1 << TARGET_SIZE_2];
-#endif
+struct tramp_insns
+{
+ u_int ldrpc;
+};
+
#include "pcnt.h"
#include "arm_features.h"
-#if defined(BASE_ADDR_FIXED)
-#elif defined(BASE_ADDR_DYNAMIC)
-u_char *translation_cache;
-#else
-u_char translation_cache[1 << TARGET_SIZE_2] __attribute__((aligned(4096)));
-#endif
-static u_int needs_clear_cache[1<<(TARGET_SIZE_2-17)];
-
#define CALLER_SAVE_REGS 0x0007ffff
#define unused __attribute__((unused))
emit_cmovb_imm(1,rt);
}
+static int can_jump_or_call(const void *a)
+{
+ intptr_t diff = (u_char *)a - out;
+ return (-134217728 <= diff && diff <= 134217727);
+}
+
static void emit_call(const void *a)
{
intptr_t diff = (u_char *)a - out;
// addr is in the current recompiled block (max 256k)
// offset shouldn't exceed +/-1MB
emit_adr(addr, 1);
- emit_jmp(linker);
+ emit_far_jump(linker);
}
static void check_extjump2(void *src)
if(cc<0)
emit_loadreg(CCREG,2);
emit_addimm(cc<0?2:cc,CLOCK_ADJUST((int)stubs[n].d+1),2);
- emit_call(handler);
+ emit_far_call(handler);
// (no cycle reload after read)
if(itype[i]==C1LS||itype[i]==C2LS||(rt>=0&&rt1[i]!=0)) {
loadstore_extend(type,0,rt);
emit_addimm64(1, l1 & 0xfff, 1);
}
else
- emit_call(do_memhandler_pre);
+ emit_far_call(do_memhandler_pre);
- emit_call(handler);
+ emit_far_call(handler);
// (no cycle reload after read)
if(rt>=0&&rt1[i]!=0)
emit_loadreg(CCREG,2);
emit_addimm(cc<0?2:cc,CLOCK_ADJUST((int)stubs[n].d+1),2);
// returns new cycle_count
- emit_call(handler);
+ emit_far_call(handler);
emit_addimm(0,-CLOCK_ADJUST((int)stubs[n].d+1),cc<0?2:cc);
if(cc<0)
emit_storereg(CCREG,2);
emit_loadreg(CCREG, (cc_use = 2));
emit_addimm(cc_use, CLOCK_ADJUST(adj+1), 2);
- emit_call(do_memhandler_pre);
- emit_call(handler);
- emit_call(do_memhandler_post);
+ emit_far_call(do_memhandler_pre);
+ emit_far_call(handler);
+ emit_far_call(do_memhandler_post);
emit_addimm(0, -CLOCK_ADJUST(adj+1), cc_use);
if (cc < 0)
emit_storereg(CCREG, cc_use);
emit_loadlp_ofs(0, 0); // ldr x1, source
emit_loadlp_ofs(0, 1); // ldr x2, copy
emit_movz(slen*4, 2);
- emit_call(verify_code_arm64);
+ emit_far_call(verify_code_arm64);
void *jmp = out;
emit_cbz(0, 0);
emit_movz(vaddr & 0xffff, 0);
emit_movk_lsl16(vaddr >> 16, 0);
- emit_call(get_addr);
+ emit_far_call(get_addr);
emit_jmpreg(0);
set_jump_target(jmp, out);
}
save_load_regs_all(1, reglist);
#ifdef PCNT
emit_movimm(op, 0);
- emit_call(pcnt_gte_start);
+ emit_far_call(pcnt_gte_start);
#endif
// pointer to cop2 regs
emit_addimm64(FP, (u_char *)&psxRegs.CP2D.r[0] - (u_char *)&dynarec_local, 0);
{
#ifdef PCNT
emit_movimm(op, 0);
- emit_call(pcnt_gte_end);
+ emit_far_call(pcnt_gte_end);
#endif
save_load_regs_all(0, reglist);
}
c2op_prologue(c2op,reglist);
emit_movimm(source[i],1); // opcode
emit_writeword(1,&psxRegs.code);
- emit_call(need_flags?gte_handlers[c2op]:gte_handlers_nf[c2op]);
+ emit_far_call(need_flags?gte_handlers[c2op]:gte_handlers_nf[c2op]);
break;
}
c2op_epilogue(c2op,reglist);
{
if (rs != 0)
emit_mov(rs, 0);
- emit_call(get_addr_ht);
+ emit_far_call(get_addr_ht);
emit_jmpreg(0);
}
}
// CPU-architecture-specific initialization
-static void arch_init() {
+static void arch_init(void)
+{
+ uintptr_t diff = (u_char *)&ndrc->tramp.f - (u_char *)&ndrc->tramp.ops;
+ struct tramp_insns *ops = ndrc->tramp.ops;
+ size_t i;
+ assert(!(diff & 3));
+ start_tcache_write(ops, (u_char *)ops + sizeof(ndrc->tramp.ops));
+ for (i = 0; i < ARRAY_SIZE(ndrc->tramp.ops); i++) {
+ ops[i].ldr = 0x58000000 | imm19_rt(diff >> 2, 17); // ldr x17, [=val]
+ ops[i].br = 0xd61f0000 | rm_rn_rd(0, 17, 0); // br x17
+ }
+ end_tcache_write(ops, (u_char *)ops + sizeof(ndrc->tramp.ops));
}
// vim:shiftwidth=2:expandtab
#define SSP_CALLER_REGS (8*20)
#define SSP_ALL (SSP_CALLEE_REGS+SSP_CALLER_REGS)
+#define TARGET_SIZE_2 24 // 2^24 = 16 megabytes
+
#ifndef __ASSEMBLER__
extern char *invc_ptr;
-#define TARGET_SIZE_2 24 // 2^24 = 16 megabytes
+struct tramp_insns
+{
+ u_int ldr;
+ u_int br;
+};
-// Code generator target address
-#if defined(BASE_ADDR_DYNAMIC)
- // for platforms that can't just use .bss buffer (are there any on arm64?)
- extern u_char *translation_cache;
-#else
- // using a static buffer in .bss
- extern u_char translation_cache[1 << TARGET_SIZE_2];
-#endif
+static void clear_cache_arm64(char *start, char *end);
#endif // !__ASSEMBLY__
#define MAXBLOCK 4096
#define MAX_OUTPUT_BLOCK_SIZE 262144
+struct ndrc_mem
+{
+ u_char translation_cache[1 << TARGET_SIZE_2];
+ struct
+ {
+ struct tramp_insns ops[2048 / sizeof(struct tramp_insns)];
+ const void *f[2048 / sizeof(void *)];
+ } tramp;
+};
+
+#ifdef BASE_ADDR_DYNAMIC
+static struct ndrc_mem *ndrc;
+#else
+static struct ndrc_mem ndrc_ __attribute__((aligned(4096)));
+static struct ndrc_mem *ndrc = &ndrc_;
+#endif
+
// stubs
enum stub_type {
CC_STUB = 1,
static void *get_direct_memhandler(void *table, u_int addr,
enum stub_type type, uintptr_t *addr_host);
static void pass_args(int a0, int a1);
+static void emit_far_jump(const void *f);
+static void emit_far_call(const void *f);
static void mprotect_w_x(void *start, void *end, int is_x)
{
static void *start_block(void)
{
u_char *end = out + MAX_OUTPUT_BLOCK_SIZE;
- if (end > translation_cache + (1<<TARGET_SIZE_2))
- end = translation_cache + (1<<TARGET_SIZE_2);
+ if (end > ndrc->translation_cache + sizeof(ndrc->translation_cache))
+ end = ndrc->translation_cache + sizeof(ndrc->translation_cache);
start_tcache_write(out, end);
return out;
}
#include "assem_arm64.c"
#endif
+static void *get_trampoline(const void *f)
+{
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(ndrc->tramp.f); i++) {
+ if (ndrc->tramp.f[i] == f || ndrc->tramp.f[i] == NULL)
+ break;
+ }
+ if (i == ARRAY_SIZE(ndrc->tramp.f)) {
+ SysPrintf("trampoline table is full, last func %p\n", f);
+ abort();
+ }
+ if (ndrc->tramp.f[i] == NULL) {
+ start_tcache_write(&ndrc->tramp.f[i], &ndrc->tramp.f[i + 1]);
+ ndrc->tramp.f[i] = f;
+ end_tcache_write(&ndrc->tramp.f[i], &ndrc->tramp.f[i + 1]);
+ }
+ return &ndrc->tramp.ops[i];
+}
+
+static void emit_far_jump(const void *f)
+{
+ if (can_jump_or_call(f)) {
+ emit_jmp(f);
+ return;
+ }
+
+ f = get_trampoline(f);
+ emit_jmp(f);
+}
+
+static void emit_far_call(const void *f)
+{
+ if (can_jump_or_call(f)) {
+ emit_call(f);
+ return;
+ }
+
+ f = get_trampoline(f);
+ emit_call(f);
+}
+
// Add virtual address mapping to linked list
void ll_add(struct ll_entry **head,int vaddr,void *addr)
{
set_jump_target(stubs[n].addr, out);
save_regs(reglist);
if(stubs[n].b!=0) emit_mov(stubs[n].b,0);
- emit_call(invalidate_addr);
+ emit_far_call(invalidate_addr);
restore_regs(reglist);
emit_jmp(stubs[n].retaddr); // return address
}
emit_movimm(start+i*4+4,0);
emit_writeword(0,&pcaddr);
emit_addimm(HOST_CCREG,2,HOST_CCREG);
- emit_call(get_addr_ht);
+ emit_far_call(get_addr_ht);
emit_jmpreg(0);
}
}
emit_storereg(CCREG,HOST_CCREG);
emit_loadreg(rs1[i],1);
emit_movimm(copr,0);
- emit_call(pcsx_mtc0_ds);
+ emit_far_call(pcsx_mtc0_ds);
emit_loadreg(rs1[i],s);
return;
}
emit_movimm(0,HOST_TEMPREG);
emit_writeword(HOST_TEMPREG,&pending_exception);
}
- //else if(copr==12&&is_delayslot) emit_call((int)MTC0_R12);
- //else
if(s==HOST_CCREG)
emit_loadreg(rs1[i],1);
else if(s!=1)
emit_mov(s,1);
emit_movimm(copr,0);
- emit_call(pcsx_mtc0);
+ emit_far_call(pcsx_mtc0);
if(copr==9||copr==11||copr==12||copr==13) {
emit_readword(&Count,HOST_CCREG);
emit_readword(&next_interupt,HOST_TEMPREG);
emit_jeq(0);
emit_readword(&pcaddr, 0);
emit_addimm(HOST_CCREG,2,HOST_CCREG);
- emit_call(get_addr_ht);
+ emit_far_call(get_addr_ht);
emit_jmpreg(0);
set_jump_target(jaddr, out);
}
if(regs[i].regmap_entry[HOST_CCREG]!=CCREG) emit_loadreg(CCREG,HOST_CCREG);
emit_movimm(start+(i-ds)*4,EAX); // Get PC
emit_addimm(HOST_CCREG,CLOCK_ADJUST(ccadj[i]),HOST_CCREG); // CHECK: is this right? There should probably be an extra cycle...
- emit_jmp(ds?fp_exception_ds:fp_exception);
+ emit_far_jump(ds?fp_exception_ds:fp_exception);
}
static void cop2_get_dreg(u_int copr,signed char tl,signed char temp)
if(cc<0)
emit_loadreg(CCREG,2);
emit_addimm(cc<0?2:cc,CLOCK_ADJUST((int)stubs[n].d+1),2);
- emit_call((opcode[i]==0x2a?jump_handle_swl:jump_handle_swr));
+ emit_far_call((opcode[i]==0x2a?jump_handle_swl:jump_handle_swr));
emit_addimm(0,-CLOCK_ADJUST((int)stubs[n].d+1),cc<0?2:cc);
if(cc<0)
emit_storereg(CCREG,2);
emit_addimm(HOST_CCREG,CLOCK_ADJUST(ccadj[i]),HOST_CCREG); // XXX
emit_add(2,HOST_CCREG,2);
emit_writeword(2,&psxRegs.cycle);
- emit_call(func);
- emit_jmp(jump_to_new_pc);
+ emit_far_call(func);
+ emit_far_jump(jump_to_new_pc);
}
static void syscall_assemble(int i,struct regstat *i_regs)
save_regs(reglist);
emit_movimm(start+i*4,0);
emit_writeword(0,&pcaddr);
- emit_call(do_insn_cmp);
+ emit_far_call(do_insn_cmp);
//emit_readword(&cycle,0);
//emit_addimm(0,2,0);
//emit_writeword(0,&cycle);
// Update cycle count
assert(branch_regs[i].regmap[HOST_CCREG]==CCREG||branch_regs[i].regmap[HOST_CCREG]==-1);
if(stubs[n].a) emit_addimm(HOST_CCREG,CLOCK_ADJUST((signed int)stubs[n].a),HOST_CCREG);
- emit_call(cc_interrupt);
+ emit_far_call(cc_interrupt);
if(stubs[n].a) emit_addimm(HOST_CCREG,-CLOCK_ADJUST((signed int)stubs[n].a),HOST_CCREG);
if(stubs[n].d==TAKEN) {
if(internal_branch(ba[i]))
((volatile u_int *)out)[0]++; // make cache dirty
for (i = 0; i < ARRAY_SIZE(ret); i++) {
- out = translation_cache;
+ out = ndrc->translation_cache;
beginning = start_block();
emit_movimm(DRC_TEST_VAL + i, 0); // test
emit_ret();
SysPrintf("test passed.\n");
else
SysPrintf("test failed, will likely crash soon (r=%08x %08x)\n", ret[0], ret[1]);
- out = translation_cache;
+ out = ndrc->translation_cache;
}
// clear the state completely, instead of just marking
void new_dynarec_clear_full()
{
int n;
- out = translation_cache;
+ out = ndrc->translation_cache;
memset(invalid_code,1,sizeof(invalid_code));
memset(hash_table,0xff,sizeof(hash_table));
memset(mini_ht,-1,sizeof(mini_ht));
{
SysPrintf("Init new dynarec\n");
- // allocate/prepare a buffer for translation cache
- // see assem_arm.h for some explanation
-#if defined(BASE_ADDR_FIXED)
- if (mmap(translation_cache, 1 << TARGET_SIZE_2,
- PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE | MAP_ANONYMOUS,
- -1, 0) != translation_cache) {
- SysPrintf("mmap() failed: %s\n", strerror(errno));
- SysPrintf("disable BASE_ADDR_FIXED and recompile\n");
- abort();
- }
-#elif defined(BASE_ADDR_DYNAMIC)
+#ifdef BASE_ADDR_DYNAMIC
#ifdef VITA
sceBlock = sceKernelAllocMemBlockForVM("code", 1 << TARGET_SIZE_2);
if (sceBlock < 0)
SysPrintf("sceKernelAllocMemBlockForVM failed\n");
- int ret = sceKernelGetMemBlockBase(sceBlock, (void **)&translation_cache);
+ int ret = sceKernelGetMemBlockBase(sceBlock, (void **)&ndrc);
if (ret < 0)
SysPrintf("sceKernelGetMemBlockBase failed\n");
#else
- translation_cache = mmap (NULL, 1 << TARGET_SIZE_2,
+ uintptr_t desired_addr = 0;
+ #ifdef __ELF__
+ extern char _end;
+ desired_addr = ((uintptr_t)&_end + 0xffffff) & ~0xffffffl;
+ #endif
+ ndrc = mmap((void *)desired_addr, sizeof(*ndrc),
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- if (translation_cache == MAP_FAILED) {
+ if (ndrc == MAP_FAILED) {
SysPrintf("mmap() failed: %s\n", strerror(errno));
abort();
}
#else
#ifndef NO_WRITE_EXEC
// not all systems allow execute in data segment by default
- if (mprotect(translation_cache, 1<<TARGET_SIZE_2, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
+ if (mprotect(ndrc, sizeof(ndrc->translation_cache) + sizeof(ndrc->tramp.ops),
+ PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
SysPrintf("mprotect() failed: %s\n", strerror(errno));
#endif
#endif
- out = translation_cache;
+ out = ndrc->translation_cache;
cycle_multiplier=200;
new_dynarec_clear_full();
#ifdef HOST_IMM8
void new_dynarec_cleanup()
{
int n;
-#if defined(BASE_ADDR_FIXED) || defined(BASE_ADDR_DYNAMIC)
+#ifdef BASE_ADDR_DYNAMIC
#ifdef VITA
sceKernelFreeMemBlock(sceBlock);
sceBlock = -1;
#else
- if (munmap(translation_cache, 1<<TARGET_SIZE_2) < 0)
+ if (munmap(ndrc, sizeof(*ndrc)) < 0)
SysPrintf("munmap() failed\n");
#endif
#endif
invalid_code[start>>12]=0;
emit_movimm(start,0);
emit_writeword(0,&pcaddr);
- emit_jmp(new_dyna_leave);
+ emit_far_jump(new_dyna_leave);
literal_pool(0);
end_block(beginning);
ll_add_flags(jump_in+page,start,state_rflags,(void *)beginning);
emit_cmp(0,1);
#ifdef __aarch64__
emit_jeq(out + 4*2);
- emit_jmp(new_dyna_leave);
+ emit_far_jump(new_dyna_leave);
#else
emit_jne(new_dyna_leave);
#endif
// If we're within 256K of the end of the buffer,
// start over from the beginning. (Is 256K enough?)
- if (out > translation_cache+(1<<TARGET_SIZE_2)-MAX_OUTPUT_BLOCK_SIZE)
- out = translation_cache;
+ if (out > ndrc->translation_cache + sizeof(ndrc->translation_cache) - MAX_OUTPUT_BLOCK_SIZE)
+ out = ndrc->translation_cache;
// Trap writes to any of the pages we compiled
for(i=start>>12;i<=(start+slen*4)>>12;i++) {
/* Pass 10 - Free memory by expiring oldest blocks */
- int end=(((out-translation_cache)>>(TARGET_SIZE_2-16))+16384)&65535;
+ int end=(((out-ndrc->translation_cache)>>(TARGET_SIZE_2-16))+16384)&65535;
while(expirep!=end)
{
int shift=TARGET_SIZE_2-3; // Divide into 8 blocks
- uintptr_t base=(uintptr_t)translation_cache+((expirep>>13)<<shift); // Base address of this block
+ uintptr_t base=(uintptr_t)ndrc->translation_cache+((expirep>>13)<<shift); // Base address of this block
inv_debug("EXP: Phase %d\n",expirep);
switch((expirep>>11)&3)
{