added OP_CALL_FALLBACK

This commit is contained in:
Anthony Pesch 2016-10-21 18:37:36 -07:00
parent 3490477976
commit 7f0989e8e8
6 changed files with 20 additions and 3 deletions

View File

@ -1652,6 +1652,15 @@ EMITTER(CALL_EXTERNAL) {
e.call(e.rax);
}
EMITTER(CALL_FALLBACK) {
void *fallback = (void *)instr->arg[0]->i64;
uint32_t addr = instr->arg[1]->i32;
e.mov(arg0, addr);
e.mov(e.rax, reinterpret_cast<uint64_t>(fallback));
e.call(e.rax);
}
struct jit_backend *x64_backend_create(const struct jit_guest *guest) {
struct x64_backend *backend = reinterpret_cast<struct x64_backend *>(
calloc(1, sizeof(struct x64_backend)));

View File

@ -737,3 +737,9 @@ void ir_call_external_2(struct ir *ir, struct ir_value *addr,
ir_set_arg0(ir, instr, addr);
ir_set_arg1(ir, instr, arg0);
}
void ir_call_fallback(struct ir *ir, void *fallback, uint32_t raw_instr) {
struct ir_instr *instr = ir_append_instr(ir, OP_CALL_FALLBACK, VALUE_V);
ir_set_arg0(ir, instr, ir_alloc_i64(ir, (uint64_t)fallback));
ir_set_arg1(ir, instr, ir_alloc_i32(ir, raw_instr));
}

View File

@ -325,5 +325,6 @@ void ir_branch_cond(struct ir *ir, struct ir_value *cond,
void ir_call_external_1(struct ir *ir, struct ir_value *addr);
void ir_call_external_2(struct ir *ir, struct ir_value *addr,
struct ir_value *arg0);
void ir_call_fallback(struct ir *ir, void *fallback, uint32_t raw_instr);
#endif

View File

@ -48,3 +48,4 @@ IR_OP(LSHD)
IR_OP(BRANCH)
IR_OP(BRANCH_COND)
IR_OP(CALL_EXTERNAL)
IR_OP(CALL_FALLBACK)

View File

@ -287,9 +287,9 @@ struct jit *jit_create(struct jit_guest *guest, struct jit_frontend *frontend,
// initialize all entries in block jit to reference the default block
jit->default_code = default_code;
jit->code = malloc(jit->guest.max_blocks * sizeof(struct jit_block));
jit->code = malloc(jit->guest.block_max * sizeof(struct jit_block));
for (int i = 0; i < jit->guest.max_blocks; i++) {
for (int i = 0; i < jit->guest.block_max; i++) {
jit->code[i] = default_code;
}

View File

@ -25,7 +25,7 @@ struct jit_guest {
// used by the jit to map guest addresses to block offsets
uint32_t block_mask;
uint32_t block_shift;
int max_blocks;
int block_max;
// used by the backend
void *ctx_base;