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 "helper-tcg.h" 23 #include "qemu/accel.h" 24 #include "hw/core/accel-cpu.h" 25 26 #include "tcg-cpu.h" 27 28 /* Frob eflags into and out of the CPU temporary format. */ 29 30 static void x86_cpu_exec_enter(CPUState *cs) 31 { 32 X86CPU *cpu = X86_CPU(cs); 33 CPUX86State *env = &cpu->env; 34 35 CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); 36 env->df = 1 - (2 * ((env->eflags >> 10) & 1)); 37 CC_OP = CC_OP_EFLAGS; 38 env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); 39 } 40 41 static void x86_cpu_exec_exit(CPUState *cs) 42 { 43 X86CPU *cpu = X86_CPU(cs); 44 CPUX86State *env = &cpu->env; 45 46 env->eflags = cpu_compute_eflags(env); 47 } 48 49 static void x86_cpu_synchronize_from_tb(CPUState *cs, 50 const TranslationBlock *tb) 51 { 52 X86CPU *cpu = X86_CPU(cs); 53 54 cpu->env.eip = tb->pc - tb->cs_base; 55 } 56 57 #include "hw/core/tcg-cpu-ops.h" 58 59 static const struct TCGCPUOps x86_tcg_ops = { 60 .initialize = tcg_x86_init, 61 .synchronize_from_tb = x86_cpu_synchronize_from_tb, 62 .cpu_exec_enter = x86_cpu_exec_enter, 63 .cpu_exec_exit = x86_cpu_exec_exit, 64 .cpu_exec_interrupt = x86_cpu_exec_interrupt, 65 .do_interrupt = x86_cpu_do_interrupt, 66 .tlb_fill = x86_cpu_tlb_fill, 67 #ifndef CONFIG_USER_ONLY 68 .debug_excp_handler = breakpoint_handler, 69 #endif /* !CONFIG_USER_ONLY */ 70 }; 71 72 static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) 73 { 74 /* for x86, all cpus use the same set of operations */ 75 cc->tcg_ops = &x86_tcg_ops; 76 } 77 78 static void tcg_cpu_class_init(CPUClass *cc) 79 { 80 cc->init_accel_cpu = tcg_cpu_init_ops; 81 } 82 83 static void tcg_cpu_xsave_init(void) 84 { 85 #define XO(bit, field) \ 86 x86_ext_save_areas[bit].offset = offsetof(X86XSaveArea, field); 87 88 XO(XSTATE_FP_BIT, legacy); 89 XO(XSTATE_SSE_BIT, legacy); 90 XO(XSTATE_YMM_BIT, avx_state); 91 XO(XSTATE_BNDREGS_BIT, bndreg_state); 92 XO(XSTATE_BNDCSR_BIT, bndcsr_state); 93 XO(XSTATE_OPMASK_BIT, opmask_state); 94 XO(XSTATE_ZMM_Hi256_BIT, zmm_hi256_state); 95 XO(XSTATE_Hi16_ZMM_BIT, hi16_zmm_state); 96 XO(XSTATE_PKRU_BIT, pkru_state); 97 98 #undef XO 99 } 100 101 /* 102 * TCG-specific defaults that override all CPU models when using TCG 103 */ 104 static PropValue tcg_default_props[] = { 105 { "vme", "off" }, 106 { NULL, NULL }, 107 }; 108 109 static void tcg_cpu_instance_init(CPUState *cs) 110 { 111 X86CPU *cpu = X86_CPU(cs); 112 /* Special cases not set in the X86CPUDefinition structs: */ 113 x86_cpu_apply_props(cpu, tcg_default_props); 114 115 tcg_cpu_xsave_init(); 116 } 117 118 static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) 119 { 120 AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); 121 122 #ifndef CONFIG_USER_ONLY 123 acc->cpu_realizefn = tcg_cpu_realizefn; 124 #endif /* CONFIG_USER_ONLY */ 125 126 acc->cpu_class_init = tcg_cpu_class_init; 127 acc->cpu_instance_init = tcg_cpu_instance_init; 128 } 129 static const TypeInfo tcg_cpu_accel_type_info = { 130 .name = ACCEL_CPU_NAME("tcg"), 131 132 .parent = TYPE_ACCEL_CPU, 133 .class_init = tcg_cpu_accel_class_init, 134 .abstract = true, 135 }; 136 static void tcg_cpu_accel_register_types(void) 137 { 138 type_register_static(&tcg_cpu_accel_type_info); 139 } 140 type_init(tcg_cpu_accel_register_types); 141