xref: /reactos/subsystems/mvdm/ntvdm/hardware/cmos.h (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * COPYRIGHT:       GPL - See COPYING in the top level directory
3*c2c66affSColin Finck  * PROJECT:         ReactOS Virtual DOS Machine
4*c2c66affSColin Finck  * FILE:            subsystems/mvdm/ntvdm/hardware/cmos.h
5*c2c66affSColin Finck  * PURPOSE:         CMOS Real Time Clock emulation
6*c2c66affSColin Finck  * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7*c2c66affSColin Finck  */
8*c2c66affSColin Finck 
9*c2c66affSColin Finck #ifndef _CMOS_H_
10*c2c66affSColin Finck #define _CMOS_H_
11*c2c66affSColin Finck 
12*c2c66affSColin Finck /* DEFINES ********************************************************************/
13*c2c66affSColin Finck 
14*c2c66affSColin Finck #define RTC_IRQ_NUMBER      8
15*c2c66affSColin Finck #define CMOS_ADDRESS_PORT   0x70
16*c2c66affSColin Finck #define CMOS_DATA_PORT      0x71
17*c2c66affSColin Finck #define CMOS_DISABLE_NMI    (1 << 7)
18*c2c66affSColin Finck #define CMOS_BATTERY_OK     0x80
19*c2c66affSColin Finck 
20*c2c66affSColin Finck /* Status Register B flags */
21*c2c66affSColin Finck #define CMOS_STB_DST            (1 << 0)
22*c2c66affSColin Finck #define CMOS_STB_24HOUR         (1 << 1)
23*c2c66affSColin Finck #define CMOS_STB_BINARY         (1 << 2)
24*c2c66affSColin Finck #define CMOS_STB_SQUARE_WAVE    (1 << 3)
25*c2c66affSColin Finck #define CMOS_STB_INT_ON_UPDATE  (1 << 4)
26*c2c66affSColin Finck #define CMOS_STB_INT_ON_ALARM   (1 << 5)
27*c2c66affSColin Finck #define CMOS_STB_INT_PERIODIC   (1 << 6)
28*c2c66affSColin Finck #define CMOS_STB_UPDATE_CYCLE   (1 << 7)
29*c2c66affSColin Finck 
30*c2c66affSColin Finck /* Status Register C flags */
31*c2c66affSColin Finck #define CMOS_STC_UF     (1 << 4)
32*c2c66affSColin Finck #define CMOS_STC_AF     (1 << 5)
33*c2c66affSColin Finck #define CMOS_STC_PF     (1 << 6)
34*c2c66affSColin Finck #define CMOS_STC_IRQF   (1 << 7)
35*c2c66affSColin Finck 
36*c2c66affSColin Finck /* Default register values */
37*c2c66affSColin Finck #define CMOS_DEFAULT_STA    0x26
38*c2c66affSColin Finck #define CMOS_DEFAULT_STB    CMOS_STB_24HOUR
39*c2c66affSColin Finck 
40*c2c66affSColin Finck // Bit 0: Floppy, Bit 1: FPU, Bit 2: Mouse, Bits 4-5: 80x25 Color Video, Bits 6-7: 2 floppy drives
41*c2c66affSColin Finck #define CMOS_EQUIPMENT_LIST 0x6F
42*c2c66affSColin Finck 
43*c2c66affSColin Finck 
44*c2c66affSColin Finck #define WRITE_CMOS_DATA(Cmos, Value)    \
45*c2c66affSColin Finck     ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)
46*c2c66affSColin Finck 
47*c2c66affSColin Finck #define READ_CMOS_DATA(Cmos, Value)     \
48*c2c66affSColin Finck     ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)
49*c2c66affSColin Finck 
50*c2c66affSColin Finck typedef enum _CMOS_REGISTERS
51*c2c66affSColin Finck {
52*c2c66affSColin Finck     CMOS_REG_SECONDS,
53*c2c66affSColin Finck     CMOS_REG_ALARM_SEC,
54*c2c66affSColin Finck     CMOS_REG_MINUTES,
55*c2c66affSColin Finck     CMOS_REG_ALARM_MIN,
56*c2c66affSColin Finck     CMOS_REG_HOURS,
57*c2c66affSColin Finck     CMOS_REG_ALARM_HRS,
58*c2c66affSColin Finck     CMOS_REG_DAY_OF_WEEK,
59*c2c66affSColin Finck     CMOS_REG_DAY,
60*c2c66affSColin Finck     CMOS_REG_MONTH,
61*c2c66affSColin Finck     CMOS_REG_YEAR,
62*c2c66affSColin Finck     CMOS_REG_STATUS_A,
63*c2c66affSColin Finck     CMOS_REG_STATUS_B,
64*c2c66affSColin Finck     CMOS_REG_STATUS_C,
65*c2c66affSColin Finck     CMOS_REG_STATUS_D,
66*c2c66affSColin Finck     CMOS_REG_DIAGNOSTICS,
67*c2c66affSColin Finck     CMOS_REG_SHUTDOWN_STATUS,
68*c2c66affSColin Finck     CMOS_REG_EQUIPMENT_LIST         = 0x14,
69*c2c66affSColin Finck     CMOS_REG_BASE_MEMORY_LOW        = 0x15,
70*c2c66affSColin Finck     CMOS_REG_BASE_MEMORY_HIGH       = 0x16,
71*c2c66affSColin Finck     CMOS_REG_EXT_MEMORY_LOW         = 0x17,
72*c2c66affSColin Finck     CMOS_REG_EXT_MEMORY_HIGH        = 0x18,
73*c2c66affSColin Finck     CMOS_REG_SYSOP                  = 0x2D,
74*c2c66affSColin Finck     CMOS_REG_ACTUAL_EXT_MEMORY_LOW  = 0x30,
75*c2c66affSColin Finck     CMOS_REG_ACTUAL_EXT_MEMORY_HIGH = 0x31,
76*c2c66affSColin Finck     CMOS_REG_CENTURY                = 0x32,
77*c2c66affSColin Finck     CMOS_REG_MAX                    = 0x40
78*c2c66affSColin Finck } CMOS_REGISTERS, *PCMOS_REGISTERS;
79*c2c66affSColin Finck 
80*c2c66affSColin Finck /*
81*c2c66affSColin Finck  * CMOS Memory Map
82*c2c66affSColin Finck  *
83*c2c66affSColin Finck  * See the following documentation for more information:
84*c2c66affSColin Finck  * http://www.intel-assembler.it/portale/5/cmos-memory-map-123/cmos-memory-map-123.asp
85*c2c66affSColin Finck  * http://wiki.osdev.org/CMOS
86*c2c66affSColin Finck  * http://www.walshcomptech.com/ohlandl/config/cmos_registers.html
87*c2c66affSColin Finck  * http://www.fysnet.net/cmosinfo.htm
88*c2c66affSColin Finck  * http://www.bioscentral.com/misc/cmosmap.htm
89*c2c66affSColin Finck  */
90*c2c66affSColin Finck #pragma pack(push, 1)
91*c2c66affSColin Finck typedef struct
92*c2c66affSColin Finck {
93*c2c66affSColin Finck     BYTE Second;        // 0x00
94*c2c66affSColin Finck     BYTE AlarmSecond;   // 0x01
95*c2c66affSColin Finck     BYTE Minute;        // 0x02
96*c2c66affSColin Finck     BYTE AlarmMinute;   // 0x03
97*c2c66affSColin Finck     BYTE Hour;          // 0x04
98*c2c66affSColin Finck     BYTE AlarmHour;     // 0x05
99*c2c66affSColin Finck     BYTE DayOfWeek;     // 0x06
100*c2c66affSColin Finck     BYTE Day;           // 0x07
101*c2c66affSColin Finck     BYTE Month;         // 0x08
102*c2c66affSColin Finck     BYTE Year;          // 0x09
103*c2c66affSColin Finck 
104*c2c66affSColin Finck     BYTE StatusRegA;    // 0x0a
105*c2c66affSColin Finck     BYTE StatusRegB;    // 0x0b
106*c2c66affSColin Finck } CMOS_CLOCK, *PCMOS_CLOCK;
107*c2c66affSColin Finck 
108*c2c66affSColin Finck typedef struct
109*c2c66affSColin Finck {
110*c2c66affSColin Finck     union
111*c2c66affSColin Finck     {
112*c2c66affSColin Finck         struct
113*c2c66affSColin Finck         {
114*c2c66affSColin Finck             CMOS_CLOCK;                 // 0x00 - 0x0b
115*c2c66affSColin Finck             BYTE StatusRegC;            // 0x0c
116*c2c66affSColin Finck             BYTE StatusRegD;            // 0x0d
117*c2c66affSColin Finck             BYTE Diagnostics;           // 0x0e
118*c2c66affSColin Finck             BYTE ShutdownStatus;        // 0x0f
119*c2c66affSColin Finck             BYTE FloppyDrivesType;      // 0x10
120*c2c66affSColin Finck             BYTE Reserved0;             // 0x11
121*c2c66affSColin Finck             BYTE HardDrivesType;        // 0x12
122*c2c66affSColin Finck             BYTE Reserved1;             // 0x13
123*c2c66affSColin Finck             BYTE EquipmentList;         // 0x14
124*c2c66affSColin Finck             BYTE BaseMemoryLow;         // 0x15
125*c2c66affSColin Finck             BYTE BaseMemoryHigh;        // 0x16
126*c2c66affSColin Finck             BYTE ExtMemoryLow;          // 0x17
127*c2c66affSColin Finck             BYTE ExtMemoryHigh;         // 0x18
128*c2c66affSColin Finck             BYTE ExtHardDrivesType[2];  // 0x19 - 0x1a
129*c2c66affSColin Finck             BYTE Reserved2[0x15];       // 0x1b
130*c2c66affSColin Finck             BYTE ActualExtMemoryLow;    // 0x30
131*c2c66affSColin Finck             BYTE ActualExtMemoryHigh;   // 0x31
132*c2c66affSColin Finck             BYTE Century;               // 0x32
133*c2c66affSColin Finck         };
134*c2c66affSColin Finck         BYTE Regs1[0x10];               // 0x00 - 0x0f
135*c2c66affSColin Finck         BYTE Regs [0x40];               // 0x00 - 0x3f
136*c2c66affSColin Finck     };
137*c2c66affSColin Finck 
138*c2c66affSColin Finck     /*
139*c2c66affSColin Finck      * Extended information 0x40 - 0x7f
140*c2c66affSColin Finck      */
141*c2c66affSColin Finck } CMOS_MEMORY, *PCMOS_MEMORY;
142*c2c66affSColin Finck #pragma pack(pop)
143*c2c66affSColin Finck 
144*c2c66affSColin Finck C_ASSERT(sizeof(CMOS_MEMORY) == 0x40);
145*c2c66affSColin Finck 
146*c2c66affSColin Finck /* FUNCTIONS ******************************************************************/
147*c2c66affSColin Finck 
148*c2c66affSColin Finck BOOLEAN IsNmiEnabled(VOID);
149*c2c66affSColin Finck DWORD RtcGetTicksPerSecond(VOID);
150*c2c66affSColin Finck 
151*c2c66affSColin Finck VOID CmosInitialize(VOID);
152*c2c66affSColin Finck VOID CmosCleanup(VOID);
153*c2c66affSColin Finck 
154*c2c66affSColin Finck #endif /* _CMOS_H_ */
155