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,
70 CMOS_REG_ACTUAL_EXT_MEMORY_LOW
= 0x30,
71 CMOS_REG_ACTUAL_EXT_MEMORY_HIGH
= 0x31,
73 } CMOS_REGISTERS
, *PCMOS_REGISTERS
;
78 * See the following documentation for more information:
79 * http://www.intel-assembler.it/portale/5/cmos-memory-map-123/cmos-memory-map-123.asp
80 * http://wiki.osdev.org/CMOS
81 * http://www.walshcomptech.com/ohlandl/config/cmos_registers.html
82 * http://www.fysnet.net/cmosinfo.htm
83 * http://www.bioscentral.com/misc/cmosmap.htm
89 BYTE AlarmSecond
; // 0x01
91 BYTE AlarmMinute
; // 0x03
93 BYTE AlarmHour
; // 0x05
94 BYTE DayOfWeek
; // 0x06
99 BYTE StatusRegA
; // 0x0a
100 BYTE StatusRegB
; // 0x0b
101 } CMOS_CLOCK
, *PCMOS_CLOCK
;
109 CMOS_CLOCK
; // 0x00 - 0x0b
110 BYTE StatusRegC
; // 0x0c
111 BYTE StatusRegD
; // 0x0d
112 BYTE Diagnostics
; // 0x0e
113 BYTE ShutdownStatus
; // 0x0f
115 BYTE Regs1
[0x10]; // 0x00 - 0x0f
116 BYTE Regs
[0x40]; // 0x00 - 0x3f
120 * Extended information 0x40 - 0x7f
122 } CMOS_MEMORY
, *PCMOS_MEMORY
;
125 C_ASSERT(sizeof(CMOS_MEMORY
) == 0x40);
127 /* FUNCTIONS ******************************************************************/
129 BOOLEAN
IsNmiEnabled(VOID
);
130 DWORD
RtcGetTicksPerSecond(VOID
);
131 VOID
RtcPeriodicTick(VOID
);
132 VOID
RtcTimeUpdate(VOID
);
134 VOID
CmosInitialize(VOID
);
135 VOID
CmosCleanup(VOID
);