ac243ad9b5a8f0b560d894e00f461a3048a1f459
[reactos.git] / reactos / subsystems / mvdm / ntvdm / hardware / 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 /* DEFINES ********************************************************************/
13
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
19
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)
27
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)
33
34 /* Default register values */
35 #define CMOS_DEFAULT_STA 0x26
36 #define CMOS_DEFAULT_STB CMOS_STB_24HOUR
37
38 #define WRITE_CMOS_DATA(Cmos, Value) \
39 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)
40
41 #define READ_CMOS_DATA(Cmos, Value) \
42 ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)
43
44 typedef enum _CMOS_REGISTERS
45 {
46 CMOS_REG_SECONDS,
47 CMOS_REG_ALARM_SEC,
48 CMOS_REG_MINUTES,
49 CMOS_REG_ALARM_MIN,
50 CMOS_REG_HOURS,
51 CMOS_REG_ALARM_HRS,
52 CMOS_REG_DAY_OF_WEEK,
53 CMOS_REG_DAY,
54 CMOS_REG_MONTH,
55 CMOS_REG_YEAR,
56 CMOS_REG_STATUS_A,
57 CMOS_REG_STATUS_B,
58 CMOS_REG_STATUS_C,
59 CMOS_REG_STATUS_D,
60 CMOS_REG_DIAGNOSTICS,
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,
68 CMOS_REG_MAX = 0x40
69 } CMOS_REGISTERS, *PCMOS_REGISTERS;
70
71 /*
72 * CMOS Memory Map
73 *
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
80 */
81 #pragma pack(push, 1)
82 typedef struct
83 {
84 BYTE Second; // 0x00
85 BYTE AlarmSecond; // 0x01
86 BYTE Minute; // 0x02
87 BYTE AlarmMinute; // 0x03
88 BYTE Hour; // 0x04
89 BYTE AlarmHour; // 0x05
90 BYTE DayOfWeek; // 0x06
91 BYTE Day; // 0x07
92 BYTE Month; // 0x08
93 BYTE Year; // 0x09
94
95 BYTE StatusRegA; // 0x0a
96 BYTE StatusRegB; // 0x0b
97 } CMOS_CLOCK, *PCMOS_CLOCK;
98
99 typedef struct
100 {
101 union
102 {
103 struct
104 {
105 CMOS_CLOCK; // 0x00 - 0x0b
106 BYTE StatusRegC; // 0x0c
107 BYTE StatusRegD; // 0x0d
108 BYTE Diagnostics; // 0x0e
109 BYTE ShutdownStatus; // 0x0f
110 };
111 BYTE Regs1[0x10]; // 0x00 - 0x0f
112 BYTE Regs [0x40]; // 0x00 - 0x3f
113 };
114
115 /*
116 * Extended information 0x40 - 0x7f
117 */
118 } CMOS_MEMORY, *PCMOS_MEMORY;
119 #pragma pack(pop)
120
121 C_ASSERT(sizeof(CMOS_MEMORY) == 0x40);
122
123 /* FUNCTIONS ******************************************************************/
124
125 BOOLEAN IsNmiEnabled(VOID);
126 DWORD RtcGetTicksPerSecond(VOID);
127
128 VOID CmosInitialize(VOID);
129 VOID CmosCleanup(VOID);
130
131 #endif // _CMOS_H_
132
133 /* EOF */