Fix x86_64 support
PATCH 5/5 Fix x86_64 support
This is the very same patch I sent to this list some weeks ago. It implements DIRECT_JUMP for x86_64, making it work with gcc4.
exec-all.h +16 -1
@@ -142,6 +142,9 @@ static inline int tlb_set_page(CPUState *env, target_ulong vaddr,#if defined(__i386__) && !defined(_WIN32)#define USE_DIRECT_JUMP #endif +#if defined(__x86_64__) +#define USE_DIRECT_JUMP +#endif typedef struct TranslationBlock { target_ulong pc; /* simulated PC corresponding to this block (EIP + CS base) */
@@ -228,7 +231,7 @@ static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr asmvolatile ("sync" : : :"memory" ); asm volatile ("isync" : : : "memory"); } -#elif defined(__i386__) +#elif defined(__i386__) || defined(__x86_64__)static inline void tb_set_jmp_target1 (unsigned long jmp_addr,unsigned long addr) {/* patch the branch destination */
@@ -320,6 +323,18 @@ do {\ "1:\n");\ } while (0) +#elif defined(__x86_64__) && defined(USE_DIRECT_JUMP ) + +#define GOTO_TB (opname, tbparam, n)\ +do {\ + asm volatile (ASM_DATA_SECTION\ + ASM_OP_LABEL_NAME(n, opname) ":\n"\ + ".quad 1f\n"\ + ASM_PREVIOUS_SECTION \ + "jmp " ASM_NAME(__op_jmp) #n "\n"\ + "1:\n");\ +} while (0) +#else /* jump to next block operations (more portable code, does not need
dyngen.c +11 -0
@@ -1931,6 +2076,17 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, type =ELF32_R_TYPE (rel->r_info); addend = rel->r_addend; reloc_offset = rel->r_offset - start_offset; +if (strstart (sym_name,"__op_jmp" , &p)) { +int n; + n =strtol (p,NULL ,10 ); +/* __op_jmp relocations are done at +runtime to do translated block +chaining: the offset of the instruction +needs to be stored */ +fprintf (outfile," jmp_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n" , + n, reloc_offset); +continue ; + }switch (type) {case R_X86_64_32 : fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (uint32_t)%s + %d;\n",