# HG changeset patch # User John Tsiombikas # Date 1307882721 -10800 # Node ID 710739e33da8cd8d2f829496679f46dca92c9764 # Parent 92297f65aaef532dba5a91e1848bc91dae7be455 - now read_rtc doesn't try to read weekday as it's probably wrong anyway, and doesn't set yearday either - mktime now fixes yearday and weekday - moved init_timer and init_rtc just before enabling the interrupts in main diff -r 92297f65aaef -r 710739e33da8 run --- a/run Sun Jun 12 01:46:53 2011 +0300 +++ b/run Sun Jun 12 15:45:21 2011 +0300 @@ -1,3 +1,3 @@ #!/bin/sh -qemu -kernel kernel.elf +qemu -kernel kernel.elf -soundhw pcspk diff -r 92297f65aaef -r 710739e33da8 src/klibc/time.c --- a/src/klibc/time.c Sun Jun 12 01:46:53 2011 +0300 +++ b/src/klibc/time.c Sun Jun 12 15:45:21 2011 +0300 @@ -9,6 +9,9 @@ #define DAYSEC (24 * HOURSEC) #define YEARDAYS(x) (is_leap_year(x) ? 366 : 365) +/* 1-1-1970 was a thursday */ +#define EPOCH_WDAY 4 + static int is_leap_year(int yr); static int mdays[2][12] = { @@ -53,10 +56,16 @@ int year = 1970; int days = day_of_year(tm->tm_year + 1900, tm->tm_mon, tm->tm_mday - 1); + /* set correct yearday */ + tm->tm_yday = days; + for(i=0; itm_wday = (days + EPOCH_WDAY) % 7; + return (time_t)days * DAYSEC + tm->tm_hour * HOURSEC + tm->tm_min * MINSEC + tm->tm_sec; } @@ -76,7 +85,7 @@ days = *tp / DAYSEC; t = *tp % DAYSEC; - tm->tm_wday = (days + 4) % 7; + tm->tm_wday = (days + EPOCH_WDAY) % 7; while(days >= (yrdays = YEARDAYS(year))) { days -= yrdays; diff -r 92297f65aaef -r 710739e33da8 src/main.c --- a/src/main.c Sun Jun 12 01:46:53 2011 +0300 +++ b/src/main.c Sun Jun 12 15:45:21 2011 +0300 @@ -55,14 +55,15 @@ init_segm(); init_intr(); - init_rtc(); - init_timer(); - /* initialize the physical memory manager */ init_mem(mbinf); /* initialize paging and the virtual memory manager */ init_vm(); + /* initialize the timer and RTC */ + init_timer(); + init_rtc(); + /* initialization complete, enable interrupts */ enable_intr(); diff -r 92297f65aaef -r 710739e33da8 src/rtc.c --- a/src/rtc.c Sun Jun 12 01:46:53 2011 +0300 +++ b/src/rtc.c Sun Jun 12 15:45:21 2011 +0300 @@ -59,7 +59,6 @@ tm->tm_mday = read_reg(REG_DAY); tm->tm_mon = read_reg(REG_MONTH); tm->tm_year = read_reg(REG_YEAR); - tm->tm_wday = read_reg(REG_WEEKDAY); /* in 12hour mode, bit 7 means post-meridiem */ pm = tm->tm_hour & HOUR_PM_BIT; @@ -74,7 +73,6 @@ tm->tm_mday = BCD_TO_BIN(tm->tm_mday); tm->tm_mon = BCD_TO_BIN(tm->tm_mon); tm->tm_year = BCD_TO_BIN(tm->tm_year); - tm->tm_wday = BCD_TO_BIN(tm->tm_wday); } /* make the year an offset from 1900 */ @@ -95,8 +93,6 @@ } tm->tm_mon -= 1; /* we want months to start from 0 */ - tm->tm_wday -= 1; /* we want weekdays to start from 0 */ - tm->tm_yday = day_of_year(tm->tm_year + 1900, tm->tm_mon, tm->tm_mday - 1); } static int read_reg(int reg) diff -r 92297f65aaef -r 710739e33da8 src/rtc.h --- a/src/rtc.h Sun Jun 12 01:46:53 2011 +0300 +++ b/src/rtc.h Sun Jun 12 15:45:21 2011 +0300 @@ -1,6 +1,8 @@ #ifndef _RTC_H_ #define _RTC_H_ +#include + /* the time read from rtc during init */ time_t start_time; diff -r 92297f65aaef -r 710739e33da8 src/timer.c --- a/src/timer.c Sun Jun 12 01:46:53 2011 +0300 +++ b/src/timer.c Sun Jun 12 15:45:21 2011 +0300 @@ -71,9 +71,7 @@ nticks++; if(nticks % TICK_FREQ_HZ == 0) { - /*printf("%lu sec\n", nticks / TICK_FREQ_HZ);*/ time_t t = time(0); - printf("%s", asctime(gmtime(&t))); } }