]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Split out symbolic constant support into a separate file
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 8 Jan 2016 18:25:40 +0000 (18:25 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 11 Jan 2016 17:34:34 +0000 (17:34 +0000)
While moving, rename _INIT_GDTE() to INIT_GDTE() and drop INIT_GDTE_RAW()
entirely.  Document the new INIT_GDTE() and implement INIT_GDTE_SYM() using
it.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/desc.c
arch/x86/hvm/traps.c
include/arch/x86/desc.h
include/arch/x86/symbolic-const.h [new file with mode: 0644]

index 605876926a115634d249eb1e925ea228cb64c192..ec49b47414402c18dde8a8d8764b6c0d2febfb98 100644 (file)
@@ -1,5 +1,6 @@
 #include <arch/x86/desc.h>
 #include <arch/x86/segment.h>
+#include <arch/x86/symbolic-const.h>
 
 user_desc gdt[NR_GDT_ENTRIES] =
 {
index a860153041a2c23c3ad48f476682133518139969..f2455bd88f74ba9af0dbe7b091e52c10c0347129 100644 (file)
@@ -106,7 +106,7 @@ void arch_init_traps(void)
 
     asm volatile ("lidt idt_ptr");
 
-    gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE_RAW((unsigned long)&tss, 0x67, 0x89);
+    gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89);
     asm volatile ("ltr %w0" :: "rm" (GDTE_TSS * 8));
 }
 
index dc55726a395c2c908b34da621f7c1b8ac732243b..f8e6235ce29f47753c3393ede26bca1dd82bd759 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <xtf/types.h>
 #include <xtf/compiler.h>
-#include <xtf/macro_magic.h>
 
 #include <arch/x86/segment.h>
 
@@ -120,31 +119,19 @@ struct __packed seg_gate64 {
 #define SEG_ATTR_E      0x0004 /**< Expand-down? (0 = normal, 1 = expand-down) */
 #define SEG_ATTR_W      0x0002 /**< Writable? (0 = RO seg, 1 = RW seg) */
 
-/* Macro magic to expand symbolic SEG_ATTR names into a constant */
-#define _GDTE_ATTR0()       (0)
-#define _GDTE_ATTR1(x)      (SEG_ATTR_ ## x)
-#define _GDTE_ATTR2(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR1(__VA_ARGS__))
-#define _GDTE_ATTR3(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR2(__VA_ARGS__))
-#define _GDTE_ATTR4(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR3(__VA_ARGS__))
-#define _GDTE_ATTR5(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR4(__VA_ARGS__))
-#define _GDTE_ATTR6(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR5(__VA_ARGS__))
-#define _GDTE_ATTR7(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR6(__VA_ARGS__))
-#define _GDTE_ATTR8(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR7(__VA_ARGS__))
-
-#define GDTE_ATTR(...) VAR_MACRO(_GDTE_ATTR, __VA_ARGS__)
-
-
-#define _INIT_GDTE(base, limit, attr) { { {                           \
+/**
+ * Initialise an LDT/GDT entry using a raw attribute number.
+ *
+ * @param base  Segment base.
+ * @param limit Segment limit.
+ * @param attr  Segment attributes.
+ */
+#define INIT_GDTE(base, limit, attr) { { {                            \
      .lo = (((base) & 0xffff) << 16) | ((limit) & 0xffff),            \
      .hi = ((base) & 0xff000000) | ((limit) & 0xf0000) |              \
            (((attr) & 0xf0ff) << 8) | (((base) & 0xff0000) >> 16)     \
      } } }
 
-/** Initialise an LDT/GDT entry using a raw attribute number. */
-#define INIT_GDTE_RAW(base, limit, attr) _INIT_GDTE(base, limit, attr)
-/** Initialise an LDT/GDT entry using symbol attributes. */
-#define INIT_GDTE_SYM(base, limit, ...)  _INIT_GDTE(base, limit, GDTE_ATTR(__VA_ARGS__))
-
 /** Long mode lgdt/lidt table pointer. */
 struct __packed desc_ptr64 {
     uint16_t limit;
diff --git a/include/arch/x86/symbolic-const.h b/include/arch/x86/symbolic-const.h
new file mode 100644 (file)
index 0000000..26d2edf
--- /dev/null
@@ -0,0 +1,53 @@
+/**
+ * @file include/arch/x86/symbolic-const.h
+ *
+ * Macros for creating constants using mnemonics.
+ */
+#ifndef XTF_X86_SYMBOLIC_CONST_H
+#define XTF_X86_SYMBOLIC_CONST_H
+
+#include <xtf/macro_magic.h>
+
+#include <arch/x86/desc.h>
+
+/* Macro magic to expand symbolic SEG_ATTR names into a constant */
+#define _GDTE_ATTR0()       (0)
+#define _GDTE_ATTR1(x)      (SEG_ATTR_ ## x)
+#define _GDTE_ATTR2(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR1(__VA_ARGS__))
+#define _GDTE_ATTR3(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR2(__VA_ARGS__))
+#define _GDTE_ATTR4(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR3(__VA_ARGS__))
+#define _GDTE_ATTR5(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR4(__VA_ARGS__))
+#define _GDTE_ATTR6(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR5(__VA_ARGS__))
+#define _GDTE_ATTR7(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR6(__VA_ARGS__))
+#define _GDTE_ATTR8(x, ...) (SEG_ATTR_ ## x | _GDTE_ATTR7(__VA_ARGS__))
+
+#define _GDTE_ATTR(...) VAR_MACRO(_GDTE_ATTR, __VA_ARGS__)
+
+/**
+ * Initialise an LDT/GDT entry using SEG_ATTR_ mnemonics.
+ *
+ * @param base  Segment base.
+ * @param limit Segment limit.
+ * @param ...   Partial SEG_ATTR_ tokens for attributes.
+ *
+ * Example usage:
+ * - INIT_GDTE_SYM(0, 0xfffff, P)
+ *   - uses @ref SEG_ATTR_P
+ *
+ * - INIT_GDTE_SYM(0, 0xfffff, CODE, L)
+ *   - uses @ref SEG_ATTR_CODE and @ref SEG_ATTR_L
+ */
+#define INIT_GDTE_SYM(base, limit, ...) \
+    INIT_GDTE(base, limit, _GDTE_ATTR(__VA_ARGS__))
+
+#endif /* XTF_X86_SYMBOLIC_CONST_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */