--- trunk/src/devices/dev_8253.c 2007/10/08 16:19:11 18 +++ trunk/src/devices/dev_8253.c 2007/10/08 16:19:37 22 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Anders Gavare. All rights reserved. + * Copyright (C) 2005-2006 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: dev_8253.c,v 1.5 2005/10/26 14:37:03 debug Exp $ + * $Id: dev_8253.c,v 1.9 2006/02/09 20:02:58 debug Exp $ * * 8253/8254 Programmable Interval Timer. * @@ -51,6 +51,7 @@ struct pit8253_data { int irq_nr; + int in_use; int counter_select; }; @@ -61,6 +62,10 @@ void dev_8253_tick(struct cpu *cpu, void *extra) { struct pit8253_data *d = (struct pit8253_data *) extra; + + if (!d->in_use) + return; + cpu_interrupt(cpu, d->irq_nr); } @@ -68,9 +73,7 @@ /* * dev_8253_access(): */ -int dev_8253_access(struct cpu *cpu, struct memory *mem, - uint64_t relative_addr, unsigned char *data, size_t len, - int writeflag, void *extra) +DEVICE_ACCESS(8253) { struct pit8253_data *d = (struct pit8253_data *) extra; uint64_t idata = 0, odata = 0; @@ -78,6 +81,8 @@ if (writeflag == MEM_WRITE) idata = memory_readmax64(cpu, data, len); + d->in_use = 1; + /* TODO: ack somewhere else */ cpu_interrupt_ack(cpu, d->irq_nr); @@ -87,8 +92,8 @@ /* TODO */ } else { /* TODO */ - odata = 1; -odata = random(); + /* odata = 1; */ + odata = random(); } break; case 0x03: @@ -116,10 +121,7 @@ } -/* - * devinit_8253(): - */ -int devinit_8253(struct devinit *devinit) +DEVINIT(8253) { struct pit8253_data *d = malloc(sizeof(struct pit8253_data)); @@ -129,10 +131,11 @@ } memset(d, 0, sizeof(struct pit8253_data)); d->irq_nr = devinit->irq_nr; + d->in_use = devinit->in_use; memory_device_register(devinit->machine->memory, devinit->name, devinit->addr, DEV_8253_LENGTH, dev_8253_access, (void *)d, - MEM_DEFAULT, NULL); + DM_DEFAULT, NULL); machine_add_tickfunction(devinit->machine, dev_8253_tick, d, TICK_SHIFT);