Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/813236/?format=api
{ "id": 813236, "url": "http://patchwork.ozlabs.org/api/patches/813236/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913090522.4022-4-Sergio.G.DelReal@gmail.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170913090522.4022-4-Sergio.G.DelReal@gmail.com>", "list_archive_url": null, "date": "2017-09-13T09:05:11", "name": "[v4,03/14] hvf: fix licensing issues; isolate task handling code (GPL v2-only)", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "0d275cf67510efd255e508517825ce1e0300daaa", "submitter": { "id": 70675, "url": "http://patchwork.ozlabs.org/api/people/70675/?format=api", "name": "Sergio Andres Gomez Del Real", "email": "sergio.g.delreal@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913090522.4022-4-Sergio.G.DelReal@gmail.com/mbox/", "series": [ { "id": 2843, "url": "http://patchwork.ozlabs.org/api/series/2843/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2843", "date": "2017-09-13T09:05:08", "name": "add support for Hypervisor.framework in QEMU", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/2843/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/813236/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/813236/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"ozRDf2VV\"; dkim-atps=neutral" ], "Received": [ "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xsbQ65Vr5z9sMN\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 19:06:54 +1000 (AEST)", "from localhost ([::1]:41058 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1ds3dE-0001bL-QE\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 05:06:52 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:33978)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <sergio.g.delreal@gmail.com>) id 1ds3cK-0001SV-6Q\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:06:02 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <sergio.g.delreal@gmail.com>) id 1ds3cA-0007Kd-Kz\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:05:56 -0400", "from mail-ua0-x242.google.com ([2607:f8b0:400c:c08::242]:36251)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <sergio.g.delreal@gmail.com>)\n\tid 1ds3cA-0007K3-7k\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:05:46 -0400", "by mail-ua0-x242.google.com with SMTP id k23so3890707uaf.3\n\tfor <qemu-devel@nongnu.org>; Wed, 13 Sep 2017 02:05:46 -0700 (PDT)", "from localhost.localdomain ([190.66.154.128])\n\tby smtp.gmail.com with ESMTPSA id\n\tr74sm2677601vkf.19.2017.09.13.02.05.42\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tWed, 13 Sep 2017 02:05:43 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=VDO9r2vVw2LHUExxKpVBNEMb8BGth37VAHnKgyMdmOE=;\n\tb=ozRDf2VVegqAR1AbmkshWHJlki4DrLkMnn+iRdJvJmt0CfUGNxz3PbinMQ5NGv/4Hi\n\tWRJ8Qehpmdixn4mdms6Bcb2uBLdWtPw4AiVUltVkFyN4odzOGeQHoaiMuKKZo92fb6NN\n\ttuDtZQrlCoYilLJF+Gk+QPy+XYZMRDEZrHxfHQML3tA4I+lPnza+u15mPlPMmEJ26/GT\n\ta6GZSZ/OG9hRLql2Pk80zpHEDpkW5OweEYtXJ7pPqiLyAi9e44GRgc+ArDjTHXc7/XsZ\n\tSoKG3JBJsyOczTiQXSu6eztAWG0caUtIYFOtb/z1Y6+EGzIZ5NTPIhOspOf7lsJNVT29\n\tvWUA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=VDO9r2vVw2LHUExxKpVBNEMb8BGth37VAHnKgyMdmOE=;\n\tb=F0lXF6pSLfx3HUqm01byKNf3C4cLNlernTmAZ6R/AAIBhPaw8I5WtIQjceBiHsnyR4\n\tmc5qF/BZXaTubFwm+ANHurbKGGADEbXfRHaDZ4XbEpMT6+pL+a2xGaamTfxIXCuQ2NZy\n\t7i7tkecrrunrUB+YVEPnK1noQJ48XEgrdG0c2Gaf4YCB3FA6UXMRxqY2Bh94axU2lgow\n\tZXBG5TVHdKG84C4xCn3BSe9V/dnCdSeTZcv+sVQyLDU7LMT7lRlFLcw2WwdZOrjqSGPG\n\tsQf9CsMMvg3JGr+dTiaZGqn8OxyshXjjGkDloFtmWyzIdzQ6A146rwZiHwIq0MuOSlMb\n\tTbKg==", "X-Gm-Message-State": "AHPjjUjJ6I/GqYEr2mI8qx5qlxgFmuU06mfeTFeepJYLPbQt9v7KDgk/\n\t9eaMDcBLCtG/v4Ac", "X-Google-Smtp-Source": "ADKCNb4O1cy06fBLGrowWgFeN8S5fQHaOirfFXoDz4iA0AwyyqBtXjfmMa8hac6lASvJ4YlyVifaeQ==", "X-Received": "by 10.176.23.132 with SMTP id r4mr10488928uaf.121.1505293544207; \n\tWed, 13 Sep 2017 02:05:44 -0700 (PDT)", "From": "Sergio Andres Gomez Del Real <sergio.g.delreal@gmail.com>", "X-Google-Original-From": "Sergio Andres Gomez Del Real\n\t<Sergio.G.DelReal@gmail.com>", "To": "qemu-devel@nongnu.org", "Date": "Wed, 13 Sep 2017 04:05:11 -0500", "Message-Id": "<20170913090522.4022-4-Sergio.G.DelReal@gmail.com>", "X-Mailer": "git-send-email 2.11.0", "In-Reply-To": "<20170913090522.4022-1-Sergio.G.DelReal@gmail.com>", "References": "<20170913090522.4022-1-Sergio.G.DelReal@gmail.com>", "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.", "X-Received-From": "2607:f8b0:400c:c08::242", "Subject": "[Qemu-devel] [PATCH v4 03/14] hvf: fix licensing issues;\n\tisolate task handling code (GPL v2-only)", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.21", "Precedence": "list", "List-Id": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Cc": "Sergio Andres Gomez Del Real <Sergio.G.DelReal@gmail.com>,\n\tpbonzini@redhat.com, stefanha@gmail.com", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>" }, "content": "This patch replaces the license header for those files that were either\nGPL v2-or-v3, or GPL v2-only; the replacing license is GPL v2-or-later.\nThe code for task switching/handling, which is derived from KVM and\nhence is GPL v2-only, is isolated in the new files (with this license)\nx86_task.c/.h, and the corresponding compilation rule is added to\ntarget/i386/hvf-utils/Makefile.objs.\nNote that rules for compiling are still missing from\ntarget/i386/Makefile.objs; they will be added later in this patchset.\n\nSigned-off-by: Sergio Andres Gomez Del Real <Sergio.G.DelReal@gmail.com>\n---\n target/i386/hvf-all.c | 173 +++----------------------------\n target/i386/hvf-utils/Makefile.objs | 2 +-\n target/i386/hvf-utils/vmx.h | 14 +--\n target/i386/hvf-utils/x86.c | 14 +--\n target/i386/hvf-utils/x86.h | 14 +--\n target/i386/hvf-utils/x86_cpuid.c | 6 +-\n target/i386/hvf-utils/x86_cpuid.h | 14 +--\n target/i386/hvf-utils/x86_decode.c | 14 +--\n target/i386/hvf-utils/x86_decode.h | 14 +--\n target/i386/hvf-utils/x86_descr.c | 14 +--\n target/i386/hvf-utils/x86_descr.h | 14 +--\n target/i386/hvf-utils/x86_emu.c | 14 +--\n target/i386/hvf-utils/x86_emu.h | 14 +--\n target/i386/hvf-utils/x86_gen.h | 14 +--\n target/i386/hvf-utils/x86_mmu.c | 14 +--\n target/i386/hvf-utils/x86_mmu.h | 14 +--\n target/i386/hvf-utils/x86_task.c | 201 ++++++++++++++++++++++++++++++++++++\n target/i386/hvf-utils/x86_task.h | 18 ++++\n target/i386/hvf-utils/x86hvf.c | 14 +--\n target/i386/hvf-utils/x86hvf.h | 14 +--\n 20 files changed, 340 insertions(+), 270 deletions(-)\n create mode 100644 target/i386/hvf-utils/x86_task.c\n create mode 100644 target/i386/hvf-utils/x86_task.h", "diff": "diff --git a/target/i386/hvf-all.c b/target/i386/hvf-all.c\nindex d5e18faa68..270ec56b8d 100644\n--- a/target/i386/hvf-all.c\n+++ b/target/i386/hvf-all.c\n@@ -5,15 +5,19 @@\n // Copyright 2017 The Android Open Source Project\n // \n // QEMU Hypervisor.framework support\n-// \n-// This software is licensed under the terms of the GNU General Public\n-// License version 2, as published by the Free Software Foundation, and\n-// may be copied, distributed, and modified under those terms.\n-// \n+//\n+// This program is free software; you can redistribute it and/or\n+// modify it under the terms of the GNU Lesser General Public\n+// License as published by the Free Software Foundation; either\n+// version 2 of the License, or (at your option) any later version.\n+//\n // This program is distributed in the hope that it will be useful,\n // but WITHOUT ANY WARRANTY; without even the implied warranty of\n-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n-// GNU General Public License for more details.\n+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+// Lesser General Public License for more details.\n+//\n+// You should have received a copy of the GNU Lesser General Public\n+// License along with this program; if not, see <http://www.gnu.org/licenses/>.\n #include \"qemu/osdep.h\"\n #include \"qemu-common.h\"\n #include \"qemu/error-report.h\"\n@@ -28,6 +32,7 @@\n #include \"hvf-utils/x86_decode.h\"\n #include \"hvf-utils/x86_emu.h\"\n #include \"hvf-utils/x86_cpuid.h\"\n+#include \"hvf-utils/x86_task.h\"\n #include \"hvf-utils/x86hvf.h\"\n \n #include <Hypervisor/hv.h>\n@@ -224,160 +229,6 @@ void update_apic_tpr(CPUState *cpu)\n \n #define VECTORING_INFO_VECTOR_MASK 0xff\n \n-// TODO: taskswitch handling\n-static void save_state_to_tss32(CPUState *cpu, struct x86_tss_segment32 *tss)\n-{\n- /* CR3 and ldt selector are not saved intentionally */\n- tss->eip = EIP(cpu);\n- tss->eflags = EFLAGS(cpu);\n- tss->eax = EAX(cpu);\n- tss->ecx = ECX(cpu);\n- tss->edx = EDX(cpu);\n- tss->ebx = EBX(cpu);\n- tss->esp = ESP(cpu);\n- tss->ebp = EBP(cpu);\n- tss->esi = ESI(cpu);\n- tss->edi = EDI(cpu);\n-\n- tss->es = vmx_read_segment_selector(cpu, REG_SEG_ES).sel;\n- tss->cs = vmx_read_segment_selector(cpu, REG_SEG_CS).sel;\n- tss->ss = vmx_read_segment_selector(cpu, REG_SEG_SS).sel;\n- tss->ds = vmx_read_segment_selector(cpu, REG_SEG_DS).sel;\n- tss->fs = vmx_read_segment_selector(cpu, REG_SEG_FS).sel;\n- tss->gs = vmx_read_segment_selector(cpu, REG_SEG_GS).sel;\n-}\n-\n-static void load_state_from_tss32(CPUState *cpu, struct x86_tss_segment32 *tss)\n-{\n- wvmcs(cpu->hvf_fd, VMCS_GUEST_CR3, tss->cr3);\n-\n- RIP(cpu) = tss->eip;\n- EFLAGS(cpu) = tss->eflags | 2;\n-\n- /* General purpose registers */\n- RAX(cpu) = tss->eax;\n- RCX(cpu) = tss->ecx;\n- RDX(cpu) = tss->edx;\n- RBX(cpu) = tss->ebx;\n- RSP(cpu) = tss->esp;\n- RBP(cpu) = tss->ebp;\n- RSI(cpu) = tss->esi;\n- RDI(cpu) = tss->edi;\n-\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ldt}}, REG_SEG_LDTR);\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->es}}, REG_SEG_ES);\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->cs}}, REG_SEG_CS);\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ss}}, REG_SEG_SS);\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ds}}, REG_SEG_DS);\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->fs}}, REG_SEG_FS);\n- vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->gs}}, REG_SEG_GS);\n-\n-#if 0\n- load_segment(cpu, REG_SEG_LDTR, tss->ldt);\n- load_segment(cpu, REG_SEG_ES, tss->es);\n- load_segment(cpu, REG_SEG_CS, tss->cs);\n- load_segment(cpu, REG_SEG_SS, tss->ss);\n- load_segment(cpu, REG_SEG_DS, tss->ds);\n- load_segment(cpu, REG_SEG_FS, tss->fs);\n- load_segment(cpu, REG_SEG_GS, tss->gs);\n-#endif\n-}\n-\n-static int task_switch_32(CPUState *cpu, x68_segment_selector tss_sel, x68_segment_selector old_tss_sel,\n- uint64_t old_tss_base, struct x86_segment_descriptor *new_desc)\n-{\n- struct x86_tss_segment32 tss_seg;\n- uint32_t new_tss_base = x86_segment_base(new_desc);\n- uint32_t eip_offset = offsetof(struct x86_tss_segment32, eip);\n- uint32_t ldt_sel_offset = offsetof(struct x86_tss_segment32, ldt);\n-\n- vmx_read_mem(cpu, &tss_seg, old_tss_base, sizeof(tss_seg));\n- save_state_to_tss32(cpu, &tss_seg);\n-\n- vmx_write_mem(cpu, old_tss_base + eip_offset, &tss_seg.eip, ldt_sel_offset - eip_offset);\n- vmx_read_mem(cpu, &tss_seg, new_tss_base, sizeof(tss_seg));\n-\n- if (old_tss_sel.sel != 0xffff) {\n- tss_seg.prev_tss = old_tss_sel.sel;\n-\n- vmx_write_mem(cpu, new_tss_base, &tss_seg.prev_tss, sizeof(tss_seg.prev_tss));\n- }\n- load_state_from_tss32(cpu, &tss_seg);\n- return 0;\n-}\n-\n-static void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type)\n-{\n- uint64_t rip = rreg(cpu->hvf_fd, HV_X86_RIP);\n- if (!gate_valid || (gate_type != VMCS_INTR_T_HWEXCEPTION &&\n- gate_type != VMCS_INTR_T_HWINTR &&\n- gate_type != VMCS_INTR_T_NMI)) {\n- int ins_len = rvmcs(cpu->hvf_fd, VMCS_EXIT_INSTRUCTION_LENGTH);\n- macvm_set_rip(cpu, rip + ins_len);\n- return;\n- }\n-\n- load_regs(cpu);\n-\n- struct x86_segment_descriptor curr_tss_desc, next_tss_desc;\n- int ret;\n- x68_segment_selector old_tss_sel = vmx_read_segment_selector(cpu, REG_SEG_TR);\n- uint64_t old_tss_base = vmx_read_segment_base(cpu, REG_SEG_TR);\n- uint32_t desc_limit;\n- struct x86_call_gate task_gate_desc;\n- struct vmx_segment vmx_seg;\n-\n- x86_read_segment_descriptor(cpu, &next_tss_desc, tss_sel);\n- x86_read_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel);\n-\n- if (reason == TSR_IDT_GATE && gate_valid) {\n- int dpl;\n-\n- ret = x86_read_call_gate(cpu, &task_gate_desc, gate);\n-\n- dpl = task_gate_desc.dpl;\n- x68_segment_selector cs = vmx_read_segment_selector(cpu, REG_SEG_CS);\n- if (tss_sel.rpl > dpl || cs.rpl > dpl)\n- ;//DPRINTF(\"emulate_gp\");\n- }\n-\n- desc_limit = x86_segment_limit(&next_tss_desc);\n- if (!next_tss_desc.p || ((desc_limit < 0x67 && (next_tss_desc.type & 8)) || desc_limit < 0x2b)) {\n- VM_PANIC(\"emulate_ts\");\n- }\n-\n- if (reason == TSR_IRET || reason == TSR_JMP) {\n- curr_tss_desc.type &= ~(1 << 1); /* clear busy flag */\n- x86_write_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel);\n- }\n-\n- if (reason == TSR_IRET)\n- EFLAGS(cpu) &= ~RFLAGS_NT;\n-\n- if (reason != TSR_CALL && reason != TSR_IDT_GATE)\n- old_tss_sel.sel = 0xffff;\n-\n- if (reason != TSR_IRET) {\n- next_tss_desc.type |= (1 << 1); /* set busy flag */\n- x86_write_segment_descriptor(cpu, &next_tss_desc, tss_sel);\n- }\n-\n- if (next_tss_desc.type & 8)\n- ret = task_switch_32(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc);\n- else\n- //ret = task_switch_16(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc);\n- VM_PANIC(\"task_switch_16\");\n-\n- macvm_set_cr0(cpu->hvf_fd, rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0) | CR0_TS);\n- x86_segment_descriptor_to_vmx(cpu, tss_sel, &next_tss_desc, &vmx_seg);\n- vmx_write_segment_descriptor(cpu, &vmx_seg, REG_SEG_TR);\n-\n- store_regs(cpu);\n-\n- hv_vcpu_invalidate_tlb(cpu->hvf_fd);\n- hv_vcpu_flush(cpu->hvf_fd);\n-}\n-\n static void hvf_handle_interrupt(CPUState * cpu, int mask)\n {\n cpu->interrupt_request |= mask;\ndiff --git a/target/i386/hvf-utils/Makefile.objs b/target/i386/hvf-utils/Makefile.objs\nindex 7df219ad9c..79d8969ca8 100644\n--- a/target/i386/hvf-utils/Makefile.objs\n+++ b/target/i386/hvf-utils/Makefile.objs\n@@ -1 +1 @@\n-obj-y += x86.o x86_cpuid.o x86_decode.o x86_descr.o x86_emu.o x86_flags.o x86_mmu.o x86hvf.o\n+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\ndiff --git a/target/i386/hvf-utils/vmx.h b/target/i386/hvf-utils/vmx.h\nindex 8a080e6777..e5359df87f 100644\n--- a/target/i386/hvf-utils/vmx.h\n+++ b/target/i386/hvf-utils/vmx.h\n@@ -6,17 +6,17 @@\n * Interfaces to Hypervisor.framework to read/write X86 registers and VMCS.\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #ifndef VMX_H\ndiff --git a/target/i386/hvf-utils/x86.c b/target/i386/hvf-utils/x86.c\nindex e3db2c9c8b..4debbff31c 100644\n--- a/target/i386/hvf-utils/x86.c\n+++ b/target/i386/hvf-utils/x86.c\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #include \"qemu/osdep.h\"\ndiff --git a/target/i386/hvf-utils/x86.h b/target/i386/hvf-utils/x86.h\nindex 5dffdd6568..d433d15ea4 100644\n--- a/target/i386/hvf-utils/x86.h\n+++ b/target/i386/hvf-utils/x86.h\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Veertu Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #pragma once\ndiff --git a/target/i386/hvf-utils/x86_cpuid.c b/target/i386/hvf-utils/x86_cpuid.c\nindex e496cf001c..4abeb5c2da 100644\n--- a/target/i386/hvf-utils/x86_cpuid.c\n+++ b/target/i386/hvf-utils/x86_cpuid.c\n@@ -4,18 +4,18 @@\n * Copyright (c) 2003 Fabrice Bellard\n * Copyright (c) 2017 Google Inc.\n *\n- * This library is free software; you can redistribute it and/or\n+ * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2 of the License, or (at your option) any later version.\n *\n- * This library is distributed in the hope that it will be useful,\n+ * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n- * License along with this library; if not, see <http://www.gnu.org/licenses/>.\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n *\n * cpuid\n */\ndiff --git a/target/i386/hvf-utils/x86_cpuid.h b/target/i386/hvf-utils/x86_cpuid.h\nindex 02f2f115b0..b84a2f08df 100644\n--- a/target/i386/hvf-utils/x86_cpuid.h\n+++ b/target/i386/hvf-utils/x86_cpuid.h\n@@ -2,17 +2,17 @@\n * Copyright (C) 2016 Veertu Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n #ifndef __CPUID_H__\n #define __CPUID_H__\ndiff --git a/target/i386/hvf-utils/x86_decode.c b/target/i386/hvf-utils/x86_decode.c\nindex b4d8e22449..8deaab11d2 100644\n--- a/target/i386/hvf-utils/x86_decode.c\n+++ b/target/i386/hvf-utils/x86_decode.c\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #include \"qemu/osdep.h\"\ndiff --git a/target/i386/hvf-utils/x86_decode.h b/target/i386/hvf-utils/x86_decode.h\nindex 3a22d7d1a5..fde524f819 100644\n--- a/target/i386/hvf-utils/x86_decode.h\n+++ b/target/i386/hvf-utils/x86_decode.h\n@@ -2,17 +2,17 @@\n * Copyright (C) 2016 Veertu Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #pragma once\ndiff --git a/target/i386/hvf-utils/x86_descr.c b/target/i386/hvf-utils/x86_descr.c\nindex c3b089aaa8..0b9562818f 100644\n--- a/target/i386/hvf-utils/x86_descr.c\n+++ b/target/i386/hvf-utils/x86_descr.c\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #include \"qemu/osdep.h\"\ndiff --git a/target/i386/hvf-utils/x86_descr.h b/target/i386/hvf-utils/x86_descr.h\nindex 78fb1bc420..9917585aeb 100644\n--- a/target/i386/hvf-utils/x86_descr.h\n+++ b/target/i386/hvf-utils/x86_descr.h\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #pragma once\ndiff --git a/target/i386/hvf-utils/x86_emu.c b/target/i386/hvf-utils/x86_emu.c\nindex 8b5efc76f0..76680921d1 100644\n--- a/target/i386/hvf-utils/x86_emu.c\n+++ b/target/i386/hvf-utils/x86_emu.c\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n /////////////////////////////////////////////////////////////////////////\ndiff --git a/target/i386/hvf-utils/x86_emu.h b/target/i386/hvf-utils/x86_emu.h\nindex 42cc5e4296..f6feff5553 100644\n--- a/target/i386/hvf-utils/x86_emu.h\n+++ b/target/i386/hvf-utils/x86_emu.h\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n #ifndef __X86_EMU_H__\n #define __X86_EMU_H__\ndiff --git a/target/i386/hvf-utils/x86_gen.h b/target/i386/hvf-utils/x86_gen.h\nindex e4340fa244..2045b0e69d 100644\n--- a/target/i386/hvf-utils/x86_gen.h\n+++ b/target/i386/hvf-utils/x86_gen.h\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n #ifndef __X86_GEN_H__\n #define __X86_GEN_H__\ndiff --git a/target/i386/hvf-utils/x86_mmu.c b/target/i386/hvf-utils/x86_mmu.c\nindex 00fae735be..95b3d15b94 100644\n--- a/target/i386/hvf-utils/x86_mmu.c\n+++ b/target/i386/hvf-utils/x86_mmu.c\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n #include \"qemu/osdep.h\"\n \ndiff --git a/target/i386/hvf-utils/x86_mmu.h b/target/i386/hvf-utils/x86_mmu.h\nindex f794d04b3d..aa0fcfafd2 100644\n--- a/target/i386/hvf-utils/x86_mmu.h\n+++ b/target/i386/hvf-utils/x86_mmu.h\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n #ifndef __X86_MMU_H__\n #define __X86_MMU_H__\ndiff --git a/target/i386/hvf-utils/x86_task.c b/target/i386/hvf-utils/x86_task.c\nnew file mode 100644\nindex 0000000000..1a2646437a\n--- /dev/null\n+++ b/target/i386/hvf-utils/x86_task.c\n@@ -0,0 +1,201 @@\n+// This software is licensed under the terms of the GNU General Public\n+// License version 2, as published by the Free Software Foundation, and\n+// may be copied, distributed, and modified under those terms.\n+// \n+// This program is distributed in the hope that it will be useful,\n+// but WITHOUT ANY WARRANTY; without even the implied warranty of\n+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+// GNU General Public License for more details.\n+#include \"qemu/osdep.h\"\n+#include \"qemu-common.h\"\n+#include \"qemu/error-report.h\"\n+\n+#include \"sysemu/hvf.h\"\n+#include \"hvf-i386.h\"\n+#include \"hvf-utils/vmcs.h\"\n+#include \"hvf-utils/vmx.h\"\n+#include \"hvf-utils/x86.h\"\n+#include \"hvf-utils/x86_descr.h\"\n+#include \"hvf-utils/x86_mmu.h\"\n+#include \"hvf-utils/x86_decode.h\"\n+#include \"hvf-utils/x86_emu.h\"\n+#include \"hvf-utils/x86_cpuid.h\"\n+#include \"hvf-utils/x86_task.h\"\n+#include \"hvf-utils/x86hvf.h\"\n+\n+#include <Hypervisor/hv.h>\n+#include <Hypervisor/hv_vmx.h>\n+\n+#include \"exec/address-spaces.h\"\n+#include \"exec/exec-all.h\"\n+#include \"exec/ioport.h\"\n+#include \"hw/i386/apic_internal.h\"\n+#include \"hw/boards.h\"\n+#include \"qemu/main-loop.h\"\n+#include \"strings.h\"\n+#include \"sysemu/accel.h\"\n+#include \"sysemu/sysemu.h\"\n+#include \"target/i386/cpu.h\"\n+\n+// TODO: taskswitch handling\n+static void save_state_to_tss32(CPUState *cpu, struct x86_tss_segment32 *tss)\n+{\n+ X86CPU *x86_cpu = X86_CPU(cpu);\n+ CPUX86State *env = &x86_cpu->env;\n+\n+ /* CR3 and ldt selector are not saved intentionally */\n+ tss->eip = EIP(env);\n+ tss->eflags = EFLAGS(env);\n+ tss->eax = EAX(env);\n+ tss->ecx = ECX(env);\n+ tss->edx = EDX(env);\n+ tss->ebx = EBX(env);\n+ tss->esp = ESP(env);\n+ tss->ebp = EBP(env);\n+ tss->esi = ESI(env);\n+ tss->edi = EDI(env);\n+\n+ tss->es = vmx_read_segment_selector(cpu, REG_SEG_ES).sel;\n+ tss->cs = vmx_read_segment_selector(cpu, REG_SEG_CS).sel;\n+ tss->ss = vmx_read_segment_selector(cpu, REG_SEG_SS).sel;\n+ tss->ds = vmx_read_segment_selector(cpu, REG_SEG_DS).sel;\n+ tss->fs = vmx_read_segment_selector(cpu, REG_SEG_FS).sel;\n+ tss->gs = vmx_read_segment_selector(cpu, REG_SEG_GS).sel;\n+}\n+\n+static void load_state_from_tss32(CPUState *cpu, struct x86_tss_segment32 *tss)\n+{\n+ X86CPU *x86_cpu = X86_CPU(cpu);\n+ CPUX86State *env = &x86_cpu->env;\n+\n+ wvmcs(cpu->hvf_fd, VMCS_GUEST_CR3, tss->cr3);\n+\n+ RIP(env) = tss->eip;\n+ EFLAGS(env) = tss->eflags | 2;\n+\n+ /* General purpose registers */\n+ RAX(env) = tss->eax;\n+ RCX(env) = tss->ecx;\n+ RDX(env) = tss->edx;\n+ RBX(env) = tss->ebx;\n+ RSP(env) = tss->esp;\n+ RBP(env) = tss->ebp;\n+ RSI(env) = tss->esi;\n+ RDI(env) = tss->edi;\n+\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ldt}}, REG_SEG_LDTR);\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->es}}, REG_SEG_ES);\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->cs}}, REG_SEG_CS);\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ss}}, REG_SEG_SS);\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ds}}, REG_SEG_DS);\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->fs}}, REG_SEG_FS);\n+ vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->gs}}, REG_SEG_GS);\n+\n+#if 0\n+ load_segment(cpu, REG_SEG_LDTR, tss->ldt);\n+ load_segment(cpu, REG_SEG_ES, tss->es);\n+ load_segment(cpu, REG_SEG_CS, tss->cs);\n+ load_segment(cpu, REG_SEG_SS, tss->ss);\n+ load_segment(cpu, REG_SEG_DS, tss->ds);\n+ load_segment(cpu, REG_SEG_FS, tss->fs);\n+ load_segment(cpu, REG_SEG_GS, tss->gs);\n+#endif\n+}\n+\n+static int task_switch_32(CPUState *cpu, x68_segment_selector tss_sel, x68_segment_selector old_tss_sel,\n+ uint64_t old_tss_base, struct x86_segment_descriptor *new_desc)\n+{\n+ struct x86_tss_segment32 tss_seg;\n+ uint32_t new_tss_base = x86_segment_base(new_desc);\n+ uint32_t eip_offset = offsetof(struct x86_tss_segment32, eip);\n+ uint32_t ldt_sel_offset = offsetof(struct x86_tss_segment32, ldt);\n+\n+ vmx_read_mem(cpu, &tss_seg, old_tss_base, sizeof(tss_seg));\n+ save_state_to_tss32(cpu, &tss_seg);\n+\n+ vmx_write_mem(cpu, old_tss_base + eip_offset, &tss_seg.eip, ldt_sel_offset - eip_offset);\n+ vmx_read_mem(cpu, &tss_seg, new_tss_base, sizeof(tss_seg));\n+\n+ if (old_tss_sel.sel != 0xffff) {\n+ tss_seg.prev_tss = old_tss_sel.sel;\n+\n+ vmx_write_mem(cpu, new_tss_base, &tss_seg.prev_tss, sizeof(tss_seg.prev_tss));\n+ }\n+ load_state_from_tss32(cpu, &tss_seg);\n+ return 0;\n+}\n+\n+void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type)\n+{\n+ uint64_t rip = rreg(cpu->hvf_fd, HV_X86_RIP);\n+ if (!gate_valid || (gate_type != VMCS_INTR_T_HWEXCEPTION &&\n+ gate_type != VMCS_INTR_T_HWINTR &&\n+ gate_type != VMCS_INTR_T_NMI)) {\n+ int ins_len = rvmcs(cpu->hvf_fd, VMCS_EXIT_INSTRUCTION_LENGTH);\n+ macvm_set_rip(cpu, rip + ins_len);\n+ return;\n+ }\n+\n+ load_regs(cpu);\n+\n+ struct x86_segment_descriptor curr_tss_desc, next_tss_desc;\n+ int ret;\n+ x68_segment_selector old_tss_sel = vmx_read_segment_selector(cpu, REG_SEG_TR);\n+ uint64_t old_tss_base = vmx_read_segment_base(cpu, REG_SEG_TR);\n+ uint32_t desc_limit;\n+ struct x86_call_gate task_gate_desc;\n+ struct vmx_segment vmx_seg;\n+\n+ X86CPU *x86_cpu = X86_CPU(cpu);\n+ CPUX86State *env = &x86_cpu->env;\n+\n+ x86_read_segment_descriptor(cpu, &next_tss_desc, tss_sel);\n+ x86_read_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel);\n+\n+ if (reason == TSR_IDT_GATE && gate_valid) {\n+ int dpl;\n+\n+ ret = x86_read_call_gate(cpu, &task_gate_desc, gate);\n+\n+ dpl = task_gate_desc.dpl;\n+ x68_segment_selector cs = vmx_read_segment_selector(cpu, REG_SEG_CS);\n+ if (tss_sel.rpl > dpl || cs.rpl > dpl)\n+ ;//DPRINTF(\"emulate_gp\");\n+ }\n+\n+ desc_limit = x86_segment_limit(&next_tss_desc);\n+ if (!next_tss_desc.p || ((desc_limit < 0x67 && (next_tss_desc.type & 8)) || desc_limit < 0x2b)) {\n+ VM_PANIC(\"emulate_ts\");\n+ }\n+\n+ if (reason == TSR_IRET || reason == TSR_JMP) {\n+ curr_tss_desc.type &= ~(1 << 1); /* clear busy flag */\n+ x86_write_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel);\n+ }\n+\n+ if (reason == TSR_IRET)\n+ EFLAGS(env) &= ~RFLAGS_NT;\n+\n+ if (reason != TSR_CALL && reason != TSR_IDT_GATE)\n+ old_tss_sel.sel = 0xffff;\n+\n+ if (reason != TSR_IRET) {\n+ next_tss_desc.type |= (1 << 1); /* set busy flag */\n+ x86_write_segment_descriptor(cpu, &next_tss_desc, tss_sel);\n+ }\n+\n+ if (next_tss_desc.type & 8)\n+ ret = task_switch_32(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc);\n+ else\n+ //ret = task_switch_16(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc);\n+ VM_PANIC(\"task_switch_16\");\n+\n+ macvm_set_cr0(cpu->hvf_fd, rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0) | CR0_TS);\n+ x86_segment_descriptor_to_vmx(cpu, tss_sel, &next_tss_desc, &vmx_seg);\n+ vmx_write_segment_descriptor(cpu, &vmx_seg, REG_SEG_TR);\n+\n+ store_regs(cpu);\n+\n+ hv_vcpu_invalidate_tlb(cpu->hvf_fd);\n+ hv_vcpu_flush(cpu->hvf_fd);\n+}\ndiff --git a/target/i386/hvf-utils/x86_task.h b/target/i386/hvf-utils/x86_task.h\nnew file mode 100644\nindex 0000000000..4f1b188d2e\n--- /dev/null\n+++ b/target/i386/hvf-utils/x86_task.h\n@@ -0,0 +1,18 @@\n+/* This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 or\n+ * (at your option) version 3 of the License.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License along\n+ * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ */\n+#ifndef HVF_TASK\n+#define HVF_TASK\n+void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel,\n+ int reason, bool gate_valid, uint8_t gate, uint64_t gate_type);\n+#endif\ndiff --git a/target/i386/hvf-utils/x86hvf.c b/target/i386/hvf-utils/x86hvf.c\nindex d5668df37f..aba8983dc7 100644\n--- a/target/i386/hvf-utils/x86hvf.c\n+++ b/target/i386/hvf-utils/x86hvf.c\n@@ -4,17 +4,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n \n #include \"qemu/osdep.h\"\ndiff --git a/target/i386/hvf-utils/x86hvf.h b/target/i386/hvf-utils/x86hvf.h\nindex fbc2158a2b..0c5bc3dcf8 100644\n--- a/target/i386/hvf-utils/x86hvf.h\n+++ b/target/i386/hvf-utils/x86hvf.h\n@@ -3,17 +3,17 @@\n * Copyright (C) 2017 Google Inc,\n *\n * This program is free software; you can redistribute it and/or\n- * modify it under the terms of the GNU General Public License as\n- * published by the Free Software Foundation; either version 2 or\n- * (at your option) version 3 of the License.\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n- * GNU General Public License for more details.\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n *\n- * You should have received a copy of the GNU General Public License along\n- * with this program; if not, see <http://www.gnu.org/licenses/>.\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.\n */\n #ifndef X86HVF_H\n #define X86HVF_H\n", "prefixes": [ "v4", "03/14" ] }