From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Gs5KI-0007eX-MQ for qemu-devel@nongnu.org; Wed, 06 Dec 2006 17:33:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Gs5K6-0007av-63 for qemu-devel@nongnu.org; Wed, 06 Dec 2006 17:33:17 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gs5K6-0007as-0e for qemu-devel@nongnu.org; Wed, 06 Dec 2006 17:33:06 -0500 Received: from [82.232.2.251] (helo=mail.aurel32.net) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Gs5K5-00070q-NR for qemu-devel@nongnu.org; Wed, 06 Dec 2006 17:33:06 -0500 Received: from bode.aurel32.net ([2001:618:400:fc13:214:6cff:fe33:3ae9]) by mail.aurel32.net with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Gs5K0-0004Ny-Gl for qemu-devel@nongnu.org; Wed, 06 Dec 2006 23:33:00 +0100 Received: from aurel32 by bode.aurel32.net with local (Exim 4.63) (envelope-from ) id 1Gs5K0-0003Ag-B6 for qemu-devel@nongnu.org; Wed, 06 Dec 2006 23:33:00 +0100 Date: Wed, 6 Dec 2006 23:33:00 +0100 From: Aurelien Jarno Message-ID: <20061206223258.GA12170@bode.aurel32.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Subject: [Qemu-devel] [PATCH] Move RTC date/time initialisation to hw/mc146818rtc.c Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hello all, This patch moves the initialisation of the RTC date/time from hw/pc.c into hw/mc146818rtc.c, to avoid duplication of code. I guess all platforms using this RTC chip will want to setup at least the date and time. Aurelien Index: hw/mc146818rtc.c =================================================================== RCS file: /sources/qemu/qemu/hw/mc146818rtc.c,v retrieving revision 1.6 diff -u -d -p -r1.6 mc146818rtc.c --- hw/mc146818rtc.c 3 Jun 2004 12:51:19 -0000 1.6 +++ hw/mc146818rtc.c 6 Dec 2006 22:20:44 -0000 @@ -380,6 +380,29 @@ void rtc_set_date(RTCState *s, const str rtc_copy_date(s); } +/* PC cmos mappings */ +#define REG_IBM_CENTURY_BYTE 0x32 +#define REG_IBM_PS2_CENTURY_BYTE 0x37 + +void rtc_set_date_from_host(RTCState *s) +{ + time_t ti; + struct tm *tm; + int val; + + /* set the CMOS date */ + time(&ti); + if (rtc_utc) + tm = gmtime(&ti); + else + tm = localtime(&ti); + rtc_set_date(s, tm); + + val = to_bcd(s, (tm->tm_year / 100) + 19); + rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); + rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); +} + static void rtc_save(QEMUFile *f, void *opaque) { RTCState *s = opaque; @@ -444,6 +467,8 @@ RTCState *rtc_init(int base, int irq) s->cmos_data[RTC_REG_C] = 0x00; s->cmos_data[RTC_REG_D] = 0x80; + rtc_set_date_from_host(s); + s->periodic_timer = qemu_new_timer(vm_clock, rtc_periodic_timer, s); s->second_timer = qemu_new_timer(vm_clock, Index: hw/pc.c =================================================================== RCS file: /sources/qemu/qemu/hw/pc.c,v retrieving revision 1.62 diff -u -d -p -r1.62 pc.c --- hw/pc.c 24 Sep 2006 18:48:00 -0000 1.62 +++ hw/pc.c 6 Dec 2006 22:20:44 -0000 @@ -111,14 +111,6 @@ static void pic_irq_request(void *opaque /* PC cmos mappings */ #define REG_EQUIPMENT_BYTE 0x14 -#define REG_IBM_CENTURY_BYTE 0x32 -#define REG_IBM_PS2_CENTURY_BYTE 0x37 - - -static inline int to_bcd(RTCState *s, int a) -{ - return ((a / 10) << 4) | (a % 10); -} static int cmos_get_fd_drive_type(int fd0) { @@ -171,18 +163,6 @@ static void cmos_init(int ram_size, int struct tm *tm; int i; - /* set the CMOS date */ - time(&ti); - if (rtc_utc) - tm = gmtime(&ti); - else - tm = localtime(&ti); - rtc_set_date(s, tm); - - val = to_bcd(s, (tm->tm_year / 100) + 19); - rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); - rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); - /* various important CMOS locations needed by PC/Bochs bios */ /* memory size */ -- .''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' aurel32@debian.org | aurelien@aurel32.net `- people.debian.org/~aurel32 | www.aurel32.net