ia64/xen-unstable

changeset 11113:4210049a5854

Add utilities needed for SMBIOS generation to hvmloader.
Signed-off-by: Andrew D. Ball <aball@us.ibm.com>
author kfraser@localhost.localdomain
date Mon Aug 14 17:28:25 2006 +0100 (2006-08-14)
parents 963a67ab8130
children 5a454f6e320f
files tools/firmware/hvmloader/hvmloader.c tools/firmware/hvmloader/util.c tools/firmware/hvmloader/util.h
line diff
     1.1 --- a/tools/firmware/hvmloader/hvmloader.c	Mon Aug 14 16:41:20 2006 +0100
     1.2 +++ b/tools/firmware/hvmloader/hvmloader.c	Mon Aug 14 17:28:25 2006 +0100
     1.3 @@ -116,15 +116,6 @@ check_amd(void)
     1.4  }
     1.5  
     1.6  static void
     1.7 -cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
     1.8 -{
     1.9 -	__asm__ __volatile__(
    1.10 -		"cpuid"
    1.11 -		: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
    1.12 -		: "0" (idx) );
    1.13 -}
    1.14 -
    1.15 -static void
    1.16  wrmsr(uint32_t idx, uint64_t v)
    1.17  {
    1.18  	__asm__ __volatile__(
     2.1 --- a/tools/firmware/hvmloader/util.c	Mon Aug 14 16:41:20 2006 +0100
     2.2 +++ b/tools/firmware/hvmloader/util.c	Mon Aug 14 17:28:25 2006 +0100
     2.3 @@ -20,6 +20,7 @@
     2.4  
     2.5  #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
     2.6  #include "util.h"
     2.7 +#include <stdint.h>
     2.8  
     2.9  void outw(uint16_t addr, uint16_t val)
    2.10  {
    2.11 @@ -94,3 +95,82 @@ void puts(const char *s)
    2.12  	while (*s)
    2.13  		outb(0xE9, *s++);
    2.14  }
    2.15 +
    2.16 +char *
    2.17 +strcpy(char *dest, const char *src)
    2.18 +{
    2.19 +	char *p = dest;
    2.20 +	while (*src)
    2.21 +		*p++ = *src++;
    2.22 +	*p = 0;
    2.23 +	return dest;
    2.24 +}
    2.25 +
    2.26 +char *
    2.27 +strncpy(char *dest, const char *src, unsigned n)
    2.28 +{
    2.29 +	int i = 0;
    2.30 +	char *p = dest;
    2.31 +
    2.32 +	/* write non-NUL characters from src into dest until we run
    2.33 +	   out of room in dest or encounter a NUL in src */
    2.34 +	while (i < n && *src) {
    2.35 +		*p++ = *src++;
    2.36 +		++i;
    2.37 +	}
    2.38 +
    2.39 +	/* pad remaining bytes of dest with NUL bytes */
    2.40 +	while (i < n) {
    2.41 +		*p++ = 0;
    2.42 +		++i;
    2.43 +	}
    2.44 +
    2.45 +	return dest;
    2.46 +}
    2.47 +
    2.48 +unsigned
    2.49 +strlen(const char *s)
    2.50 +{
    2.51 +	int i = 0;
    2.52 +	while (*s++)
    2.53 +		++i;
    2.54 +	return i;
    2.55 +}
    2.56 +
    2.57 +void *
    2.58 +memset(void *s, int c, unsigned n)
    2.59 +{
    2.60 +	uint8_t b = (uint8_t) c;
    2.61 +	uint8_t *p = (uint8_t *)s;
    2.62 +	int i;
    2.63 +	for (i = 0; i < n; ++i)
    2.64 +		*p++ = b;
    2.65 +	return s;
    2.66 +}
    2.67 +
    2.68 +int
    2.69 +memcmp(const void *s1, const void *s2, unsigned n)
    2.70 +{
    2.71 +	unsigned i;
    2.72 +	uint8_t *p1 = (uint8_t *) s1;
    2.73 +	uint8_t *p2 = (uint8_t *) s2;
    2.74 +
    2.75 +	for (i = 0; i < n; ++i) {
    2.76 +		if (p1[i] < p2[i])
    2.77 +			return -1;
    2.78 +		else if (p1[i] > p2[i])
    2.79 +			return 1;
    2.80 +	}
    2.81 +
    2.82 +	return 0;
    2.83 +}
    2.84 +
    2.85 +void
    2.86 +cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
    2.87 +{
    2.88 +	__asm__ __volatile__(
    2.89 +		"cpuid"
    2.90 +		: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
    2.91 +		: "0" (idx) );
    2.92 +}
    2.93 +
     3.1 --- a/tools/firmware/hvmloader/util.h	Mon Aug 14 16:41:20 2006 +0100
     3.2 +++ b/tools/firmware/hvmloader/util.h	Mon Aug 14 17:28:25 2006 +0100
     3.3 @@ -8,9 +8,21 @@ void outb(uint16_t addr, uint8_t val);
     3.4  /* I/O input */
     3.5  uint8_t inb(uint16_t addr);
     3.6  
     3.7 +/* Do cpuid instruction, with operation 'idx' */
     3.8 +void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
     3.9 +           uint32_t *ecx, uint32_t *edx);
    3.10 +
    3.11 +/* Return number of vcpus. */
    3.12 +int get_vcpu_nr(void);
    3.13 +
    3.14  /* String and memory functions */
    3.15  int strcmp(const char *cs, const char *ct);
    3.16 +char *strcpy(char *dest, const char *src);
    3.17 +char *strncpy(char *dest, const char *src, unsigned n);
    3.18 +unsigned strlen(const char *s);
    3.19 +int memcmp(const void *s1, const void *s2, unsigned n);
    3.20  void *memcpy(void *dest, const void *src, unsigned n);
    3.21 +void *memset(void *s, int c, unsigned n);
    3.22  char *itoa(char *a, unsigned int i);
    3.23  
    3.24  /* Debug output */