* [PATCH] minios: replace mktime implementation
@ 2009-05-22 13:08 Stefano Stabellini
2009-05-22 18:35 ` Nigel Gamble
0 siblings, 1 reply; 5+ messages in thread
From: Stefano Stabellini @ 2009-05-22 13:08 UTC (permalink / raw)
To: xen-devel
Hi all,
in the efforts to clarify MiniOS license it came to my attention that
few portions of MiniOS were taken from other GPL projects, one of them
is the mktime implementation.
This patch replaces the current GPL licensed mktime implementation with a
different and BSD licensed version.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
diff -r 61404d971c92 extras/mini-os/arch/ia64/time.c
--- a/extras/mini-os/arch/ia64/time.c Thu May 21 04:31:47 2009 +0100
+++ b/extras/mini-os/arch/ia64/time.c Fri May 22 14:04:02 2009 +0100
@@ -1,24 +1,7 @@
/*
* Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
* Description: simple ia64 specific time handling
- * mktime() is taken from Linux (see copyright below)
* Parts are taken from FreeBSD.
- *
- ****************************************************************************
- * For the copy of the mktime() from linux.
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************
*
@@ -57,6 +40,49 @@
static uint64_t processor_frequency;
static uint64_t itm_val;
+static int is_leap_year(int year)
+{
+ if( year % 4 == 0 )
+ {
+ if( year % 100 == 0 )
+ {
+ if( year % 400 == 0 ) return 1;
+ else return 0;
+ }
+ return 1;
+ }
+ return 0;
+}
+
+static int count_leap_years(int epoch, int year)
+{
+ int i, result = 0;
+ for( i = epoch ; i < year ; i++ ) if( is_leap_year(i) ) result++;
+ return result;
+}
+
+static int get_day(int year, int mon, int day) {
+ int result;
+ switch(mon)
+ {
+ case 0: result = 0; break;
+ case 1: result = 31; break; /* 1: 31 */
+ case 2: result = 59; break; /* 2: 31+28 */
+ case 3: result = 90; break; /* 3: 59+31 */
+ case 4: result = 120;break; /* 4: 90+30 */
+ case 5: result = 151;break; /* 5: 120+31 */
+ case 6: result = 181;break; /* 6: 151+30 */
+ case 7: result = 212;break; /* 7: 181+31 */
+ case 8: result = 243;break; /* 8: 212+31 */
+ case 9: result = 273;break; /* 9: 243+30 */
+ case 10:result = 304;break; /* 10:273+31 */
+ case 11:result = 334;break; /* 11:304+30 */
+ default: break;
+ }
+ if( is_leap_year(year) && mon > 2 ) result++;
+ result += day - 1;
+ return result;
+}
/*
* mktime() is take from Linux. See copyright above.
@@ -64,38 +90,24 @@
* Assumes input in normal date format, i.e. 1980-12-31 23:59:59
* => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
*
- * [For the Julian calendar (which was used in Russia before 1917,
- * Britain & colonies before 1752, anywhere else before 1582,
- * and is still in use by some communities) leave out the
- * -year/100+year/400 terms, and add 10.]
- *
- * This algorithm was first published by Gauss (I think).
- *
* WARNING: this function will overflow on 2106-02-07 06:28:16 on
* machines were long is 32-bit! (However, as time_t is signed, we
* will already get problems at other places on 2038-01-19 03:14:08)
*/
-static unsigned long
-_mktime(const unsigned int year0, const unsigned int mon0,
- const unsigned int day, const unsigned int hour,
- const unsigned int min, const unsigned int sec)
+static unsigned long _mktime(const unsigned int year, const unsigned int mon,
+ const unsigned int day, const unsigned int hour,
+ const unsigned int min, const unsigned int sec)
{
- unsigned int mon = mon0, year = year0;
+ unsigned long result = 0;
- /* 1..12 -> 11,12,1..10 */
- if (0 >= (int) (mon -= 2)) {
- mon += 12; /* Puts Feb last since it has leap day */
- year -= 1;
- }
+ result = sec;
+ result += min * 60;
+ result += hour * 3600;
+ result += get_day(year, mon - 1, day) * 86400;
+ result += (year - 1970) * 31536000;
+ result += count_leap_years(1970, year) * 86400;
- return (
- (
- ((unsigned long)
- (year/4 - year/100 + year/400 + 367*mon/12 + day) +
- year*365 - 719499
- ) * 24 + hour /* now have hours */
- ) * 60 + min /* now have minutes */
- ) * 60 + sec; /* finally seconds */
+ return result;
}
static inline uint64_t
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] minios: replace mktime implementation
2009-05-22 13:08 [PATCH] minios: replace mktime implementation Stefano Stabellini
@ 2009-05-22 18:35 ` Nigel Gamble
2009-05-26 15:07 ` Stefano Stabellini
0 siblings, 1 reply; 5+ messages in thread
From: Nigel Gamble @ 2009-05-22 18:35 UTC (permalink / raw)
To: Stefano Stabellini; +Cc: xen-devel
You should also take a look at minios/arch/x86/x86_64.S. It is
remarkably similar to linux/arch/x86/kernel/entry_64.S. Some
comments, macros names etc. are identical. It's obvious that both
files share a common ancestor, at least.
I used minios as a starting point to port a proprietary OS from a
proprietary CPU to x86_64 on Xen at my last job, and we became
concerned about whether this file was contaminated with GPL code.
Nigel
On May 22, 2009, at 6:08 AM, Stefano Stabellini wrote:
> Hi all,
> in the efforts to clarify MiniOS license it came to my attention that
> few portions of MiniOS were taken from other GPL projects, one of them
> is the mktime implementation.
> This patch replaces the current GPL licensed mktime implementation
> with a
> different and BSD licensed version.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] minios: replace mktime implementation
2009-05-22 18:35 ` Nigel Gamble
@ 2009-05-26 15:07 ` Stefano Stabellini
2009-05-27 18:21 ` Nigel Gamble
0 siblings, 1 reply; 5+ messages in thread
From: Stefano Stabellini @ 2009-05-26 15:07 UTC (permalink / raw)
To: Nigel Gamble; +Cc: xen-devel
Nigel Gamble wrote:
> You should also take a look at minios/arch/x86/x86_64.S. It is
> remarkably similar to linux/arch/x86/kernel/entry_64.S. Some
> comments, macros names etc. are identical. It's obvious that both
> files share a common ancestor, at least.
>
I checked and going back in time in 2003 entry.S in MiniOS has been
rewritten to be able to license MiniOS under BSD, so we should be fine.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] minios: replace mktime implementation
2009-05-26 15:07 ` Stefano Stabellini
@ 2009-05-27 18:21 ` Nigel Gamble
2009-05-27 19:05 ` Keir Fraser
0 siblings, 1 reply; 5+ messages in thread
From: Nigel Gamble @ 2009-05-27 18:21 UTC (permalink / raw)
To: Stefano Stabellini; +Cc: xen-devel
On May 26, 2009, at 8:07 AM, Stefano Stabellini wrote:
> Nigel Gamble wrote:
>
>> You should also take a look at minios/arch/x86/x86_64.S. It is
>> remarkably similar to linux/arch/x86/kernel/entry_64.S. Some
>> comments, macros names etc. are identical. It's obvious that both
>> files share a common ancestor, at least.
>>
>
> I checked and going back in time in 2003 entry.S in MiniOS has been
> rewritten to be able to license MiniOS under BSD, so we should be
> fine.
Yes, it looks like this is true of x86_32.S, but it looks to me as if
x86_64.S was missed, because it is still clearly derived from Linux,
not BSD.
Nigel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] minios: replace mktime implementation
2009-05-27 18:21 ` Nigel Gamble
@ 2009-05-27 19:05 ` Keir Fraser
0 siblings, 0 replies; 5+ messages in thread
From: Keir Fraser @ 2009-05-27 19:05 UTC (permalink / raw)
To: Nigel Gamble, Stefano Stabellini; +Cc: xen-devel
On 27/05/2009 19:21, "Nigel Gamble" <nigel@nrg.org> wrote:
>> I checked and going back in time in 2003 entry.S in MiniOS has been
>> rewritten to be able to license MiniOS under BSD, so we should be
>> fine.
>
> Yes, it looks like this is true of x86_32.S, but it looks to me as if
> x86_64.S was missed, because it is still clearly derived from Linux,
> not BSD.
Yes, you're quite obviously right. Stefano, we should at least remove all
the commented out Linux code (most of which is CFI_* stack unwinding
directives) and probably expand out many of the macros, most of which are
used only once anyway. Plus rename/reorg where possible in line with
x86_32.S. That's maybe an hour's work at most and I'd be comfortable
claiming copyright on the result, or at least I'm certain it would be as
clean as x86_32.S at that point (Which was never clean-room rewritten).
-- Keir
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-05-27 19:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-22 13:08 [PATCH] minios: replace mktime implementation Stefano Stabellini
2009-05-22 18:35 ` Nigel Gamble
2009-05-26 15:07 ` Stefano Stabellini
2009-05-27 18:21 ` Nigel Gamble
2009-05-27 19:05 ` Keir Fraser
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.