diff options
Diffstat (limited to 'src/kernel/idt.c')
-rw-r--r-- | src/kernel/idt.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/kernel/idt.c b/src/kernel/idt.c index 9b3ba96..99284ac 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -2,6 +2,7 @@ #include "window.h" #include "drive.h" #include "panic.h" +#include "cmos.h" #include "pmap.h" #include "task.h" #include "util.h" @@ -141,6 +142,21 @@ uint32_t sc_is_task_running(uint32_t handle) { return tasks[handle - 1].page_directory ? 1 : 0; } +static const uint16_t days_into_four_years_per_month[] = { + 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, + 366, 366+31, 366+59, 366+90, 366+120, 366+151, 366+181, 366+212, 366+243, 366+273, 366+304, 366+334, + 731, 731+31, 731+59, 731+90, 731+120, 731+151, 731+181, 731+212, 731+243, 731+273, 731+304, 731+334, + 1096, 1096+31, 1096+59, 1096+90, 1096+120, 1096+151, 1096+181, 1096+212, 1096+243, 1096+273, 1096+304, 1096+334 +}; + +//gregorian, assumes year is in 2001 to 2099 +uint32_t sc_get_timestamp() { + const struct rtc_time time = get_rtc_time(); + const uint32_t secs_into_month = time.seconds + time.minutes * 60 + time.hours * 3600 + (time.day_of_month - 1) * 86400; + const uint32_t days_to_month_into_four_years = days_into_four_years_per_month[time.month + (time.year % 4) * 12 - 1]; + return secs_into_month + days_to_month_into_four_years * 86400 + (time.year / 4) * (365 * 4 + 1) * 86400; +} + void const *syscall_table[] = { &sc_open_file, &sc_close_file, @@ -166,7 +182,8 @@ void const *syscall_table[] = { &sc_wait_any_ipc_sent, &find_unread_ipc, &sc_wait_ipc_read, - &sc_is_task_running + &sc_is_task_running, + &sc_get_timestamp }; //these aren't really void ()'s, but gcc complains if we take an address of a void, so we give it a type |