4 * Copyright (c) 2008 CodeSourcery
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
26 #include "qemu-timer.h"
44 static uint64_t syborg_rtc_read(void *opaque
, target_phys_addr_t offset
,
47 SyborgRTCState
*s
= (SyborgRTCState
*)opaque
;
49 switch (offset
>> 2) {
53 return (uint32_t)s
->data
;
55 return (uint32_t)(s
->data
>> 32);
57 cpu_abort(cpu_single_env
, "syborg_rtc_read: Bad offset %x\n",
63 static void syborg_rtc_write(void *opaque
, target_phys_addr_t offset
,
64 uint64_t value
, unsigned size
)
66 SyborgRTCState
*s
= (SyborgRTCState
*)opaque
;
70 switch (offset
>> 2) {
72 now
= qemu_get_clock_ns(vm_clock
);
74 s
->offset
= s
->data
- now
;
76 s
->data
= now
+ s
->offset
;
84 s
->data
= (s
->data
& ~(uint64_t)0xffffffffu
) | value
;
87 s
->data
= (s
->data
& 0xffffffffu
) | ((uint64_t)value
<< 32);
90 cpu_abort(cpu_single_env
, "syborg_rtc_write: Bad offset %x\n",
96 static const MemoryRegionOps syborg_rtc_ops
= {
97 .read
= syborg_rtc_read
,
98 .write
= syborg_rtc_write
,
99 .endianness
= DEVICE_NATIVE_ENDIAN
,
102 static const VMStateDescription vmstate_syborg_rtc
= {
103 .name
= "syborg_keyboard",
105 .minimum_version_id
= 1,
106 .minimum_version_id_old
= 1,
107 .fields
= (VMStateField
[]) {
108 VMSTATE_INT64(offset
, SyborgRTCState
),
109 VMSTATE_INT64(data
, SyborgRTCState
),
110 VMSTATE_END_OF_LIST()
114 static int syborg_rtc_init(SysBusDevice
*dev
)
116 SyborgRTCState
*s
= FROM_SYSBUS(SyborgRTCState
, dev
);
119 memory_region_init_io(&s
->iomem
, &syborg_rtc_ops
, s
, "rtc", 0x1000);
120 sysbus_init_mmio(dev
, &s
->iomem
);
122 qemu_get_timedate(&tm
, 0);
123 s
->offset
= (uint64_t)mktime(&tm
) * 1000000000;
125 vmstate_register(&dev
->qdev
, -1, &vmstate_syborg_rtc
, s
);
129 static void syborg_rtc_register_devices(void)
131 sysbus_register_dev("syborg,rtc", sizeof(SyborgRTCState
), syborg_rtc_init
);
134 device_init(syborg_rtc_register_devices
)