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 /* DEFINES ********************************************************************/
14 #define RTC_IRQ_NUMBER 8
15 #define CMOS_ADDRESS_PORT 0x70
16 #define CMOS_DATA_PORT 0x71
17 #define CMOS_DISABLE_NMI (1 << 7)
18 #define CMOS_BATTERY_OK 0x80
20 /* Status Register B flags */
21 #define CMOS_STB_24HOUR (1 << 1)
22 #define CMOS_STB_BINARY (1 << 2)
23 #define CMOS_STB_SQUARE_WAVE (1 << 3)
24 #define CMOS_STB_INT_ON_UPDATE (1 << 4)
25 #define CMOS_STB_INT_ON_ALARM (1 << 5)
26 #define CMOS_STB_INT_PERIODIC (1 << 6)
28 /* Status Register C flags */
29 #define CMOS_STC_UF CMOS_STB_INT_ON_UPDATE
30 #define CMOS_STC_AF CMOS_STB_INT_ON_ALARM
31 #define CMOS_STC_PF CMOS_STB_INT_PERIODIC
32 #define CMOS_STC_IRQF (1 << 7)
34 /* Default register values */
35 #define CMOS_DEFAULT_STA 0x26
36 #define CMOS_DEFAULT_STB CMOS_STB_24HOUR
38 #define WRITE_CMOS_DATA(Cmos, Value) \
39 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)
41 #define READ_CMOS_DATA(Cmos, Value) \
42 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)
44 typedef enum _CMOS_REGISTERS
61 CMOS_REG_SHUTDOWN_STATUS
,
62 CMOS_REG_BASE_MEMORY_LOW
= 0x15,
63 CMOS_REG_BASE_MEMORY_HIGH
= 0x16,
64 CMOS_REG_EXT_MEMORY_LOW
= 0x17,
65 CMOS_REG_EXT_MEMORY_HIGH
= 0x18,
66 CMOS_REG_ACTUAL_EXT_MEMORY_LOW
= 0x30,
67 CMOS_REG_ACTUAL_EXT_MEMORY_HIGH
= 0x31,
69 } CMOS_REGISTERS
, *PCMOS_REGISTERS
;
74 * See the following documentation for more information:
75 * http://www.intel-assembler.it/portale/5/cmos-memory-map-123/cmos-memory-map-123.asp
76 * http://wiki.osdev.org/CMOS
77 * http://www.walshcomptech.com/ohlandl/config/cmos_registers.html
78 * http://www.fysnet.net/cmosinfo.htm
79 * http://www.bioscentral.com/misc/cmosmap.htm
85 BYTE AlarmSecond
; // 0x01
87 BYTE AlarmMinute
; // 0x03
89 BYTE AlarmHour
; // 0x05
90 BYTE DayOfWeek
; // 0x06
95 BYTE StatusRegA
; // 0x0a
96 BYTE StatusRegB
; // 0x0b
97 } CMOS_CLOCK
, *PCMOS_CLOCK
;
105 CMOS_CLOCK
; // 0x00 - 0x0b
106 BYTE StatusRegC
; // 0x0c
107 BYTE StatusRegD
; // 0x0d
108 BYTE Diagnostics
; // 0x0e
109 BYTE ShutdownStatus
; // 0x0f
111 BYTE Regs1
[0x10]; // 0x00 - 0x0f
112 BYTE Regs
[0x40]; // 0x00 - 0x3f
116 * Extended information 0x40 - 0x7f
118 } CMOS_MEMORY
, *PCMOS_MEMORY
;
121 C_ASSERT(sizeof(CMOS_MEMORY
) == 0x40);
123 /* FUNCTIONS ******************************************************************/
125 BOOLEAN
IsNmiEnabled(VOID
);
126 DWORD
RtcGetTicksPerSecond(VOID
);
128 VOID
CmosInitialize(VOID
);
129 VOID
CmosCleanup(VOID
);