mirror of https://github.com/inolen/redream.git
don't copy jit memory interface struct
This commit is contained in:
parent
0907a66cd5
commit
b32ffe7a68
|
@ -11,7 +11,6 @@
|
||||||
#include "hw/memory.h"
|
#include "hw/memory.h"
|
||||||
#include "hw/scheduler.h"
|
#include "hw/scheduler.h"
|
||||||
#include "hw/sh4/sh4_code_cache.h"
|
#include "hw/sh4/sh4_code_cache.h"
|
||||||
#include "jit/backend/backend.h"
|
|
||||||
#include "jit/frontend/sh4/sh4_analyze.h"
|
#include "jit/frontend/sh4/sh4_analyze.h"
|
||||||
#include "sys/time.h"
|
#include "sys/time.h"
|
||||||
#include "ui/nuklear.h"
|
#include "ui/nuklear.h"
|
||||||
|
@ -703,19 +702,19 @@ static bool sh4_init(struct device *dev) {
|
||||||
sh4->scheduler = dc->scheduler;
|
sh4->scheduler = dc->scheduler;
|
||||||
sh4->space = sh4->base.memory->space;
|
sh4->space = sh4->base.memory->space;
|
||||||
|
|
||||||
struct jit_memory_interface memory_if = {
|
sh4->memory_if =
|
||||||
&sh4->ctx,
|
(struct jit_memory_interface){&sh4->ctx,
|
||||||
sh4->base.memory->space->protected_base,
|
sh4->base.memory->space->protected_base,
|
||||||
sh4->base.memory->space,
|
sh4->base.memory->space,
|
||||||
&as_read8,
|
&as_read8,
|
||||||
&as_read16,
|
&as_read16,
|
||||||
&as_read32,
|
&as_read32,
|
||||||
&as_read64,
|
&as_read64,
|
||||||
&as_write8,
|
&as_write8,
|
||||||
&as_write16,
|
&as_write16,
|
||||||
&as_write32,
|
&as_write32,
|
||||||
&as_write64};
|
&as_write64};
|
||||||
sh4->code_cache = sh4_cache_create(&memory_if, &sh4_compile_pc);
|
sh4->code_cache = sh4_cache_create(&sh4->memory_if, &sh4_compile_pc);
|
||||||
|
|
||||||
// initialize context
|
// initialize context
|
||||||
sh4->ctx.sh4 = sh4;
|
sh4->ctx.sh4 = sh4;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "hw/dreamcast.h"
|
#include "hw/dreamcast.h"
|
||||||
#include "hw/memory.h"
|
#include "hw/memory.h"
|
||||||
#include "hw/sh4/sh4_types.h"
|
#include "hw/sh4/sh4_types.h"
|
||||||
|
#include "jit/backend/backend.h"
|
||||||
#include "jit/frontend/sh4/sh4_context.h"
|
#include "jit/frontend/sh4/sh4_context.h"
|
||||||
|
|
||||||
struct dreamcast;
|
struct dreamcast;
|
||||||
|
@ -37,6 +38,7 @@ struct sh4 {
|
||||||
struct scheduler *scheduler;
|
struct scheduler *scheduler;
|
||||||
struct address_space *space;
|
struct address_space *space;
|
||||||
|
|
||||||
|
struct jit_memory_interface memory_if;
|
||||||
struct sh4_cache *code_cache;
|
struct sh4_cache *code_cache;
|
||||||
struct sh4_ctx ctx;
|
struct sh4_ctx ctx;
|
||||||
uint8_t cache[0x2000]; // 8kb cache
|
uint8_t cache[0x2000]; // 8kb cache
|
||||||
|
|
|
@ -281,7 +281,7 @@ code_pointer_t sh4_cache_compile_code(struct sh4_cache *cache,
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sh4_cache *sh4_cache_create(const struct jit_memory_interface *memory_if,
|
struct sh4_cache *sh4_cache_create(struct jit_memory_interface *memory_if,
|
||||||
code_pointer_t default_code) {
|
code_pointer_t default_code) {
|
||||||
struct sh4_cache *cache = calloc(1, sizeof(struct sh4_cache));
|
struct sh4_cache *cache = calloc(1, sizeof(struct sh4_cache));
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ code_pointer_t sh4_cache_compile_code(struct sh4_cache *cache,
|
||||||
uint32_t guest_addr, uint8_t *guest_ptr,
|
uint32_t guest_addr, uint8_t *guest_ptr,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
struct sh4_cache *sh4_cache_create(const struct jit_memory_interface *memory_if,
|
struct sh4_cache *sh4_cache_create(struct jit_memory_interface *memory_if,
|
||||||
code_pointer_t default_code);
|
code_pointer_t default_code);
|
||||||
void sh4_cache_destroy(struct sh4_cache *cache);
|
void sh4_cache_destroy(struct sh4_cache *cache);
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ enum xmm_constant {
|
||||||
|
|
||||||
struct x64_backend {
|
struct x64_backend {
|
||||||
struct jit_backend base;
|
struct jit_backend base;
|
||||||
struct jit_memory_interface memory_if;
|
struct jit_memory_interface *memory_if;
|
||||||
|
|
||||||
Xbyak::CodeGenerator *codegen;
|
Xbyak::CodeGenerator *codegen;
|
||||||
csh capstone_handle;
|
csh capstone_handle;
|
||||||
|
@ -351,8 +351,8 @@ static void x64_backend_emit_prolog(struct x64_backend *backend, struct ir *ir,
|
||||||
e.sub(e.rsp, stack_size);
|
e.sub(e.rsp, stack_size);
|
||||||
|
|
||||||
// copy guest context and memory base to argument registers
|
// copy guest context and memory base to argument registers
|
||||||
e.mov(e.r14, reinterpret_cast<uint64_t>(backend->memory_if.ctx_base));
|
e.mov(e.r14, reinterpret_cast<uint64_t>(backend->memory_if->ctx_base));
|
||||||
e.mov(e.r15, reinterpret_cast<uint64_t>(backend->memory_if.mem_base));
|
e.mov(e.r15, reinterpret_cast<uint64_t>(backend->memory_if->mem_base));
|
||||||
|
|
||||||
*out_stack_size = stack_size;
|
*out_stack_size = stack_size;
|
||||||
}
|
}
|
||||||
|
@ -518,7 +518,7 @@ static bool x64_backend_handle_exception(struct jit_backend *base,
|
||||||
// figure out the guest address that was being accessed
|
// figure out the guest address that was being accessed
|
||||||
const uint8_t *fault_addr = reinterpret_cast<const uint8_t *>(ex->fault_addr);
|
const uint8_t *fault_addr = reinterpret_cast<const uint8_t *>(ex->fault_addr);
|
||||||
const uint8_t *protected_start =
|
const uint8_t *protected_start =
|
||||||
reinterpret_cast<const uint8_t *>(backend->memory_if.mem_base);
|
reinterpret_cast<const uint8_t *>(backend->memory_if->mem_base);
|
||||||
uint32_t guest_addr = static_cast<uint32_t>(fault_addr - protected_start);
|
uint32_t guest_addr = static_cast<uint32_t>(fault_addr - protected_start);
|
||||||
|
|
||||||
// instead of handling the dynamic callback from inside of the exception
|
// instead of handling the dynamic callback from inside of the exception
|
||||||
|
@ -537,26 +537,26 @@ static bool x64_backend_handle_exception(struct jit_backend *base,
|
||||||
if (mov.is_load) {
|
if (mov.is_load) {
|
||||||
// prep argument registers (memory object, guest_addr) for read function
|
// prep argument registers (memory object, guest_addr) for read function
|
||||||
ex->thread_state.r[x64_arg0_idx] =
|
ex->thread_state.r[x64_arg0_idx] =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.mem_self);
|
reinterpret_cast<uint64_t>(backend->memory_if->mem_self);
|
||||||
ex->thread_state.r[x64_arg1_idx] = static_cast<uint64_t>(guest_addr);
|
ex->thread_state.r[x64_arg1_idx] = static_cast<uint64_t>(guest_addr);
|
||||||
|
|
||||||
// prep function call address for thunk
|
// prep function call address for thunk
|
||||||
switch (mov.operand_size) {
|
switch (mov.operand_size) {
|
||||||
case 1:
|
case 1:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.r8);
|
reinterpret_cast<uint64_t>(backend->memory_if->r8);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.r16);
|
reinterpret_cast<uint64_t>(backend->memory_if->r16);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.r32);
|
reinterpret_cast<uint64_t>(backend->memory_if->r32);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.r64);
|
reinterpret_cast<uint64_t>(backend->memory_if->r64);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ static bool x64_backend_handle_exception(struct jit_backend *base,
|
||||||
// prep argument registers (memory object, guest_addr, value) for write
|
// prep argument registers (memory object, guest_addr, value) for write
|
||||||
// function
|
// function
|
||||||
ex->thread_state.r[x64_arg0_idx] =
|
ex->thread_state.r[x64_arg0_idx] =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.mem_self);
|
reinterpret_cast<uint64_t>(backend->memory_if->mem_self);
|
||||||
ex->thread_state.r[x64_arg1_idx] = static_cast<uint64_t>(guest_addr);
|
ex->thread_state.r[x64_arg1_idx] = static_cast<uint64_t>(guest_addr);
|
||||||
ex->thread_state.r[x64_arg2_idx] = ex->thread_state.r[mov.reg];
|
ex->thread_state.r[x64_arg2_idx] = ex->thread_state.r[mov.reg];
|
||||||
|
|
||||||
|
@ -575,19 +575,19 @@ static bool x64_backend_handle_exception(struct jit_backend *base,
|
||||||
switch (mov.operand_size) {
|
switch (mov.operand_size) {
|
||||||
case 1:
|
case 1:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.w8);
|
reinterpret_cast<uint64_t>(backend->memory_if->w8);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.w16);
|
reinterpret_cast<uint64_t>(backend->memory_if->w16);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.w32);
|
reinterpret_cast<uint64_t>(backend->memory_if->w32);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
ex->thread_state.rax =
|
ex->thread_state.rax =
|
||||||
reinterpret_cast<uint64_t>(backend->memory_if.w64);
|
reinterpret_cast<uint64_t>(backend->memory_if->w64);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,23 +731,23 @@ EMITTER(LOAD_SLOW) {
|
||||||
void *fn = nullptr;
|
void *fn = nullptr;
|
||||||
switch (instr->result->type) {
|
switch (instr->result->type) {
|
||||||
case VALUE_I8:
|
case VALUE_I8:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.r8);
|
fn = reinterpret_cast<void *>(backend->memory_if->r8);
|
||||||
break;
|
break;
|
||||||
case VALUE_I16:
|
case VALUE_I16:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.r16);
|
fn = reinterpret_cast<void *>(backend->memory_if->r16);
|
||||||
break;
|
break;
|
||||||
case VALUE_I32:
|
case VALUE_I32:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.r32);
|
fn = reinterpret_cast<void *>(backend->memory_if->r32);
|
||||||
break;
|
break;
|
||||||
case VALUE_I64:
|
case VALUE_I64:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.r64);
|
fn = reinterpret_cast<void *>(backend->memory_if->r64);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_FATAL("Unexpected load result type");
|
LOG_FATAL("Unexpected load result type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.mov(arg0, reinterpret_cast<uint64_t>(backend->memory_if.mem_self));
|
e.mov(arg0, reinterpret_cast<uint64_t>(backend->memory_if->mem_self));
|
||||||
e.mov(arg1, a);
|
e.mov(arg1, a);
|
||||||
e.call(reinterpret_cast<void *>(fn));
|
e.call(reinterpret_cast<void *>(fn));
|
||||||
e.mov(result, e.rax);
|
e.mov(result, e.rax);
|
||||||
|
@ -760,23 +760,23 @@ EMITTER(STORE_SLOW) {
|
||||||
void *fn = nullptr;
|
void *fn = nullptr;
|
||||||
switch (instr->arg[1]->type) {
|
switch (instr->arg[1]->type) {
|
||||||
case VALUE_I8:
|
case VALUE_I8:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.w8);
|
fn = reinterpret_cast<void *>(backend->memory_if->w8);
|
||||||
break;
|
break;
|
||||||
case VALUE_I16:
|
case VALUE_I16:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.w16);
|
fn = reinterpret_cast<void *>(backend->memory_if->w16);
|
||||||
break;
|
break;
|
||||||
case VALUE_I32:
|
case VALUE_I32:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.w32);
|
fn = reinterpret_cast<void *>(backend->memory_if->w32);
|
||||||
break;
|
break;
|
||||||
case VALUE_I64:
|
case VALUE_I64:
|
||||||
fn = reinterpret_cast<void *>(backend->memory_if.w64);
|
fn = reinterpret_cast<void *>(backend->memory_if->w64);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_FATAL("Unexpected store value type");
|
LOG_FATAL("Unexpected store value type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.mov(arg0, reinterpret_cast<uint64_t>(backend->memory_if.mem_self));
|
e.mov(arg0, reinterpret_cast<uint64_t>(backend->memory_if->mem_self));
|
||||||
e.mov(arg1, a);
|
e.mov(arg1, a);
|
||||||
e.mov(arg2, b);
|
e.mov(arg2, b);
|
||||||
e.call(reinterpret_cast<void *>(fn));
|
e.call(reinterpret_cast<void *>(fn));
|
||||||
|
@ -1648,7 +1648,7 @@ EMITTER(BRANCH_COND) {
|
||||||
EMITTER(CALL_EXTERNAL) {
|
EMITTER(CALL_EXTERNAL) {
|
||||||
const Xbyak::Reg addr = x64_backend_register(backend, instr->arg[0]);
|
const Xbyak::Reg addr = x64_backend_register(backend, instr->arg[0]);
|
||||||
|
|
||||||
e.mov(arg0, reinterpret_cast<uint64_t>(backend->memory_if.ctx_base));
|
e.mov(arg0, reinterpret_cast<uint64_t>(backend->memory_if->ctx_base));
|
||||||
if (instr->arg[1]) {
|
if (instr->arg[1]) {
|
||||||
const Xbyak::Reg arg = x64_backend_register(backend, instr->arg[1]);
|
const Xbyak::Reg arg = x64_backend_register(backend, instr->arg[1]);
|
||||||
e.mov(arg1, arg);
|
e.mov(arg1, arg);
|
||||||
|
@ -1657,8 +1657,7 @@ EMITTER(CALL_EXTERNAL) {
|
||||||
e.call(e.rax);
|
e.call(e.rax);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct jit_backend *x64_backend_create(
|
struct jit_backend *x64_backend_create(struct jit_memory_interface *memory_if) {
|
||||||
const struct jit_memory_interface *memory_if) {
|
|
||||||
struct x64_backend *backend = reinterpret_cast<struct x64_backend *>(
|
struct x64_backend *backend = reinterpret_cast<struct x64_backend *>(
|
||||||
calloc(1, sizeof(struct x64_backend)));
|
calloc(1, sizeof(struct x64_backend)));
|
||||||
|
|
||||||
|
@ -1669,7 +1668,7 @@ struct jit_backend *x64_backend_create(
|
||||||
backend->base.dump_code = &x64_backend_dump_code;
|
backend->base.dump_code = &x64_backend_dump_code;
|
||||||
backend->base.handle_exception = &x64_backend_handle_exception;
|
backend->base.handle_exception = &x64_backend_handle_exception;
|
||||||
|
|
||||||
backend->memory_if = *memory_if;
|
backend->memory_if = memory_if;
|
||||||
|
|
||||||
backend->codegen = new Xbyak::CodeGenerator(x64_code_size, x64_code);
|
backend->codegen = new Xbyak::CodeGenerator(x64_code_size, x64_code);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
extern const struct jit_register x64_registers[];
|
extern const struct jit_register x64_registers[];
|
||||||
extern const int x64_num_registers;
|
extern const int x64_num_registers;
|
||||||
|
|
||||||
struct jit_backend *x64_backend_create(
|
struct jit_backend *x64_backend_create(struct jit_memory_interface *memory_if);
|
||||||
const struct jit_memory_interface *memory_if);
|
|
||||||
void x64_backend_destroy(struct jit_backend *b);
|
void x64_backend_destroy(struct jit_backend *b);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue