time: Work around potential issue with day wraparound
This commit is contained in:
parent
f59a1eac0b
commit
08547c0d8f
@ -28,8 +28,10 @@ static uint64_t get_unix_epoch(uint8_t seconds, uint8_t minutes, uint8_t hours,
|
||||
|
||||
#if bios == 1
|
||||
uint64_t time(void) {
|
||||
struct rm_regs r = {0};
|
||||
struct rm_regs r;
|
||||
|
||||
again:
|
||||
r = (struct rm_regs){0};
|
||||
r.eax = 0x0400;
|
||||
rm_int(0x1a, &r, &r);
|
||||
|
||||
@ -38,6 +40,7 @@ uint64_t time(void) {
|
||||
uint16_t year = bcd_to_int( r.ecx & 0x00ff) +
|
||||
/* century */ bcd_to_int((r.ecx & 0xff00) >> 8) * 100;
|
||||
|
||||
r = (struct rm_regs){0};
|
||||
r.eax = 0x0200;
|
||||
rm_int(0x1a, &r, &r);
|
||||
|
||||
@ -45,6 +48,14 @@ uint64_t time(void) {
|
||||
uint8_t minute = bcd_to_int( r.ecx & 0x00ff);
|
||||
uint8_t hour = bcd_to_int((r.ecx & 0xff00) >> 8);
|
||||
|
||||
// Check RTC day wraparound
|
||||
r = (struct rm_regs){0};
|
||||
r.eax = 0x0400;
|
||||
rm_int(0x1a, &r, &r);
|
||||
if (bcd_to_int(r.edx & 0x00ff) != day) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return get_unix_epoch(second, minute, hour, day, month, year);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user