1 /* 2 * i386 TCG cpu class initialization 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "qemu/osdep.h" 21 #include "cpu.h" 22 #include "tcg-cpu.h" 23 #include "exec/exec-all.h" 24 #include "sysemu/runstate.h" 25 #include "helper-tcg.h" 26 27 #if !defined(CONFIG_USER_ONLY) 28 #include "hw/i386/apic.h" 29 #endif 30 31 /* Frob eflags into and out of the CPU temporary format. */ 32 33 static void x86_cpu_exec_enter(CPUState *cs) 34 { 35 X86CPU *cpu = X86_CPU(cs); 36 CPUX86State *env = &cpu->env; 37 38 CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); 39 env->df = 1 - (2 * ((env->eflags >> 10) & 1)); 40 CC_OP = CC_OP_EFLAGS; 41 env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); 42 } 43 44 static void x86_cpu_exec_exit(CPUState *cs) 45 { 46 X86CPU *cpu = X86_CPU(cs); 47 CPUX86State *env = &cpu->env; 48 49 env->eflags = cpu_compute_eflags(env); 50 } 51 52 static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb) 53 { 54 X86CPU *cpu = X86_CPU(cs); 55 56 cpu->env.eip = tb->pc - tb->cs_base; 57 } 58 59 void tcg_cpu_common_class_init(CPUClass *cc) 60 { 61 cc->do_interrupt = x86_cpu_do_interrupt; 62 cc->cpu_exec_interrupt = x86_cpu_exec_interrupt; 63 cc->synchronize_from_tb = x86_cpu_synchronize_from_tb; 64 cc->cpu_exec_enter = x86_cpu_exec_enter; 65 cc->cpu_exec_exit = x86_cpu_exec_exit; 66 cc->tcg_initialize = tcg_x86_init; 67 cc->tlb_fill = x86_cpu_tlb_fill; 68 #ifndef CONFIG_USER_ONLY 69 cc->debug_excp_handler = breakpoint_handler; 70 #endif 71 } 72