2019-07-19 00:00:00 +00:00
|
|
|
|
/* https://github.com/cirosantilli/x86-bare-metal-examples#rct */
|
2018-12-04 09:46:27 +00:00
|
|
|
|
|
2020-05-03 00:02:54 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* Reference: https://wiki.osdev.org/CMOS
|
|
|
|
|
|
Register Contents Range
|
|
|
|
|
|
0x00 Seconds 0–59
|
|
|
|
|
|
0x02 Minutes 0–59
|
|
|
|
|
|
0x04 Hours 0–23 in 24-hour mode,
|
|
|
|
|
|
1–12 in 12-hour mode, highest bit set if pm
|
|
|
|
|
|
0x07 Day of Month 1–31
|
|
|
|
|
|
0x08 Month 1–12
|
|
|
|
|
|
0x09 Year 0–99
|
|
|
|
|
|
|
|
|
|
|
|
0x0A Status Register A
|
|
|
|
|
|
RTC has an "Update in progress" flag (bit 7 of Status Register A).
|
|
|
|
|
|
To read the time and date properly you have to wait until
|
|
|
|
|
|
the "Update in progress" flag goes from "set" to "clear".
|
|
|
|
|
|
*/
|
2015-09-29 23:55:54 +02:00
|
|
|
|
.equ RTCaddress, 0x70
|
|
|
|
|
|
.equ RTCdata, 0x71
|
|
|
|
|
|
|
2015-11-09 12:15:15 +01:00
|
|
|
|
#include "common.h"
|
|
|
|
|
|
BEGIN
|
2015-09-29 23:55:54 +02:00
|
|
|
|
update_in_progress:
|
2020-05-03 00:02:54 +08:00
|
|
|
|
mov $0x0A, %al
|
2015-09-29 23:55:54 +02:00
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
|
in $RTCdata, %al
|
|
|
|
|
|
testb $0x80, %al
|
|
|
|
|
|
jne update_in_progress
|
|
|
|
|
|
|
|
|
|
|
|
/* Second. */
|
2020-05-03 00:02:54 +08:00
|
|
|
|
mov $0x00, %al
|
2015-09-29 23:55:54 +02:00
|
|
|
|
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-10-21 15:55:27 +02:00
|
|
|
|
PUTC
|
2015-09-29 23:55:54 +02:00
|
|
|
|
|
|
|
|
|
|
/* Minute. */
|
|
|
|
|
|
mov $0x02, %al
|
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
|
PRINT_HEX <%al>
|
2015-10-21 15:55:27 +02:00
|
|
|
|
PUTC
|
2015-09-29 23:55:54 +02:00
|
|
|
|
|
|
|
|
|
|
/* Hour. */
|
|
|
|
|
|
mov $0x04, %al
|
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
|
PRINT_HEX <%al>
|
2015-10-21 15:55:27 +02:00
|
|
|
|
PUTC
|
2015-09-29 23:55:54 +02:00
|
|
|
|
|
|
|
|
|
|
/* Day. */
|
|
|
|
|
|
mov $0x07, %al
|
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
|
PRINT_HEX <%al>
|
2015-10-21 15:55:27 +02:00
|
|
|
|
PUTC
|
2015-09-29 23:55:54 +02:00
|
|
|
|
|
|
|
|
|
|
/* Month. */
|
|
|
|
|
|
mov $0x08, %al
|
|
|
|
|
|
out %al, $RTCaddress
|
|
|
|
|
|
in $RTCdata, %al
|
2015-10-20 21:04:49 +02:00
|
|
|
|
PRINT_HEX <%al>
|
2015-10-21 15:55:27 +02:00
|
|
|
|
PUTC
|
2015-09-29 23:55:54 +02:00
|
|
|
|
|
|
|
|
|
|
/* 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
|