]> xenbits.xensource.com Git - xen.git/commitdiff
hvmloader: Small cleanups.
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 14 Apr 2008 13:10:11 +0000 (14:10 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 14 Apr 2008 13:10:11 +0000 (14:10 +0100)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
tools/firmware/hvmloader/hvmloader.c
tools/firmware/hvmloader/util.c
tools/firmware/hvmloader/util.h

index f27191cf29bccbff4d99dd88500bcd203d4fd991..44104551342c9b9d6f45d81c8ab039e963284427 100644 (file)
@@ -108,14 +108,6 @@ cirrus_check(void)
     return inb(0x3C5) == 0x12;
 }
 
-static void
-wrmsr(uint32_t idx, uint64_t v)
-{
-    __asm__ __volatile__ (
-        "wrmsr"
-        : : "c" (idx), "a" ((uint32_t)v), "d" ((uint32_t)(v>>32)) );
-}
-
 static void
 init_hypercalls(void)
 {
@@ -131,11 +123,7 @@ init_hypercalls(void)
     *(uint32_t *)(signature + 8) = edx;
     signature[12] = '\0';
 
-    if ( strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002) )
-    {
-        printf("FATAL: Xen hypervisor not detected\n");
-        __asm__ __volatile__( "ud2" );
-    }
+    BUG_ON(strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002));
 
     /* Fill in hypercall transfer pages. */
     cpuid(0x40000002, &eax, &ebx, &ecx, &edx);
index b57575fe9ad9ae1553c53018ce3201a3b4f60914..37f40ef2fa2ef243be54c8e266e30c2d7452bdbc 100644 (file)
 #include <xen/memory.h>
 #include <xen/hvm/hvm_info_table.h>
 
+void wrmsr(uint32_t idx, uint64_t v)
+{
+    asm volatile (
+        "wrmsr"
+        : : "c" (idx), "a" ((uint32_t)v), "d" ((uint32_t)(v>>32)) );
+}
+
+uint64_t rdmsr(uint32_t idx)
+{
+    uint32_t lo, hi;
+
+    asm volatile (
+        "rdmsr"
+        : "=a" (lo), "=d" (hi) : "c" (idx) );
+
+    return (lo | ((uint64_t)hi << 32));
+}
+
 void outb(uint16_t addr, uint8_t val)
 {
-    __asm__ __volatile__ ( "outb %%al, %%dx" : : "d" (addr), "a" (val) );
+    asm volatile ( "outb %%al, %%dx" : : "d" (addr), "a" (val) );
 }
 
 void outw(uint16_t addr, uint16_t val)
 {
-    __asm__ __volatile__ ( "outw %%ax, %%dx" : : "d" (addr), "a" (val) );
+    asm volatile ( "outw %%ax, %%dx" : : "d" (addr), "a" (val) );
 }
 
 void outl(uint16_t addr, uint32_t val)
 {
-    __asm__ __volatile__ ( "outl %%eax, %%dx" : : "d" (addr), "a" (val) );
+    asm volatile ( "outl %%eax, %%dx" : : "d" (addr), "a" (val) );
 }
 
 uint8_t inb(uint16_t addr)
 {
     uint8_t val;
-    __asm__ __volatile__ ( "inb %%dx,%%al" : "=a" (val) : "d" (addr) );
+    asm volatile ( "inb %%dx,%%al" : "=a" (val) : "d" (addr) );
     return val;
 }
 
 uint16_t inw(uint16_t addr)
 {
     uint16_t val;
-    __asm__ __volatile__ ( "inw %%dx,%%ax" : "=a" (val) : "d" (addr) );
+    asm volatile ( "inw %%dx,%%ax" : "=a" (val) : "d" (addr) );
     return val;
 }
 
 uint32_t inl(uint16_t addr)
 {
     uint32_t val;
-    __asm__ __volatile__ ( "inl %%dx,%%eax" : "=a" (val) : "d" (addr) );
+    asm volatile ( "inl %%dx,%%eax" : "=a" (val) : "d" (addr) );
     return val;
 }
 
@@ -118,7 +136,7 @@ void *memcpy(void *dest, const void *src, unsigned n)
 {
     int t0, t1, t2;
 
-    __asm__ __volatile__ (
+    asm volatile (
         "cld\n"
         "rep; movsl\n"
         "testb $2,%b4\n"
@@ -219,7 +237,7 @@ memcmp(const void *s1, const void *s2, unsigned n)
 void
 cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 {
-    __asm__ __volatile__ (
+    asm volatile (
         "cpuid"
         : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
         : "0" (idx) );
@@ -516,14 +534,14 @@ void __assert_failed(char *assertion, char *file, int line)
     printf("HVMLoader assertion '%s' failed at %s:%d\n",
            assertion, file, line);
     for ( ; ; )
-        __asm__ __volatile__ ( "ud2" );
+        asm volatile ( "ud2" );
 }
 
 void __bug(char *file, int line)
 {
     printf("HVMLoader bug at %s:%d\n", file, line);
     for ( ; ; )
-        __asm__ __volatile__ ( "ud2" );
+        asm volatile ( "ud2" );
 }
 
 static int validate_hvm_info(struct hvm_info_table *t)
index ac06983d9b18eeea01c43984a8f9cad5017fcf14..846335208f552decce497d6e4f38ee147412b47b 100644 (file)
@@ -19,6 +19,10 @@ void __bug(char *file, int line) __attribute__((noreturn));
 #define BUG_ON(p) do { if (p) BUG(); } while (0)
 #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
 
+/* MSR access */
+void wrmsr(uint32_t idx, uint64_t v);
+uint64_t rdmsr(uint32_t idx);
+
 /* I/O output */
 void outb(uint16_t addr, uint8_t  val);
 void outw(uint16_t addr, uint16_t val);