diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 3c3baaccfa..ab549710f7 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -63,7 +63,7 @@ typedef struct RTCState { ISADevice parent_obj; MemoryRegion io; - uint8_t cmos_data[128]; + uint8_t cmos_data[256]; uint8_t cmos_index; int32_t base_year; uint64_t base_rtc; @@ -392,8 +392,10 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, { RTCState *s = opaque; - if ((addr & 1) == 0) { + if (addr == 0) { s->cmos_index = data & 0x7f; + } else if (addr == 2) { + s->cmos_index = data; } else { CMOS_DPRINTF("cmos: write index=0x%02x val=0x%02x\n", s->cmos_index, data); @@ -404,10 +406,11 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, s->cmos_data[s->cmos_index] = data; check_update_timer(s); break; - case RTC_IBM_PS2_CENTURY_BYTE: - s->cmos_index = RTC_CENTURY; - /* fall through */ - case RTC_CENTURY: + //case RTC_IBM_PS2_CENTURY_BYTE: + // s->cmos_index = RTC_CENTURY; + // /* fall through */ + //case RTC_CENTURY: + case RTC_XBOX_CENTURY: case RTC_SECONDS: case RTC_MINUTES: case RTC_HOURS: @@ -526,7 +529,8 @@ static void rtc_get_time(RTCState *s, struct tm *tm) tm->tm_mon = rtc_from_bcd(s, s->cmos_data[RTC_MONTH]) - 1; tm->tm_year = rtc_from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year + - rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900; + //rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900; + rtc_from_bcd(s, s->cmos_data[RTC_XBOX_CENTURY]) * 100 - 1900; } static void rtc_set_time(RTCState *s) @@ -561,7 +565,8 @@ static void rtc_set_cmos(RTCState *s, const struct tm *tm) s->cmos_data[RTC_MONTH] = rtc_to_bcd(s, tm->tm_mon + 1); year = tm->tm_year + 1900 - s->base_year; s->cmos_data[RTC_YEAR] = rtc_to_bcd(s, year % 100); - s->cmos_data[RTC_CENTURY] = rtc_to_bcd(s, year / 100); + //s->cmos_data[RTC_CENTURY] = rtc_to_bcd(s, year / 100); + s->cmos_data[RTC_XBOX_CENTURY] = rtc_to_bcd(s, year / 100); } static void rtc_update_time(RTCState *s) @@ -613,10 +618,11 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr, return 0xff; } else { switch(s->cmos_index) { - case RTC_IBM_PS2_CENTURY_BYTE: - s->cmos_index = RTC_CENTURY; - /* fall through */ - case RTC_CENTURY: + //case RTC_IBM_PS2_CENTURY_BYTE: + // s->cmos_index = RTC_CENTURY; + // /* fall through */ + //case RTC_CENTURY: + case RTC_XBOX_CENTURY: case RTC_SECONDS: case RTC_MINUTES: case RTC_HOURS: @@ -676,14 +682,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr, void rtc_set_memory(ISADevice *dev, int addr, int val) { RTCState *s = MC146818_RTC(dev); - if (addr >= 0 && addr <= 127) + if (addr >= 0 && addr < sizeof(s->cmos_data)) s->cmos_data[addr] = val; } int rtc_get_memory(ISADevice *dev, int addr) { RTCState *s = MC146818_RTC(dev); - assert(addr >= 0 && addr <= 127); + assert(addr >= 0 && addr < sizeof(s->cmos_data)); return s->cmos_data[addr]; } @@ -863,7 +869,7 @@ static void rtc_realizefn(DeviceState *dev, Error **errp) s->suspend_notifier.notify = rtc_notify_suspend; qemu_register_suspend_notifier(&s->suspend_notifier); - memory_region_init_io(&s->io, OBJECT(s), &cmos_ops, s, "rtc", 2); + memory_region_init_io(&s->io, OBJECT(s), &cmos_ops, s, "rtc", 4); isa_register_ioport(isadev, &s->io, base); qdev_set_legacy_instance_id(dev, base, 3); diff --git a/hw/xbox/xbox.c b/hw/xbox/xbox.c index 0eae08b59b..1511f8b779 100644 --- a/hw/xbox/xbox.c +++ b/hw/xbox/xbox.c @@ -203,9 +203,17 @@ void xbox_init_common(QEMUMachineInitArgs *args, idebus[0] = qdev_get_child_bus(&ide_dev->qdev, "ide.0"); idebus[1] = qdev_get_child_bus(&ide_dev->qdev, "ide.1"); - - pc_cmos_init(ram_size, 0, boot_device, - NULL, idebus[0], idebus[1], rtc_state); + // xbox bios wants this bit pattern set to mark the data as valid + uint8_t bits = 0x55; + for (i = 0x10; i < 0x70; i++) { + rtc_set_memory(rtc_state, i, bits); + bits = ~bits; + } + bits = 0x55; + for (i = 0x80; i < 0x100; i++) { + rtc_set_memory(rtc_state, i, bits); + bits = ~bits; + } /* smbus devices */ uint8_t *eeprom_buf = g_malloc0(256); @@ -243,6 +251,7 @@ void xbox_init_common(QEMUMachineInitArgs *args, static void xbox_init(QEMUMachineInitArgs *args) { +#if 0 /* Placeholder blank eeprom for xbox 1.0: * Serial number 000000000000 * Mac address 00:00:00:00:00:00 @@ -282,6 +291,42 @@ static void xbox_init(QEMUMachineInitArgs *args) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +#endif + /* bunnie's eeprom */ + const uint8_t eeprom[] = { + 0xe3, 0x1c, 0x5c, 0x23, 0x6a, 0x58, 0x68, 0x37, + 0xb7, 0x12, 0x26, 0x6c, 0x99, 0x11, 0x30, 0xd1, + 0xe2, 0x3e, 0x4d, 0x56, 0xf7, 0x73, 0x2b, 0x73, + 0x85, 0xfe, 0x7f, 0x0a, 0x08, 0xef, 0x15, 0x3c, + 0x77, 0xee, 0x6d, 0x4e, 0x93, 0x2f, 0x28, 0xee, + 0xf8, 0x61, 0xf7, 0x94, 0x17, 0x1f, 0xfc, 0x11, + 0x0b, 0x84, 0x44, 0xed, 0x31, 0x30, 0x35, 0x35, + 0x38, 0x31, 0x31, 0x31, 0x34, 0x30, 0x30, 0x33, + 0x00, 0x50, 0xf2, 0x4f, 0x65, 0x52, 0x00, 0x00, + 0x0a, 0x1e, 0x35, 0x33, 0x71, 0x85, 0x31, 0x4d, + 0x59, 0x12, 0x38, 0x48, 0x1c, 0x91, 0x53, 0x60, + 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x75, 0x61, 0x57, 0xfb, 0x2c, 0x01, 0x00, 0x00, + 0x45, 0x53, 0x54, 0x00, 0x45, 0x44, 0x54, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x05, 0x00, 0x02, 0x04, 0x01, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc4, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; ISABus *isa_bus; xbox_init_common(args, (uint8_t*)eeprom, &isa_bus); diff --git a/include/hw/timer/mc146818rtc_regs.h b/include/hw/timer/mc146818rtc_regs.h index ccdee42b3c..a238a6a8de 100644 --- a/include/hw/timer/mc146818rtc_regs.h +++ b/include/hw/timer/mc146818rtc_regs.h @@ -47,6 +47,7 @@ /* PC cmos mappings */ #define RTC_CENTURY 0x32 #define RTC_IBM_PS2_CENTURY_BYTE 0x37 +#define RTC_XBOX_CENTURY 0x7f #define REG_A_UIP 0x80