2015-09-29 23:55:54 +02:00
|
|
|
/*
|
2015-09-30 19:03:23 +02:00
|
|
|
# in RTC
|
2015-09-29 23:55:54 +02:00
|
|
|
|
2015-09-30 19:03:23 +02:00
|
|
|
Real time clock.
|
|
|
|
|
|
|
|
|
|
Gives wall time with precision of seconds.
|
|
|
|
|
|
|
|
|
|
Uses a separate battery to keep going.
|
2015-09-29 23:55:54 +02:00
|
|
|
|
|
|
|
|
http://stackoverflow.com/questions/1465927/how-can-i-access-system-time-using-nasm
|
2015-09-30 19:03:23 +02:00
|
|
|
|
|
|
|
|
http://wiki.osdev.org/RTC
|
|
|
|
|
|
|
|
|
|
http://wiki.osdev.org/CMOS
|
|
|
|
|
|
|
|
|
|
Kenrel 4.2 usage: https://github.com/torvalds/linux/blob/v4.2/arch/x86/kernel/rtc.c#L121
|
|
|
|
|
|
|
|
|
|
## Milliseconds
|
|
|
|
|
|
|
|
|
|
Not possible. Must use the PIT.
|
|
|
|
|
|
|
|
|
|
## Time zone
|
|
|
|
|
|
|
|
|
|
QEMU uses UTC.
|
2015-09-29 23:55:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
BEGIN
|
|
|
|
|
|
2015-09-30 19:03:23 +02:00
|
|
|
/*
|
|
|
|
|
TODO what do those numbers mean? Where is this all documented?
|
|
|
|
|
*/
|
2015-09-29 23:55:54 +02:00
|
|
|
.equ RTCaddress, 0x70
|
|
|
|
|
.equ RTCdata, 0x71
|
|
|
|
|
|
|
|
|
|
update_in_progress:
|
|
|
|
|
mov $10, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
|
|
|
|
testb $0x80, %al
|
|
|
|
|
jne update_in_progress
|
|
|
|
|
|
|
|
|
|
/* Second. */
|
|
|
|
|
mov $0, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
|
|
|
|
|
|
|
|
|
/* Only print if second changed. */
|
|
|
|
|
cmp %al, %cl
|
|
|
|
|
je update_in_progress
|
|
|
|
|
mov %al, %cl
|
|
|
|
|
|
2015-10-20 21:04:49 +02:00
|
|
|
PRINT_HEX <%al>
|
2015-09-29 23:55:54 +02:00
|
|
|
PUTC($0x20)
|
|
|
|
|
|
|
|
|
|
/* Minute. */
|
|
|
|
|
mov $0x02, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
PRINT_HEX <%al>
|
2015-09-29 23:55:54 +02:00
|
|
|
PUTC($0x20)
|
|
|
|
|
|
|
|
|
|
/* Hour. */
|
|
|
|
|
mov $0x04, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
PRINT_HEX <%al>
|
2015-09-29 23:55:54 +02:00
|
|
|
PUTC($0x20)
|
|
|
|
|
|
|
|
|
|
/* Day. */
|
|
|
|
|
mov $0x07, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
PRINT_HEX <%al>
|
2015-09-29 23:55:54 +02:00
|
|
|
PUTC($0x20)
|
|
|
|
|
|
|
|
|
|
/* Month. */
|
|
|
|
|
mov $0x08, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
PRINT_HEX <%al>
|
2015-09-29 23:55:54 +02:00
|
|
|
PUTC($0x20)
|
|
|
|
|
|
|
|
|
|
/* Year. */
|
|
|
|
|
mov $0x09, %al
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
PRINT_HEX <%al>
|
2015-09-29 23:55:54 +02:00
|
|
|
PRINT_NEWLINE
|
|
|
|
|
|
|
|
|
|
jmp update_in_progress
|