[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] [3/5] SMBIOS -- add some utilities to hvmloader for SMBIOS generation


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: "Andrew D. Ball" <aball@xxxxxxxxxx>
  • Date: Fri, 11 Aug 2006 18:05:11 -0400
  • Delivery-date: Mon, 14 Aug 2006 08:15:11 -0700
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

Add utilities needed for SMBIOS generation to hvmloader.

Signed-off-by: Andrew D. Ball <aball@xxxxxxxxxx>

diff -r 1d817bfc5ed9 tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c   Fri Aug 11 14:22:54 2006 +0100
+++ b/tools/firmware/hvmloader/util.c   Fri Aug 11 15:43:13 2006 -0400
@@ -20,6 +20,7 @@
 
 #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
 #include "util.h"
+#include <stdint.h>
 
 void outw(uint16_t addr, uint16_t val)
 {
@@ -94,3 +95,82 @@ void puts(const char *s)
        while (*s)
                outb(0xE9, *s++);
 }
+
+char *
+strcpy(char *dest, const char *src)
+{
+    char *p = dest;
+    while (*src)
+        *p++ = *src++;
+    *p = 0;
+    return dest;
+}
+
+char *
+strncpy(char *dest, const char *src, unsigned n)
+{
+    int i = 0;
+    char *p = dest;
+
+    /* write non-NUL characters from src into dest until we run
+       out of room in dest or encounter a NUL in src */
+    while (i < n && *src) {
+        *p++ = *src++;
+        ++i;
+    }
+
+    /* pad remaining bytes of dest with NUL bytes */
+    while (i < n) {
+        *p++ = 0;
+        ++i;
+    }
+
+    return dest;
+}
+
+unsigned
+strlen(const char *s)
+{
+    int i = 0;
+    while (*s++)
+        ++i;
+    return i;
+}
+
+void *
+memset(void *s, int c, unsigned n)
+{
+    uint8_t b = (uint8_t) c;
+    uint8_t *p = (uint8_t *)s;
+    int i;
+    for (i = 0; i < n; ++i)
+        *p++ = b;
+    return s;
+}
+
+int
+memcmp(const void *s1, const void *s2, unsigned n)
+{
+    unsigned i;
+    uint8_t *p1 = (uint8_t *) s1;
+    uint8_t *p2 = (uint8_t *) s2;
+
+    for (i = 0; i < n; ++i) {
+        if (p1[i] < p2[i])
+            return -1;
+        else if (p1[i] > p2[i])
+            return 1;
+    }
+
+    return 0;
+}
+
+void
+cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+        __asm__ __volatile__(
+                "cpuid"
+                : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+                : "0" (idx) );
+}
+
diff -r 1d817bfc5ed9 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Fri Aug 11 14:22:54 2006 +0100
+++ b/tools/firmware/hvmloader/util.h   Fri Aug 11 16:12:56 2006 -0400
@@ -8,9 +8,20 @@ void outb(uint16_t addr, uint8_t val);
 /* I/O input */
 uint8_t inb(uint16_t addr);
 
+/* Do cpuid instruction, with operation 'idx' */
+void
+cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t 
*edx);
+/* return number of vcpus */
+int get_vcpu_nr(void);
+
 /* String and memory functions */
 int strcmp(const char *cs, const char *ct);
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, unsigned n);
+unsigned strlen(const char *s);
+int memcmp(const void *s1, const void *s2, unsigned n);
 void *memcpy(void *dest, const void *src, unsigned n);
+void *memset(void *s, int c, unsigned n);
 char *itoa(char *a, unsigned int i);
 
 /* Debug output */



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.