Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Change the layout of the SEG state:
details: https://anonhg.NetBSD.org/src/rev/a352832a1ce1
branches: trunk
changeset: 839577:a352832a1ce1
user: maxv <maxv%NetBSD.org@localhost>
date: Tue Feb 26 12:23:12 2019 +0000
description:
Change the layout of the SEG state:
- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.
- Compress it. This divides its size by two.
- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.
diffstat:
lib/libnvmm/libnvmm_x86.c | 49 ++++++++++++++++---------------
sys/dev/nvmm/x86/nvmm_x86.c | 62 +++++++++++++++++++++++----------------
sys/dev/nvmm/x86/nvmm_x86.h | 35 +++++++++++----------
sys/dev/nvmm/x86/nvmm_x86_svm.c | 40 ++++++++++---------------
sys/dev/nvmm/x86/nvmm_x86_vmx.c | 51 +++++++++++++++-----------------
tests/lib/libnvmm/h_io_assist.c | 7 ++-
tests/lib/libnvmm/h_mem_assist.c | 7 ++-
7 files changed, 127 insertions(+), 124 deletions(-)
diffs (truncated from 550 to 300 lines):
diff -r 997999f7fc38 -r a352832a1ce1 lib/libnvmm/libnvmm_x86.c
--- a/lib/libnvmm/libnvmm_x86.c Tue Feb 26 10:30:28 2019 +0000
+++ b/lib/libnvmm/libnvmm_x86.c Tue Feb 26 12:23:12 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: libnvmm_x86.c,v 1.25 2019/02/26 10:18:39 maxv Exp $ */
+/* $NetBSD: libnvmm_x86.c,v 1.26 2019/02/26 12:23:12 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -60,11 +60,12 @@
nvmm_vcpu_dump(struct nvmm_machine *mach, nvmm_cpuid_t cpuid)
{
struct nvmm_x64_state state;
+ uint16_t *attr;
size_t i;
int ret;
const char *segnames[] = {
- "CS", "DS", "ES", "FS", "GS", "SS", "GDT", "IDT", "LDT", "TR"
+ "ES", "CS", "SS", "DS", "FS", "GS", "GDT", "IDT", "LDT", "TR"
};
ret = nvmm_vcpu_getstate(mach, cpuid, &state, NVMM_X64_STATE_ALL);
@@ -72,26 +73,26 @@
return -1;
printf("+ VCPU id=%d\n", (int)cpuid);
- printf("| -> RIP=%p\n", (void *)state.gprs[NVMM_X64_GPR_RIP]);
- printf("| -> RSP=%p\n", (void *)state.gprs[NVMM_X64_GPR_RSP]);
- printf("| -> RAX=%p\n", (void *)state.gprs[NVMM_X64_GPR_RAX]);
- printf("| -> RBX=%p\n", (void *)state.gprs[NVMM_X64_GPR_RBX]);
- printf("| -> RCX=%p\n", (void *)state.gprs[NVMM_X64_GPR_RCX]);
+ printf("| -> RIP=%"PRIx64"\n", state.gprs[NVMM_X64_GPR_RIP]);
+ printf("| -> RSP=%"PRIx64"\n", state.gprs[NVMM_X64_GPR_RSP]);
+ printf("| -> RAX=%"PRIx64"\n", state.gprs[NVMM_X64_GPR_RAX]);
+ printf("| -> RBX=%"PRIx64"\n", state.gprs[NVMM_X64_GPR_RBX]);
+ printf("| -> RCX=%"PRIx64"\n", state.gprs[NVMM_X64_GPR_RCX]);
printf("| -> RFLAGS=%p\n", (void *)state.gprs[NVMM_X64_GPR_RFLAGS]);
for (i = 0; i < NVMM_X64_NSEG; i++) {
- printf("| -> %s: sel=0x%lx base=%p, limit=%p, P=%d, D=%d L=%d\n",
+ attr = (uint16_t *)&state.segs[i].attrib;
+ printf("| -> %s: sel=0x%x base=%"PRIx64", limit=%x, attrib=%x\n",
segnames[i],
state.segs[i].selector,
- (void *)state.segs[i].base,
- (void *)state.segs[i].limit,
- state.segs[i].attrib.p, state.segs[i].attrib.def32,
- state.segs[i].attrib.lng);
+ state.segs[i].base,
+ state.segs[i].limit,
+ *attr);
}
- printf("| -> MSR_EFER=%p\n", (void *)state.msrs[NVMM_X64_MSR_EFER]);
- printf("| -> CR0=%p\n", (void *)state.crs[NVMM_X64_CR_CR0]);
- printf("| -> CR3=%p\n", (void *)state.crs[NVMM_X64_CR_CR3]);
- printf("| -> CR4=%p\n", (void *)state.crs[NVMM_X64_CR_CR4]);
- printf("| -> CR8=%p\n", (void *)state.crs[NVMM_X64_CR_CR8]);
+ printf("| -> MSR_EFER=%"PRIx64"\n", state.msrs[NVMM_X64_MSR_EFER]);
+ printf("| -> CR0=%"PRIx64"\n", state.crs[NVMM_X64_CR_CR0]);
+ printf("| -> CR3=%"PRIx64"\n", state.crs[NVMM_X64_CR_CR3]);
+ printf("| -> CR4=%"PRIx64"\n", state.crs[NVMM_X64_CR_CR4]);
+ printf("| -> CR8=%"PRIx64"\n", state.crs[NVMM_X64_CR_CR8]);
return 0;
}
@@ -449,21 +450,21 @@
static inline bool
is_64bit(struct nvmm_x64_state *state)
{
- return (state->segs[NVMM_X64_SEG_CS].attrib.lng != 0);
+ return (state->segs[NVMM_X64_SEG_CS].attrib.l != 0);
}
static inline bool
is_32bit(struct nvmm_x64_state *state)
{
- return (state->segs[NVMM_X64_SEG_CS].attrib.lng == 0) &&
- (state->segs[NVMM_X64_SEG_CS].attrib.def32 == 1);
+ return (state->segs[NVMM_X64_SEG_CS].attrib.l == 0) &&
+ (state->segs[NVMM_X64_SEG_CS].attrib.def == 1);
}
static inline bool
is_16bit(struct nvmm_x64_state *state)
{
- return (state->segs[NVMM_X64_SEG_CS].attrib.lng == 0) &&
- (state->segs[NVMM_X64_SEG_CS].attrib.def32 == 0);
+ return (state->segs[NVMM_X64_SEG_CS].attrib.l == 0) &&
+ (state->segs[NVMM_X64_SEG_CS].attrib.def == 0);
}
static int
@@ -479,8 +480,8 @@
goto error;
}
- limit = (seg->limit + 1);
- if (__predict_true(seg->attrib.gran)) {
+ limit = (uint64_t)seg->limit + 1;
+ if (__predict_true(seg->attrib.g)) {
limit *= PAGE_SIZE;
}
diff -r 997999f7fc38 -r a352832a1ce1 sys/dev/nvmm/x86/nvmm_x86.c
--- a/sys/dev/nvmm/x86/nvmm_x86.c Tue Feb 26 10:30:28 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86.c Tue Feb 26 12:23:12 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_x86.c,v 1.1 2019/02/23 12:27:00 maxv Exp $ */
+/* $NetBSD: nvmm_x86.c,v 1.2 2019/02/26 12:23:12 maxv Exp $ */
/*
* Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.1 2019/02/23 12:27:00 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.2 2019/02/26 12:23:12 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -54,12 +54,33 @@
const struct nvmm_x64_state nvmm_x86_reset_state = {
.segs = {
+ [NVMM_X64_SEG_ES] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = 3,
+ .s = 1,
+ .p = 1,
+ }
+ },
[NVMM_X64_SEG_CS] = {
.selector = 0xF000,
.base = 0xFFFF0000,
.limit = 0xFFFF,
.attrib = {
- .type = SDT_MEMRWA,
+ .type = 3,
+ .s = 1,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_SS] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = 3,
+ .s = 1,
.p = 1,
}
},
@@ -68,16 +89,8 @@
.base = 0x00000000,
.limit = 0xFFFF,
.attrib = {
- .type = SDT_MEMRWA,
- .p = 1,
- }
- },
- [NVMM_X64_SEG_ES] = {
- .selector = 0x0000,
- .base = 0x00000000,
- .limit = 0xFFFF,
- .attrib = {
- .type = SDT_MEMRWA,
+ .type = 3,
+ .s = 1,
.p = 1,
}
},
@@ -86,7 +99,8 @@
.base = 0x00000000,
.limit = 0xFFFF,
.attrib = {
- .type = SDT_MEMRWA,
+ .type = 3,
+ .s = 1,
.p = 1,
}
},
@@ -95,16 +109,8 @@
.base = 0x00000000,
.limit = 0xFFFF,
.attrib = {
- .type = SDT_MEMRWA,
- .p = 1,
- }
- },
- [NVMM_X64_SEG_SS] = {
- .selector = 0x0000,
- .base = 0x00000000,
- .limit = 0xFFFF,
- .attrib = {
- .type = SDT_MEMRWA,
+ .type = 3,
+ .s = 1,
.p = 1,
}
},
@@ -113,7 +119,8 @@
.base = 0x00000000,
.limit = 0xFFFF,
.attrib = {
- .type = SDT_MEMRW,
+ .type = 2,
+ .s = 1,
.p = 1,
}
},
@@ -122,7 +129,8 @@
.base = 0x00000000,
.limit = 0xFFFF,
.attrib = {
- .type = SDT_MEMRW,
+ .type = 2,
+ .s = 1,
.p = 1,
}
},
@@ -132,6 +140,7 @@
.limit = 0xFFFF,
.attrib = {
.type = SDT_SYSLDT,
+ .s = 0,
.p = 1,
}
},
@@ -141,6 +150,7 @@
.limit = 0xFFFF,
.attrib = {
.type = SDT_SYS286BSY,
+ .s = 0,
.p = 1,
}
},
diff -r 997999f7fc38 -r a352832a1ce1 sys/dev/nvmm/x86/nvmm_x86.h
--- a/sys/dev/nvmm/x86/nvmm_x86.h Tue Feb 26 10:30:28 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86.h Tue Feb 26 12:23:12 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_x86.h,v 1.6 2019/02/23 12:27:00 maxv Exp $ */
+/* $NetBSD: nvmm_x86.h,v 1.7 2019/02/26 12:23:12 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -33,12 +33,12 @@
#define _NVMM_X86_H_
/* Segments. */
-#define NVMM_X64_SEG_CS 0
-#define NVMM_X64_SEG_DS 1
-#define NVMM_X64_SEG_ES 2
-#define NVMM_X64_SEG_FS 3
-#define NVMM_X64_SEG_GS 4
-#define NVMM_X64_SEG_SS 5
+#define NVMM_X64_SEG_ES 0
+#define NVMM_X64_SEG_CS 1
+#define NVMM_X64_SEG_SS 2
+#define NVMM_X64_SEG_DS 3
+#define NVMM_X64_SEG_FS 4
+#define NVMM_X64_SEG_GS 5
#define NVMM_X64_SEG_GDT 6
#define NVMM_X64_SEG_IDT 7
#define NVMM_X64_SEG_LDT 8
@@ -109,18 +109,19 @@
#include <x86/cpu_extended_state.h>
struct nvmm_x64_state_seg {
- uint64_t selector;
+ uint16_t selector;
struct { /* hidden */
- uint64_t type:5;
- uint64_t dpl:2;
- uint64_t p:1;
- uint64_t avl:1;
- uint64_t lng:1;
- uint64_t def32:1;
- uint64_t gran:1;
- uint64_t rsvd:52;
+ uint16_t type:4;
+ uint16_t s:1;
+ uint16_t dpl:2;
+ uint16_t p:1;
+ uint16_t avl:1;
+ uint16_t l:1;
+ uint16_t def:1;
+ uint16_t g:1;
+ uint16_t rsvd:4;
} attrib;
- uint64_t limit; /* hidden */
+ uint32_t limit; /* hidden */
uint64_t base; /* hidden */
};
diff -r 997999f7fc38 -r a352832a1ce1 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c Tue Feb 26 10:30:28 2019 +0000
Home |
Main Index |
Thread Index |
Old Index