hvf: use yacc & re2c to generate a system config parser
[hvf.git] / include / clock.h
blobd4fd4ff81ceef3cfd4ae574050e2314db3ab5c81
1 /*
2 * (C) Copyright 2007-2010 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #ifndef __CLOCK_H
9 #define __CLOCK_H
12 * The TOD hardware adds 1 to the 51st bit every microsecond
13 * The timer hardware subtracts 1 from the 51st bit every microsecond
15 #define CLK_MICROSEC 0x1000UL
16 #define CLK_SEC 0xf4240000ULL
17 #define CLK_MIN 0x3938700000ULL
18 #define CLK_HOUR 0xd693a400000ULL
19 #define CLK_DAY 0x141dd76000000ULL
20 #define CLK_YEAR 0x1cae8c13e000000ULL
21 #define CLK_FOURYEARS 0x72ce4e26e000000ULL
23 struct datetime {
24 short int dy, dm, dd;
25 short int th, tm, ts;
26 u32 tmicro;
29 extern struct datetime *parse_tod(struct datetime *dt, u64 tod);
31 static inline int get_tod(u64 *tod)
33 int cc;
35 asm volatile(
36 #if 0
38 * STCKF was added to the z9, and therefore generates a
39 * operation exception on any pre-z9 hardware.
41 * GNU as doesn't like stckf mnemonic, so let's just invoke
42 * it by hand.
44 ".insn s,0xb27c0000,%0\n"
45 #else
46 "stck %0\n"
47 #endif
48 "ipm %1\n"
49 "srl %1,28\n"
50 : /* output */
51 "=m" (*tod),
52 "=d" (cc)
53 : /* input */
54 : /* clobber */
55 "cc"
58 return cc;
61 static inline int get_parsed_tod(struct datetime *dt)
63 u64 tod;
64 int ret;
66 ret = get_tod(&tod);
67 if (!ret)
68 parse_tod(dt, tod);
70 return ret;
73 static inline int leap_year(int year)
75 return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
78 #endif