xref: /qemu/target/i386/emulate/x86_emu.h (revision 77a2dba45cc9a1be7fec6ab88f43d2fa18af52a3)
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 "cpu.h"
25 
26 struct x86_emul_ops {
27     void (*read_mem)(CPUState *cpu, void *data, target_ulong addr, int bytes);
28     void (*write_mem)(CPUState *cpu, void *data, target_ulong addr, int bytes);
29     void (*read_segment_descriptor)(CPUState *cpu, struct x86_segment_descriptor *desc,
30                                     enum X86Seg seg);
31     void (*handle_io)(CPUState *cpu, uint16_t port, void *data, int direction,
32                       int size, int count);
33     void (*simulate_rdmsr)(CPUState *cs);
34     void (*simulate_wrmsr)(CPUState *cs);
35 };
36 
37 extern const struct x86_emul_ops *emul_ops;
38 
39 void init_emu(const struct x86_emul_ops *ops);
40 bool exec_instruction(CPUX86State *env, struct x86_decode *ins);
41 void x86_emul_raise_exception(CPUX86State *env, int exception_index, int error_code);
42 
43 target_ulong read_reg(CPUX86State *env, int reg, int size);
44 void write_reg(CPUX86State *env, int reg, target_ulong val, int size);
45 target_ulong read_val_from_reg(void *reg_ptr, int size);
46 void write_val_to_reg(void *reg_ptr, target_ulong val, int size);
47 void write_val_ext(CPUX86State *env, struct x86_decode_op *decode, target_ulong val, int size);
48 uint8_t *read_mmio(CPUX86State *env, target_ulong ptr, int bytes);
49 target_ulong read_val_ext(CPUX86State *env, struct x86_decode_op *decode, int size);
50 
51 void exec_movzx(CPUX86State *env, struct x86_decode *decode);
52 void exec_shl(CPUX86State *env, struct x86_decode *decode);
53 void exec_movsx(CPUX86State *env, struct x86_decode *decode);
54 void exec_ror(CPUX86State *env, struct x86_decode *decode);
55 void exec_rol(CPUX86State *env, struct x86_decode *decode);
56 void exec_rcl(CPUX86State *env, struct x86_decode *decode);
57 void exec_rcr(CPUX86State *env, struct x86_decode *decode);
58 #endif
59