Skip to content

Commit

Permalink
x86_64: fix in storing unix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Jan 5, 2025
1 parent 9407725 commit 088f2ae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/platform/x86_64/cmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

static lock_t lock = LOCK_INITIAL;
static time_t initialTimestamp = 0;
static uint64_t initialUptime = 0;
static const int daysPerMonth[] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 // common year
};
Expand Down Expand Up @@ -45,7 +46,7 @@ void cmosWrite(uint8_t index, uint8_t value) {

time_t platformTimestamp() {
if(initialTimestamp)
return initialTimestamp + (platformUptime() / PLATFORM_TIMER_FREQUENCY);
return initialTimestamp + ((platformUptime()-initialUptime) / PLATFORM_TIMER_FREQUENCY);

acquireLockBlocking(&lock);

Expand Down Expand Up @@ -96,6 +97,7 @@ time_t platformTimestamp() {
initialTimestamp = sec + (min*60) + (hour*3600) + (yearDay * 86400);
initialTimestamp += ((year-70) * 31536000) + (((year-69)/4) * 86400);
initialTimestamp -= (((year-1)/100) * 86400) + (((year+299)/400) * 86400);
initialUptime = platformUptime();

releaseLock(&lock);
return initialTimestamp;
Expand Down

0 comments on commit 088f2ae

Please sign in to comment.