JIT: Follow call instructions

This commit is contained in:
Fabian 2018-06-18 11:58:05 -06:00
parent ede7b705b5
commit 5995414f87
2 changed files with 16 additions and 5 deletions

View file

@ -179,9 +179,7 @@ const encodings = [
{ opcode: 0xE6, block_boundary: 1, imm8: 1, skip: 1, }, // out
{ opcode: 0xE7, block_boundary: 1, os: 1, imm8: 1, skip: 1, },
// E8 call: Has immediate jump offset, but we don't really want to follow
// into other functions while generating code
{ opcode: 0xE8, block_boundary: 1, /* jump_offset_imm: 1, */ os: 1, imm1632: 1, custom: 1, skip: 1, },
{ opcode: 0xE8, block_boundary: 1, jump_offset_imm: 1, os: 1, imm1632: 1, custom: 1, skip: 1, }, // call
{ opcode: 0xE9, block_boundary: 1, jump_offset_imm: 1, no_next_instruction: 1, os: 1, imm1632: 1, custom: 1, skip: 1, },
{ opcode: 0xEA, block_boundary: 1, no_next_instruction: 1, os: 1, imm1632: 1, extra_imm16: 1, skip: 1, }, // jmpf
{ opcode: 0xEB, block_boundary: 1, jump_offset_imm: 1, no_next_instruction: 1, imm8s: 1, custom: 1, skip: 1, },

View file

@ -1301,10 +1301,13 @@ static bool jit_find_basic_blocks(uint32_t phys_addr, bool* requires_loop_limit)
int32_t instruction_end = *instruction_pointer;
bool has_next_instruction = (analysis.flags & JIT_INSTR_NO_NEXT_INSTRUCTION_FLAG) == 0;
if((analysis.flags & JIT_INSTR_BLOCK_BOUNDARY_FLAG) == 0)
{
// ordinary instruction, continue at next
assert(!has_jump_target);
assert(has_next_instruction);
if(find_basic_block_index(&basic_blocks, *instruction_pointer) != -1)
{
@ -1326,6 +1329,17 @@ static bool jit_find_basic_blocks(uint32_t phys_addr, bool* requires_loop_limit)
{
// non-conditional jump: continue at jump target
if(has_next_instruction)
{
// Execution will eventually come back to the next instruction (CALL)
assert(marked_as_entry_count < 1000);
marked_as_entry[marked_as_entry_count++] = *instruction_pointer;
assert(to_visit_stack_count < 1000);
to_visit_stack[to_visit_stack_count++] = *instruction_pointer;
}
if(same_page(jump_target, *instruction_pointer))
{
assert(jump_target);
@ -1348,6 +1362,7 @@ static bool jit_find_basic_blocks(uint32_t phys_addr, bool* requires_loop_limit)
else
{
// conditional jump: continue at next and continue at jump target
assert(has_next_instruction);
assert(to_visit_stack_count < 1000);
to_visit_stack[to_visit_stack_count++] = *instruction_pointer;
@ -1392,8 +1407,6 @@ static bool jit_find_basic_blocks(uint32_t phys_addr, bool* requires_loop_limit)
assert((analysis.flags & JIT_INSTR_BLOCK_BOUNDARY_FLAG) && !has_jump_target);
bool has_next_instruction = (analysis.flags & JIT_INSTR_NO_NEXT_INSTRUCTION_FLAG) == 0;
if(has_next_instruction)
{
// block boundary, but execution will eventually come back