Skip to content

Commit 2dd3a0a

Browse files
committed
x86: Use CMOS century register to calculate year correctly
1 parent ac72311 commit 2dd3a0a

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

api/hw/cmos.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace hw
4545
static const reg_t r_day = 0x7;
4646
static const reg_t r_month = 0x8;
4747
static const reg_t r_year = 0x9;
48-
static const reg_t r_cent = 0x48;
48+
//static const reg_t r_cent = 0x48;
4949

5050
// RTC Alarm registers
5151
static const reg_t r_alarm_sec = 0x1;
@@ -164,7 +164,7 @@ namespace hw
164164
};
165165

166166
uint8_t century() { return f.century; }
167-
uint16_t year() { return (f.century + 20) * 100 + f.year; }
167+
uint16_t year() { return f.century * 100 + f.year; }
168168
uint8_t month() { return f.month; }
169169
uint8_t day_of_month() { return f.day_of_month; }
170170
uint8_t day_of_week() { return f.day_of_week; }

src/hw/cmos.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <hw/cmos.hpp>
22
#include <statman>
3+
#include "../platform/x86_pc/acpi.hpp"
34

45
using namespace hw;
56
uint8_t CMOS::reg_b_value = 0;
@@ -18,6 +19,7 @@ void CMOS::init()
1819
CMOS::Time& CMOS::Time::hw_update() {
1920
// We're supposed to check this before every read
2021
while (update_in_progress());
22+
const reg_t r_cent = x86::ACPI::get().cmos_century();
2123

2224
if (CMOS::mode_binary()) {
2325
f.second = get(r_sec);
@@ -36,7 +38,7 @@ CMOS::Time& CMOS::Time::hw_update() {
3638
f.day_of_month = bcd_to_binary(get(r_day));
3739
f.month = bcd_to_binary(get(r_month));
3840
f.year = bcd_to_binary(get(r_year));
39-
f.century = get(r_cent);
41+
f.century = bcd_to_binary(get(r_cent));
4042
}
4143

4244
// Convert to 24-hour clock if necessary
@@ -51,7 +53,7 @@ CMOS::Time& CMOS::Time::hw_update() {
5153
std::string CMOS::Time::to_string(){
5254
std::array<char,20> str;
5355
sprintf(str.data(), "%.2i-%.2i-%iT%.2i:%.2i:%.2iZ",
54-
(f.century + 20) * 100 + f.year,
56+
f.century * 100 + f.year,
5557
f.month,
5658
f.day_of_month,
5759
f.hour, f.minute, f.second);

0 commit comments

Comments
 (0)