diff --git a/kernel/src/rtc.cpp b/kernel/src/rtc.cpp index bec584d4..2b3abf6c 100644 --- a/kernel/src/rtc.cpp +++ b/kernel/src/rtc.cpp @@ -7,9 +7,14 @@ #include "rtc.hpp" #include "kernel_utils.hpp" +#include "acpi.hpp" +#include "acpica.hpp" +#include "logging.hpp" namespace { +constexpr const size_t FADT2_REVISION_ID = 3; + #define CURRENT_YEAR 2013 #define cmos_address 0x70 #define cmos_data 0x71 @@ -33,6 +38,7 @@ datetime rtc::all_data(){ uint8_t day; uint8_t month; uint8_t year; + uint8_t century = 0x0; uint8_t last_second; uint8_t last_minute; @@ -40,11 +46,14 @@ datetime rtc::all_data(){ uint8_t last_day; uint8_t last_month; uint8_t last_year; + uint8_t last_century; uint8_t registerB; - //TODO When ACPI gets supported, get the address - //of the century register and use it to make - //better year calculation + int century_register = 0x0; + + if (acpi::initialized() && AcpiGbl_FADT.Header.Revision >= FADT2_REVISION_ID && AcpiGbl_FADT.Century){ + century_register = AcpiGbl_FADT.Century; + } while (get_update_in_progress_flag()){}; // Make sure an update isn't in progress @@ -55,6 +64,10 @@ datetime rtc::all_data(){ month = get_RTC_register(0x08); year = get_RTC_register(0x09); + if(century_register){ + century = get_RTC_register(century_register); + } + do { last_second = second; last_minute = minute; @@ -62,6 +75,7 @@ datetime rtc::all_data(){ last_day = day; last_month = month; last_year = year; + last_century = century; while (get_update_in_progress_flag()){}; // Make sure an update isn't in progress @@ -71,8 +85,12 @@ datetime rtc::all_data(){ day = get_RTC_register(0x07); month = get_RTC_register(0x08); year = get_RTC_register(0x09); + + if(century_register){ + century = get_RTC_register(century_register); + } } while( (last_second != second) || (last_minute != minute) || (last_hour != hour) || - (last_day != day) || (last_month != month) || (last_year != year) ); + (last_day != day) || (last_month != month) || (last_year != year) || (last_century != century)); registerB = get_RTC_register(0x0B); @@ -85,6 +103,7 @@ datetime rtc::all_data(){ day = (day & 0x0F) + ((day / 16) * 10); month = (month & 0x0F) + ((month / 16) * 10); year = (year & 0x0F) + ((year / 16) * 10); + century = (century & 0x0F) + ((century / 16) * 10); } // Convert 12 hour clock to 24 hour clock if necessary @@ -95,9 +114,15 @@ datetime rtc::all_data(){ // Calculate the full (4-digit) year - uint16_t full_year = year + (CURRENT_YEAR / 100) * 100; - if(full_year < CURRENT_YEAR){ - full_year += 100; + uint16_t full_year; + + if(century_register){ + full_year = year + century * 100; + } else { + full_year = year + (CURRENT_YEAR / 100) * 100; + if(full_year < CURRENT_YEAR){ + full_year += 100; + } } return {full_year, month, day, hour, minute, second, 0, 0};