diff options
author | Carsten Otte <cotte@de.ibm.com> | 2007-10-29 16:08:51 +0100 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 17:52:57 +0200 |
commit | 5fb76f9be1a050a25e21a44ab2003c9d36a72a77 (patch) | |
tree | fa5a184ade52e55746efb1bab59fa283ee3535ed /drivers/kvm/x86.c | |
parent | 1fe779f8eccd16e527315e1bafd2b3a876ff2489 (diff) | |
download | lwn-5fb76f9be1a050a25e21a44ab2003c9d36a72a77.tar.gz lwn-5fb76f9be1a050a25e21a44ab2003c9d36a72a77.zip |
KVM: Portability: Move memory segmentation to x86.c
This patch moves the definition of segment_descriptor_64 for AMD64 and
EM64T from kvm_main.c to segment_descriptor.h. It also adds a proper
#ifndef...#define...#endif around that header file.
The implementation of segment_base is moved from kvm_main.c to x86.c.
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/x86.c')
-rw-r--r-- | drivers/kvm/x86.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index b84cb6707f78..5a959220410a 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c @@ -16,16 +16,49 @@ #include "kvm.h" #include "x86.h" +#include "segment_descriptor.h" #include "irq.h" #include <linux/kvm.h> #include <linux/fs.h> #include <linux/vmalloc.h> +#include <linux/module.h> #include <asm/uaccess.h> #define MAX_IO_MSRS 256 +unsigned long segment_base(u16 selector) +{ + struct descriptor_table gdt; + struct segment_descriptor *d; + unsigned long table_base; + unsigned long v; + + if (selector == 0) + return 0; + + asm("sgdt %0" : "=m"(gdt)); + table_base = gdt.base; + + if (selector & 4) { /* from ldt */ + u16 ldt_selector; + + asm("sldt %0" : "=g"(ldt_selector)); + table_base = segment_base(ldt_selector); + } + d = (struct segment_descriptor *)(table_base + (selector & ~7)); + v = d->base_low | ((unsigned long)d->base_mid << 16) | + ((unsigned long)d->base_high << 24); +#ifdef CONFIG_X86_64 + if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11)) + v |= ((unsigned long) \ + ((struct segment_descriptor_64 *)d)->base_higher) << 32; +#endif + return v; +} +EXPORT_SYMBOL_GPL(segment_base); + /* * List of msr numbers which we expose to userspace through KVM_GET_MSRS * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. |