* [Qemu-devel] [PATCH] Support epoch of 1980 in RTC emulation for MIPS Magnum
@ 2009-01-11 17:37 Stuart Brady
2009-01-11 17:47 ` M. Warner Losh
0 siblings, 1 reply; 4+ messages in thread
From: Stuart Brady @ 2009-01-11 17:37 UTC (permalink / raw)
To: qemu-devel
On the MIPS Magnum, the time that is held in the RTC's NVRAM should be
relative to midnight on 1980-01-01. This patch adds an extra parameter
to rtc_init(), allowing different epochs to be used. For the Magnum,
1980 is specified, and for all other machines, 2000 is specified.
I've not modified the handling of the century byte, as I'm not entirely
sure what's required. With an epoch of 1980 and a year of 2009, you
could argue that the century byte should hold either 0, 1, 19 or 20.
Signed-off-by: Stuart Brady <stuart.brady@gmail.com>
diff -urpN qemu-old/hw/mc146818rtc.c qemu-new/hw/mc146818rtc.c
--- qemu-old/hw/mc146818rtc.c 2009-01-11 16:35:07.000000000 +0000
+++ qemu-new/hw/mc146818rtc.c 2009-01-11 16:49:22.000000000 +0000
@@ -60,6 +60,7 @@ struct RTCState {
uint8_t cmos_data[128];
uint8_t cmos_index;
struct tm current_tm;
+ int base_year;
qemu_irq irq;
int it_shift;
/* periodic timer */
@@ -217,7 +218,7 @@ static void rtc_set_time(RTCState *s)
tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1;
tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
- tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + 100;
+ tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year - 1900;
}
static void rtc_copy_date(RTCState *s)
@@ -238,7 +239,8 @@ static void rtc_copy_date(RTCState *s)
s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday + 1);
s->cmos_data[RTC_DAY_OF_MONTH] = to_bcd(s, tm->tm_mday);
s->cmos_data[RTC_MONTH] = to_bcd(s, tm->tm_mon + 1);
- s->cmos_data[RTC_YEAR] = to_bcd(s, tm->tm_year % 100);
+ s->cmos_data[RTC_YEAR] = to_bcd(s, (tm->tm_year + 10000 - s->base_year)
+ % 100);
}
/* month is between 0 and 11. */
@@ -473,7 +475,7 @@ static int rtc_load(QEMUFile *f, void *o
return 0;
}
-RTCState *rtc_init(int base, qemu_irq irq)
+RTCState *rtc_init(int base, qemu_irq irq, int base_year)
{
RTCState *s;
@@ -487,6 +489,7 @@ RTCState *rtc_init(int base, qemu_irq ir
s->cmos_data[RTC_REG_C] = 0x00;
s->cmos_data[RTC_REG_D] = 0x80;
+ s->base_year = base_year;
rtc_set_date_from_host(s);
s->periodic_timer = qemu_new_timer(vm_clock,
@@ -578,7 +581,8 @@ static CPUWriteMemoryFunc *rtc_mm_write[
&cmos_mm_writel,
};
-RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq)
+RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
+ int base_year)
{
RTCState *s;
int io_memory;
@@ -593,6 +597,7 @@ RTCState *rtc_mm_init(target_phys_addr_t
s->cmos_data[RTC_REG_C] = 0x00;
s->cmos_data[RTC_REG_D] = 0x80;
+ s->base_year = base_year;
rtc_set_date_from_host(s);
s->periodic_timer = qemu_new_timer(vm_clock,
diff -urpN qemu-old/hw/mips_jazz.c qemu-new/hw/mips_jazz.c
--- qemu-old/hw/mips_jazz.c 2009-01-11 16:34:58.000000000 +0000
+++ qemu-new/hw/mips_jazz.c 2009-01-11 16:15:29.000000000 +0000
@@ -240,7 +240,7 @@ void mips_jazz_init (ram_addr_t ram_size
fdctrl_init(rc4030[1], 0, 1, 0x80003000, fds);
/* Real time clock */
- rtc_init(0x70, i8259[8]);
+ rtc_init(0x70, i8259[8], 1980);
s_rtc = cpu_register_io_memory(0, rtc_read, rtc_write, env);
cpu_register_physical_memory(0x80004000, 0x00001000, s_rtc);
diff -urpN qemu-old/hw/mips_malta.c qemu-new/hw/mips_malta.c
--- qemu-old/hw/mips_malta.c 2009-01-11 16:34:58.000000000 +0000
+++ qemu-new/hw/mips_malta.c 2009-01-11 16:15:29.000000000 +0000
@@ -916,7 +916,7 @@ void mips_malta_init (ram_addr_t ram_siz
/* Super I/O */
i8042_init(i8259[1], i8259[12], 0x60);
- rtc_state = rtc_init(0x70, i8259[8]);
+ rtc_state = rtc_init(0x70, i8259[8], 2000);
if (serial_hds[0])
serial_init(0x3f8, i8259[4], 115200, serial_hds[0]);
if (serial_hds[1])
diff -urpN qemu-old/hw/mips_r4k.c qemu-new/hw/mips_r4k.c
--- qemu-old/hw/mips_r4k.c 2009-01-11 16:34:58.000000000 +0000
+++ qemu-new/hw/mips_r4k.c 2009-01-11 16:15:29.000000000 +0000
@@ -229,7 +229,7 @@ void mips_r4k_init (ram_addr_t ram_size,
/* The PIC is attached to the MIPS CPU INT0 pin */
i8259 = i8259_init(env->irq[2]);
- rtc_state = rtc_init(0x70, i8259[8]);
+ rtc_state = rtc_init(0x70, i8259[8], 2000);
/* Register 64 KB of ISA IO space at 0x14000000 */
isa_mmio_init(0x14000000, 0x00010000);
diff -urpN qemu-old/hw/pc.c qemu-new/hw/pc.c
--- qemu-old/hw/pc.c 2009-01-11 16:34:58.000000000 +0000
+++ qemu-new/hw/pc.c 2009-01-11 16:15:29.000000000 +0000
@@ -966,7 +966,7 @@ static void pc_init1(ram_addr_t ram_size
}
}
- rtc_state = rtc_init(0x70, i8259[8]);
+ rtc_state = rtc_init(0x70, i8259[8], 2000);
qemu_register_boot_set(pc_boot_set, rtc_state);
diff -urpN qemu-old/hw/pc.h qemu-new/hw/pc.h
--- qemu-old/hw/pc.h 2009-01-11 16:34:58.000000000 +0000
+++ qemu-new/hw/pc.h 2009-01-11 16:15:29.000000000 +0000
@@ -81,8 +81,9 @@ void i8042_mm_init(qemu_irq kbd_irq, qem
typedef struct RTCState RTCState;
-RTCState *rtc_init(int base, qemu_irq irq);
-RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq);
+RTCState *rtc_init(int base, qemu_irq irq, int base_year);
+RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
+ int base_year);
void rtc_set_memory(RTCState *s, int addr, int val);
void rtc_set_date(RTCState *s, const struct tm *tm);
void cmos_set_s3_resume(void);
diff -urpN qemu-old/hw/ppc_prep.c qemu-new/hw/ppc_prep.c
--- qemu-old/hw/ppc_prep.c 2009-01-11 16:34:58.000000000 +0000
+++ qemu-new/hw/ppc_prep.c 2009-01-11 16:15:29.000000000 +0000
@@ -664,7 +664,7 @@ static void ppc_prep_init (ram_addr_t ra
vga_ram_size, 0, 0);
// openpic = openpic_init(0x00000000, 0xF0000000, 1);
// pit = pit_init(0x40, i8259[0]);
- rtc_init(0x70, i8259[8]);
+ rtc_init(0x70, i8259[8], 2000);
serial_init(0x3f8, i8259[4], 115200, serial_hds[0]);
nb_nics1 = nb_nics;
--
Stuart Brady
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Support epoch of 1980 in RTC emulation for MIPS Magnum
2009-01-11 17:37 [Qemu-devel] [PATCH] Support epoch of 1980 in RTC emulation for MIPS Magnum Stuart Brady
@ 2009-01-11 17:47 ` M. Warner Losh
2009-01-17 1:39 ` Stuart Brady
0 siblings, 1 reply; 4+ messages in thread
From: M. Warner Losh @ 2009-01-11 17:47 UTC (permalink / raw)
To: qemu-devel, sdbrady
In message: <20090111173701.GA5213@miranda.arrow>
Stuart Brady <sdbrady@ntlworld.com> writes:
: I've not modified the handling of the century byte, as I'm not entirely
: sure what's required. With an epoch of 1980 and a year of 2009, you
: could argue that the century byte should hold either 0, 1, 19 or 20.
What does WinNT/mips expect?
Warner
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Support epoch of 1980 in RTC emulation for MIPS Magnum
2009-01-11 17:47 ` M. Warner Losh
@ 2009-01-17 1:39 ` Stuart Brady
2009-01-17 5:42 ` M. Warner Losh
0 siblings, 1 reply; 4+ messages in thread
From: Stuart Brady @ 2009-01-17 1:39 UTC (permalink / raw)
To: qemu-devel
On Sun, Jan 11, 2009 at 10:47:33AM -0700, M. Warner Losh wrote:
> In message: <20090111173701.GA5213@miranda.arrow>
> Stuart Brady <sdbrady@ntlworld.com> writes:
> : I've not modified the handling of the century byte, as I'm not entirely
> : sure what's required. With an epoch of 1980 and a year of 2009, you
> : could argue that the century byte should hold either 0, 1, 19 or 20.
>
> What does WinNT/mips expect?
I've been informed that WinNT 3.50/MIPS does not read the century byte,
and I expect that other versions do the same, as an epoch of 1980 will
won't break until 2080.
Cheers,
--
Stuart Brady
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Support epoch of 1980 in RTC emulation for MIPS Magnum
2009-01-17 1:39 ` Stuart Brady
@ 2009-01-17 5:42 ` M. Warner Losh
0 siblings, 0 replies; 4+ messages in thread
From: M. Warner Losh @ 2009-01-17 5:42 UTC (permalink / raw)
To: qemu-devel, sdbrady
In message: <20090117013919.GA14281@miranda.arrow>
Stuart Brady <sdbrady@ntlworld.com> writes:
: On Sun, Jan 11, 2009 at 10:47:33AM -0700, M. Warner Losh wrote:
: > In message: <20090111173701.GA5213@miranda.arrow>
: > Stuart Brady <sdbrady@ntlworld.com> writes:
: > : I've not modified the handling of the century byte, as I'm not entirely
: > : sure what's required. With an epoch of 1980 and a year of 2009, you
: > : could argue that the century byte should hold either 0, 1, 19 or 20.
: >
: > What does WinNT/mips expect?
:
: I've been informed that WinNT 3.50/MIPS does not read the century byte,
: and I expect that other versions do the same, as an epoch of 1980 will
: won't break until 2080.
OpenBSD/arc and NetBSD/arc then would be the only other ones that
might care. OpenBSD/arc is hard for me to check on, since it is so
old.
NetBSD/arc uses a common set of routines to read it, so it is a little
hard to trace through. But my quick look shows that there's no
function to read the centry set, so the common code will never read
the centry byte.
Warner
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-01-17 5:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-11 17:37 [Qemu-devel] [PATCH] Support epoch of 1980 in RTC emulation for MIPS Magnum Stuart Brady
2009-01-11 17:47 ` M. Warner Losh
2009-01-17 1:39 ` Stuart Brady
2009-01-17 5:42 ` M. Warner Losh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).