xref: /qemu/target/i386/tcg/tcg-cpu.c (revision 138ca49a)
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,
53                                         const TranslationBlock *tb)
54 {
55     X86CPU *cpu = X86_CPU(cs);
56 
57     cpu->env.eip = tb->pc - tb->cs_base;
58 }
59 
60 void tcg_cpu_common_class_init(CPUClass *cc)
61 {
62     cc->do_interrupt = x86_cpu_do_interrupt;
63     cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
64     cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
65     cc->cpu_exec_enter = x86_cpu_exec_enter;
66     cc->cpu_exec_exit = x86_cpu_exec_exit;
67     cc->tcg_initialize = tcg_x86_init;
68     cc->tlb_fill = x86_cpu_tlb_fill;
69 #ifndef CONFIG_USER_ONLY
70     cc->debug_excp_handler = breakpoint_handler;
71 #endif
72 }
73