[NTVDM]
[reactos.git] / subsystems / ntvdm / cmos.h
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: cmos.h
5 * PURPOSE: CMOS Real Time Clock emulation
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 */
8
9 #ifndef _CMOS_H_
10 #define _CMOS_H_
11
12 /* INCLUDES *******************************************************************/
13
14 #include "ntvdm.h"
15
16 /* DEFINES ********************************************************************/
17
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
23
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)
31
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)
37
38 /* Default register values */
39 #define CMOS_DEFAULT_STA 0x26
40 #define CMOS_DEFAULT_STB CMOS_STB_24HOUR
41
42 #define WRITE_CMOS_DATA(Cmos, Value) \
43 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)
44
45 #define READ_CMOS_DATA(Cmos, Value) \
46 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)
47
48 typedef enum _CMOS_REGISTERS
49 {
50 CMOS_REG_SECONDS,
51 CMOS_REG_ALARM_SEC,
52 CMOS_REG_MINUTES,
53 CMOS_REG_ALARM_MIN,
54 CMOS_REG_HOURS,
55 CMOS_REG_ALARM_HRS,
56 CMOS_REG_DAY_OF_WEEK,
57 CMOS_REG_DAY,
58 CMOS_REG_MONTH,
59 CMOS_REG_YEAR,
60 CMOS_REG_STATUS_A,
61 CMOS_REG_STATUS_B,
62 CMOS_REG_STATUS_C,
63 CMOS_REG_STATUS_D,
64 CMOS_REG_DIAGNOSTICS,
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_MAX = 0x40
71 } CMOS_REGISTERS, *PCMOS_REGISTERS;
72
73 /*
74 * CMOS Memory Map
75 *
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
82 */
83 #pragma pack(push, 1)
84 typedef struct
85 {
86 BYTE Second; // 0x00
87 BYTE AlarmSecond; // 0x01
88 BYTE Minute; // 0x02
89 BYTE AlarmMinute; // 0x03
90 BYTE Hour; // 0x04
91 BYTE AlarmHour; // 0x05
92 BYTE DayOfWeek; // 0x06
93 BYTE Day; // 0x07
94 BYTE Month; // 0x08
95 BYTE Year; // 0x09
96
97 BYTE StatusRegA; // 0x0a
98 BYTE StatusRegB; // 0x0b
99 } CMOS_CLOCK, *PCMOS_CLOCK;
100
101 typedef struct
102 {
103 union
104 {
105 struct
106 {
107 CMOS_CLOCK; // 0x00 - 0x0b
108 BYTE StatusRegC; // 0x0c
109 BYTE StatusRegD; // 0x0d
110 BYTE Diagnostics; // 0x0e
111 BYTE ShutdownStatus; // 0x0f
112 };
113 BYTE Regs1[0x10]; // 0x00 - 0x0f
114 BYTE Regs [0x40]; // 0x00 - 0x3f
115 };
116
117 /*
118 * Extended information 0x40 - 0x7f
119 */
120 } CMOS_MEMORY, *PCMOS_MEMORY;
121 #pragma pack(pop)
122
123 C_ASSERT(sizeof(CMOS_MEMORY) == 0x40);
124
125 /* FUNCTIONS ******************************************************************/
126
127 BOOLEAN IsNmiEnabled(VOID);
128 DWORD RtcGetTicksPerSecond(VOID);
129 VOID RtcPeriodicTick(VOID);
130 VOID RtcTimeUpdate(VOID);
131
132 BOOLEAN CmosInitialize(VOID);
133 VOID CmosCleanup(VOID);
134
135 #endif // _CMOS_H_
136
137 /* EOF */