ia64/xen-unstable

view tools/ioemu/target-i386-dm/rtc-dm.c @ 15841:c5f735271e22

[IA64] Foreign p2m: Fix vti domain builder.

It should set arch_domain::convmem_end.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Thu Sep 06 13:48:43 2007 -0600 (2007-09-06)
parents 00618037d37d
children
line source
1 /*
2 * QEMU MC146818 RTC emulation
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
25 #include "vl.h"
27 // #define DEBUG_CMOS
29 struct RTCState {
30 uint8_t cmos_data[128];
31 uint8_t cmos_index;
32 };
34 static inline int to_bcd(RTCState *s, int a)
35 {
36 return ((a / 10) << 4) | (a % 10);
37 }
39 void rtc_set_memory(RTCState *s, int addr, int val)
40 {
41 if (addr >= 0 && addr <= 127)
42 s->cmos_data[addr] = val;
43 }
45 static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
46 {
47 RTCState *s = opaque;
49 if ((addr & 1) == 0) {
50 s->cmos_index = data & 0x7f;
51 } else {
52 #ifdef DEBUG_CMOS
53 printf("cmos: write index=0x%02x val=0x%02x\n",
54 s->cmos_index, data);
55 #endif
56 s->cmos_data[s->cmos_index] = data;
57 }
58 }
60 static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
61 {
62 RTCState *s = opaque;
63 int ret;
64 if ((addr & 1) == 0) {
65 return 0xff;
66 } else {
67 ret = s->cmos_data[s->cmos_index];
68 #ifdef DEBUG_CMOS
69 printf("cmos: read index=0x%02x val=0x%02x\n",
70 s->cmos_index, ret);
71 #endif
72 return ret;
73 }
74 }
76 static void rtc_save(QEMUFile *f, void *opaque)
77 {
78 RTCState *s = opaque;
80 qemu_put_buffer(f, s->cmos_data, 128);
81 qemu_put_8s(f, &s->cmos_index);
82 }
84 static int rtc_load(QEMUFile *f, void *opaque, int version_id)
85 {
86 RTCState *s = opaque;
88 if (version_id != 1)
89 return -EINVAL;
91 qemu_get_buffer(f, s->cmos_data, 128);
92 qemu_get_8s(f, &s->cmos_index);
94 return 0;
95 }
97 RTCState *rtc_init(int base, int irq)
98 {
99 RTCState *s;
100 time_t ti;
101 struct tm *tm;
102 int val;
104 s = qemu_mallocz(sizeof(RTCState));
105 if (!s)
106 return NULL;
108 /* PC cmos mappings */
109 #define REG_IBM_CENTURY_BYTE 0x32
110 #define REG_IBM_PS2_CENTURY_BYTE 0x37
111 time(&ti);
112 tm = gmtime(&ti); /* XXX localtime and update from guest? */
113 val = to_bcd(s, (tm->tm_year / 100) + 19);
114 rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val);
115 rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val);
117 register_ioport_write(base, 2, 1, cmos_ioport_write, s);
118 register_ioport_read(base, 2, 1, cmos_ioport_read, s);
120 register_savevm("mc146818rtc", base, 1, rtc_save, rtc_load, s);
121 return s;
122 }
124 void rtc_set_date(RTCState *s, const struct tm *tm) {}