debuggers.hg

view tools/firmware/hvmloader/util.c @ 10986:49dcd838b7df

[HVMLOADER] HVM loader initialises hypercall shim and uses
it to interrogate Xen version information. Also add support
for HVM hypercall execution on 64-bit host.

Signed-off-by: Steven Smith <ssmith@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Aug 04 20:30:12 2006 +0100 (2006-08-04)
parents
children 4210049a5854
line source
1 /*
2 * util.c: Helper library functions for HVMLoader.
3 *
4 * Leendert van Doorn, leendert@watson.ibm.com
5 * Copyright (c) 2005, International Business Machines Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place - Suite 330, Boston, MA 02111-1307 USA.
19 */
21 #include "../acpi/acpi2_0.h" /* for ACPI_PHYSICAL_ADDRESS */
22 #include "util.h"
24 void outw(uint16_t addr, uint16_t val)
25 {
26 __asm__ __volatile__ ("outw %%ax, %%dx" :: "d"(addr), "a"(val));
27 }
29 void outb(uint16_t addr, uint8_t val)
30 {
31 __asm__ __volatile__ ("outb %%al, %%dx" :: "d"(addr), "a"(val));
32 }
34 uint8_t inb(uint16_t addr)
35 {
36 uint8_t val;
37 __asm__ __volatile__ ("inb %w1,%0" : "=a" (val) : "Nd" (addr));
38 return val;
39 }
41 char *itoa(char *a, unsigned int i)
42 {
43 unsigned int _i = i, x = 0;
45 do {
46 x++;
47 _i /= 10;
48 } while (_i != 0);
50 a += x;
51 *a-- = '\0';
53 do {
54 *a-- = (i % 10) + '0';
55 i /= 10;
56 } while (i != 0);
58 return a + 1;
59 }
61 int strcmp(const char *cs, const char *ct)
62 {
63 signed char res;
65 while (((res = *cs - *ct++) == 0) && (*cs++ != '\0'))
66 continue;
68 return res;
69 }
71 void *memcpy(void *dest, const void *src, unsigned n)
72 {
73 int t0, t1, t2;
75 __asm__ __volatile__(
76 "cld\n"
77 "rep; movsl\n"
78 "testb $2,%b4\n"
79 "je 1f\n"
80 "movsw\n"
81 "1: testb $1,%b4\n"
82 "je 2f\n"
83 "movsb\n"
84 "2:"
85 : "=&c" (t0), "=&D" (t1), "=&S" (t2)
86 : "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
87 : "memory"
88 );
89 return dest;
90 }
92 void puts(const char *s)
93 {
94 while (*s)
95 outb(0xE9, *s++);
96 }