Make dev node count correct, since for example Mac Virtual PC BIOS reports slightly...
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / pcrtc.c
1 /* $Id$
2 *
3 * FreeLoader
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "freeldr.h"
21 #include "arch.h"
22 #include "machine.h"
23 #include "machpc.h"
24
25 #define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
26
27 VOID
28 PcRTCGetCurrentDateTime(PU32 Year, PU32 Month, PU32 Day, PU32 Hour, PU32 Minute, PU32 Second)
29 {
30 REGS Regs;
31
32 if (NULL != Year || NULL != Month || NULL != Day)
33 {
34 /* Some BIOSes, such es the 1998/07/25 system ROM
35 * in the Compaq Deskpro EP/SB, leave CF unchanged
36 * if successful, so CF should be cleared before
37 * calling this function. */
38 __asm__ ("clc");
39
40 /* Int 1Ah AH=04h
41 * TIME - GET REAL-TIME CLOCK DATE (AT,XT286,PS)
42 *
43 * AH = 04h
44 * CF clear to avoid bug
45 * Return:
46 * CF clear if successful
47 * CH = century (BCD)
48 * CL = year (BCD)
49 * DH = month (BCD)
50 * DL = day (BCD)
51 * CF set on error
52 */
53 Regs.b.ah = 0x04;
54 Int386(0x1A, &Regs, &Regs);
55
56 if (NULL != Year)
57 {
58 *Year = 100 * BCD_INT(Regs.b.cl) + BCD_INT(Regs.b.ch);
59 }
60 if (NULL != Month)
61 {
62 *Month = BCD_INT(Regs.b.dh);
63 }
64 if (NULL != Day)
65 {
66 *Day = BCD_INT(Regs.b.dl);
67 }
68 }
69
70 if (NULL != Hour || NULL != Minute || NULL != Second)
71 {
72 /* Some BIOSes leave CF unchanged if successful,
73 * so CF should be cleared before calling this function. */
74 __asm__ ("clc");
75
76 /* Int 1Ah AH=02h
77 * TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS)
78 *
79 * AH = 02h
80 * CF clear to avoid bug
81 * Return:
82 * CF clear if successful
83 * CH = hour (BCD)
84 * CL = minutes (BCD)
85 * DH = seconds (BCD)
86 * DL = daylight savings flag (00h standard time, 01h daylight time)
87 * CF set on error (i.e. clock not running or in middle of update)
88 */
89 Regs.b.ah = 0x02;
90 Int386(0x1A, &Regs, &Regs);
91
92 if (NULL != Hour)
93 {
94 *Hour = BCD_INT(Regs.b.ch);
95 }
96 if (NULL != Minute)
97 {
98 *Minute = BCD_INT(Regs.b.cl);
99 }
100 if (NULL != Second)
101 {
102 *Second = BCD_INT(Regs.b.dh);
103 }
104 }
105 }
106
107 /* EOF */