Skip to contentSkip to conversation

i386: hvf: miscellaneous cleanups

PATCH In review Paolo Bonzini 2 participants 10 messages Oct 3, 2017

lore
Share & tools
lore
#0 lore raw

cover i386: hvf: miscellaneous cleanups

This is an initial set of (untested!) cleanups for the HVF code. If anyone could pick them up, I think they represent the bare minimum that has to be done before we can commit HVF support to master. It's by no means the end, but the existing MMU code in target/i386 could definitely stand a rewrite, and HVF could then use it as well.

They are available at git://github.com/bonzini/qemu.git, branch hvf.

Alex (both of them), Sergio, anyone else who can help?

Paolo

Paolo Bonzini (10):
i386: hvf: move all hvf files in the same directory
i386: hvf: header cleanup
i386: hvf: unify register enums between HVF and the rest
i386: hvf: remove more dead emulator code
i386: hvf: remove ZERO_INIT macro
i386: hvf: abort on decoding error
i386: hvf: simplify flag handling
i386: hvf: remove addr_t
i386: hvf: simplify and fix in/out handling
i386: hvf: cleanup x86_gen.h

 target/i386/Makefile.objs                    |   2 +-
 target/i386/cpu.h                            |  62 ++++---
 target/i386/hvf-utils/panic.h                |  45 +++++
 target/i386/hvf-utils/x86_flags.h            | 243 ---------------------------
 target/i386/{hvf-utils => hvf}/Makefile.objs |   1 +
 target/i386/{hvf-utils => hvf}/README.md     |   0
 target/i386/{ => hvf}/hvf-i386.h             |   2 +-
 target/i386/{hvf-all.c => hvf/hvf.c}         |  36 ++--
 target/i386/{hvf-utils => hvf}/vmcs.h        |   0
 target/i386/{hvf-utils => hvf}/vmx.h         |  10 +-
 target/i386/{hvf-utils => hvf}/x86.c         |  23 +--
 target/i386/{hvf-utils => hvf}/x86.h         | 167 ++++++------------
 target/i386/{hvf-utils => hvf}/x86_cpuid.c   |   0
 target/i386/{hvf-utils => hvf}/x86_cpuid.h   |   0
 target/i386/{hvf-utils => hvf}/x86_decode.c  | 144 ++++++++--------
 target/i386/{hvf-utils => hvf}/x86_decode.h  |  23 ++-
 target/i386/{hvf-utils => hvf}/x86_descr.c   |  26 +--
 target/i386/{hvf-utils => hvf}/x86_descr.h   |  21 ++-
 target/i386/{hvf-utils => hvf}/x86_emu.c     | 238 ++++++++++----------------
 target/i386/{hvf-utils => hvf}/x86_emu.h     |  14 +-
 target/i386/{hvf-utils => hvf}/x86_flags.c   | 237 ++++++++++++--------------
 target/i386/hvf/x86_flags.h                  |  77 +++++++++
 target/i386/{hvf-utils => hvf}/x86_gen.h     |   4 -
 target/i386/{hvf-utils => hvf}/x86_mmu.c     |  36 ++--
 target/i386/{hvf-utils => hvf}/x86_mmu.h     |   8 +-
 target/i386/{hvf-utils => hvf}/x86_task.c    |  65 +++----
 target/i386/{hvf-utils => hvf}/x86_task.h    |   0
 target/i386/{hvf-utils => hvf}/x86hvf.c      |  32 ++--
 target/i386/{hvf-utils => hvf}/x86hvf.h      |   0
 29 files changed, 624 insertions(+), 892 deletions(-)
 create mode 100644 target/i386/hvf-utils/panic.h
 delete mode 100644 target/i386/hvf-utils/x86_flags.h
 rename target/i386/{hvf-utils => hvf}/Makefile.objs (87%)
 rename target/i386/{hvf-utils => hvf}/README.md (100%)
 rename target/i386/{ => hvf}/hvf-i386.h (97%)
 rename target/i386/{hvf-all.c => hvf/hvf.c} (97%)
 rename target/i386/{hvf-utils => hvf}/vmcs.h (100%)
 rename target/i386/{hvf-utils => hvf}/vmx.h (97%)
 rename target/i386/{hvf-utils => hvf}/x86.c (88%)
 rename target/i386/{hvf-utils => hvf}/x86.h (71%)
 rename target/i386/{hvf-utils => hvf}/x86_cpuid.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_cpuid.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_decode.c (96%)
 rename target/i386/{hvf-utils => hvf}/x86_decode.h (94%)
 rename target/i386/{hvf-utils => hvf}/x86_descr.c (82%)
 rename target/i386/{hvf-utils => hvf}/x86_descr.h (75%)
 rename target/i386/{hvf-utils => hvf}/x86_emu.c (84%)
 rename target/i386/{hvf-utils => hvf}/x86_emu.h (75%)
 rename target/i386/{hvf-utils => hvf}/x86_flags.c (57%)
 create mode 100644 target/i386/hvf/x86_flags.h
 rename target/i386/{hvf-utils => hvf}/x86_gen.h (93%)
 rename target/i386/{hvf-utils => hvf}/x86_mmu.c (85%)
 rename target/i386/{hvf-utils => hvf}/x86_mmu.h (84%)
 rename target/i386/{hvf-utils => hvf}/x86_task.c (81%)
 rename target/i386/{hvf-utils => hvf}/x86_task.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86hvf.c (93%)
 rename target/i386/{hvf-utils => hvf}/x86hvf.h (100%)
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/10 i386: hvf: move all hvf files in the same directory

Just call it hvf/, no need for the "utils" suffix.

---
 target/i386/Makefile.objs                    |  2 +-
 target/i386/cpu.h                            |  2 +-
 target/i386/{hvf-utils => hvf}/Makefile.objs |  1 +
 target/i386/{hvf-utils => hvf}/README.md     |  0
 target/i386/{ => hvf}/hvf-i386.h             |  2 +-
 target/i386/{hvf-all.c => hvf/hvf.c}         | 20 ++++++++++----------
 target/i386/{hvf-utils => hvf}/vmcs.h        |  0
 target/i386/{hvf-utils => hvf}/vmx.h         |  0
 target/i386/{hvf-utils => hvf}/x86.c         |  0
 target/i386/{hvf-utils => hvf}/x86.h         |  0
 target/i386/{hvf-utils => hvf}/x86_cpuid.c   |  0
 target/i386/{hvf-utils => hvf}/x86_cpuid.h   |  0
 target/i386/{hvf-utils => hvf}/x86_decode.c  |  0
 target/i386/{hvf-utils => hvf}/x86_decode.h  |  0
 target/i386/{hvf-utils => hvf}/x86_descr.c   |  0
 target/i386/{hvf-utils => hvf}/x86_descr.h   |  0
 target/i386/{hvf-utils => hvf}/x86_emu.c     |  0
 target/i386/{hvf-utils => hvf}/x86_emu.h     |  0
 target/i386/{hvf-utils => hvf}/x86_flags.c   |  0
 target/i386/{hvf-utils => hvf}/x86_flags.h   |  0
 target/i386/{hvf-utils => hvf}/x86_gen.h     |  0
 target/i386/{hvf-utils => hvf}/x86_mmu.c     |  0
 target/i386/{hvf-utils => hvf}/x86_mmu.h     |  0
 target/i386/{hvf-utils => hvf}/x86_task.c    | 20 ++++++++++----------
 target/i386/{hvf-utils => hvf}/x86_task.h    |  0
 target/i386/{hvf-utils => hvf}/x86hvf.c      |  0
 target/i386/{hvf-utils => hvf}/x86hvf.h      |  0
 27 files changed, 24 insertions(+), 23 deletions(-)
 rename target/i386/{hvf-utils => hvf}/Makefile.objs (87%)
 rename target/i386/{hvf-utils => hvf}/README.md (100%)
 rename target/i386/{ => hvf}/hvf-i386.h (97%)
 rename target/i386/{hvf-all.c => hvf/hvf.c} (98%)
 rename target/i386/{hvf-utils => hvf}/vmcs.h (100%)
 rename target/i386/{hvf-utils => hvf}/vmx.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_cpuid.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_cpuid.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_decode.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_decode.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_descr.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_descr.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_emu.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_emu.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_flags.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_flags.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_gen.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_mmu.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86_mmu.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86_task.c (95%)
 rename target/i386/{hvf-utils => hvf}/x86_task.h (100%)
 rename target/i386/{hvf-utils => hvf}/x86hvf.c (100%)
 rename target/i386/{hvf-utils => hvf}/x86hvf.h (100%)
target/i386/Makefile.objs +1 -1
index 0bef89c099..44103a693b 100644
@@ -12,5 +12,5 @@ obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-windows.o
 endif
 ifdef CONFIG_DARWIN
 obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-darwin.o
-obj-$(CONFIG_HVF) += hvf-utils/ hvf-all.o
+obj-$(CONFIG_HVF) += hvf/
 endif
target/i386/cpu.h +1 -1
index 0ae99ef424..238d3e3535 100644
@@ -24,7 +24,7 @@
 #include "cpu-qom.h"
 #include "hyperv-proto.h"
 #if defined(CONFIG_HVF)
-#include "target/i386/hvf-utils/x86.h"
+#include "target/i386/hvf/x86.h"
 #endif
 
 #ifdef TARGET_X86_64
target/i386/hvf/Makefile.objs renamed from target/i386/hvf-utils/Makefile.objs +1 -0
similarity index 87%
rename from target/i386/hvf-utils/Makefile.objs
rename to target/i386/hvf/Makefile.objs
index 79d8969ca8..927b86bc67 100644
@@ -1 +1,2 @@
+obj-y += hvf.o
 obj-y += x86.o x86_cpuid.o x86_decode.o x86_descr.o x86_emu.o x86_flags.o x86_mmu.o x86hvf.o x86_task.o
target/i386/hvf/README.md renamed from target/i386/hvf-utils/README.md +0 -0
similarity index 100%
rename from target/i386/hvf-utils/README.md
rename to target/i386/hvf/README.md
target/i386/hvf/hvf-i386.h renamed from target/i386/hvf-i386.h +1 -1
similarity index 97%
rename from target/i386/hvf-i386.h
rename to target/i386/hvf/hvf-i386.h
index 797718ce34..2232501552 100644
@@ -18,7 +18,7 @@
 
 #include "sysemu/hvf.h"
 #include "cpu.h"
-#include "hvf-utils/x86.h"
+#include "x86.h"
 
 #define HVF_MAX_VCPU 0x10
 #define MAX_VM_ID 0x40
target/i386/hvf/hvf.c renamed from target/i386/hvf-all.c +10 -10
similarity index 98%
rename from target/i386/hvf-all.c
rename to target/i386/hvf/hvf.c
index 81d9b64eae..863226cc9a 100644
@@ -24,16 +24,16 @@
 
 #include "sysemu/hvf.h"
 #include "hvf-i386.h"
-#include "hvf-utils/vmcs.h"
-#include "hvf-utils/vmx.h"
-#include "hvf-utils/x86.h"
-#include "hvf-utils/x86_descr.h"
-#include "hvf-utils/x86_mmu.h"
-#include "hvf-utils/x86_decode.h"
-#include "hvf-utils/x86_emu.h"
-#include "hvf-utils/x86_cpuid.h"
-#include "hvf-utils/x86_task.h"
-#include "hvf-utils/x86hvf.h"
+#include "vmcs.h"
+#include "vmx.h"
+#include "x86.h"
+#include "x86_descr.h"
+#include "x86_mmu.h"
+#include "x86_decode.h"
+#include "x86_emu.h"
+#include "x86_cpuid.h"
+#include "x86_task.h"
+#include "x86hvf.h"
 
 #include <Hypervisor/hv.h>
 #include <Hypervisor/hv_vmx.h>
target/i386/hvf/vmcs.h renamed from target/i386/hvf-utils/vmcs.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/vmcs.h
rename to target/i386/hvf/vmcs.h
target/i386/hvf/vmx.h renamed from target/i386/hvf-utils/vmx.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/vmx.h
rename to target/i386/hvf/vmx.h
target/i386/hvf/x86.c renamed from target/i386/hvf-utils/x86.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86.c
rename to target/i386/hvf/x86.c
target/i386/hvf/x86.h renamed from target/i386/hvf-utils/x86.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86.h
rename to target/i386/hvf/x86.h
target/i386/hvf/x86_cpuid.c renamed from target/i386/hvf-utils/x86_cpuid.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_cpuid.c
rename to target/i386/hvf/x86_cpuid.c
target/i386/hvf/x86_cpuid.h renamed from target/i386/hvf-utils/x86_cpuid.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_cpuid.h
rename to target/i386/hvf/x86_cpuid.h
target/i386/hvf/x86_decode.c renamed from target/i386/hvf-utils/x86_decode.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_decode.c
rename to target/i386/hvf/x86_decode.c
target/i386/hvf/x86_decode.h renamed from target/i386/hvf-utils/x86_decode.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_decode.h
rename to target/i386/hvf/x86_decode.h
target/i386/hvf/x86_descr.c renamed from target/i386/hvf-utils/x86_descr.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_descr.c
rename to target/i386/hvf/x86_descr.c
target/i386/hvf/x86_descr.h renamed from target/i386/hvf-utils/x86_descr.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_descr.h
rename to target/i386/hvf/x86_descr.h
target/i386/hvf/x86_emu.c renamed from target/i386/hvf-utils/x86_emu.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_emu.c
rename to target/i386/hvf/x86_emu.c
target/i386/hvf/x86_emu.h renamed from target/i386/hvf-utils/x86_emu.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_emu.h
rename to target/i386/hvf/x86_emu.h
target/i386/hvf/x86_flags.c renamed from target/i386/hvf-utils/x86_flags.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_flags.c
rename to target/i386/hvf/x86_flags.c
target/i386/hvf/x86_flags.h renamed from target/i386/hvf-utils/x86_flags.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_flags.h
rename to target/i386/hvf/x86_flags.h
target/i386/hvf/x86_gen.h renamed from target/i386/hvf-utils/x86_gen.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_gen.h
rename to target/i386/hvf/x86_gen.h
target/i386/hvf/x86_mmu.c renamed from target/i386/hvf-utils/x86_mmu.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_mmu.c
rename to target/i386/hvf/x86_mmu.c
target/i386/hvf/x86_mmu.h renamed from target/i386/hvf-utils/x86_mmu.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_mmu.h
rename to target/i386/hvf/x86_mmu.h
target/i386/hvf/x86_task.c renamed from target/i386/hvf-utils/x86_task.c +10 -10
similarity index 95%
rename from target/i386/hvf-utils/x86_task.c
rename to target/i386/hvf/x86_task.c
index 1a2646437a..22fde7fc39 100644
@@ -12,16 +12,16 @@
 
 #include "sysemu/hvf.h"
 #include "hvf-i386.h"
-#include "hvf-utils/vmcs.h"
-#include "hvf-utils/vmx.h"
-#include "hvf-utils/x86.h"
-#include "hvf-utils/x86_descr.h"
-#include "hvf-utils/x86_mmu.h"
-#include "hvf-utils/x86_decode.h"
-#include "hvf-utils/x86_emu.h"
-#include "hvf-utils/x86_cpuid.h"
-#include "hvf-utils/x86_task.h"
-#include "hvf-utils/x86hvf.h"
+#include "vmcs.h"
+#include "vmx.h"
+#include "x86.h"
+#include "x86_descr.h"
+#include "x86_mmu.h"
+#include "x86_decode.h"
+#include "x86_emu.h"
+#include "x86_cpuid.h"
+#include "x86_task.h"
+#include "x86hvf.h"
 
 #include <Hypervisor/hv.h>
 #include <Hypervisor/hv_vmx.h>
target/i386/hvf/x86_task.h renamed from target/i386/hvf-utils/x86_task.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86_task.h
rename to target/i386/hvf/x86_task.h
target/i386/hvf/x86hvf.c renamed from target/i386/hvf-utils/x86hvf.c +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86hvf.c
rename to target/i386/hvf/x86hvf.c
target/i386/hvf/x86hvf.h renamed from target/i386/hvf-utils/x86hvf.h +0 -0
similarity index 100%
rename from target/i386/hvf-utils/x86hvf.h
rename to target/i386/hvf/x86hvf.h
Signature · 1 line
2.13.6
#2 lore raw

PATCH 2/10 i386: hvf: header cleanup

In reply to Paolo Bonzini

Remove inclusions of system headers and avoid "pragma once".

---
 target/i386/hvf/x86.h        | 8 +++-----
 target/i386/hvf/x86_decode.h | 9 ++++-----
 target/i386/hvf/x86_descr.h  | 5 ++++-
 3 files changed, 11 insertions(+), 11 deletions(-)
target/i386/hvf/x86.h +3 -5
index 7fd8fede80..ae957fc895 100644
@@ -16,12 +16,9 @@
  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef HVF_X86_H
+#define HVF_X86_H 1
 
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <stdarg.h>
 #include "qemu-common.h"
 #include "x86_gen.h"
 
@@ -474,3 +471,4 @@ static inline uint64_t rdtscp(void)
     return tsc;
 }
 
+#endif
target/i386/hvf/x86_decode.h +4 -5
index 329131360f..50957819f6 100644
@@ -15,12 +15,9 @@
  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef HVF_X86_DECODE_H
+#define HVF_X86_DECODE_H 1
 
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <stdarg.h>
 #include "qemu-common.h"
 #include "x86.h"
 #include "cpu.h"
@@ -323,3 +320,5 @@ void calc_modrm_operand64(CPUX86State *env, struct x86_decode *decode,
                           struct x86_decode_op *op);
 void set_addressing_size(CPUX86State *env, struct x86_decode *decode);
 void set_operand_size(CPUX86State *env, struct x86_decode *decode);
+
+#endif
target/i386/hvf/x86_descr.h +4 -1
index 1285dd3897..034d8e95c5 100644
@@ -16,7 +16,8 @@
  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef HVF_X86_DESCR_H
+#define HVF_X86_DESCR_H 1
 
 #include "x86.h"
 
@@ -53,3 +54,5 @@ uint32_t vmx_read_segment_ar(CPUState *cpu, x86_reg_segment seg);
 void vmx_segment_to_x86_descriptor(struct CPUState *cpu,
                                    struct vmx_segment *vmx_desc,
                                    struct x86_segment_descriptor *desc);
+
+#endif
Signature · 1 line
2.13.6
#3 lore raw

PATCH 3/10 i386: hvf: unify register enums between HVF and the rest

In reply to Paolo Bonzini
---
 target/i386/cpu.h            |  60 +++++++++++-------
 target/i386/hvf/vmx.h        |  10 +--
 target/i386/hvf/x86.c        |  10 +--
 target/i386/hvf/x86.h        | 145 +++++++++++++------------------------------
 target/i386/hvf/x86_decode.c |  80 ++++++++++++------------
 target/i386/hvf/x86_decode.h |   2 +-
 target/i386/hvf/x86_descr.c  |  26 ++++----
 target/i386/hvf/x86_descr.h  |  16 ++---
 target/i386/hvf/x86_emu.c    |  66 ++++++++++----------
 target/i386/hvf/x86_task.c   |  48 +++++++-------
 target/i386/hvf/x86hvf.c     |  32 +++++-----
 11 files changed, 224 insertions(+), 271 deletions(-)
target/i386/cpu.h +36 -24
index 238d3e3535..fb38de7b0e 100644
@@ -59,30 +59,42 @@
 #include "fpu/softfloat.h"
 #endif
 
-#define R_EAX 0
-#define R_ECX 1
-#define R_EDX 2
-#define R_EBX 3
-#define R_ESP 4
-#define R_EBP 5
-#define R_ESI 6
-#define R_EDI 7
-
-#define R_AL 0
-#define R_CL 1
-#define R_DL 2
-#define R_BL 3
-#define R_AH 4
-#define R_CH 5
-#define R_DH 6
-#define R_BH 7
-
-#define R_ES 0
-#define R_CS 1
-#define R_SS 2
-#define R_DS 3
-#define R_FS 4
-#define R_GS 5
+enum {
+    R_RAX = 0,
+    R_RCX = 1,
+    R_RDX = 2,
+    R_RBX = 3,
+    R_RSP = 4,
+    R_RBP = 5,
+    R_RSI = 6,
+    R_RDI = 7,
+    R_R8 = 8,
+    R_R9 = 9,
+    R_R10 = 10,
+    R_R11 = 11,
+    R_R12 = 12,
+    R_R13 = 13,
+    R_R14 = 14,
+    R_R15 = 15,
+
+    R_AL = 0,
+    R_CL = 1,
+    R_DL = 2,
+    R_BL = 3,
+    R_AH = 4,
+    R_CH = 5,
+    R_DH = 6,
+    R_BH = 7,
+};
+
+typedef enum X86Seg {
+    R_ES = 0,
+    R_CS = 1,
+    R_SS = 2,
+    R_DS = 3,
+    R_FS = 4,
+    R_GS = 5,
+} X86Seg;
 
 /* segment descriptor fields */
 #define DESC_G_SHIFT    23
target/i386/hvf/vmx.h +5 -5
index 102075d0d4..9dfcd2f2eb 100644
@@ -88,14 +88,14 @@ static void enter_long_mode(hv_vcpuid_t vcpu, uint64_t cr0, uint64_t efer)
 {
     uint64_t entry_ctls;
 
-    efer |= EFER_LMA;
+    efer |= MSR_EFER_LMA;
     wvmcs(vcpu, VMCS_GUEST_IA32_EFER, efer);
     entry_ctls = rvmcs(vcpu, VMCS_ENTRY_CTLS);
     wvmcs(vcpu, VMCS_ENTRY_CTLS, rvmcs(vcpu, VMCS_ENTRY_CTLS) |
           VM_ENTRY_GUEST_LMA);
 
     uint64_t guest_tr_ar = rvmcs(vcpu, VMCS_GUEST_TR_ACCESS_RIGHTS);
-    if ((efer & EFER_LME) &&
+    if ((efer & MSR_EFER_LME) &&
         (guest_tr_ar & AR_TYPE_MASK) != AR_TYPE_BUSY_64_TSS) {
         wvmcs(vcpu, VMCS_GUEST_TR_ACCESS_RIGHTS,
               (guest_tr_ar & ~AR_TYPE_MASK) | AR_TYPE_BUSY_64_TSS);
@@ -109,7 +109,7 @@ static void exit_long_mode(hv_vcpuid_t vcpu, uint64_t cr0, uint64_t efer)
     entry_ctls = rvmcs(vcpu, VMCS_ENTRY_CTLS);
     wvmcs(vcpu, VMCS_ENTRY_CTLS, entry_ctls & ~VM_ENTRY_GUEST_LMA);
 
-    efer &= ~EFER_LMA;
+    efer &= ~MSR_EFER_LMA;
     wvmcs(vcpu, VMCS_GUEST_IA32_EFER, efer);
 }
 
@@ -121,7 +121,7 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
     uint64_t old_cr0 = rvmcs(vcpu, VMCS_GUEST_CR0);
 
     if ((cr0 & CR0_PG) && (rvmcs(vcpu, VMCS_GUEST_CR4) & CR4_PAE) &&
-        !(efer & EFER_LME)) {
+        !(efer & MSR_EFER_LME)) {
         address_space_rw(&address_space_memory,
                          rvmcs(vcpu, VMCS_GUEST_CR3) & ~0x1f,
                          MEMTXATTRS_UNSPECIFIED,
@@ -138,7 +138,7 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
     cr0 &= ~CR0_CD;
     wvmcs(vcpu, VMCS_GUEST_CR0, cr0 | CR0_NE | CR0_ET);
 
-    if (efer & EFER_LME) {
+    if (efer & MSR_EFER_LME) {
         if (!(old_cr0 & CR0_PG) && (cr0 & CR0_PG)) {
             enter_long_mode(vcpu, cr0, efer);
         }
target/i386/hvf/x86.c +5 -5
index 625ea6cac0..ca0ec2968a 100644
@@ -134,13 +134,13 @@ bool x86_is_v8086(struct CPUState *cpu)
 
 bool x86_is_long_mode(struct CPUState *cpu)
 {
-    return rvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER) & EFER_LMA;
+    return rvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER) & MSR_EFER_LMA;
 }
 
 bool x86_is_long64_mode(struct CPUState *cpu)
 {
     struct vmx_segment desc;
-    vmx_read_segment_descriptor(cpu, &desc, REG_SEG_CS);
+    vmx_read_segment_descriptor(cpu, &desc, R_CS);
 
     return x86_is_long_mode(cpu) && ((desc.ar >> 13) & 1);
 }
@@ -157,13 +157,13 @@ bool x86_is_pae_enabled(struct CPUState *cpu)
     return cr4 & CR4_PAE;
 }
 
-addr_t linear_addr(struct CPUState *cpu, addr_t addr, x86_reg_segment seg)
+addr_t linear_addr(struct CPUState *cpu, addr_t addr, X86Seg seg)
 {
     return vmx_read_segment_base(cpu, seg) + addr;
 }
 
 addr_t linear_addr_size(struct CPUState *cpu, addr_t addr, int size,
-                        x86_reg_segment seg)
+                        X86Seg seg)
 {
     switch (size) {
     case 2:
@@ -180,5 +180,5 @@ addr_t linear_addr_size(struct CPUState *cpu, addr_t addr, int size,
 
 addr_t linear_rip(struct CPUState *cpu, addr_t rip)
 {
-    return linear_addr(cpu, rip, REG_SEG_CS);
+    return linear_addr(cpu, rip, R_CS);
 }
target/i386/hvf/x86.h +43 -102

178 lines not on this page · raw message

target/i386/hvf/x86_decode.c +40 -40

222 lines not on this page · raw message

target/i386/hvf/x86_decode.h +1 -1
index 50957819f6..1b73a1f5b6 100644
@@ -309,7 +309,7 @@ addr_t get_reg_val(CPUX86State *env, int reg, int is_extended, int size);
 void calc_modrm_operand(CPUX86State *env, struct x86_decode *decode,
                         struct x86_decode_op *op);
 addr_t decode_linear_addr(CPUX86State *env, struct x86_decode *decode,
-                          addr_t addr, x86_reg_segment seg);
+                          addr_t addr, enum X86Seg seg);
 
 void init_decoder(void);
 void calc_modrm_operand16(CPUX86State *env, struct x86_decode *decode,
target/i386/hvf/x86_descr.c +13 -13
index 0b9562818f..269c46f53a 100644
@@ -21,12 +21,12 @@
 #include "vmx.h"
 #include "x86_descr.h"
 
-#define VMX_SEGMENT_FIELD(seg)                      \
-    [REG_SEG_##seg] = {                           \
-        .selector = VMCS_GUEST_##seg##_SELECTOR,             \
-        .base = VMCS_GUEST_##seg##_BASE,                     \
-        .limit = VMCS_GUEST_##seg##_LIMIT,                   \
-        .ar_bytes = VMCS_GUEST_##seg##_ACCESS_RIGHTS,             \
+#define VMX_SEGMENT_FIELD(seg)                        \
+    [R_##seg] = {                                     \
+        .selector = VMCS_GUEST_##seg##_SELECTOR,      \
+        .base = VMCS_GUEST_##seg##_BASE,              \
+        .limit = VMCS_GUEST_##seg##_LIMIT,            \
+        .ar_bytes = VMCS_GUEST_##seg##_ACCESS_RIGHTS, \
 }
 
 static const struct vmx_segment_field {
@@ -45,34 +45,34 @@ static const struct vmx_segment_field {
     VMX_SEGMENT_FIELD(TR),
 };
 
-uint32_t vmx_read_segment_limit(CPUState *cpu, x86_reg_segment seg)
+uint32_t vmx_read_segment_limit(CPUState *cpu, X86Seg seg)
 {
     return (uint32_t)rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].limit);
 }
 
-uint32_t vmx_read_segment_ar(CPUState *cpu, x86_reg_segment seg)
+uint32_t vmx_read_segment_ar(CPUState *cpu, X86Seg seg)
 {
     return (uint32_t)rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].ar_bytes);
 }
 
-uint64_t vmx_read_segment_base(CPUState *cpu, x86_reg_segment seg)
+uint64_t vmx_read_segment_base(CPUState *cpu, X86Seg seg)
 {
     return rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].base);
 }
 
-x68_segment_selector vmx_read_segment_selector(CPUState *cpu, x86_reg_segment seg)
+x68_segment_selector vmx_read_segment_selector(CPUState *cpu, X86Seg seg)
 {
     x68_segment_selector sel;
     sel.sel = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].selector);
     return sel;
 }
 
-void vmx_write_segment_selector(struct CPUState *cpu, x68_segment_selector selector, x86_reg_segment seg)
+void vmx_write_segment_selector(struct CPUState *cpu, x68_segment_selector selector, X86Seg seg)
 {
     wvmcs(cpu->hvf_fd, vmx_segment_fields[seg].selector, selector.sel);
 }
 
-void vmx_read_segment_descriptor(struct CPUState *cpu, struct vmx_segment *desc, x86_reg_segment seg)
+void vmx_read_segment_descriptor(struct CPUState *cpu, struct vmx_segment *desc, X86Seg seg)
 {
     desc->sel = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].selector);
     desc->base = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].base);
@@ -80,7 +80,7 @@ void vmx_read_segment_descriptor(struct CPUState *cpu, struct vmx_segment *desc,
     desc->ar = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].ar_bytes);
 }
 
-void vmx_write_segment_descriptor(CPUState *cpu, struct vmx_segment *desc, x86_reg_segment seg)
+void vmx_write_segment_descriptor(CPUState *cpu, struct vmx_segment *desc, X86Seg seg)
 {
     const struct vmx_segment_field *sf = &vmx_segment_fields[seg];
 
target/i386/hvf/x86_descr.h +8 -8
index 034d8e95c5..25a2b1731c 100644
@@ -30,18 +30,18 @@ typedef struct vmx_segment {
 
 /* deal with vmstate descriptors */
 void vmx_read_segment_descriptor(struct CPUState *cpu,
-                                 struct vmx_segment *desc, x86_reg_segment seg);
+                                 struct vmx_segment *desc, enum X86Seg seg);
 void vmx_write_segment_descriptor(CPUState *cpu, struct vmx_segment *desc,
-                                  x86_reg_segment seg);
+                                  enum X86Seg seg);
 
 x68_segment_selector vmx_read_segment_selector(struct CPUState *cpu,
-                                               x86_reg_segment seg);
+                                               enum X86Seg seg);
 void vmx_write_segment_selector(struct CPUState *cpu,
                                 x68_segment_selector selector,
-                                x86_reg_segment seg);
+                                enum X86Seg seg);
 
-uint64_t vmx_read_segment_base(struct CPUState *cpu, x86_reg_segment seg);
-void vmx_write_segment_base(struct CPUState *cpu, x86_reg_segment seg,
+uint64_t vmx_read_segment_base(struct CPUState *cpu, enum X86Seg seg);
+void vmx_write_segment_base(struct CPUState *cpu, enum X86Seg seg,
                             uint64_t base);
 
 void x86_segment_descriptor_to_vmx(struct CPUState *cpu,
@@ -49,8 +49,8 @@ void x86_segment_descriptor_to_vmx(struct CPUState *cpu,
                                    struct x86_segment_descriptor *desc,
                                    struct vmx_segment *vmx_desc);
 
-uint32_t vmx_read_segment_limit(CPUState *cpu, x86_reg_segment seg);
-uint32_t vmx_read_segment_ar(CPUState *cpu, x86_reg_segment seg);
+uint32_t vmx_read_segment_limit(CPUState *cpu, enum X86Seg seg);
+uint32_t vmx_read_segment_ar(CPUState *cpu, enum X86Seg seg);
 void vmx_segment_to_x86_descriptor(struct CPUState *cpu,
                                    struct vmx_segment *vmx_desc,
                                    struct x86_segment_descriptor *desc);
target/i386/hvf/x86_emu.c +33 -33

169 lines not on this page · raw message

target/i386/hvf/x86_task.c +24 -24

80 lines not on this page · raw message

target/i386/hvf/x86hvf.c +16 -16
index 83eb3be065..087deac6a9 100644
@@ -107,28 +107,28 @@ void hvf_put_segments(CPUState *cpu_state)
     macvm_set_cr0(cpu_state->hvf_fd, env->cr[0]);
 
     hvf_set_segment(cpu_state, &seg, &env->segs[R_CS], false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_CS);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_CS);
     
     hvf_set_segment(cpu_state, &seg, &env->segs[R_DS], false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_DS);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_DS);
 
     hvf_set_segment(cpu_state, &seg, &env->segs[R_ES], false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_ES);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_ES);
 
     hvf_set_segment(cpu_state, &seg, &env->segs[R_SS], false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_SS);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_SS);
 
     hvf_set_segment(cpu_state, &seg, &env->segs[R_FS], false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_FS);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_FS);
 
     hvf_set_segment(cpu_state, &seg, &env->segs[R_GS], false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_GS);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_GS);
 
     hvf_set_segment(cpu_state, &seg, &env->tr, true);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_TR);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_TR);
 
     hvf_set_segment(cpu_state, &seg, &env->ldt, false);
-    vmx_write_segment_descriptor(cpu_state, &seg, REG_SEG_LDTR);
+    vmx_write_segment_descriptor(cpu_state, &seg, R_LDTR);
     
     hv_vcpu_flush(cpu_state->hvf_fd);
 }
@@ -183,28 +183,28 @@ void hvf_get_segments(CPUState *cpu_state)
 
     env->interrupt_injected = -1;
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_CS);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_CS);
     hvf_get_segment(&env->segs[R_CS], &seg);
     
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_DS);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_DS);
     hvf_get_segment(&env->segs[R_DS], &seg);
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_ES);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_ES);
     hvf_get_segment(&env->segs[R_ES], &seg);
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_FS);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_FS);
     hvf_get_segment(&env->segs[R_FS], &seg);
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_GS);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_GS);
     hvf_get_segment(&env->segs[R_GS], &seg);
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_SS);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_SS);
     hvf_get_segment(&env->segs[R_SS], &seg);
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_TR);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_TR);
     hvf_get_segment(&env->tr, &seg);
 
-    vmx_read_segment_descriptor(cpu_state, &seg, REG_SEG_LDTR);
+    vmx_read_segment_descriptor(cpu_state, &seg, R_LDTR);
     hvf_get_segment(&env->ldt, &seg);
 
     env->idt.limit = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_IDTR_LIMIT);
Signature · 1 line
2.13.6
#4 lore raw

PATCH 4/10 i386: hvf: remove more dead emulator code

In reply to Paolo Bonzini
---
 target/i386/hvf/hvf.c        |  2 --
 target/i386/hvf/x86.h        |  5 -----
 target/i386/hvf/x86_decode.c | 22 +++++++++++-----------
 target/i386/hvf/x86_emu.c    | 25 ++++++++-----------------
 target/i386/hvf/x86_flags.c  | 10 ----------
 target/i386/hvf/x86_flags.h  |  1 -
 target/i386/hvf/x86_mmu.c    |  6 ++----
 target/i386/hvf/x86_task.c   | 10 ----------
 8 files changed, 21 insertions(+), 60 deletions(-)
target/i386/hvf/hvf.c +0 -2
index 863226cc9a..ae3ecad2a4 100644
@@ -739,7 +739,6 @@ int hvf_vcpu_exec(CPUState *cpu)
             uint32_t port =  exit_qual >> 16;
             /*uint32_t rep = (exit_qual & 0x20) != 0;*/
 
-#if 1
             if (!string && in) {
                 uint64_t val = 0;
                 load_regs(cpu);
@@ -762,7 +761,6 @@ int hvf_vcpu_exec(CPUState *cpu)
                 macvm_set_rip(cpu, rip + ins_len);
                 break;
             }
-#endif
             struct x86_decode decode;
 
             load_regs(cpu);
target/i386/hvf/x86.h +0 -5
index 650bb718bf..94ac67b5cb 100644
@@ -103,10 +103,6 @@ typedef struct x86_reg_flags {
     };
 } __attribute__ ((__packed__)) x86_reg_flags;
 
-typedef struct x86_efer {
-    uint64_t efer;
-} __attribute__ ((__packed__)) x86_efer;
-
 typedef enum x86_reg_cr0 {
     CR0_PE =            (1L << 0),
     CR0_MP =            (1L << 1),
@@ -306,7 +302,6 @@ typedef struct HVFX86EmulatorState {
     struct x86_register regs[16];
     struct x86_reg_flags   rflags;
     struct lazy_flags   lflags;
-    struct x86_efer efer;
     uint8_t mmio_buf[4096];
 } HVFX86EmulatorState;
 
target/i386/hvf/x86_decode.c +11 -11
index 86e7c4ee7a..24c732d9f1 100644
@@ -630,7 +630,7 @@ static void decode_aegroup(CPUX86State *env, struct x86_decode *decode)
         }
         break;
     default:
-        VM_PANIC_ON_EX(1, "0xae: reg %d\n", decode->modrm.reg);
+        VM_PANIC_EX("0xae: reg %d\n", decode->modrm.reg);
         break;
     }
 }
@@ -654,14 +654,14 @@ static void decode_d9_4(CPUX86State *env, struct x86_decode *decode)
         decode->cmd = X86_DECODE_CMD_FABS;
         break;
     case 0xe4:
-        VM_PANIC_ON_EX(1, "FTST");
+        VM_PANIC("FTST");
         break;
     case 0xe5:
         /* FXAM */
         decode->cmd = X86_DECODE_CMD_FXAM;
         break;
     default:
-        VM_PANIC_ON_EX(1, "FLDENV");
+        VM_PANIC("FLDENV");
         break;
     }
 }
@@ -670,16 +670,16 @@ static void decode_db_4(CPUX86State *env, struct x86_decode *decode)
 {
     switch (decode->modrm.modrm) {
     case 0xe0:
-        VM_PANIC_ON_EX(1, "unhandled FNENI: %x %x\n", decode->opcode[0],
-                       decode->modrm.modrm);
+        VM_PANIC_EX("unhandled FNENI: %x %x\n", decode->opcode[0],
+                    decode->modrm.modrm);
         break;
     case 0xe1:
-        VM_PANIC_ON_EX(1, "unhandled FNDISI: %x %x\n", decode->opcode[0],
-                       decode->modrm.modrm);
+        VM_PANIC_EX("unhandled FNDISI: %x %x\n", decode->opcode[0],
+                    decode->modrm.modrm);
         break;
     case 0xe2:
-        VM_PANIC_ON_EX(1, "unhandled FCLEX: %x %x\n", decode->opcode[0],
-                       decode->modrm.modrm);
+        VM_PANIC_EX("unhandled FCLEX: %x %x\n", decode->opcode[0],
+                    decode->modrm.modrm);
         break;
     case 0xe3:
         decode->cmd = X86_DECODE_CMD_FNINIT;
@@ -688,8 +688,8 @@ static void decode_db_4(CPUX86State *env, struct x86_decode *decode)
         decode->cmd = X86_DECODE_CMD_FNSETPM;
         break;
     default:
-        VM_PANIC_ON_EX(1, "unhandled fpu opcode: %x %x\n", decode->opcode[0],
-                       decode->modrm.modrm);
+        VM_PANIC_EX("unhandled fpu opcode: %x %x\n", decode->opcode[0],
+                    decode->modrm.modrm);
         break;
     }
 }
target/i386/hvf/x86_emu.c +8 -17
index b64e490c2d..3a995fe687 100644
@@ -837,7 +837,6 @@ void simulate_wrmsr(struct CPUState *cpu)
         abort();
         break;
     case MSR_EFER:
-        env->hvf_emul->efer.efer = data;
         /*printf("new efer %llx\n", EFER(cpu));*/
         wvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER, data);
         if (data & MSR_EFER_NXE) {
@@ -1511,23 +1510,15 @@ bool exec_instruction(struct CPUX86State *env, struct x86_decode *ins)
     printf("%d, %llx: exec_instruction %s\n", hvf_vcpu_id(cpu),  RIP(cpu),
           decode_cmd_to_string(ins->cmd));*/
 
-    if (0 && ins->is_fpu) {
-        VM_PANIC("emulate fpu\n");
-    } else {
-        if (!_cmd_handler[ins->cmd].handler) {
-            printf("Unimplemented handler (%llx) for %d (%x %x) \n", RIP(env),
-                    ins->cmd, ins->opcode[0],
-                    ins->opcode_len > 1 ? ins->opcode[1] : 0);
-            RIP(env) += ins->len;
-            return true;
-        }
-
-        VM_PANIC_ON_EX(!_cmd_handler[ins->cmd].handler,
-                "Unimplemented handler (%llx) for %d (%x %x) \n", RIP(env),
-                 ins->cmd, ins->opcode[0],
-                 ins->opcode_len > 1 ? ins->opcode[1] : 0);
-        _cmd_handler[ins->cmd].handler(env, ins);
+    if (!_cmd_handler[ins->cmd].handler) {
+        printf("Unimplemented handler (%llx) for %d (%x %x) \n", RIP(env),
+                ins->cmd, ins->opcode[0],
+                ins->opcode_len > 1 ? ins->opcode[1] : 0);
+        RIP(env) += ins->len;
+        return true;
     }
+
+    _cmd_handler[ins->cmd].handler(env, ins);
     return true;
 }
 
target/i386/hvf/x86_flags.c +0 -10
index c833774485..e7bbce75e1 100644
@@ -301,16 +301,6 @@ void set_SF(CPUX86State *env, bool val)
     env->hvf_emul->lflags.auxbits ^= (temp_sf ^ val) << LF_BIT_SD;
 }
 
-void set_OSZAPC(CPUX86State *env, uint32_t flags32)
-{
-    set_OF(env, env->hvf_emul->rflags.of);
-    set_SF(env, env->hvf_emul->rflags.sf);
-    set_ZF(env, env->hvf_emul->rflags.zf);
-    set_AF(env, env->hvf_emul->rflags.af);
-    set_PF(env, env->hvf_emul->rflags.pf);
-    set_CF(env, env->hvf_emul->rflags.cf);
-}
-
 void lflags_to_rflags(CPUX86State *env)
 {
     env->hvf_emul->rflags.cf = get_CF(env);
target/i386/hvf/x86_flags.h +0 -1
index 57a524240c..3e487535ea 100644
@@ -190,7 +190,6 @@ bool get_SF(CPUX86State *env);
 void set_SF(CPUX86State *env, bool val);
 bool get_OF(CPUX86State *env);
 void set_OF(CPUX86State *env, bool val);
-void set_OSZAPC(CPUX86State *env, uint32_t flags32);
 
 void SET_FLAGS_OxxxxC(CPUX86State *env, uint32_t new_of, uint32_t new_cf);
 
target/i386/hvf/x86_mmu.c +2 -4
index 26e9e95b0b..1084670c1d 100644
@@ -238,8 +238,7 @@ void vmx_write_mem(struct CPUState *cpu, addr_t gva, void *data, int bytes)
         int copy = MIN(bytes, 0x1000 - (gva & 0xfff));
 
         if (!mmu_gva_to_gpa(cpu, gva, &gpa)) {
-            VM_PANIC_ON_EX(1, "%s: mmu_gva_to_gpa %llx failed\n", __func__,
-                           gva);
+            VM_PANIC_EX("%s: mmu_gva_to_gpa %llx failed\n", __func__, gva);
         } else {
             address_space_rw(&address_space_memory, gpa, MEMTXATTRS_UNSPECIFIED,
                              data, copy, 1);
@@ -260,8 +259,7 @@ void vmx_read_mem(struct CPUState *cpu, void *data, addr_t gva, int bytes)
         int copy = MIN(bytes, 0x1000 - (gva & 0xfff));
 
         if (!mmu_gva_to_gpa(cpu, gva, &gpa)) {
-            VM_PANIC_ON_EX(1, "%s: mmu_gva_to_gpa %llx failed\n", __func__,
-                           gva);
+            VM_PANIC_EX("%s: mmu_gva_to_gpa %llx failed\n", __func__, gva);
         }
         address_space_rw(&address_space_memory, gpa, MEMTXATTRS_UNSPECIFIED,
                          data, copy, 0);
target/i386/hvf/x86_task.c +0 -10
index 6dbb1c6ce1..b6ce2a151b 100644
@@ -90,16 +90,6 @@ static void load_state_from_tss32(CPUState *cpu, struct x86_tss_segment32 *tss)
     vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ds}}, R_DS);
     vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->fs}}, R_FS);
     vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->gs}}, R_GS);
-
-#if 0
-    load_segment(cpu, R_LDTR, tss->ldt);
-    load_segment(cpu, R_ES, tss->es);
-    load_segment(cpu, R_CS, tss->cs);
-    load_segment(cpu, R_SS, tss->ss);
-    load_segment(cpu, R_DS, tss->ds);
-    load_segment(cpu, R_FS, tss->fs);
-    load_segment(cpu, R_GS, tss->gs);
-#endif
 }
 
 static int task_switch_32(CPUState *cpu, x68_segment_selector tss_sel, x68_segment_selector old_tss_sel,
Signature · 1 line
2.13.6
#5 lore raw

PATCH 5/10 i386: hvf: remove ZERO_INIT macro

In reply to Paolo Bonzini
---
 target/i386/hvf/x86.c        | 3 ++-
 target/i386/hvf/x86_decode.c | 3 +--
 target/i386/hvf/x86_gen.h    | 2 --
 3 files changed, 3 insertions(+), 5 deletions(-)
target/i386/hvf/x86.c +2 -1
index ca0ec2968a..8002a41d30 100644
@@ -53,7 +53,8 @@ bool x86_read_segment_descriptor(struct CPUState *cpu,
     addr_t base;
     uint32_t limit;
 
-    ZERO_INIT(*desc);
+    memset(desc, 0, sizeof(*desc));
+
     /* valid gdt descriptors start from index 1 */
     if (!sel.index && GDT_SEL == sel.ti) {
         return false;
target/i386/hvf/x86_decode.c +1 -2
index 24c732d9f1..08b6036f2e 100644
@@ -2090,8 +2090,7 @@ static void decode_opcodes(CPUX86State *env, struct x86_decode *decode)
 
 uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode)
 {
-    ZERO_INIT(*decode);
-
+    memset(decode, 0, sizeof(*decode));
     decode_prefix(env, decode);
     set_addressing_size(env, decode);
     set_operand_size(env, decode);
target/i386/hvf/x86_gen.h +0 -2
index 2045b0e69d..d33dea842e 100644
@@ -48,6 +48,4 @@ typedef uint64_t addr_t;
     } \
 }
 
-#define ZERO_INIT(obj) memset((void *) &obj, 0, sizeof(obj))
-
 #endif
Signature · 1 line
2.13.6
#6 lore raw

PATCH 6/10 i386: hvf: abort on decoding error

In reply to Paolo Bonzini

Rather than unsupported situations, some VM_PANIC calls actually are caused by internal errors. Convert them to just abort.

---
 target/i386/hvf/hvf.c     |  2 +-
 target/i386/hvf/x86_emu.c | 10 ++++------
 2 files changed, 5 insertions(+), 7 deletions(-)
target/i386/hvf/hvf.c +1 -1
index ae3ecad2a4..f2dc37d826 100644
@@ -767,7 +767,7 @@ int hvf_vcpu_exec(CPUState *cpu)
             env->hvf_emul->fetch_rip = rip;
 
             decode_instruction(env, &decode);
-            VM_PANIC_ON(ins_len != decode.len);
+            assert(ins_len == decode.len);
             exec_instruction(env, &decode);
             store_regs(cpu);
 
target/i386/hvf/x86_emu.c +4 -6
index 3a995fe687..63c2b5a54d 100644
@@ -146,7 +146,7 @@ addr_t read_reg(CPUX86State *env, int reg, int size)
     case 8:
         return env->hvf_emul->regs[reg].rrx;
     default:
-        VM_PANIC_ON("read_reg size");
+        abort();
     }
     return 0;
 }
@@ -167,7 +167,7 @@ void write_reg(CPUX86State *env, int reg, addr_t val, int size)
         env->hvf_emul->regs[reg].rrx = val;
         break;
     default:
-        VM_PANIC_ON("write_reg size");
+        abort();
     }
 }
 
@@ -189,8 +189,7 @@ addr_t read_val_from_reg(addr_t reg_ptr, int size)
         val = *(uint64_t *)reg_ptr;
         break;
     default:
-        VM_PANIC_ON_EX(1, "read_val: Unknown size %d\n", size);
-        break;
+        abort();
     }
     return val;
 }
@@ -211,8 +210,7 @@ void write_val_to_reg(addr_t reg_ptr, addr_t val, int size)
         *(uint64_t *)reg_ptr = val;
         break;
     default:
-        VM_PANIC("write_val: Unknown size\n");
-        break;
+        abort();
     }
 }
 
Signature · 1 line
2.13.6
#7 lore raw

PATCH 9/10 i386: hvf: simplify and fix in/out handling

In reply to Paolo Bonzini

Reading a 32-bit port should clear the upper 32-bits of the register.

---
 target/i386/hvf/hvf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/i386/hvf/hvf.c +4 -4
index 5194b94591..35e39afefd 100644
@@ -748,16 +748,16 @@ int hvf_vcpu_exec(CPUState *cpu)
                 } else if (size == 2) {
                     AX(env) = val;
                 } else if (size == 4) {
-                    RAX(env) = (uint32_t)val;
+                    RRX(env) = (uint32_t)val;
                 } else {
-                    VM_PANIC("size");
+                    RRX(env) = (uint64_t)val;
                 }
                 RIP(env) += ins_len;
                 store_regs(cpu);
                 break;
             } else if (!string && !in) {
-                RAX(env) = rreg(cpu->hvf_fd, HV_X86_RAX);
-                hvf_handle_io(env, port, &RAX(env), 1, size, 1);
+                RRX(env) = rreg(cpu->hvf_fd, HV_X86_RAX);
+                hvf_handle_io(env, port, &RRX(env), 1, size, 1);
                 macvm_set_rip(cpu, rip + ins_len);
                 break;
             }
Signature · 1 line
2.13.6
#8 lore raw

PATCH 10/10 i386: hvf: cleanup x86_gen.h

In reply to Paolo Bonzini

This only includes VM_PANIC now. No need to include it from headers.

---
 target/i386/hvf-utils/panic.h | 45 +++++++++++++++++++++++++++++++++++++++++++
 target/i386/hvf/x86.h         |  1 -
 target/i386/hvf/x86_decode.c  |  3 +--
 target/i386/hvf/x86_emu.c     |  2 +-
 target/i386/hvf/x86_flags.c   |  1 +
 target/i386/hvf/x86_flags.h   |  1 -
 target/i386/hvf/x86_mmu.c     |  1 +
 target/i386/hvf/x86_mmu.h     |  2 --
 target/i386/hvf/x86_task.c    |  1 +
 9 files changed, 50 insertions(+), 7 deletions(-)
 create mode 100644 target/i386/hvf-utils/panic.h
target/i386/hvf-utils/panic.h new file +45 -0
new file mode 100644
index 0000000000..411ef43a5b
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016 Veertu Inc,
+ * Copyright (C) 2017 Google Inc,
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef HVF_PANIC_H
+#define HVF_PANIC_H
+
+#define VM_PANIC(x) {\
+    printf("%s\n", x); \
+    abort(); \
+}
+
+#define VM_PANIC_ON(x) {\
+    if (x) { \
+        printf("%s\n", #x); \
+        abort(); \
+    } \
+}
+
+#define VM_PANIC_EX(...) {\
+    printf(__VA_ARGS__); \
+    abort(); \
+}
+
+#define VM_PANIC_ON_EX(x, ...) {\
+    if (x) { \
+        printf(__VA_ARGS__); \
+        abort(); \
+    } \
+}
+
+#endif
target/i386/hvf/x86.h +0 -1
index a7fc65a487..595d5aca04 100644
@@ -20,7 +20,6 @@
 #define HVF_X86_H 1
 
 #include "qemu-common.h"
-#include "x86_gen.h"
 
 typedef struct x86_register {
     union {
target/i386/hvf/x86_decode.c +1 -2
index f6096ca307..ff31f4f577 100644
@@ -17,11 +17,10 @@
  */
 
 #include "qemu/osdep.h"
-
+#include "panic.h"
 #include "x86_decode.h"
 #include "string.h"
 #include "vmx.h"
-#include "x86_gen.h"
 #include "x86_mmu.h"
 #include "x86_descr.h"
 
target/i386/hvf/x86_emu.c +1 -1
index 8f45f01eed..44b0b83fea 100644
@@ -36,7 +36,7 @@
 /////////////////////////////////////////////////////////////////////////
 
 #include "qemu/osdep.h"
-
+#include "panic.h"
 #include "qemu-common.h"
 #include "x86_decode.h"
 #include "x86.h"
target/i386/hvf/x86_flags.c +1 -0
index b1f240ca0f..f79ff096f6 100644
@@ -22,6 +22,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "panic.h"
 #include "qemu-common.h"
 
 #include "cpu.h"
target/i386/hvf/x86_flags.h +0 -1
index 69d8672d24..c46a5fd8a8 100644
@@ -23,7 +23,6 @@
 #ifndef __X86_FLAGS_H__
 #define __X86_FLAGS_H__
 
-#include "x86_gen.h"
 #include "cpu.h"
 void lflags_to_rflags(CPUX86State *env);
 void rflags_to_lflags(CPUX86State *env);
target/i386/hvf/x86_mmu.c +1 -0
index af11635fba..682e29774e 100644
@@ -16,6 +16,7 @@
  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
+#include "panic.h"
 
 #include "qemu-common.h"
 #include "x86.h"
target/i386/hvf/x86_mmu.h +0 -2
index ae02cb6916..0bd1acc94f 100644
@@ -18,8 +18,6 @@
 #ifndef __X86_MMU_H__
 #define __X86_MMU_H__
 
-#include "x86_gen.h"
-
 #define PT_PRESENT      (1 << 0)
 #define PT_WRITE        (1 << 1)
 #define PT_USER         (1 << 2)
target/i386/hvf/x86_task.c +1 -0
index b6ce2a151b..f77edda580 100644
@@ -7,6 +7,7 @@
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 #include "qemu/osdep.h"
+#include "panic.h"
 #include "qemu-common.h"
 #include "qemu/error-report.h"
 
Signature · 1 line
2.13.6
#9 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

Alex (both of them), Sergio, anyone else who can help?

Very interested in this (and thanks!) but it will be a while before I have a sensible number of cycles available to play with this one again.

Signature · 1 line
Alex Bligh