]> xenbits.xensource.com Git - xtf.git/commitdiff
Introduce static inline helpers for {l,s}{gdt,idt,ldt,tr}()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 7 Oct 2016 15:03:03 +0000 (16:03 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 11 Oct 2016 10:39:15 +0000 (11:39 +0100)
And replace existing opencoded examples.  The m16 forms of str/sldt are awkard
to encode in a way which doesn't impact the more common reg encoding.  Leave
the asm constraints as reg only, which causes the processor to zero-extend the
selector into the destination register.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/hvm/traps.c
include/arch/x86/lib.h

index 792a5968f85168e51c48af1e6a47640e44b99125..b957fe1a1c34b77721a0b324a91ac6564609754b 100644 (file)
@@ -117,10 +117,10 @@ void arch_init_traps(void)
 
     setup_gate(X86_VEC_RET2KERN, &entry_ret_to_kernel, 3);
 
-    asm volatile ("lidt idt_ptr");
+    lidt(&idt_ptr);
 
     gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89);
-    asm volatile ("ltr %w0" :: "rm" (GDTE_TSS * 8));
+    ltr(GDTE_TSS * 8);
 }
 
 void __noreturn arch_crash_hard(void)
index df5002aacf487cc571a6d0c3814d508c38b6bc69..3073e91cc673b7d464938a802d098c1488d49fa9 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <xtf/types.h>
 #include <xen/arch-x86/xen.h>
+#include <arch/x86/desc.h>
 
 static inline uint64_t rdmsr(uint32_t idx)
 {
@@ -306,6 +307,54 @@ static inline void invlpg(const void *va)
     asm volatile ("invlpg (%0)" :: "r" (va));
 }
 
+static inline void lgdt(const desc_ptr *gdtr)
+{
+    asm volatile ("lgdt %0" :: "m" (*gdtr));
+}
+
+static inline void lidt(const desc_ptr *idtr)
+{
+    asm volatile ("lidt %0" :: "m" (*idtr));
+}
+
+static inline void lldt(unsigned int sel)
+{
+    asm volatile ("lldt %w0" :: "rm" (sel));
+}
+
+static inline void ltr(unsigned int sel)
+{
+    asm volatile ("ltr %w0" :: "rm" (sel));
+}
+
+static inline void sgdt(desc_ptr *gdtr)
+{
+    asm volatile ("sgdt %0" : "=m" (*gdtr));
+}
+
+static inline void sidt(desc_ptr *idtr)
+{
+    asm volatile ("sidt %0" : "=m" (*idtr));
+}
+
+static inline unsigned int sldt(void)
+{
+    unsigned int sel;
+
+    asm volatile ("sldt %0" : "=r" (sel));
+
+    return sel;
+}
+
+static inline unsigned int str(void)
+{
+    unsigned int sel;
+
+    asm volatile ("str %0" : "=r" (sel));
+
+    return sel;
+}
+
 #endif /* XTF_X86_LIB_H */
 
 /*