debuggers.hg

view tools/ioemu/patches/hypervisor-rtc @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 # HG changeset patch
2 # User kfraser@localhost.localdomain
3 # Node ID 71e2a165aa7f81602c569430b18ba1ea705f0b70
4 # Parent da66691687dfd90c55420cfdf27f55d18cca7810
5 [HVM] Move RTC emulation into the hypervisor.
6 Signed-off-by: Xiaowei Yang <xiaowei.yang@intel.com>
8 Index: ioemu/Makefile.target
9 ===================================================================
10 --- ioemu.orig/Makefile.target 2007-05-09 14:12:44.000000000 +0100
11 +++ ioemu/Makefile.target 2007-05-09 14:14:08.000000000 +0100
12 @@ -324,7 +324,11 @@
13 endif
15 # qemu-dm objects
16 +ifeq ($(ARCH),ia64)
17 LIBOBJS=helper2.o exec-dm.o i8259-dm.o
18 +else
19 +LIBOBJS=helper2.o exec-dm.o i8259-dm.o rtc-dm.o
20 +endif
22 all: $(PROGS)
24 @@ -386,7 +390,11 @@
25 ifeq ($(TARGET_BASE_ARCH), i386)
26 # Hardware support
27 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
28 +ifeq ($(ARCH),ia64)
29 VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
30 +else
31 +VL_OBJS+= fdc.o serial.o pc.o
32 +endif
33 VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
34 VL_OBJS+= usb-uhci.o smbus_eeprom.o
35 VL_OBJS+= piix4acpi.o
36 Index: ioemu/target-i386-dm/rtc-dm.c
37 ===================================================================
38 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
39 +++ ioemu/target-i386-dm/rtc-dm.c 2007-05-09 14:14:13.000000000 +0100
40 @@ -0,0 +1,124 @@
41 +/*
42 + * QEMU MC146818 RTC emulation
43 + *
44 + * Copyright (c) 2003-2004 Fabrice Bellard
45 + *
46 + * Permission is hereby granted, free of charge, to any person obtaining a copy
47 + * of this software and associated documentation files (the "Software"), to deal
48 + * in the Software without restriction, including without limitation the rights
49 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50 + * copies of the Software, and to permit persons to whom the Software is
51 + * furnished to do so, subject to the following conditions:
52 + *
53 + * The above copyright notice and this permission notice shall be included in
54 + * all copies or substantial portions of the Software.
55 + *
56 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
59 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
62 + * THE SOFTWARE.
63 + */
64 +
65 +#include "vl.h"
66 +
67 +// #define DEBUG_CMOS
68 +
69 +struct RTCState {
70 + uint8_t cmos_data[128];
71 + uint8_t cmos_index;
72 +};
73 +
74 +static inline int to_bcd(RTCState *s, int a)
75 +{
76 + return ((a / 10) << 4) | (a % 10);
77 +}
78 +
79 +void rtc_set_memory(RTCState *s, int addr, int val)
80 +{
81 + if (addr >= 0 && addr <= 127)
82 + s->cmos_data[addr] = val;
83 +}
84 +
85 +static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
86 +{
87 + RTCState *s = opaque;
88 +
89 + if ((addr & 1) == 0) {
90 + s->cmos_index = data & 0x7f;
91 + } else {
92 +#ifdef DEBUG_CMOS
93 + printf("cmos: write index=0x%02x val=0x%02x\n",
94 + s->cmos_index, data);
95 +#endif
96 + s->cmos_data[s->cmos_index] = data;
97 + }
98 +}
99 +
100 +static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
101 +{
102 + RTCState *s = opaque;
103 + int ret;
104 + if ((addr & 1) == 0) {
105 + return 0xff;
106 + } else {
107 + ret = s->cmos_data[s->cmos_index];
108 +#ifdef DEBUG_CMOS
109 + printf("cmos: read index=0x%02x val=0x%02x\n",
110 + s->cmos_index, ret);
111 +#endif
112 + return ret;
113 + }
114 +}
115 +
116 +static void rtc_save(QEMUFile *f, void *opaque)
117 +{
118 + RTCState *s = opaque;
119 +
120 + qemu_put_buffer(f, s->cmos_data, 128);
121 + qemu_put_8s(f, &s->cmos_index);
122 +}
123 +
124 +static int rtc_load(QEMUFile *f, void *opaque, int version_id)
125 +{
126 + RTCState *s = opaque;
127 +
128 + if (version_id != 1)
129 + return -EINVAL;
130 +
131 + qemu_get_buffer(f, s->cmos_data, 128);
132 + qemu_get_8s(f, &s->cmos_index);
133 +
134 + return 0;
135 +}
136 +
137 +RTCState *rtc_init(int base, int irq)
138 +{
139 + RTCState *s;
140 + time_t ti;
141 + struct tm *tm;
142 + int val;
143 +
144 + s = qemu_mallocz(sizeof(RTCState));
145 + if (!s)
146 + return NULL;
147 +
148 +/* PC cmos mappings */
149 +#define REG_IBM_CENTURY_BYTE 0x32
150 +#define REG_IBM_PS2_CENTURY_BYTE 0x37
151 + time(&ti);
152 + tm = gmtime(&ti); /* XXX localtime and update from guest? */
153 + val = to_bcd(s, (tm->tm_year / 100) + 19);
154 + rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val);
155 + rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val);
156 +
157 + register_ioport_write(base, 2, 1, cmos_ioport_write, s);
158 + register_ioport_read(base, 2, 1, cmos_ioport_read, s);
159 +
160 + register_savevm("mc146818rtc", base, 1, rtc_save, rtc_load, s);
161 + return s;
162 +}
163 +
164 +void rtc_set_date(RTCState *s, const struct tm *tm) {}