mirror of https://github.com/inolen/redream.git
replace jit_block pointer with addr / size as arguments to dump_code and translate_code
This commit is contained in:
parent
d3946809a0
commit
5d844c5092
|
@ -50,7 +50,7 @@ static int interp_backend_handle_exception(struct jit_backend *base,
|
|||
}
|
||||
|
||||
static void interp_backend_dump_code(struct jit_backend *base,
|
||||
const struct jit_block *block,
|
||||
const uint8_t *addr, int size,
|
||||
FILE *output) {}
|
||||
|
||||
static void interp_backend_reset(struct jit_backend *base) {}
|
||||
|
|
|
@ -576,14 +576,12 @@ static int x64_backend_handle_exception(struct jit_backend *base,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void x64_backend_dump_code(struct jit_backend *base,
|
||||
const struct jit_block *block, FILE *output) {
|
||||
static void x64_backend_dump_code(struct jit_backend *base, const uint8_t *addr,
|
||||
int size, FILE *output) {
|
||||
struct x64_backend *backend = container_of(base, struct x64_backend, base);
|
||||
const uint8_t *code = (const uint8_t *)block->host_addr;
|
||||
int size = block->host_size;
|
||||
|
||||
cs_insn *insns;
|
||||
size_t count = cs_disasm(backend->capstone_handle, code, size, 0, 0, &insns);
|
||||
size_t count = cs_disasm(backend->capstone_handle, addr, size, 0, 0, &insns);
|
||||
CHECK(count);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
|
|
|
@ -17,15 +17,15 @@ static const struct jit_opdef *armv3_frontend_lookup_op(
|
|||
}
|
||||
|
||||
static void armv3_frontend_dump_code(struct jit_frontend *base,
|
||||
const struct jit_block *block,
|
||||
uint32_t begin_addr, int size,
|
||||
FILE *output) {
|
||||
struct armv3_frontend *frontend = (struct armv3_frontend *)base;
|
||||
struct jit_guest *guest = frontend->guest;
|
||||
|
||||
char buffer[128];
|
||||
|
||||
for (int offset = 0; offset < block->guest_size; offset += 4) {
|
||||
uint32_t addr = block->guest_addr + offset;
|
||||
for (int offset = 0; offset < size; offset += 4) {
|
||||
uint32_t addr = begin_addr + offset;
|
||||
uint32_t data = guest->r32(guest->space, addr);
|
||||
|
||||
armv3_format(addr, data, buffer, sizeof(buffer));
|
||||
|
@ -36,13 +36,13 @@ static void armv3_frontend_dump_code(struct jit_frontend *base,
|
|||
}
|
||||
|
||||
static void armv3_frontend_translate_code(struct jit_frontend *base,
|
||||
struct jit_block *block,
|
||||
uint32_t begin_addr, int size,
|
||||
struct ir *ir) {
|
||||
struct armv3_frontend *frontend = (struct armv3_frontend *)base;
|
||||
struct armv3_guest *guest = (struct armv3_guest *)frontend->guest;
|
||||
|
||||
for (int offset = 0; offset < block->guest_size; offset += 4) {
|
||||
uint32_t addr = block->guest_addr + offset;
|
||||
for (int offset = 0; offset < size; offset += 4) {
|
||||
uint32_t addr = begin_addr + offset;
|
||||
uint32_t data = guest->r32(guest->space, addr);
|
||||
struct jit_opdef *def = armv3_get_opdef(data);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ static const struct jit_opdef *sh4_frontend_lookup_op(struct jit_frontend *base,
|
|||
}
|
||||
|
||||
static void sh4_frontend_dump_code(struct jit_frontend *base,
|
||||
const struct jit_block *block,
|
||||
uint32_t begin_addr, int size,
|
||||
FILE *output) {
|
||||
struct sh4_frontend *frontend = (struct sh4_frontend *)base;
|
||||
struct jit_guest *guest = frontend->guest;
|
||||
|
@ -43,8 +43,8 @@ static void sh4_frontend_dump_code(struct jit_frontend *base,
|
|||
|
||||
int offset = 0;
|
||||
|
||||
while (offset < block->guest_size) {
|
||||
uint32_t addr = block->guest_addr + offset;
|
||||
while (offset < size) {
|
||||
uint32_t addr = begin_addr + offset;
|
||||
uint16_t data = guest->r16(guest->space, addr);
|
||||
union sh4_instr instr = {data};
|
||||
struct jit_opdef *def = sh4_get_opdef(data);
|
||||
|
@ -55,7 +55,7 @@ static void sh4_frontend_dump_code(struct jit_frontend *base,
|
|||
offset += 2;
|
||||
|
||||
if (def->flags & SH4_FLAG_DELAYED) {
|
||||
uint32_t delay_addr = block->guest_addr + offset;
|
||||
uint32_t delay_addr = begin_addr + offset;
|
||||
uint16_t delay_data = guest->r16(guest->space, delay_addr);
|
||||
union sh4_instr delay_instr = {delay_data};
|
||||
|
||||
|
@ -140,7 +140,7 @@ static int sh4_frontend_is_idle_loop(struct sh4_frontend *frontend,
|
|||
}
|
||||
|
||||
static void sh4_frontend_translate_code(struct jit_frontend *base,
|
||||
struct jit_block *block,
|
||||
uint32_t begin_addr, int size,
|
||||
struct ir *ir) {
|
||||
struct sh4_frontend *frontend = (struct sh4_frontend *)base;
|
||||
struct sh4_guest *guest = (struct sh4_guest *)frontend->guest;
|
||||
|
@ -148,11 +148,15 @@ static void sh4_frontend_translate_code(struct jit_frontend *base,
|
|||
|
||||
PROF_ENTER("cpu", "sh4_frontend_translate_code");
|
||||
|
||||
int offset = 0;
|
||||
struct jit_opdef *def = NULL;
|
||||
struct ir_insert_point delay_point;
|
||||
|
||||
/* cheap idle skip. in an idle loop, the block is just spinning, waiting for
|
||||
an interrupt such as vblank before it'll exit. scale the block's number of
|
||||
cycles in order to yield execution faster, enabling the interrupt to
|
||||
actually be generated */
|
||||
int idle_loop = sh4_frontend_is_idle_loop(frontend, block->guest_addr);
|
||||
int idle_loop = sh4_frontend_is_idle_loop(frontend, begin_addr);
|
||||
int cycle_scale = idle_loop ? 10 : 1;
|
||||
|
||||
/* generate code specialized for the current fpscr state */
|
||||
|
@ -164,13 +168,8 @@ static void sh4_frontend_translate_code(struct jit_frontend *base,
|
|||
flags |= SH4_DOUBLE_SZ;
|
||||
}
|
||||
|
||||
/* translate the actual block */
|
||||
int offset = 0;
|
||||
struct jit_opdef *def = NULL;
|
||||
struct ir_insert_point delay_point;
|
||||
|
||||
while (offset < block->guest_size) {
|
||||
uint32_t addr = block->guest_addr + offset;
|
||||
while (offset < size) {
|
||||
uint32_t addr = begin_addr + offset;
|
||||
uint16_t data = guest->r16(guest->space, addr);
|
||||
union sh4_instr instr = {data};
|
||||
sh4_translate_cb cb = sh4_get_translator(data);
|
||||
|
@ -191,7 +190,7 @@ static void sh4_frontend_translate_code(struct jit_frontend *base,
|
|||
offset += 2;
|
||||
|
||||
if (def->flags & SH4_FLAG_DELAYED) {
|
||||
uint32_t delay_addr = block->guest_addr + offset;
|
||||
uint32_t delay_addr = begin_addr + offset;
|
||||
uint32_t delay_data = guest->r16(guest->space, delay_addr);
|
||||
union sh4_instr delay_instr = {delay_data};
|
||||
sh4_translate_cb delay_cb = sh4_get_translator(delay_data);
|
||||
|
@ -237,7 +236,7 @@ static void sh4_frontend_translate_code(struct jit_frontend *base,
|
|||
struct ir_instr *tail_instr =
|
||||
list_last_entry(&tail_block->instrs, struct ir_instr, it);
|
||||
ir_set_current_instr(ir, tail_instr);
|
||||
ir_branch(ir, ir_alloc_i32(ir, block->guest_addr + block->guest_size));
|
||||
ir_branch(ir, ir_alloc_i32(ir, begin_addr + size));
|
||||
}
|
||||
|
||||
PROF_LEAVE();
|
||||
|
|
|
@ -342,14 +342,14 @@ void jit_compile_code(struct jit *jit, uint32_t guest_addr) {
|
|||
jit_free_block(jit, existing);
|
||||
}
|
||||
|
||||
/* translate the source machine code into ir */
|
||||
/* translate guest code into ir */
|
||||
struct ir ir = {0};
|
||||
ir.buffer = jit->ir_buffer;
|
||||
ir.capacity = sizeof(jit->ir_buffer);
|
||||
jit->frontend->translate_code(jit->frontend, block, &ir);
|
||||
jit->frontend->translate_code(jit->frontend, guest_addr, guest_size, &ir);
|
||||
|
||||
#if 0
|
||||
jit->frontend->dump_code(jit->frontend, block);
|
||||
jit->frontend->dump_code(jit->frontend, guest_addr, guest_size);
|
||||
#endif
|
||||
|
||||
/* dump unoptimized block */
|
||||
|
|
|
@ -98,7 +98,6 @@ void jit_run(struct jit *jit, int cycles);
|
|||
|
||||
void jit_compile_code(struct jit *jit, uint32_t guest_addr);
|
||||
void jit_link_code(struct jit *jit, void *code, uint32_t target);
|
||||
|
||||
void jit_invalidate_code(struct jit *jit);
|
||||
void jit_free_code(struct jit *jit);
|
||||
|
||||
|
|
|
@ -84,8 +84,7 @@ struct jit_backend {
|
|||
/* compile interface */
|
||||
void (*reset)(struct jit_backend *);
|
||||
int (*assemble_code)(struct jit_backend *, struct jit_block *, struct ir *);
|
||||
void (*dump_code)(struct jit_backend *, const struct jit_block *,
|
||||
FILE *output);
|
||||
void (*dump_code)(struct jit_backend *, const uint8_t *, int, FILE *);
|
||||
int (*handle_exception)(struct jit_backend *, struct exception_state *);
|
||||
|
||||
/* dispatch interface */
|
||||
|
|
|
@ -27,10 +27,8 @@ struct jit_frontend {
|
|||
void (*destroy)(struct jit_frontend *);
|
||||
|
||||
void (*analyze_code)(struct jit_frontend *, uint32_t, int *);
|
||||
void (*translate_code)(struct jit_frontend *, struct jit_block *,
|
||||
struct ir *);
|
||||
void (*dump_code)(struct jit_frontend *, const struct jit_block *,
|
||||
FILE *output);
|
||||
void (*translate_code)(struct jit_frontend *, uint32_t, int, struct ir *);
|
||||
void (*dump_code)(struct jit_frontend *, uint32_t, int, FILE *output);
|
||||
|
||||
const struct jit_opdef *(*lookup_op)(struct jit_frontend *, const void *);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue