Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jumk6-0004SF-I7 for qemu-devel@nongnu.org; Sat, 10 May 2008 06:55:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jumk5-0004Rx-4o for qemu-devel@nongnu.org; Sat, 10 May 2008 06:55:53 -0400 Received: from [199.232.76.173] (port=46889 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jumk4-0004Ru-Us for qemu-devel@nongnu.org; Sat, 10 May 2008 06:55:52 -0400 Received: from savannah.gnu.org ([199.232.41.3]:36900 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jumk4-0003Rk-P8 for qemu-devel@nongnu.org; Sat, 10 May 2008 06:55:52 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1Jumk3-0007HP-TS for qemu-devel@nongnu.org; Sat, 10 May 2008 10:55:52 +0000 Received: from bellard by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1Jumk3-0007HL-JY for qemu-devel@nongnu.org; Sat, 10 May 2008 10:55:51 +0000 MIME-Version: 1.0 Errors-To: bellard Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Fabrice Bellard Message-Id: Date: Sat, 10 May 2008 10:55:51 +0000 Subject: [Qemu-devel] [4407] initial global prologue/epilogue implementation Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 4407 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4407 Author: bellard Date: 2008-05-10 10:55:51 +0000 (Sat, 10 May 2008) Log Message: ----------- initial global prologue/epilogue implementation Modified Paths: -------------- trunk/cpu-exec.c trunk/exec.c Modified: trunk/cpu-exec.c =================================================================== --- trunk/cpu-exec.c 2008-05-10 10:52:05 UTC (rev 4406) +++ trunk/cpu-exec.c 2008-05-10 10:55:51 UTC (rev 4407) @@ -18,8 +18,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" +#define CPU_NO_GLOBAL_REGS #include "exec.h" #include "disas.h" +#include "tcg.h" #if !defined(CONFIG_SOFTMMU) #undef EAX @@ -292,7 +294,6 @@ #endif #endif int ret, interrupt_request; - unsigned long (*gen_func)(void); TranslationBlock *tb; uint8_t *tc_ptr; @@ -652,67 +653,7 @@ tc_ptr = tb->tc_ptr; env->current_tb = tb; /* execute the generated code */ - gen_func = (void *)tc_ptr; -#if defined(__sparc__) - __asm__ __volatile__("call %0\n\t" - "mov %%o7,%%i0" - : /* no outputs */ - : "r" (gen_func) - : "i0", "i1", "i2", "i3", "i4", "i5", - "o0", "o1", "o2", "o3", "o4", "o5", - "l0", "l1", "l2", "l3", "l4", "l5", - "l6", "l7"); -#elif defined(__hppa__) - asm volatile ("ble 0(%%sr4,%1)\n" - "copy %%r31,%%r18\n" - "copy %%r28,%0\n" - : "=r" (next_tb) - : "r" (gen_func) - : "r1", "r2", "r3", "r4", "r5", "r6", "r7", - "r8", "r9", "r10", "r11", "r12", "r13", - "r18", "r19", "r20", "r21", "r22", "r23", - "r24", "r25", "r26", "r27", "r28", "r29", - "r30", "r31"); -#elif defined(__arm__) - asm volatile ("mov pc, %0\n\t" - ".global exec_loop\n\t" - "exec_loop:\n\t" - : /* no outputs */ - : "r" (gen_func) - : "r1", "r2", "r3", "r8", "r9", "r10", "r12", "r14"); -#elif defined(__ia64) - struct fptr { - void *ip; - void *gp; - } fp; - - fp.ip = tc_ptr; - fp.gp = code_gen_buffer + 2 * (1 << 20); - (*(void (*)(void)) &fp)(); -#elif defined(__i386) - asm volatile ("sub $12, %%esp\n\t" - "push %%ebp\n\t" - "call *%1\n\t" - "pop %%ebp\n\t" - "add $12, %%esp\n\t" - : "=a" (next_tb) - : "a" (gen_func) - : "ebx", "ecx", "edx", "esi", "edi", "cc", - "memory"); -#elif defined(__x86_64__) - asm volatile ("sub $8, %%rsp\n\t" - "push %%rbp\n\t" - "call *%1\n\t" - "pop %%rbp\n\t" - "add $8, %%rsp\n\t" - : "=a" (next_tb) - : "a" (gen_func) - : "rbx", "rcx", "rdx", "rsi", "rdi", "r8", "r9", - "r10", "r11", "r12", "r13", "r14", "r15", "cc", - "memory"); -#else - next_tb = gen_func(); -#endif + next_tb = tcg_qemu_tb_exec(tc_ptr); env->current_tb = NULL; /* reset soft MMU for next block (it can currently only be set by a memory fault) */ Modified: trunk/exec.c =================================================================== --- trunk/exec.c 2008-05-10 10:52:05 UTC (rev 4406) +++ trunk/exec.c 2008-05-10 10:55:51 UTC (rev 4407) @@ -89,6 +89,7 @@ /* any access to the tbs or the page table must use this lock */ spinlock_t tb_lock = SPIN_LOCK_UNLOCKED; +uint8_t code_gen_prologue[1024] __attribute__((aligned (32))); uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE] __attribute__((aligned (32))); uint8_t *code_gen_ptr; @@ -173,6 +174,31 @@ void *opaque[TARGET_PAGE_SIZE][2][4]; } subpage_t; +#ifdef _WIN32 +static void map_exec(void *addr, long size) +{ + DWORD old_protect; + VirtualProtect(addr, size, + PAGE_EXECUTE_READWRITE, &old_protect); + +} +#else +static void map_exec(void *addr, long size) +{ + unsigned long start, end; + + start = (unsigned long)addr; + start &= ~(qemu_real_host_page_size - 1); + + end = (unsigned long)addr + size; + end += qemu_real_host_page_size - 1; + end &= ~(qemu_real_host_page_size - 1); + + mprotect((void *)start, end - start, + PROT_READ | PROT_WRITE | PROT_EXEC); +} +#endif + static void page_init(void) { /* NOTE: we can always suppose that qemu_host_page_size >= @@ -184,26 +210,12 @@ GetSystemInfo(&system_info); qemu_real_host_page_size = system_info.dwPageSize; - - VirtualProtect(code_gen_buffer, sizeof(code_gen_buffer), - PAGE_EXECUTE_READWRITE, &old_protect); } #else qemu_real_host_page_size = getpagesize(); - { - unsigned long start, end; - - start = (unsigned long)code_gen_buffer; - start &= ~(qemu_real_host_page_size - 1); - - end = (unsigned long)code_gen_buffer + sizeof(code_gen_buffer); - end += qemu_real_host_page_size - 1; - end &= ~(qemu_real_host_page_size - 1); - - mprotect((void *)start, end - start, - PROT_READ | PROT_WRITE | PROT_EXEC); - } #endif + map_exec(code_gen_buffer, sizeof(code_gen_buffer)); + map_exec(code_gen_prologue, sizeof(code_gen_prologue)); if (qemu_host_page_size == 0) qemu_host_page_size = qemu_real_host_page_size;