diff --git a/hw/hpet.c b/hw/hpet.c index 8729fb2..c2615c1 100644 --- a/hw/hpet.c +++ b/hw/hpet.c @@ -29,6 +29,7 @@ #include "console.h" #include "qemu-timer.h" #include "hpet_emul.h" +#include "mc146818rtc.h" //#define HPET_DEBUG #ifdef HPET_DEBUG @@ -39,14 +40,6 @@ static HPETState *hpet_statep; -uint32_t hpet_in_legacy_mode(void) -{ - if (hpet_statep) - return hpet_statep->config & HPET_CFG_LEGACY; - else - return 0; -} - static uint32_t timer_int_route(struct HPETTimer *timer) { uint32_t route; @@ -139,7 +132,7 @@ static void update_irq(struct HPETTimer *timer) qemu_irq irq; int route; - if (timer->tn <= 1 && hpet_in_legacy_mode()) { + if (timer->tn <= 1 && (timer->state->config & HPET_CFG_LEGACY)) { /* if LegacyReplacementRoute bit is set, HPET specification requires * timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC, * timer1 be routed to IRQ8 in NON-APIC or IRQ8 in the I/O APIC. @@ -474,8 +467,10 @@ static void hpet_ram_writel(void *opaque, target_phys_addr_t addr, /* i8254 and RTC are disabled when HPET is in legacy mode */ if (activating_bit(old_val, new_val, HPET_CFG_LEGACY)) { hpet_pit_disable(); + rtc_disable_interrupts = 1; } else if (deactivating_bit(old_val, new_val, HPET_CFG_LEGACY)) { hpet_pit_enable(); + rtc_disable_interrupts = 0; } break; case HPET_CFG + 4: diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c index 571c593..61d5980 100644 --- a/hw/mc146818rtc.c +++ b/hw/mc146818rtc.c @@ -94,6 +94,9 @@ typedef struct RTCState { QEMUTimer *second_timer2; } RTCState; + +int rtc_disable_interrupts = 0; + static void rtc_irq_raise(qemu_irq irq) { /* When HPET is operating in legacy mode, RTC interrupts are disabled @@ -101,9 +104,7 @@ static void rtc_irq_raise(qemu_irq irq) * mode is established while interrupt is raised. We want it to * be lowered in any case */ -#if defined TARGET_I386 - if (!hpet_in_legacy_mode()) -#endif + if (!rtc_disable_interrupts) qemu_irq_raise(irq); } @@ -148,14 +149,10 @@ static void rtc_timer_update(RTCState *s, int64_t current_time) int enable_pie; period_code = s->cmos_data[RTC_REG_A] & 0x0f; -#if defined TARGET_I386 /* disable periodic timer if hpet is in legacy mode, since interrupts are * disabled anyway. */ - enable_pie = !hpet_in_legacy_mode(); -#else - enable_pie = 1; -#endif + enable_pie = !rtc_disable_interrupts; if (period_code != 0 && (((s->cmos_data[RTC_REG_B] & REG_B_PIE) && enable_pie) || ((s->cmos_data[RTC_REG_B] & REG_B_SQWE) && s->sqw_irq))) { diff --git a/hw/mc146818rtc.h b/hw/mc146818rtc.h index 6f46a68..ff4bcda 100644 --- a/hw/mc146818rtc.h +++ b/hw/mc146818rtc.h @@ -3,6 +3,7 @@ #include "isa.h" +extern int rtc_disable_interrupts; ISADevice *rtc_init(int base_year); void rtc_set_memory(ISADevice *dev, int addr, int val); void rtc_set_date(ISADevice *dev, const struct tm *tm);