| 1 | /* |
| 2 | * Copyright (C) 2016 Veertu Inc, |
| 3 | * Copyright (C) 2017 Google Inc, |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #ifndef X86_EMU_H |
| 20 | #define X86_EMU_H |
| 21 | |
| 22 | #include "x86.h" |
| 23 | #include "x86_decode.h" |
| 24 | #include "x86_mmu.h" |
| 25 | #include "cpu.h" |
| 26 | |
| 27 | struct x86_emul_ops { |
| 28 | MMUTranslateResult (*mmu_gva_to_gpa) (CPUState *cpu, target_ulong gva, uint64_t *gpa, MMUTranslateFlags flags); |
| 29 | void (*read_segment_descriptor)(CPUState *cpu, struct x86_segment_descriptor *desc, |
| 30 | enum X86Seg seg); |
| 31 | target_ulong (*read_cr) (CPUState *cpu, int cr); |
| 32 | void (*handle_io)(CPUState *cpu, uint16_t port, void *data, int direction, |
| 33 | int size, int count); |
| 34 | bool (*simulate_rdmsr)(CPUState *cs); |
| 35 | bool (*simulate_wrmsr)(CPUState *cs); |
| 36 | bool (*is_protected_mode)(CPUState *cpu); |
| 37 | bool (*is_long_mode)(CPUState *cpu); |
| 38 | bool (*is_user_mode)(CPUState *cpu); |
| 39 | }; |
| 40 | |
| 41 | extern const struct x86_emul_ops *emul_ops; |
| 42 | |
| 43 | void init_emu(const struct x86_emul_ops *ops); |
| 44 | bool exec_instruction(CPUX86State *env, struct x86_decode *ins); |
| 45 | void x86_emul_raise_exception(CPUX86State *env, int exception_index, int error_code); |
| 46 | |
| 47 | target_ulong read_reg(CPUX86State *env, int reg, int size); |
| 48 | void write_reg(CPUX86State *env, int reg, target_ulong val, int size); |
| 49 | target_ulong x86_read_cr(CPUState *cpu, int cr); |
| 50 | |
| 51 | target_ulong read_val_from_reg(void *reg_ptr, int size); |
| 52 | void write_val_to_reg(void *reg_ptr, target_ulong val, int size); |
| 53 | bool write_val_ext(CPUX86State *env, struct x86_decode_op *decode, target_ulong val, int size); |
| 54 | uint8_t *read_mmio(CPUX86State *env, target_ulong ptr, int bytes); |
| 55 | bool read_val_ext(CPUX86State *env, struct x86_decode_op *decode, int size, target_ulong* val); |
| 56 | |
| 57 | bool exec_movzx(CPUX86State *env, struct x86_decode *decode); |
| 58 | bool exec_shl(CPUX86State *env, struct x86_decode *decode); |
| 59 | bool exec_movsx(CPUX86State *env, struct x86_decode *decode); |
| 60 | bool exec_ror(CPUX86State *env, struct x86_decode *decode); |
| 61 | bool exec_rol(CPUX86State *env, struct x86_decode *decode); |
| 62 | bool exec_rcl(CPUX86State *env, struct x86_decode *decode); |
| 63 | bool exec_rcr(CPUX86State *env, struct x86_decode *decode); |
| 64 | #endif |