aboutsummaryrefslogtreecommitdiff
path: root/hw/cuda.c
diff options
context:
space:
mode:
authoraurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-15 18:57:15 +0000
committeraurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-15 18:57:15 +0000
commit5703c174ff8bd2072e6cb77d87fa3e85c98bf043 (patch)
treec41bd7c18de546af75ad519c3b654fdaa1b3fcba /hw/cuda.c
parentc72d5bf87ee5234d885e63f47f5197e9b58ae67e (diff)
cuda: improve date/time read/write
- Allow date/time to be written - Use qemu_get_timedate() to initialize the clock Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6313 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/cuda.c')
-rw-r--r--hw/cuda.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/hw/cuda.c b/hw/cuda.c
index 92fd69bda9..3fde6cd9e1 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -131,6 +131,8 @@ typedef struct CUDAState {
CUDATimer timers[2];
+ uint32_t tick_offset;
+
uint8_t last_b; /* last value of B register */
uint8_t last_acr; /* last value of B register */
@@ -510,7 +512,8 @@ static void cuda_receive_packet(CUDAState *s,
const uint8_t *data, int len)
{
uint8_t obuf[16];
- int ti, autopoll;
+ int autopoll;
+ uint32_t ti;
switch(data[0]) {
case CUDA_AUTOPOLL:
@@ -529,10 +532,16 @@ static void cuda_receive_packet(CUDAState *s,
obuf[1] = data[1];
cuda_send_packet_to_host(s, obuf, 2);
break;
- case CUDA_GET_TIME:
case CUDA_SET_TIME:
- /* XXX: add time support ? */
- ti = time(NULL) + RTC_OFFSET;
+ ti = (((uint32_t)data[1]) << 24) + (((uint32_t)data[2]) << 16) + (((uint32_t)data[3]) << 8) + data[4];
+ s->tick_offset = ti - (qemu_get_clock(vm_clock) / ticks_per_sec);
+ obuf[0] = CUDA_PACKET;
+ obuf[1] = 0;
+ obuf[2] = 0;
+ cuda_send_packet_to_host(s, obuf, 3);
+ break;
+ case CUDA_GET_TIME:
+ ti = s->tick_offset + (qemu_get_clock(vm_clock) / ticks_per_sec);
obuf[0] = CUDA_PACKET;
obuf[1] = 0;
obuf[2] = 0;
@@ -663,6 +672,7 @@ static void cuda_save(QEMUFile *f, void *opaque)
qemu_put_ubyte(f, s->autopoll);
qemu_put_buffer(f, s->data_in, sizeof(s->data_in));
qemu_put_buffer(f, s->data_out, sizeof(s->data_out));
+ qemu_put_be32s(f, &s->tick_offset);
cuda_save_timer(f, &s->timers[0]);
cuda_save_timer(f, &s->timers[1]);
}
@@ -700,6 +710,7 @@ static int cuda_load(QEMUFile *f, void *opaque, int version_id)
s->autopoll = qemu_get_ubyte(f);
qemu_get_buffer(f, s->data_in, sizeof(s->data_in));
qemu_get_buffer(f, s->data_out, sizeof(s->data_out));
+ qemu_get_be32s(f, &s->tick_offset);
cuda_load_timer(f, &s->timers[0]);
cuda_load_timer(f, &s->timers[1]);
@@ -735,6 +746,7 @@ static void cuda_reset(void *opaque)
void cuda_init (int *cuda_mem_index, qemu_irq irq)
{
+ struct tm tm;
CUDAState *s = &cuda_state;
s->irq = irq;
@@ -744,6 +756,9 @@ void cuda_init (int *cuda_mem_index, qemu_irq irq)
s->timers[1].index = 1;
+ qemu_get_timedate(&tm, RTC_OFFSET);
+ s->tick_offset = mktimegm(&tm);
+
s->adb_poll_timer = qemu_new_timer(vm_clock, cuda_adb_poll, s);
*cuda_mem_index = cpu_register_io_memory(0, cuda_read, cuda_write, s);
register_savevm("cuda", -1, 1, cuda_save, cuda_load, s);