1 /* qemu-time.c -- stubs so clock can be linked in.
3 * Copyright (c) 2008 Anthony Green
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
18 #include <sys/times.h>
21 /* This is the base address of the mc146818 RTC i/o port. */
22 #define RTC_PORT 0x400
24 #define RTC_SECONDS 0x00
25 #define RTC_SECONDS_ALARM 0x01
26 #define RTC_MINUTES 0x02
27 #define RTC_MINUTES_ALARM 0x03
28 #define RTC_HOURS 0x04
29 #define RTC_HOURS_ALARM 0x05
30 #define RTC_DAY_OF_WEEK 0x06
31 #define RTC_DATE_OF_MONTH 0x07
32 #define RTC_MONTH 0x08
34 #define RTC_CONFIG_A 0x0A
35 #define RTC_CONFIG_B 0x0B
36 #define RTC_CONFIG_C 0x0C
37 #define RTC_CONFIG_D 0x0D
43 _times (struct tms
*buf
)
49 /* Read a value from the RTC port. */
51 rtc_read (unsigned char reg
)
53 *(volatile unsigned char *)(RTC_PORT
) = reg
;
54 return *(volatile unsigned char *)(RTC_PORT
+ 1);
57 /* Write a value to the RTC port. */
59 rtc_write (unsigned char reg
, unsigned char val
)
61 *(volatile unsigned char *)(RTC_PORT
) = reg
;
62 *(volatile unsigned char *)(RTC_PORT
+ 1) = val
;
65 /* Convert BCD to Decimal. */
66 #define BCD2DEC(BYTE) ((((BYTE >> 4) & 0xF) * 10) + (BYTE & 0xF))
69 * time -- return current time in seconds.
77 tm
.tm_sec
= BCD2DEC(rtc_read(RTC_SECONDS
));
78 tm
.tm_min
= BCD2DEC(rtc_read(RTC_MINUTES
));
79 tm
.tm_hour
= BCD2DEC(rtc_read(RTC_HOURS
));
80 tm
.tm_wday
= BCD2DEC(rtc_read(RTC_DAY_OF_WEEK
)) - 1;
81 tm
.tm_mday
= BCD2DEC(rtc_read(RTC_DATE_OF_MONTH
));
82 tm
.tm_mon
= BCD2DEC(rtc_read(RTC_MONTH
)) - 1;
83 tm
.tm_year
= BCD2DEC(rtc_read(RTC_YEAR
)) + 100;
85 /* FIXME. Not really sure how to handle this. */
97 * _gettimeofday -- implement in terms of time, which means we can't
98 * return the microseconds.
101 _gettimeofday (struct timeval
*tv
,
104 struct timezone
*tz
= tzvp
;
107 tz
->tz_minuteswest
= tz
->tz_dsttime
= 0;
110 tv
->tv_sec
= time(0);