2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
5 * PURPOSE: CMOS Real Time Clock emulation
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
12 /* INCLUDES *******************************************************************/
16 /* DEFINES ********************************************************************/
18 #define RTC_IRQ_NUMBER 8
19 #define CMOS_ADDRESS_PORT 0x70
20 #define CMOS_DATA_PORT 0x71
21 #define CMOS_DISABLE_NMI (1 << 7)
22 #define CMOS_BATTERY_OK 0x80
24 /* Status Register B flags */
25 #define CMOS_STB_24HOUR (1 << 1)
26 #define CMOS_STB_BINARY (1 << 2)
27 #define CMOS_STB_SQUARE_WAVE (1 << 3)
28 #define CMOS_STB_INT_ON_UPDATE (1 << 4)
29 #define CMOS_STB_INT_ON_ALARM (1 << 5)
30 #define CMOS_STB_INT_PERIODIC (1 << 6)
32 /* Status Register C flags */
33 #define CMOS_STC_UF CMOS_STB_INT_ON_UPDATE
34 #define CMOS_STC_AF CMOS_STB_INT_ON_ALARM
35 #define CMOS_STC_PF CMOS_STB_INT_PERIODIC
36 #define CMOS_STC_IRQF (1 << 7)
38 /* Default register values */
39 #define CMOS_DEFAULT_STA 0x26
40 #define CMOS_DEFAULT_STB CMOS_STB_24HOUR
42 #define WRITE_CMOS_DATA(Cmos, Value) \
43 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)
45 #define READ_CMOS_DATA(Cmos, Value) \
46 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)
48 typedef enum _CMOS_REGISTERS
65 CMOS_REG_SHUTDOWN_STATUS
,
66 CMOS_REG_BASE_MEMORY_LOW
= 0x15,
67 CMOS_REG_BASE_MEMORY_HIGH
= 0x16,
68 CMOS_REG_EXT_MEMORY_LOW
= 0x17,
69 CMOS_REG_EXT_MEMORY_HIGH
= 0x18,
71 } CMOS_REGISTERS
, *PCMOS_REGISTERS
;
76 * See the following documentation for more information:
77 * http://www.intel-assembler.it/portale/5/cmos-memory-map-123/cmos-memory-map-123.asp
78 * http://wiki.osdev.org/CMOS
79 * http://www.walshcomptech.com/ohlandl/config/cmos_registers.html
80 * http://www.fysnet.net/cmosinfo.htm
81 * http://www.bioscentral.com/misc/cmosmap.htm
87 BYTE AlarmSecond
; // 0x01
89 BYTE AlarmMinute
; // 0x03
91 BYTE AlarmHour
; // 0x05
92 BYTE DayOfWeek
; // 0x06
97 BYTE StatusRegA
; // 0x0a
98 BYTE StatusRegB
; // 0x0b
99 } CMOS_CLOCK
, *PCMOS_CLOCK
;
107 CMOS_CLOCK
; // 0x00 - 0x0b
108 BYTE StatusRegC
; // 0x0c
109 BYTE StatusRegD
; // 0x0d
110 BYTE Diagnostics
; // 0x0e
111 BYTE ShutdownStatus
; // 0x0f
113 BYTE Regs1
[0x10]; // 0x00 - 0x0f
114 BYTE Regs
[0x40]; // 0x00 - 0x3f
118 * Extended information 0x40 - 0x7f
120 } CMOS_MEMORY
, *PCMOS_MEMORY
;
123 C_ASSERT(sizeof(CMOS_MEMORY
) == 0x40);
125 /* FUNCTIONS ******************************************************************/
127 BOOLEAN
IsNmiEnabled(VOID
);
128 DWORD
RtcGetTicksPerSecond(VOID
);
129 VOID
RtcPeriodicTick(VOID
);
130 VOID
RtcTimeUpdate(VOID
);
132 BOOLEAN
CmosInitialize(VOID
);
133 VOID
CmosCleanup(VOID
);