loader: remove shouting from ORB's variable name
[hvf.git] / include / clock.h
blob1625ea7bbc3e798d6ff071618eb7e6f0c5d2857c
1 /*
2 * Copyright (c) 2007-2010 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
23 #ifndef __CLOCK_H
24 #define __CLOCK_H
27 * The TOD hardware adds 1 to the 51st bit every microsecond
28 * The timer hardware subtracts 1 from the 51st bit every microsecond
30 #define CLK_MICROSEC 0x1000UL
31 #define CLK_SEC 0xf4240000ULL
32 #define CLK_MIN 0x3938700000ULL
33 #define CLK_HOUR 0xd693a400000ULL
34 #define CLK_DAY 0x141dd76000000ULL
35 #define CLK_YEAR 0x1cae8c13e000000ULL
36 #define CLK_FOURYEARS 0x72ce4e26e000000ULL
38 struct datetime {
39 short int dy, dm, dd;
40 short int th, tm, ts;
41 u32 tmicro;
44 extern struct datetime *parse_tod(struct datetime *dt, u64 tod);
46 static inline int get_tod(u64 *tod)
48 int cc;
50 asm volatile(
51 #if 0
53 * STCKF was added to the z9, and therefore generates a
54 * operation exception on any pre-z9 hardware.
56 * GNU as doesn't like stckf mnemonic, so let's just invoke
57 * it by hand.
59 ".insn s,0xb27c0000,%0\n"
60 #else
61 "stck %0\n"
62 #endif
63 "ipm %1\n"
64 "srl %1,28\n"
65 : /* output */
66 "=m" (*tod),
67 "=d" (cc)
68 : /* input */
69 : /* clobber */
70 "cc"
73 return cc;
76 static inline int get_parsed_tod(struct datetime *dt)
78 u64 tod;
79 int ret;
81 ret = get_tod(&tod);
82 if (!ret)
83 parse_tod(dt, tod);
85 return ret;
88 static inline int leap_year(int year)
90 return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
93 #endif