Move date/time init to the RTC implementation.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2229 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
		
							parent
							
								
									aa328addc0
								
							
						
					
					
						commit
						ea55ffb373
					
				@ -380,6 +380,29 @@ void rtc_set_date(RTCState *s, const struct tm *tm)
 | 
				
			|||||||
    rtc_copy_date(s);
 | 
					    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)
 | 
					static void rtc_save(QEMUFile *f, void *opaque)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    RTCState *s = 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_C] = 0x00;
 | 
				
			||||||
    s->cmos_data[RTC_REG_D] = 0x80;
 | 
					    s->cmos_data[RTC_REG_D] = 0x80;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    rtc_set_date_from_host(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->periodic_timer = qemu_new_timer(vm_clock, 
 | 
					    s->periodic_timer = qemu_new_timer(vm_clock, 
 | 
				
			||||||
                                       rtc_periodic_timer, s);
 | 
					                                       rtc_periodic_timer, s);
 | 
				
			||||||
    s->second_timer = qemu_new_timer(vm_clock, 
 | 
					    s->second_timer = qemu_new_timer(vm_clock, 
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								hw/pc.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								hw/pc.c
									
									
									
									
									
								
							@ -111,14 +111,6 @@ static void pic_irq_request(void *opaque, int level)
 | 
				
			|||||||
/* PC cmos mappings */
 | 
					/* PC cmos mappings */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define REG_EQUIPMENT_BYTE          0x14
 | 
					#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)
 | 
					static int cmos_get_fd_drive_type(int fd0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -167,22 +159,8 @@ static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table
 | 
				
			|||||||
    RTCState *s = rtc_state;
 | 
					    RTCState *s = rtc_state;
 | 
				
			||||||
    int val;
 | 
					    int val;
 | 
				
			||||||
    int fd0, fd1, nb;
 | 
					    int fd0, fd1, nb;
 | 
				
			||||||
    time_t ti;
 | 
					 | 
				
			||||||
    struct tm *tm;
 | 
					 | 
				
			||||||
    int i;
 | 
					    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 */
 | 
					    /* various important CMOS locations needed by PC/Bochs bios */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* memory size */
 | 
					    /* memory size */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user