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