- Sync up Mm interface with WinLdr branch (introduce the concept of a memory type...
[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
22 #define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
23
24 VOID
25 PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second)
26 {
27 REGS Regs;
28
29 if (NULL != Year || NULL != Month || NULL != Day)
30 {
31 /* Some BIOSes, such es the 1998/07/25 system ROM
32 * in the Compaq Deskpro EP/SB, leave CF unchanged
33 * if successful, so CF should be cleared before
34 * calling this function. */
35 __asm__ ("clc");
36
37 /* Int 1Ah AH=04h
38 * TIME - GET REAL-TIME CLOCK DATE (AT,XT286,PS)
39 *
40 * AH = 04h
41 * CF clear to avoid bug
42 * Return:
43 * CF clear if successful
44 * CH = century (BCD)
45 * CL = year (BCD)
46 * DH = month (BCD)
47 * DL = day (BCD)
48 * CF set on error
49 */
50 Regs.b.ah = 0x04;
51 Int386(0x1A, &Regs, &Regs);
52
53 if (NULL != Year)
54 {
55 *Year = 100 * BCD_INT(Regs.b.ch) + BCD_INT(Regs.b.cl);
56 }
57 if (NULL != Month)
58 {
59 *Month = BCD_INT(Regs.b.dh);
60 }
61 if (NULL != Day)
62 {
63 *Day = BCD_INT(Regs.b.dl);
64 }
65 }
66
67 if (NULL != Hour || NULL != Minute || NULL != Second)
68 {
69 /* Some BIOSes leave CF unchanged if successful,
70 * so CF should be cleared before calling this function. */
71 __asm__ ("clc");
72
73 /* Int 1Ah AH=02h
74 * TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS)
75 *
76 * AH = 02h
77 * CF clear to avoid bug
78 * Return:
79 * CF clear if successful
80 * CH = hour (BCD)
81 * CL = minutes (BCD)
82 * DH = seconds (BCD)
83 * DL = daylight savings flag (00h standard time, 01h daylight time)
84 * CF set on error (i.e. clock not running or in middle of update)
85 */
86 Regs.b.ah = 0x02;
87 Int386(0x1A, &Regs, &Regs);
88
89 if (NULL != Hour)
90 {
91 *Hour = BCD_INT(Regs.b.ch);
92 }
93 if (NULL != Minute)
94 {
95 *Minute = BCD_INT(Regs.b.cl);
96 }
97 if (NULL != Second)
98 {
99 *Second = BCD_INT(Regs.b.dh);
100 }
101 }
102 }
103
104 /* EOF */