--- upstream/dynamips-0.2.7-RC1/mips64_jit.h 2007/10/06 16:23:47 7 +++ upstream/dynamips-0.2.7-RC2/mips64_jit.h 2007/10/06 16:24:54 8 @@ -9,6 +9,7 @@ #define __MIPS64_JIT_H__ #include "utils.h" +#include "sbox.h" /* Size of executable page area (in Mb) */ #ifndef __CYGWIN__ @@ -23,6 +24,11 @@ /* Maximum number of X86 chunks */ #define MIPS_JIT_MAX_CHUNKS 32 +/* Size of hash for PC lookup */ +#define MIPS_JIT_PC_HASH_BITS 16 +#define MIPS_JIT_PC_HASH_MASK ((1 << MIPS_JIT_PC_HASH_BITS) - 1) +#define MIPS_JIT_PC_HASH_SIZE (1 << MIPS_JIT_PC_HASH_BITS) + /* Instruction jump patch */ struct mips64_insn_patch { u_char *jit_insn; @@ -43,7 +49,6 @@ m_uint64_t start_pc; u_char **jit_insn_ptr; m_uint64_t acc_count; - m_uint32_t phys_page; mips_insn_t *mips_code; u_int mips_trans_pos; u_int jit_chunk_pos; @@ -76,12 +81,44 @@ static forced_inline u_char *mips64_jit_tcb_get_host_ptr(mips64_jit_tcb_t *b,m_uint64_t vaddr) { - m_uint64_t offset; + m_uint32_t offset; - offset = (vaddr - b->start_pc) >> 2; + offset = ((m_uint32_t)vaddr & MIPS_MIN_PAGE_IMASK) >> 2; return(b->jit_insn_ptr[offset]); } +/* Check if the specified address belongs to the specified block */ +static forced_inline +int mips64_jit_tcb_local_addr(mips64_jit_tcb_t *block,m_uint64_t vaddr, + u_char **jit_addr) +{ + if ((vaddr & MIPS_MIN_PAGE_MASK) == block->start_pc) { + *jit_addr = mips64_jit_tcb_get_host_ptr(block,vaddr); + return(1); + } + + return(0); +} + +/* Check if PC register matches the compiled block virtual address */ +static forced_inline +int mips64_jit_tcb_match(cpu_mips_t *cpu,mips64_jit_tcb_t *block) +{ + m_uint64_t vpage; + + vpage = cpu->pc & ~(m_uint64_t)MIPS_MIN_PAGE_IMASK; + return(block->start_pc == vpage); +} + +/* Compute the hash index for the specified PC value */ +static forced_inline m_uint32_t mips64_jit_get_pc_hash(m_uint64_t pc) +{ + m_uint32_t page_hash; + + page_hash = sbox_u32(pc >> MIPS_MIN_PAGE_SHIFT); + return((page_hash ^ (page_hash >> 12)) & MIPS_JIT_PC_HASH_MASK); +} + /* Check if there are pending IRQ */ extern void mips64_check_pending_irq(mips64_jit_tcb_t *b); @@ -97,6 +134,9 @@ /* Shutdown the JIT */ void mips64_jit_shutdown(cpu_mips_t *cpu); +/* Check if an instruction is in a delay slot or not */ +int mips64_jit_is_delay_slot(mips64_jit_tcb_t *b,m_uint64_t pc); + /* Fetch a MIPS instruction and emit corresponding x86 translated code */ struct mips64_insn_tag *mips64_jit_fetch_and_emit(cpu_mips_t *cpu, mips64_jit_tcb_t *block, @@ -110,10 +150,6 @@ void mips64_jit_tcb_free(cpu_mips_t *cpu,mips64_jit_tcb_t *block, int list_removal); -/* Check if the specified address belongs to the specified block */ -int mips64_jit_tcb_local_addr(mips64_jit_tcb_t *block,m_uint64_t vaddr, - u_char **haddr); - /* Execute compiled MIPS code */ void *mips64_jit_run_cpu(cpu_gen_t *cpu);